Commit 5da9ae25fe49a7c19dc33fb9cd6a523e64a3046e

Authored by xingyu4j
1 parent 407ac853

feat: sensitiveword

yudao-ui-admin-vue3/src/api/system/sensitiveWord/index.ts
1 import request from '@/config/axios' 1 import request from '@/config/axios'
2 -import type { SensitiveWordVO } from './types' 2 +
  3 +export type SensitiveWordVO = {
  4 + id: number
  5 + name: string
  6 + status: number
  7 + description: string
  8 + tags: string
  9 + type: number
  10 + createTime: string
  11 +}
  12 +
  13 +export interface SensitiveWordPageReqVO extends PageParam {
  14 + name?: string
  15 + status?: number
  16 +}
  17 +
  18 +export interface SensitiveWordExportReqVO {
  19 + name?: string
  20 + status?: number
  21 +}
3 22
4 // 查询敏感词列表 23 // 查询敏感词列表
5 -export const getSensitiveWordPageApi = (params) => { 24 +export const getSensitiveWordPageApi = (params: SensitiveWordPageReqVO) => {
6 return request.get({ url: '/system/sensitive-word/page', params }) 25 return request.get({ url: '/system/sensitive-word/page', params })
7 } 26 }
8 27
@@ -27,7 +46,7 @@ export const deleteSensitiveWordApi = (id: number) => { @@ -27,7 +46,7 @@ export const deleteSensitiveWordApi = (id: number) => {
27 } 46 }
28 47
29 // 导出敏感词 48 // 导出敏感词
30 -export const exportSensitiveWordApi = (params) => { 49 +export const exportSensitiveWordApi = (params: SensitiveWordExportReqVO) => {
31 return request.download({ url: '/system/sensitive-word/export-excel', params }) 50 return request.download({ url: '/system/sensitive-word/export-excel', params })
32 } 51 }
33 52
yudao-ui-admin-vue3/src/api/system/sensitiveWord/types.ts deleted
1 -export type SensitiveWordVO = {  
2 - id: number  
3 - name: string  
4 - status: number  
5 - description: string  
6 - tags: string  
7 - type: number  
8 - createTime: string  
9 -}  
yudao-ui-admin-vue3/src/views/system/sensitiveWord/index.vue
1 <template> 1 <template>
2 - <!-- 搜索工作区 -->  
3 <ContentWrap> 2 <ContentWrap>
4 - <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />  
5 - </ContentWrap>  
6 - <ContentWrap>  
7 - <!-- 操作工具栏 -->  
8 - <div class="mb-10px">  
9 - <XButton  
10 - type="primary"  
11 - preIcon="ep:zoom-in"  
12 - :title="t('action.add')"  
13 - v-hasPermi="['system:sensitive-word:create']"  
14 - @click="handleCreate()"  
15 - />  
16 - <XButton  
17 - type="warning"  
18 - preIcon="ep:download"  
19 - :title="t('action.export')"  
20 - v-hasPermi="['system:sensitive-word:export']"  
21 - @click="exportList('敏感词数据.xls')"  
22 - />  
23 - </div>  
24 <!-- 列表 --> 3 <!-- 列表 -->
25 - <Table  
26 - :columns="allSchemas.tableColumns"  
27 - :selection="false"  
28 - :data="tableObject.tableList"  
29 - :loading="tableObject.loading"  
30 - :pagination="{  
31 - total: tableObject.total  
32 - }"  
33 - v-model:pageSize="tableObject.pageSize"  
34 - v-model:currentPage="tableObject.currentPage"  
35 - @register="register"  
36 - >  
37 - <template #tags="{ row }"> 4 + <vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
  5 + <template #toolbar_buttons>
  6 + <XButton
  7 + type="primary"
  8 + preIcon="ep:zoom-in"
  9 + :title="t('action.add')"
  10 + v-hasPermi="['system:sensitive-word:create']"
  11 + @click="handleCreate()"
  12 + />
  13 + <XButton
  14 + type="warning"
  15 + preIcon="ep:download"
  16 + :title="t('action.export')"
  17 + v-hasPermi="['system:sensitive-word:export']"
  18 + @click="handleExport()"
  19 + />
  20 + </template>
  21 + <template #tags_default="{ row }">
38 <el-tag 22 <el-tag
39 :disable-transitions="true" 23 :disable-transitions="true"
40 :key="index" 24 :key="index"
@@ -44,13 +28,7 @@ @@ -44,13 +28,7 @@
44 {{ tag }} 28 {{ tag }}
45 </el-tag> 29 </el-tag>
46 </template> 30 </template>
47 - <template #status="{ row }">  
48 - <DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />  
49 - </template>  
50 - <template #createTime="{ row }">  
51 - <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>  
52 - </template>  
53 - <template #action="{ row }"> 31 + <template #actionbtns_default="{ row }">
54 <!-- 操作:修改 --> 32 <!-- 操作:修改 -->
55 <XTextButton 33 <XTextButton
56 preIcon="ep:edit" 34 preIcon="ep:edit"
@@ -63,17 +41,17 @@ @@ -63,17 +41,17 @@
63 preIcon="ep:view" 41 preIcon="ep:view"
64 :title="t('action.detail')" 42 :title="t('action.detail')"
65 v-hasPermi="['system:sensitive-word:update']" 43 v-hasPermi="['system:sensitive-word:update']"
66 - @click="handleDetail(row)" 44 + @click="handleDetail(row.id)"
67 /> 45 />
68 <!-- 操作:删除 --> 46 <!-- 操作:删除 -->
69 <XTextButton 47 <XTextButton
70 preIcon="ep:delete" 48 preIcon="ep:delete"
71 :title="t('action.del')" 49 :title="t('action.del')"
72 v-hasPermi="['system:sensitive-word:delete']" 50 v-hasPermi="['system:sensitive-word:delete']"
73 - @click="delList(row.id, false)" 51 + @click="handleDelete(row.id)"
74 /> 52 />
75 </template> 53 </template>
76 - </Table> 54 + </vxe-grid>
77 </ContentWrap> 55 </ContentWrap>
78 56
79 <XModal v-model="dialogVisible" :title="dialogTitle"> 57 <XModal v-model="dialogVisible" :title="dialogTitle">
@@ -94,7 +72,7 @@ @@ -94,7 +72,7 @@
94 <Descriptions 72 <Descriptions
95 v-if="actionType === 'detail'" 73 v-if="actionType === 'detail'"
96 :schema="allSchemas.detailSchema" 74 :schema="allSchemas.detailSchema"
97 - :data="detailRef" 75 + :data="detailData"
98 /> 76 />
99 <!-- 操作按钮 --> 77 <!-- 操作按钮 -->
100 <template #footer> 78 <template #footer>
@@ -113,24 +91,33 @@ @@ -113,24 +91,33 @@
113 </template> 91 </template>
114 <script setup lang="ts"> 92 <script setup lang="ts">
115 import { onMounted, ref, unref } from 'vue' 93 import { onMounted, ref, unref } from 'vue'
116 -import dayjs from 'dayjs'  
117 -import { ElMessage, ElTag, ElSelect, ElOption } from 'element-plus'  
118 -import { DICT_TYPE } from '@/utils/dict'  
119 -import { useTable } from '@/hooks/web/useTable'  
120 import { useI18n } from '@/hooks/web/useI18n' 94 import { useI18n } from '@/hooks/web/useI18n'
  95 +import { useMessage } from '@/hooks/web/useMessage'
  96 +import { useVxeGrid } from '@/hooks/web/useVxeGrid'
  97 +import { VxeGridInstance } from 'vxe-table'
121 import { FormExpose } from '@/components/Form' 98 import { FormExpose } from '@/components/Form'
122 -import type { SensitiveWordVO } from '@/api/system/sensitiveWord/types'  
123 -import { rules, allSchemas } from './sensitiveWord.data' 99 +import { ElTag, ElSelect, ElOption } from 'element-plus'
124 import * as SensitiveWordApi from '@/api/system/sensitiveWord' 100 import * as SensitiveWordApi from '@/api/system/sensitiveWord'
125 -const { t } = useI18n() // 国际化 101 +import { rules, allSchemas } from './sensitiveWord.data'
126 102
127 -// ========== 列表相关 ==========  
128 -const { register, tableObject, methods } = useTable<SensitiveWordVO>({  
129 - getListApi: SensitiveWordApi.getSensitiveWordPageApi,  
130 - delListApi: SensitiveWordApi.deleteSensitiveWordApi,  
131 - exportListApi: SensitiveWordApi.exportSensitiveWordApi  
132 -})  
133 -const { getList, setSearchParams, delList, exportList } = methods 103 +const { t } = useI18n() // 国际化
  104 +const message = useMessage() // 消息弹窗
  105 +// 列表相关的变量
  106 +const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
  107 +const { gridOptions, getList, deleteData, exportList } =
  108 + useVxeGrid<SensitiveWordApi.SensitiveWordVO>({
  109 + allSchemas: allSchemas,
  110 + getListApi: SensitiveWordApi.getSensitiveWordPageApi,
  111 + deleteApi: SensitiveWordApi.deleteSensitiveWordApi,
  112 + exportListApi: SensitiveWordApi.exportSensitiveWordApi
  113 + })
  114 +const actionLoading = ref(false) // 遮罩层
  115 +const actionType = ref('') // 操作按钮的类型
  116 +const dialogVisible = ref(false) // 是否显示弹出层
  117 +const dialogTitle = ref('edit') // 弹出层标题
  118 +const formRef = ref<FormExpose>() // 表单 Ref
  119 +const detailData = ref() // 详情 Ref
  120 +const tags = ref()
134 121
135 // 获取标签 122 // 获取标签
136 const tagsOptions = ref() 123 const tagsOptions = ref()
@@ -138,13 +125,7 @@ const getTags = async () =&gt; { @@ -138,13 +125,7 @@ const getTags = async () =&gt; {
138 const res = await SensitiveWordApi.getSensitiveWordTagsApi() 125 const res = await SensitiveWordApi.getSensitiveWordTagsApi()
139 tagsOptions.value = res 126 tagsOptions.value = res
140 } 127 }
141 -// ========== CRUD 相关 ==========  
142 -const actionLoading = ref(false) // 遮罩层  
143 -const actionType = ref('') // 操作按钮的类型  
144 -const dialogVisible = ref(false) // 是否显示弹出层  
145 -const dialogTitle = ref('edit') // 弹出层标题  
146 -const formRef = ref<FormExpose>() // 表单 Ref  
147 -const tags = ref() 128 +
148 // 设置标题 129 // 设置标题
149 const setDialogTile = (type: string) => { 130 const setDialogTile = (type: string) => {
150 dialogTitle.value = t('action.' + type) 131 dialogTitle.value = t('action.' + type)
@@ -158,6 +139,11 @@ const handleCreate = () =&gt; { @@ -158,6 +139,11 @@ const handleCreate = () =&gt; {
158 setDialogTile('create') 139 setDialogTile('create')
159 } 140 }
160 141
  142 +// 导出操作
  143 +const handleExport = async () => {
  144 + await exportList(xGrid, '敏感词数据.xls')
  145 +}
  146 +
161 // 修改操作 147 // 修改操作
162 const handleUpdate = async (rowId: number) => { 148 const handleUpdate = async (rowId: number) => {
163 setDialogTile('update') 149 setDialogTile('update')
@@ -167,6 +153,18 @@ const handleUpdate = async (rowId: number) =&gt; { @@ -167,6 +153,18 @@ const handleUpdate = async (rowId: number) =&gt; {
167 unref(formRef)?.setValues(res) 153 unref(formRef)?.setValues(res)
168 } 154 }
169 155
  156 +// 详情操作
  157 +const handleDetail = async (rowId: number) => {
  158 + setDialogTile('detail')
  159 + const res = await SensitiveWordApi.getSensitiveWordApi(rowId)
  160 + detailData.value = res
  161 +}
  162 +
  163 +// 删除操作
  164 +const handleDelete = async (rowId: number) => {
  165 + await deleteData(xGrid, rowId)
  166 +}
  167 +
170 // 提交按钮 168 // 提交按钮
171 const submitForm = async () => { 169 const submitForm = async () => {
172 const elForm = unref(formRef)?.getElFormRef() 170 const elForm = unref(formRef)?.getElFormRef()
@@ -176,38 +174,27 @@ const submitForm = async () =&gt; { @@ -176,38 +174,27 @@ const submitForm = async () =&gt; {
176 actionLoading.value = true 174 actionLoading.value = true
177 // 提交请求 175 // 提交请求
178 try { 176 try {
179 - const data = unref(formRef)?.formModel as SensitiveWordVO 177 + const data = unref(formRef)?.formModel as SensitiveWordApi.SensitiveWordVO
180 data.tags = tags.value 178 data.tags = tags.value
181 if (actionType.value === 'create') { 179 if (actionType.value === 'create') {
182 await SensitiveWordApi.createSensitiveWordApi(data) 180 await SensitiveWordApi.createSensitiveWordApi(data)
183 - ElMessage.success(t('common.createSuccess')) 181 + message.success(t('common.createSuccess'))
184 } else { 182 } else {
185 await SensitiveWordApi.updateSensitiveWordApi(data) 183 await SensitiveWordApi.updateSensitiveWordApi(data)
186 - ElMessage.success(t('common.updateSuccess')) 184 + message.success(t('common.updateSuccess'))
187 } 185 }
188 - // 操作成功,重新加载列表  
189 dialogVisible.value = false 186 dialogVisible.value = false
190 - await getList()  
191 } finally { 187 } finally {
192 actionLoading.value = false 188 actionLoading.value = false
  189 + // 刷新列表
  190 + await getList(xGrid)
193 } 191 }
194 } 192 }
195 }) 193 })
196 } 194 }
197 195
198 -// ========== 详情相关 ==========  
199 -const detailRef = ref() // 详情 Ref  
200 -  
201 -// 详情操作  
202 -const handleDetail = async (row: SensitiveWordVO) => {  
203 - // 设置数据  
204 - detailRef.value = row  
205 - setDialogTile('detail')  
206 -}  
207 -  
208 // ========== 初始化 ========== 196 // ========== 初始化 ==========
209 onMounted(async () => { 197 onMounted(async () => {
210 await getTags() 198 await getTags()
211 - await getList()  
212 }) 199 })
213 </script> 200 </script>
yudao-ui-admin-vue3/src/views/system/sensitiveWord/sensitiveWord.data.ts
1 import { reactive } from 'vue' 1 import { reactive } from 'vue'
2 import { useI18n } from '@/hooks/web/useI18n' 2 import { useI18n } from '@/hooks/web/useI18n'
3 import { required } from '@/utils/formRules' 3 import { required } from '@/utils/formRules'
4 -import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'  
5 import { DICT_TYPE } from '@/utils/dict' 4 import { DICT_TYPE } from '@/utils/dict'
  5 +import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
6 const { t } = useI18n() // 国际化 6 const { t } = useI18n() // 国际化
7 7
8 // 表单校验 8 // 表单校验
@@ -12,69 +12,52 @@ export const rules = reactive({ @@ -12,69 +12,52 @@ export const rules = reactive({
12 }) 12 })
13 13
14 // CrudSchema 14 // CrudSchema
15 -const crudSchemas = reactive<CrudSchema[]>([  
16 - {  
17 - label: t('common.index'),  
18 - field: 'id',  
19 - type: 'index',  
20 - form: {  
21 - show: false 15 +const crudSchemas = reactive<VxeCrudSchema>({
  16 + primaryKey: 'id',
  17 + primaryType: 'seq',
  18 + action: true,
  19 + columns: [
  20 + {
  21 + title: '敏感词',
  22 + field: 'name',
  23 + isSearch: true
22 }, 24 },
23 - detail: {  
24 - show: false  
25 - }  
26 - },  
27 - {  
28 - label: '敏感词',  
29 - field: 'name',  
30 - search: {  
31 - show: true  
32 - }  
33 - },  
34 - {  
35 - label: '标签',  
36 - field: 'tags'  
37 - },  
38 - {  
39 - label: t('common.status'),  
40 - field: 'status',  
41 - dictType: DICT_TYPE.COMMON_STATUS,  
42 - dictClass: 'number',  
43 - search: {  
44 - show: true  
45 - }  
46 - },  
47 - {  
48 - label: '描述',  
49 - field: 'description',  
50 - form: {  
51 - component: 'Input',  
52 - componentProps: {  
53 - type: 'textarea',  
54 - rows: 4  
55 - },  
56 - colProps: {  
57 - span: 24 25 + {
  26 + title: '标签',
  27 + field: 'tags',
  28 + table: {
  29 + slots: {
  30 + default: 'tags_default'
  31 + }
58 } 32 }
59 - }  
60 - },  
61 - {  
62 - label: t('common.createTime'),  
63 - field: 'createTime',  
64 - form: {  
65 - show: false  
66 - }  
67 - },  
68 - {  
69 - label: t('table.action'),  
70 - field: 'action',  
71 - width: '240px',  
72 - form: {  
73 - show: false  
74 }, 33 },
75 - detail: {  
76 - show: false 34 + {
  35 + title: t('common.status'),
  36 + field: 'status',
  37 + dictType: DICT_TYPE.COMMON_STATUS,
  38 + dictClass: 'number',
  39 + isSearch: true
  40 + },
  41 + {
  42 + title: '描述',
  43 + field: 'description',
  44 + form: {
  45 + component: 'Input',
  46 + componentProps: {
  47 + type: 'textarea',
  48 + rows: 4
  49 + },
  50 + colProps: {
  51 + span: 24
  52 + }
  53 + }
  54 + },
  55 + {
  56 + title: t('common.createTime'),
  57 + field: 'createTime',
  58 + formatter: 'formatDate',
  59 + isForm: false
77 } 60 }
78 - }  
79 -])  
80 -export const { allSchemas } = useCrudSchemas(crudSchemas) 61 + ]
  62 +})
  63 +export const { allSchemas } = useVxeCrudSchemas(crudSchemas)