敏感词管理测试

pull/420/head
liuyu 2024-03-14 09:18:21 +08:00
parent 127b7987c0
commit 71fa0c95e1
2 changed files with 107 additions and 0 deletions

View 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) // 12
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>

View File

@ -19,6 +19,13 @@
v-hasPermi="['system:sensitive-word:export']"
@click="exportList('敏感词数据.xls')"
/>
<!-- 操作测试 -->
<XButton
type="warning"
preIcon="ep:document-checked"
:title="t('action.test')"
@click="openTestForm"
/>
</template>
<template #tags_default="{ row }">
<el-tag
@ -103,11 +110,14 @@
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
</template>
</XModal>
<!-- 表单弹窗测试敏感词 -->
<SensitiveWordTestForm ref="testFormRef" />
</template>
<script lang="ts" setup>
import type { FormExpose } from '@/components/Form'
import * as SensitiveWordApi from '@/api/system/sensitiveWord'
import { rules, allSchemas } from './sensitiveWord.data'
import SensitiveWordTestForm from './SensitiveWordTestForm.vue'
defineOptions({ name: 'SystemSensitiveWord' })
@ -188,6 +198,12 @@ const submitForm = async () => {
})
}
/** 测试敏感词按钮操作 */
const testFormRef = ref()
const openTestForm = () => {
testFormRef.value.open()
}
// ========== ==========
onMounted(async () => {
await getTags()