mirror of
https://gitee.com/hhyykk/ipms-sjy-ui.git
synced 2025-07-17 04:15:07 +08:00
@ -67,10 +67,11 @@ const formRules = reactive({
|
||||
tags: [{ required: true, message: '标签不能为空', trigger: 'blur' }]
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
const tags = ref([]) // todo @blue-syd:在 openModal 里加载下
|
||||
const tags: Ref<string[]> = ref([]) // todo @blue-syd:在 openModal 里加载下
|
||||
|
||||
/** 打开弹窗 */
|
||||
const openModal = async (type: string, id?: number) => {
|
||||
const openModal = async (type: string, paramTags: string[], id?: number) => {
|
||||
tags.value = paramTags
|
||||
modelVisible.value = true
|
||||
modelTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
|
@ -45,13 +45,14 @@
|
||||
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
@click="openModal('create')"
|
||||
v-hasPermi="['system:sensitive-word:create']"
|
||||
>
|
||||
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||
</el-button>
|
||||
<el-button
|
||||
type="success"
|
||||
type="warning"
|
||||
plain
|
||||
@click="handleExport"
|
||||
:loading="exportLoading"
|
||||
@ -59,6 +60,9 @@
|
||||
>
|
||||
<Icon icon="ep:download" class="mr-5px" /> 导出
|
||||
</el-button>
|
||||
<el-button type="success" plain @click="handleTest">
|
||||
<Icon icon="ep:document-checked" class="mr-5px" /> 测试
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</content-wrap>
|
||||
@ -127,6 +131,9 @@
|
||||
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<SensitiveWordForm ref="modalRef" @success="getList" />
|
||||
|
||||
<!-- 表单弹窗:测试敏感词 -->
|
||||
<SensitiveWordTestForm ref="modalTestRef" />
|
||||
</template>
|
||||
<script setup lang="ts" name="SensitiveWord">
|
||||
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
|
||||
@ -134,6 +141,8 @@ import { dateFormatter } from '@/utils/formatTime'
|
||||
import download from '@/utils/download'
|
||||
import * as SensitiveWordApi from '@/api/system/sensitiveWord'
|
||||
import SensitiveWordForm from './form.vue' // TODO @blue-syd:组件名不对
|
||||
import SensitiveWordTestForm from './testForm.vue'
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
const { t } = useI18n() // 国际化
|
||||
|
||||
@ -179,10 +188,15 @@ const resetQuery = () => {
|
||||
/** 添加/修改操作 */
|
||||
const modalRef = ref()
|
||||
const openModal = (type: string, id?: number) => {
|
||||
modalRef.value.openModal(type, id)
|
||||
modalRef.value.openModal(type, tags.value, id)
|
||||
}
|
||||
|
||||
// TODO @blue-syd:还少一个【测试】按钮的功能,参见 http://dashboard.yudao.iocoder.cn/system/sensitive-word
|
||||
/* 测试敏感词按钮操作 */
|
||||
const modalTestRef = ref()
|
||||
const handleTest = () => {
|
||||
modalTestRef.value.openModal(tags.value)
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (id: number) => {
|
||||
|
92
src/views/system/sensitiveWord/testForm.vue
Normal file
92
src/views/system/sensitiveWord/testForm.vue
Normal file
@ -0,0 +1,92 @@
|
||||
<template>
|
||||
<!-- 对话框(测试敏感词) -->
|
||||
<Dialog :title="modelTitle" v-model="modelVisible">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="80px"
|
||||
v-loading="formLoading"
|
||||
>
|
||||
<el-form-item label="文本" prop="text">
|
||||
<el-input type="textarea" v-model="formData.text" placeholder="请输入测试文本" />
|
||||
</el-form-item>
|
||||
<el-form-item label="标签" prop="tags">
|
||||
<el-select
|
||||
v-model="formData.tags"
|
||||
multiple
|
||||
filterable
|
||||
allow-create
|
||||
placeholder="请选择文章标签"
|
||||
style="width: 380px"
|
||||
>
|
||||
<el-option v-for="tag in tags" :key="tag" :label="tag" :value="tag" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="submitForm" type="primary" :disabled="formLoading">检 测</el-button>
|
||||
<el-button @click="modelVisible = false">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import * as SensitiveWordApi from '@/api/system/sensitiveWord'
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const modelVisible = ref(false) // 弹窗的是否展示
|
||||
const modelTitle = ref('检测敏感词') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const tags: Ref<string[]> = ref([])
|
||||
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 openModal = async (paramTags: string[]) => {
|
||||
tags.value = paramTags
|
||||
modelVisible.value = true
|
||||
resetForm()
|
||||
}
|
||||
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
|
||||
|
||||
/** 提交表单 */
|
||||
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.validateText(form)
|
||||
if (data.length === 0) {
|
||||
message.success('不包含敏感词!')
|
||||
return
|
||||
}
|
||||
message.warning('包含敏感词:' + data.join(', '))
|
||||
modelVisible.value = false
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
text: '',
|
||||
tags: []
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
</script>
|
Reference in New Issue
Block a user