Skip to content

Commit 7f8f43a

Browse files
YunaiVgitee-org
authored andcommitted
!55 敏感词模块 TODO 内容修改
Merge pull request !55 from syd/dev
2 parents 6f7d064 + 21cce98 commit 7f8f43a

File tree

5 files changed

+121
-14
lines changed

5 files changed

+121
-14
lines changed

src/api/system/sensitiveWord/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import request from '@/config/axios'
2+
import qs from 'qs'
23

34
export interface SensitiveWordVO {
45
id: number
@@ -23,6 +24,11 @@ export interface SensitiveWordExportReqVO {
2324
createTime?: Date[]
2425
}
2526

27+
export interface SensitiveWordTestReqVO {
28+
text: string
29+
tag: string[]
30+
}
31+
2632
// 查询敏感词列表
2733
export const getSensitiveWordPage = (params: SensitiveWordPageReqVO) => {
2834
return request.get({ url: '/system/sensitive-word/page', params })
@@ -59,6 +65,8 @@ export const getSensitiveWordTags = () => {
5965
}
6066

6167
// 获得文本所包含的不合法的敏感词数组
62-
export const validateText = (id: number) => {
63-
return request.get({ url: '/system/sensitive-word/validate-text?' + id })
68+
export const validateText = (query: SensitiveWordTestReqVO) => {
69+
return request.get({
70+
url: '/system/sensitive-word/validate-text?' + qs.stringify(query, { arrayFormat: 'repeat' })
71+
})
6472
}

src/types/auto-components.d.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ declare module '@vue/runtime-core' {
2323
DictTag: typeof import('./../components/DictTag/src/DictTag.vue')['default']
2424
Echart: typeof import('./../components/Echart/src/Echart.vue')['default']
2525
Editor: typeof import('./../components/Editor/src/Editor.vue')['default']
26-
ElAvatar: typeof import('element-plus/es')['ElAvatar']
2726
ElBadge: typeof import('element-plus/es')['ElBadge']
2827
ElButton: typeof import('element-plus/es')['ElButton']
2928
ElButtonGroup: typeof import('element-plus/es')['ElButtonGroup']
3029
ElCard: typeof import('element-plus/es')['ElCard']
3130
ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
32-
ElCheckboxGroup: typeof import('element-plus/es')['ElCheckboxGroup']
3331
ElCol: typeof import('element-plus/es')['ElCol']
3432
ElCollapse: typeof import('element-plus/es')['ElCollapse']
3533
ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
@@ -56,30 +54,24 @@ declare module '@vue/runtime-core' {
5654
ElIcon: typeof import('element-plus/es')['ElIcon']
5755
ElImageViewer: typeof import('element-plus/es')['ElImageViewer']
5856
ElInput: typeof import('element-plus/es')['ElInput']
59-
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
6057
ElLink: typeof import('element-plus/es')['ElLink']
6158
ElOption: typeof import('element-plus/es')['ElOption']
6259
ElPagination: typeof import('element-plus/es')['ElPagination']
6360
ElPopover: typeof import('element-plus/es')['ElPopover']
6461
ElRadio: typeof import('element-plus/es')['ElRadio']
65-
ElRadioButton: typeof import('element-plus/es')['ElRadioButton']
6662
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
6763
ElRow: typeof import('element-plus/es')['ElRow']
6864
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
6965
ElSelect: typeof import('element-plus/es')['ElSelect']
7066
ElSkeleton: typeof import('element-plus/es')['ElSkeleton']
71-
ElSpace: typeof import('element-plus/es')['ElSpace']
7267
ElSwitch: typeof import('element-plus/es')['ElSwitch']
7368
ElTable: typeof import('element-plus/es')['ElTable']
7469
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
75-
ElTableV2: typeof import('element-plus/es')['ElTableV2']
7670
ElTabPane: typeof import('element-plus/es')['ElTabPane']
7771
ElTabs: typeof import('element-plus/es')['ElTabs']
7872
ElTag: typeof import('element-plus/es')['ElTag']
7973
ElTooltip: typeof import('element-plus/es')['ElTooltip']
8074
ElTransfer: typeof import('element-plus/es')['ElTransfer']
81-
ElTree: typeof import('element-plus/es')['ElTree']
82-
ElTreeSelect: typeof import('element-plus/es')['ElTreeSelect']
8375
ElUpload: typeof import('element-plus/es')['ElUpload']
8476
Error: typeof import('./../components/Error/src/Error.vue')['default']
8577
FlowCondition: typeof import('./../components/bpmnProcessDesigner/package/penal/flow-condition/FlowCondition.vue')['default']

src/views/system/sensitiveWord/form.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ const formRules = reactive({
6767
tags: [{ required: true, message: '标签不能为空', trigger: 'blur' }]
6868
})
6969
const formRef = ref() // 表单 Ref
70-
const tags = ref([]) // todo @blue-syd:在 openModal 里加载下
70+
const tags: Ref<string[]> = ref([]) // todo @blue-syd:在 openModal 里加载下
7171
7272
/** 打开弹窗 */
73-
const openModal = async (type: string, id?: number) => {
73+
const openModal = async (type: string, paramTags: string[], id?: number) => {
74+
tags.value = paramTags
7475
modelVisible.value = true
7576
modelTitle.value = t('action.' + type)
7677
formType.value = type

src/views/system/sensitiveWord/index.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,24 @@
4545
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
4646
<el-button
4747
type="primary"
48+
plain
4849
@click="openModal('create')"
4950
v-hasPermi="['system:sensitive-word:create']"
5051
>
5152
<Icon icon="ep:plus" class="mr-5px" /> 新增
5253
</el-button>
5354
<el-button
54-
type="success"
55+
type="warning"
5556
plain
5657
@click="handleExport"
5758
:loading="exportLoading"
5859
v-hasPermi="['system:sensitive-word:export']"
5960
>
6061
<Icon icon="ep:download" class="mr-5px" /> 导出
6162
</el-button>
63+
<el-button type="success" plain @click="handleTest">
64+
<Icon icon="ep:document-checked" class="mr-5px" /> 测试
65+
</el-button>
6266
</el-form-item>
6367
</el-form>
6468
</content-wrap>
@@ -127,13 +131,18 @@
127131

128132
<!-- 表单弹窗:添加/修改 -->
129133
<SensitiveWordForm ref="modalRef" @success="getList" />
134+
135+
<!-- 表单弹窗:测试敏感词 -->
136+
<SensitiveWordTestForm ref="modalTestRef" />
130137
</template>
131138
<script setup lang="ts" name="SensitiveWord">
132139
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
133140
import { dateFormatter } from '@/utils/formatTime'
134141
import download from '@/utils/download'
135142
import * as SensitiveWordApi from '@/api/system/sensitiveWord'
136143
import SensitiveWordForm from './form.vue' // TODO @blue-syd:组件名不对
144+
import SensitiveWordTestForm from './testForm.vue'
145+
137146
const message = useMessage() // 消息弹窗
138147
const { t } = useI18n() // 国际化
139148
@@ -179,10 +188,15 @@ const resetQuery = () => {
179188
/** 添加/修改操作 */
180189
const modalRef = ref()
181190
const openModal = (type: string, id?: number) => {
182-
modalRef.value.openModal(type, id)
191+
modalRef.value.openModal(type, tags.value, id)
183192
}
184193
185194
// TODO @blue-syd:还少一个【测试】按钮的功能,参见 http://dashboard.yudao.iocoder.cn/system/sensitive-word
195+
/* 测试敏感词按钮操作 */
196+
const modalTestRef = ref()
197+
const handleTest = () => {
198+
modalTestRef.value.openModal(tags.value)
199+
}
186200
187201
/** 删除按钮操作 */
188202
const handleDelete = async (id: number) => {
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<template>
2+
<!-- 对话框(测试敏感词) -->
3+
<Dialog :title="modelTitle" v-model="modelVisible">
4+
<el-form
5+
ref="formRef"
6+
:model="formData"
7+
:rules="formRules"
8+
label-width="80px"
9+
v-loading="formLoading"
10+
>
11+
<el-form-item label="文本" prop="text">
12+
<el-input type="textarea" v-model="formData.text" placeholder="请输入测试文本" />
13+
</el-form-item>
14+
<el-form-item label="标签" prop="tags">
15+
<el-select
16+
v-model="formData.tags"
17+
multiple
18+
filterable
19+
allow-create
20+
placeholder="请选择文章标签"
21+
style="width: 380px"
22+
>
23+
<el-option v-for="tag in tags" :key="tag" :label="tag" :value="tag" />
24+
</el-select>
25+
</el-form-item>
26+
</el-form>
27+
<template #footer>
28+
<div class="dialog-footer">
29+
<el-button @click="submitForm" type="primary" :disabled="formLoading">检 测</el-button>
30+
<el-button @click="modelVisible = false">取 消</el-button>
31+
</div>
32+
</template>
33+
</Dialog>
34+
</template>
35+
<script setup lang="ts">
36+
import * as SensitiveWordApi from '@/api/system/sensitiveWord'
37+
38+
const message = useMessage() // 消息弹窗
39+
40+
const modelVisible = ref(false) // 弹窗的是否展示
41+
const modelTitle = ref('检测敏感词') // 弹窗的标题
42+
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
43+
const tags: Ref<string[]> = ref([])
44+
const formData = ref({
45+
text: '',
46+
tags: []
47+
})
48+
const formRules = reactive({
49+
text: [{ required: true, message: '测试文本不能为空', trigger: 'blur' }],
50+
tags: [{ required: true, message: '标签不能为空', trigger: 'blur' }]
51+
})
52+
const formRef = ref() // 表单 Ref
53+
54+
/** 打开弹窗 */
55+
const openModal = async (paramTags: string[]) => {
56+
tags.value = paramTags
57+
modelVisible.value = true
58+
resetForm()
59+
}
60+
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
61+
62+
/** 提交表单 */
63+
const submitForm = async () => {
64+
// 校验表单
65+
if (!formRef) return
66+
const valid = await formRef.value.validate()
67+
if (!valid) return
68+
// 提交请求
69+
formLoading.value = true
70+
try {
71+
const form = formData.value as unknown as SensitiveWordApi.SensitiveWordTestReqVO
72+
const data = await SensitiveWordApi.validateText(form)
73+
if (data.length === 0) {
74+
message.success('不包含敏感词!')
75+
return
76+
}
77+
message.warning('包含敏感词:' + data.join(', '))
78+
modelVisible.value = false
79+
} finally {
80+
formLoading.value = false
81+
}
82+
}
83+
84+
/** 重置表单 */
85+
const resetForm = () => {
86+
formData.value = {
87+
text: '',
88+
tags: []
89+
}
90+
formRef.value?.resetFields()
91+
}
92+
</script>

0 commit comments

Comments
 (0)