index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div class="auxiliary-knowledge-lexicon-container layout-pd">
  3. <el-card shadow="never">
  4. <el-form :model="state.queryParams" ref="ruleFormRef" inline @submit.native.prevent>
  5. <el-form-item label="关键词" prop="Tag">
  6. <el-input v-model="state.queryParams.Tag" placeholder="请输入关键词" clearable @keyup.enter="handleQuery" class="keyword-input" />
  7. </el-form-item>
  8. <el-form-item label="分类" prop="Classify">
  9. <el-select v-model="state.queryParams.Classify" placeholder="请选择分类" @change="handleQuery">
  10. <el-option v-for="item in knowledgeWordClassify" :value="item.dicDataValue" :key="item.dicDataValue" :label="item.dicDataName" />
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item label="近义词" prop="Synonym">
  14. <el-input v-model="state.queryParams.Synonym" placeholder="请输入近义词" clearable @keyup.enter="handleQuery" />
  15. </el-form-item>
  16. <el-form-item>
  17. <el-button type="primary" @click="handleQuery" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
  18. <el-button @click="resetQuery(ruleFormRef)" class="default-button"> <SvgIcon name="ele-Refresh" class="mr5" />重置 </el-button>
  19. </el-form-item>
  20. </el-form>
  21. </el-card>
  22. <el-card shadow="never">
  23. <ProTable
  24. ref="proTableRef"
  25. :columns="columns"
  26. :data="state.tableData"
  27. @updateTable="queryList"
  28. :loading="state.loading"
  29. :total="state.total"
  30. v-model:page-index="state.queryParams.PageIndex"
  31. v-model:page-size="state.queryParams.PageSize"
  32. >
  33. <!-- 表格 header 按钮 -->
  34. <template #tableHeader="scope">
  35. <el-button type="primary" @click="addParameter" v-auth="'auxiliary:knowledgeLexicon:add'">
  36. <SvgIcon name="ele-Plus" class="mr5" />新增
  37. </el-button>
  38. <el-button type="primary" @click="businessTagRemove" v-auth="'auxiliary:knowledgeLexicon:delete'" :disabled="!scope.isSelected">
  39. <SvgIcon name="ele-Delete" class="mr5" />删除
  40. </el-button>
  41. </template>
  42. <!-- 表格操作 -->
  43. <template #operation="{ row }">
  44. <el-button link type="primary" @click="updateLexicon(row)" v-auth="'auxiliary:knowledgeLexicon:edit'" title="编辑知识库词库">
  45. 编辑
  46. </el-button>
  47. </template>
  48. </ProTable>
  49. </el-card>
  50. <!-- 新增知识库词库 -->
  51. <knowledge-lexicon-add ref="knowledgeLexiconAddRef" @updateList="queryList" :knowledgeWordClassify="knowledgeWordClassify" />
  52. <!-- 编辑知识库词库 -->
  53. <knowledge-lexicon-edit ref="knowledgeLexiconEditRef" @updateList="queryList" :knowledgeWordClassify="knowledgeWordClassify" />
  54. </div>
  55. </template>
  56. <script lang="tsx" setup name="auxiliaryKnowledgeLexicon">
  57. import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
  58. import { ElButton, ElMessage, ElMessageBox, FormInstance } from 'element-plus';
  59. import { formatDate } from '@/utils/formatTime';
  60. import { knowledgeLexiconDelete, knowledgeLexiconList, orderKnowledgeBaseData } from '@/api/auxiliary/knowledgeLexicon';
  61. // 引入组件
  62. const KnowledgeLexiconAdd = defineAsyncComponent(() => import('@/views/auxiliary/knowledgeLexicon/components/Knowledge-lexicon-add.vue')); // 新增知识库词库
  63. const KnowledgeLexiconEdit = defineAsyncComponent(() => import('@/views/auxiliary/knowledgeLexicon/components/Knowledge-lexicon-edit.vue')); // 编辑知识库词库
  64. const proTableRef = ref<RefType>(); // 表格ref
  65. // 表格配置项
  66. const columns = ref<any[]>([
  67. { type: 'selection', fixed: 'left', width: 55 },
  68. { prop: 'classify', label: '词性分类', showOverflowTooltip: true },
  69. { prop: 'tag', label: '关键词', width: 130 },
  70. { prop: 'synonym', label: '同义词', width: 130 },
  71. {
  72. prop: 'isEnable',
  73. label: '是否启用',
  74. render: (scope: any) => {
  75. return scope.row.isEnable === 1 ? '启用' : '禁用';
  76. },
  77. },
  78. { prop: 'creatorName', label: '创建人', showOverflowTooltip: true },
  79. {
  80. prop: 'creationTime',
  81. label: '创建时间',
  82. width: 170,
  83. render: (scope: any) => {
  84. return formatDate(scope.row.creationTime, 'YYYY-mm-dd HH:MM:SS');
  85. },
  86. },
  87. { prop: 'lastModificationName', label: '更新人', showOverflowTooltip: true },
  88. {
  89. prop: 'lastModificationTime',
  90. label: '更新时间',
  91. width: 170,
  92. render: (scope: any) => {
  93. return formatDate(scope.row.lastModificationTime, 'YYYY-mm-dd HH:MM:SS');
  94. },
  95. },
  96. { prop: 'operation', label: '操作', fixed: 'right', width: 100, align: 'center' },
  97. ]);
  98. // 定义变量内容
  99. const state = reactive<any>({
  100. loading: false, // 加载状态
  101. queryParams: {
  102. // 查询参数
  103. PageIndex: 1,
  104. PageSize: 10,
  105. Tag: null, // 标签
  106. Classify: null, // 标签类型
  107. Synonym: null, // 近义词
  108. },
  109. total: 0, // 总条数
  110. tableData: [], // 表格数据
  111. });
  112. const ruleFormRef = ref<any>(null); // 表单ref
  113. const knowledgeWordClassify = ref<EmptyArrayType>(); // 标签类型
  114. // 获取基础数据
  115. const getBaseData = async () => {
  116. try {
  117. const res = await orderKnowledgeBaseData();
  118. knowledgeWordClassify.value = res.result?.knowledgeWordClassify ?? [];
  119. } catch (error) {
  120. console.log(error);
  121. }
  122. };
  123. /** 搜索按钮操作 */
  124. const handleQuery = () => {
  125. state.queryParams.PageIndex = 1;
  126. queryList();
  127. };
  128. // 获取列表
  129. const queryList = () => {
  130. state.loading = true;
  131. knowledgeLexiconList(state.queryParams)
  132. .then((res) => {
  133. state.loading = false;
  134. state.tableData = res.result.items ?? [];
  135. state.total = res.result.total ?? 0;
  136. })
  137. .finally(() => {
  138. state.loading = false;
  139. });
  140. };
  141. // 重置表单
  142. const resetQuery = (formEl: FormInstance | undefined) => {
  143. if (!formEl) return;
  144. formEl.resetFields();
  145. queryList();
  146. };
  147. // 新增词库
  148. const knowledgeLexiconAddRef = ref<RefType>();
  149. const addParameter = () => {
  150. knowledgeLexiconAddRef.value.openDialog();
  151. };
  152. // 编辑知识库词库
  153. const knowledgeLexiconEditRef = ref<RefType>();
  154. const updateLexicon = (row: any) => {
  155. knowledgeLexiconEditRef.value.openDialog(row.id);
  156. };
  157. // 删除词库
  158. const businessTagRemove = () => {
  159. const ids = proTableRef.value.selectedList.map((item: any) => item.id);
  160. const names = proTableRef.value.selectedList.map((item: any) => item.tag);
  161. ElMessageBox.confirm(`您确定要删除:【${names}】,是否继续?`, '提示', {
  162. confirmButtonText: '确认',
  163. cancelButtonText: '取消',
  164. type: 'warning',
  165. draggable: true,
  166. cancelButtonClass: 'default-button',
  167. autofocus: false,
  168. })
  169. .then(() => {
  170. knowledgeLexiconDelete({ ids }).then(() => {
  171. ElMessage.success('操作成功');
  172. queryList();
  173. });
  174. })
  175. .catch(() => {});
  176. };
  177. // 页面加载时
  178. onMounted(() => {
  179. getBaseData();
  180. queryList();
  181. });
  182. </script>