|
|
@@ -3,52 +3,75 @@ import { onMounted, ref } from "vue";
|
|
|
import PageHeader from '@/components/PageHeader.vue';
|
|
|
import type { ReportTemplateSave } from '@/types/report.types';
|
|
|
import ReportTemplateQueryBox from "./components/ReportTemplateQueryBox.vue"
|
|
|
+import type { FieldType } from "./components/ReportTemplateQueryBox.vue"
|
|
|
import * as reportTemplateService from "@/services/reportTemplate.service"
|
|
|
import { CompLog } from "@/helpers/log.helper";
|
|
|
import SpinComponent from "@/components/SpinComponent.vue";
|
|
|
import { message } from "ant-design-vue";
|
|
|
|
|
|
+// 报告模板总数
|
|
|
const total = ref(0);
|
|
|
+// 报告模板列表
|
|
|
const templates = ref<ReportTemplateSave[]>([])
|
|
|
+// 加载列表的状态
|
|
|
const loading = ref(false)
|
|
|
+// 当前所在页数
|
|
|
+const currentPage = ref(1)
|
|
|
+// 查询字段
|
|
|
+const field = ref<FieldType>('title')
|
|
|
+// 查询关键词
|
|
|
+const keyword = ref('')
|
|
|
+
|
|
|
+function fetchTemplates(field?: string, keyword?: string, page?: number) {
|
|
|
+ loading.value = true
|
|
|
+ reportTemplateService.list(field, keyword, page).then((resp) => {
|
|
|
+ total.value = resp.total;
|
|
|
+ templates.value = resp.items;
|
|
|
+ loading.value = false
|
|
|
+ }).catch((err) => {
|
|
|
+ loading.value = false
|
|
|
+ CompLog.logErr(err)
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
function onQuery(queryData: { field: string, keyword: string }) {
|
|
|
- console.log(queryData);
|
|
|
+ fetchTemplates(queryData.field, queryData.keyword)
|
|
|
+}
|
|
|
+
|
|
|
+function onPaginationChange(page: number) {
|
|
|
+ fetchTemplates(field.value, keyword.value, page)
|
|
|
}
|
|
|
|
|
|
function onDelete(index: number) {
|
|
|
const template = templates.value[index];
|
|
|
- console.log('delete template', template);
|
|
|
if (template.id) {
|
|
|
- reportTemplateService.remove(template.id)
|
|
|
+ reportTemplateService.remove(template.id).then((deleted) => {
|
|
|
+ if (deleted) {
|
|
|
+ fetchTemplates()
|
|
|
+ } else {
|
|
|
+ CompLog.logErr('删除报告失败:' + template.id)
|
|
|
+ }
|
|
|
+ })
|
|
|
} else {
|
|
|
message.warning("模板ID为空,无法为您删除模板 " + template.name)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
|
- loading.value = true
|
|
|
- reportTemplateService.list().then((resp) => {
|
|
|
- total.value = resp.total;
|
|
|
- templates.value = resp.items;
|
|
|
- loading.value = false
|
|
|
- }).catch((err) => {
|
|
|
- loading.value = false
|
|
|
- CompLog.logErr(err)
|
|
|
- })
|
|
|
+ fetchTemplates();
|
|
|
});
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
<PageHeader title="报告模板管理" />
|
|
|
<div class="query-box-wrap">
|
|
|
- <ReportTemplateQueryBox @search="onQuery" />
|
|
|
+ <ReportTemplateQueryBox v-model:field="field" v-model:keyword="keyword" @search="onQuery" />
|
|
|
</div>
|
|
|
<div class="templates-wrap">
|
|
|
<SpinComponent :spinning="loading">
|
|
|
<a-card v-for="(item, index) in templates" :key="index" :title="item.name" class="template-item">
|
|
|
<template #extra>
|
|
|
- <a-button type="link">使用模板撰写报告</a-button>
|
|
|
+ <a-button type="link">使用模板创建报告</a-button>
|
|
|
<a-popconfirm
|
|
|
:title="'确定删模板 ' + item.name"
|
|
|
ok-text="确定"
|
|
|
@@ -68,6 +91,9 @@ onMounted(() => {
|
|
|
</a-card>
|
|
|
</SpinComponent>
|
|
|
</div>
|
|
|
+ <div class="pagination-wrap">
|
|
|
+ <a-pagination v-model:current="currentPage" :total="total" @change="onPaginationChange" />
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
@@ -80,11 +106,16 @@ onMounted(() => {
|
|
|
margin-top: 2em;
|
|
|
|
|
|
.template-item {
|
|
|
- margin-top: 2em;
|
|
|
+ margin-top: 1em;
|
|
|
|
|
|
&:first-child {
|
|
|
margin-top: 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+.pagination-wrap {
|
|
|
+ margin-top: 1em;
|
|
|
+ text-align: right;
|
|
|
+}
|
|
|
</style>
|