敏感词管理测试
This commit is contained in:
parent
127b7987c0
commit
71fa0c95e1
91
src/views/system/sensitiveWord/SensitiveWordTestForm.vue
Normal file
91
src/views/system/sensitiveWord/SensitiveWordTestForm.vue
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<template>
|
||||||
|
<Dialog v-model="dialogVisible" title="检测敏感词">
|
||||||
|
<el-form
|
||||||
|
ref="formRef"
|
||||||
|
v-loading="formLoading"
|
||||||
|
:model="formData"
|
||||||
|
:rules="formRules"
|
||||||
|
label-width="80px"
|
||||||
|
>
|
||||||
|
<el-form-item label="文本" prop="text">
|
||||||
|
<el-input v-model="formData.text" placeholder="请输入测试文本" type="textarea" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="标签" prop="tags">
|
||||||
|
<el-select
|
||||||
|
v-model="formData.tags"
|
||||||
|
allow-create
|
||||||
|
filterable
|
||||||
|
multiple
|
||||||
|
placeholder="请选择标签"
|
||||||
|
style="width: 380px"
|
||||||
|
>
|
||||||
|
<el-option v-for="tag in tagList" :key="tag" :label="tag" :value="tag" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<el-button :disabled="formLoading" type="primary" @click="submitForm">检 测</el-button>
|
||||||
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||||
|
</template>
|
||||||
|
</Dialog>
|
||||||
|
</template>
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import * as SensitiveWordApi from '@/api/system/sensitiveWord'
|
||||||
|
|
||||||
|
defineOptions({ name: 'SystemSensitiveWordTestForm' })
|
||||||
|
|
||||||
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||||
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
|
const formData = ref({
|
||||||
|
text: '',
|
||||||
|
tags: []
|
||||||
|
})
|
||||||
|
const formRules = reactive({
|
||||||
|
text: [{ required: true, message: '测试文本不能为空', trigger: 'blur' }],
|
||||||
|
tags: [{ required: true, message: '标签不能为空', trigger: 'blur' }]
|
||||||
|
})
|
||||||
|
const formRef = ref() // 表单 Ref
|
||||||
|
const tagList = ref([]) // 标签数组
|
||||||
|
|
||||||
|
/** 打开弹窗 */
|
||||||
|
const open = async () => {
|
||||||
|
dialogVisible.value = true
|
||||||
|
resetForm()
|
||||||
|
// 获得 Tag 标签列表
|
||||||
|
tagList.value = await SensitiveWordApi.getSensitiveWordTagsApi()
|
||||||
|
}
|
||||||
|
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||||
|
|
||||||
|
/** 提交表单 */
|
||||||
|
const submitForm = async () => {
|
||||||
|
// 校验表单
|
||||||
|
if (!formRef) return
|
||||||
|
const valid = await formRef.value.validate()
|
||||||
|
if (!valid) return
|
||||||
|
// 提交请求
|
||||||
|
formLoading.value = true
|
||||||
|
try {
|
||||||
|
const form = formData.value as unknown as SensitiveWordApi.SensitiveWordTestReqVO
|
||||||
|
const data = await SensitiveWordApi.validateTextApi(form)
|
||||||
|
if (data.length === 0) {
|
||||||
|
message.success('不包含敏感词!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
message.warning('包含敏感词:' + data.join(', '))
|
||||||
|
dialogVisible.value = false
|
||||||
|
} finally {
|
||||||
|
formLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重置表单 */
|
||||||
|
const resetForm = () => {
|
||||||
|
formData.value = {
|
||||||
|
text: '',
|
||||||
|
tags: []
|
||||||
|
}
|
||||||
|
formRef.value?.resetFields()
|
||||||
|
}
|
||||||
|
</script>
|
@ -19,6 +19,13 @@
|
|||||||
v-hasPermi="['system:sensitive-word:export']"
|
v-hasPermi="['system:sensitive-word:export']"
|
||||||
@click="exportList('敏感词数据.xls')"
|
@click="exportList('敏感词数据.xls')"
|
||||||
/>
|
/>
|
||||||
|
<!-- 操作:测试 -->
|
||||||
|
<XButton
|
||||||
|
type="warning"
|
||||||
|
preIcon="ep:document-checked"
|
||||||
|
:title="t('action.test')"
|
||||||
|
@click="openTestForm"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #tags_default="{ row }">
|
<template #tags_default="{ row }">
|
||||||
<el-tag
|
<el-tag
|
||||||
@ -103,11 +110,14 @@
|
|||||||
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
|
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
|
||||||
</template>
|
</template>
|
||||||
</XModal>
|
</XModal>
|
||||||
|
<!-- 表单弹窗:测试敏感词 -->
|
||||||
|
<SensitiveWordTestForm ref="testFormRef" />
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { FormExpose } from '@/components/Form'
|
import type { FormExpose } from '@/components/Form'
|
||||||
import * as SensitiveWordApi from '@/api/system/sensitiveWord'
|
import * as SensitiveWordApi from '@/api/system/sensitiveWord'
|
||||||
import { rules, allSchemas } from './sensitiveWord.data'
|
import { rules, allSchemas } from './sensitiveWord.data'
|
||||||
|
import SensitiveWordTestForm from './SensitiveWordTestForm.vue'
|
||||||
|
|
||||||
defineOptions({ name: 'SystemSensitiveWord' })
|
defineOptions({ name: 'SystemSensitiveWord' })
|
||||||
|
|
||||||
@ -188,6 +198,12 @@ const submitForm = async () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 测试敏感词按钮操作 */
|
||||||
|
const testFormRef = ref()
|
||||||
|
const openTestForm = () => {
|
||||||
|
testFormRef.value.open()
|
||||||
|
}
|
||||||
|
|
||||||
// ========== 初始化 ==========
|
// ========== 初始化 ==========
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await getTags()
|
await getTags()
|
||||||
|
Loading…
Reference in New Issue
Block a user