Vue3 重构:REVIEW 敏感词

This commit is contained in:
YunaiV 2023-03-26 21:16:16 +08:00
parent 7f8f43aff5
commit 9c869dee5f
7 changed files with 69 additions and 212 deletions

View File

@ -10,27 +10,13 @@ export interface SensitiveWordVO {
createTime: Date createTime: Date
} }
export interface SensitiveWordPageReqVO extends PageParam {
name?: string
tag?: string
status?: number
createTime?: Date[]
}
export interface SensitiveWordExportReqVO {
name?: string
tag?: string
status?: number
createTime?: Date[]
}
export interface SensitiveWordTestReqVO { export interface SensitiveWordTestReqVO {
text: string text: string
tag: string[] tag: string[]
} }
// 查询敏感词列表 // 查询敏感词列表
export const getSensitiveWordPage = (params: SensitiveWordPageReqVO) => { export const getSensitiveWordPage = (params: PageParam) => {
return request.get({ url: '/system/sensitive-word/page', params }) return request.get({ url: '/system/sensitive-word/page', params })
} }
@ -55,12 +41,12 @@ export const deleteSensitiveWord = (id: number) => {
} }
// 导出敏感词 // 导出敏感词
export const exportSensitiveWord = (params: SensitiveWordExportReqVO) => { export const exportSensitiveWord = (params) => {
return request.download({ url: '/system/sensitive-word/export-excel', params }) return request.download({ url: '/system/sensitive-word/export-excel', params })
} }
// 获取所有敏感词的标签数组 // 获取所有敏感词的标签数组
export const getSensitiveWordTags = () => { export const getSensitiveWordTagList = () => {
return request.get({ url: '/system/sensitive-word/get-tags' }) return request.get({ url: '/system/sensitive-word/get-tags' })
} }

View File

@ -54,11 +54,13 @@ declare module '@vue/runtime-core' {
ElIcon: typeof import('element-plus/es')['ElIcon'] ElIcon: typeof import('element-plus/es')['ElIcon']
ElImageViewer: typeof import('element-plus/es')['ElImageViewer'] ElImageViewer: typeof import('element-plus/es')['ElImageViewer']
ElInput: typeof import('element-plus/es')['ElInput'] ElInput: typeof import('element-plus/es')['ElInput']
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
ElLink: typeof import('element-plus/es')['ElLink'] ElLink: typeof import('element-plus/es')['ElLink']
ElOption: typeof import('element-plus/es')['ElOption'] ElOption: typeof import('element-plus/es')['ElOption']
ElPagination: typeof import('element-plus/es')['ElPagination'] ElPagination: typeof import('element-plus/es')['ElPagination']
ElPopover: typeof import('element-plus/es')['ElPopover'] ElPopover: typeof import('element-plus/es')['ElPopover']
ElRadio: typeof import('element-plus/es')['ElRadio'] ElRadio: typeof import('element-plus/es')['ElRadio']
ElRadioButton: typeof import('element-plus/es')['ElRadioButton']
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup'] ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
ElRow: typeof import('element-plus/es')['ElRow'] ElRow: typeof import('element-plus/es')['ElRow']
ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
@ -72,6 +74,8 @@ declare module '@vue/runtime-core' {
ElTag: typeof import('element-plus/es')['ElTag'] ElTag: typeof import('element-plus/es')['ElTag']
ElTooltip: typeof import('element-plus/es')['ElTooltip'] ElTooltip: typeof import('element-plus/es')['ElTooltip']
ElTransfer: typeof import('element-plus/es')['ElTransfer'] ElTransfer: typeof import('element-plus/es')['ElTransfer']
ElTree: typeof import('element-plus/es')['ElTree']
ElTreeSelect: typeof import('element-plus/es')['ElTreeSelect']
ElUpload: typeof import('element-plus/es')['ElUpload'] ElUpload: typeof import('element-plus/es')['ElUpload']
Error: typeof import('./../components/Error/src/Error.vue')['default'] Error: typeof import('./../components/Error/src/Error.vue')['default']
FlowCondition: typeof import('./../components/bpmnProcessDesigner/package/penal/flow-condition/FlowCondition.vue')['default'] FlowCondition: typeof import('./../components/bpmnProcessDesigner/package/penal/flow-condition/FlowCondition.vue')['default']

View File

@ -133,7 +133,6 @@
import type { FormExpose } from '@/components/Form' import type { FormExpose } from '@/components/Form'
// import // import
import * as ClientApi from '@/api/system/oauth2/client' import * as ClientApi from '@/api/system/oauth2/client'
import { rules, allSchemas } from './client.data'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //

View File

@ -1,131 +0,0 @@
<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="category">
<el-input v-model="formData.category" placeholder="请输入参数分类" />
</el-form-item>
<el-form-item label="参数名称" prop="name">
<el-input v-model="formData.name" placeholder="请输入参数名称" />
</el-form-item>
<el-form-item label="参数键名" prop="key">
<el-input v-model="formData.key" placeholder="请输入参数键名" />
</el-form-item>
<el-form-item label="参数键值" prop="value">
<el-input v-model="formData.value" placeholder="请输入参数键值" />
</el-form-item>
<el-form-item label="是否可见" prop="visible">
<el-radio-group v-model="formData.visible">
<el-radio
v-for="dict in getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="formData.remark" type="textarea" placeholder="请输入内容" />
</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 { DICT_TYPE, getDictOptions } from '@/utils/dict'
import * as ConfigApi from '@/api/infra/config'
const { t } = useI18n() //
const message = useMessage() //
const modelVisible = ref(false) //
const modelTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
category: '',
name: '',
key: '',
value: '',
visible: true,
remark: ''
})
const formRules = reactive({
category: [{ required: true, message: '参数分类不能为空', trigger: 'blur' }],
name: [{ required: true, message: '参数名称不能为空', trigger: 'blur' }],
key: [{ required: true, message: '参数键名不能为空', trigger: 'blur' }],
value: [{ required: true, message: '参数键值不能为空', trigger: 'blur' }],
visible: [{ required: true, message: '是否可见不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
/** 打开弹窗 */
const openModal = async (type: string, id?: number) => {
modelVisible.value = true
modelTitle.value = t('action.' + type)
formType.value = type
resetForm()
//
if (id) {
formLoading.value = true
try {
formData.value = await ConfigApi.getConfig(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ openModal }) // openModal
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
//
formLoading.value = true
try {
const data = formData.value as ConfigApi.ConfigVO
if (formType.value === 'create') {
await ConfigApi.createConfig(data)
message.success(t('common.createSuccess'))
} else {
await ConfigApi.updateConfig(data)
message.success(t('common.updateSuccess'))
}
modelVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
category: '',
name: '',
key: '',
value: '',
visible: true,
remark: ''
}
formRef.value?.resetFields()
}
</script>

View File

@ -33,7 +33,7 @@
placeholder="请选择文章标签" placeholder="请选择文章标签"
style="width: 380px" style="width: 380px"
> >
<el-option v-for="tag in tags" :key="tag" :label="tag" :value="tag" /> <el-option v-for="tag in tagList" :key="tag" :label="tag" :value="tag" />
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -47,7 +47,6 @@
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as SensitiveWordApi from '@/api/system/sensitiveWord' import * as SensitiveWordApi from '@/api/system/sensitiveWord'
import { CommonStatusEnum } from '@/utils/constants' import { CommonStatusEnum } from '@/utils/constants'
const { t } = useI18n() // const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
@ -67,11 +66,10 @@ const formRules = reactive({
tags: [{ required: true, message: '标签不能为空', trigger: 'blur' }] tags: [{ required: true, message: '标签不能为空', trigger: 'blur' }]
}) })
const formRef = ref() // Ref const formRef = ref() // Ref
const tags: Ref<string[]> = ref([]) // todo @blue-syd openModal const tagList = ref([]) //
/** 打开弹窗 */ /** 打开弹窗 */
const openModal = async (type: string, paramTags: string[], id?: number) => { const open = async (type: string, id?: number) => {
tags.value = paramTags
modelVisible.value = true modelVisible.value = true
modelTitle.value = t('action.' + type) modelTitle.value = t('action.' + type)
formType.value = type formType.value = type
@ -81,13 +79,14 @@ const openModal = async (type: string, paramTags: string[], id?: number) => {
formLoading.value = true formLoading.value = true
try { try {
formData.value = await SensitiveWordApi.getSensitiveWord(id) formData.value = await SensitiveWordApi.getSensitiveWord(id)
console.log(formData.value)
} finally { } finally {
formLoading.value = false formLoading.value = false
} }
} }
// Tag
tagList.value = await SensitiveWordApi.getSensitiveWordTagList()
} }
defineExpose({ openModal }) // openModal defineExpose({ open }) // open
/** 提交表单 */ /** 提交表单 */
const emit = defineEmits(['success']) // success const emit = defineEmits(['success']) // success
@ -101,10 +100,10 @@ const submitForm = async () => {
try { try {
const data = formData.value as unknown as SensitiveWordApi.SensitiveWordVO const data = formData.value as unknown as SensitiveWordApi.SensitiveWordVO
if (formType.value === 'create') { if (formType.value === 'create') {
await SensitiveWordApi.createSensitiveWord(data) // TODO @blue-syd API await SensitiveWordApi.createSensitiveWord(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await SensitiveWordApi.updateSensitiveWord(data) // TODO @blue-syd API await SensitiveWordApi.updateSensitiveWord(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
} }
modelVisible.value = false modelVisible.value = false

View File

@ -1,6 +1,5 @@
<template> <template>
<!-- 对话框(测试敏感词) --> <Dialog title="检测敏感词" v-model="modelVisible">
<Dialog :title="modelTitle" v-model="modelVisible">
<el-form <el-form
ref="formRef" ref="formRef"
:model="formData" :model="formData"
@ -17,10 +16,10 @@
multiple multiple
filterable filterable
allow-create allow-create
placeholder="请选择文章标签" placeholder="请选择标签"
style="width: 380px" style="width: 380px"
> >
<el-option v-for="tag in tags" :key="tag" :label="tag" :value="tag" /> <el-option v-for="tag in tagList" :key="tag" :label="tag" :value="tag" />
</el-select> </el-select>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -34,13 +33,10 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import * as SensitiveWordApi from '@/api/system/sensitiveWord' import * as SensitiveWordApi from '@/api/system/sensitiveWord'
const message = useMessage() // const message = useMessage() //
const modelVisible = ref(false) // const modelVisible = ref(false) //
const modelTitle = ref('检测敏感词') //
const formLoading = ref(false) // 12 const formLoading = ref(false) // 12
const tags: Ref<string[]> = ref([])
const formData = ref({ const formData = ref({
text: '', text: '',
tags: [] tags: []
@ -50,14 +46,16 @@ const formRules = reactive({
tags: [{ required: true, message: '标签不能为空', trigger: 'blur' }] tags: [{ required: true, message: '标签不能为空', trigger: 'blur' }]
}) })
const formRef = ref() // Ref const formRef = ref() // Ref
const tagList = ref([]) //
/** 打开弹窗 */ /** 打开弹窗 */
const openModal = async (paramTags: string[]) => { const open = async () => {
tags.value = paramTags
modelVisible.value = true modelVisible.value = true
resetForm() resetForm()
// Tag
tagList.value = await SensitiveWordApi.getSensitiveWordTagList()
} }
defineExpose({ openModal }) // openModal defineExpose({ open }) // open
/** 提交表单 */ /** 提交表单 */
const submitForm = async () => { const submitForm = async () => {

View File

@ -1,13 +1,20 @@
<template> <template>
<!-- 搜索 --> <!-- 搜索工作栏 -->
<content-wrap> <ContentWrap>
<el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true"> <el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="敏感词" prop="name"> <el-form-item label="敏感词" prop="name">
<el-input <el-input
v-model="queryParams.name" v-model="queryParams.name"
placeholder="请输入敏感词" placeholder="请输入敏感词"
clearable clearable
@keyup.enter="handleQuery" @keyup.enter="handleQuery"
class="!w-240px"
/> />
</el-form-item> </el-form-item>
<el-form-item label="标签" prop="tag"> <el-form-item label="标签" prop="tag">
@ -16,17 +23,19 @@
placeholder="请选择标签" placeholder="请选择标签"
clearable clearable
@keyup.enter="handleQuery" @keyup.enter="handleQuery"
class="!w-240px"
> >
<el-option v-for="tag in tags" :key="tag" :label="tag" :value="tag" /> <el-option v-for="tag in tagList" :key="tag" :label="tag" :value="tag" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="status"> <el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择启用状态" clearable> <el-select v-model="queryParams.status" placeholder="请选择启用状态" clearable>
<el-option <el-option
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)" v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="parseInt(dict.value)" :key="dict.value"
:label="dict.label" :label="dict.label"
:value="parseInt(dict.value)" :value="dict.value"
class="!w-240px"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
@ -38,6 +47,7 @@
start-placeholder="开始日期" start-placeholder="开始日期"
end-placeholder="结束日期" end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
class="!w-240px"
/> />
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
@ -46,13 +56,13 @@
<el-button <el-button
type="primary" type="primary"
plain plain
@click="openModal('create')" @click="openForm('create')"
v-hasPermi="['system:sensitive-word:create']" v-hasPermi="['system:sensitive-word:create']"
> >
<Icon icon="ep:plus" class="mr-5px" /> 新增 <Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button> </el-button>
<el-button <el-button
type="warning" type="success"
plain plain
@click="handleExport" @click="handleExport"
:loading="exportLoading" :loading="exportLoading"
@ -60,15 +70,15 @@
> >
<Icon icon="ep:download" class="mr-5px" /> 导出 <Icon icon="ep:download" class="mr-5px" /> 导出
</el-button> </el-button>
<el-button type="success" plain @click="handleTest"> <el-button type="warning" plain @click="openTestForm">
<Icon icon="ep:document-checked" class="mr-5px" /> 测试 <Icon icon="ep:document-checked" class="mr-5px" /> 测试
</el-button> </el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</content-wrap> </ContentWrap>
<!-- 列表 --> <!-- 列表 -->
<content-wrap> <ContentWrap>
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<el-table-column label="编号" align="center" prop="id" /> <el-table-column label="编号" align="center" prop="id" />
<el-table-column label="敏感词" align="center" prop="name" /> <el-table-column label="敏感词" align="center" prop="name" />
@ -81,15 +91,13 @@
<el-table-column label="标签" align="center" prop="tags"> <el-table-column label="标签" align="center" prop="tags">
<template #default="scope"> <template #default="scope">
<el-tag <el-tag
:disable-transitions="true"
:key="index"
v-for="(tag, index) in scope.row.tags"
:index="index"
class="mr-5px" class="mr-5px"
v-for="tag in scope.row.tags"
:key="tag"
:disable-transitions="true"
> >
{{ tag }} {{ tag }}
</el-tag> </el-tag>
&nbsp; &nbsp;
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
@ -104,7 +112,7 @@
<el-button <el-button
link link
type="primary" type="primary"
@click="openModal('update', scope.row.id)" @click="openForm('update', scope.row.id)"
v-hasPermi="['infra:config:update']" v-hasPermi="['infra:config:update']"
> >
编辑 编辑
@ -127,22 +135,21 @@
v-model:limit="queryParams.pageSize" v-model:limit="queryParams.pageSize"
@pagination="getList" @pagination="getList"
/> />
</content-wrap> </ContentWrap>
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<SensitiveWordForm ref="modalRef" @success="getList" /> <SensitiveWordForm ref="formRef" @success="getList" />
<!-- 表单弹窗测试敏感词 --> <!-- 表单弹窗测试敏感词 -->
<SensitiveWordTestForm ref="modalTestRef" /> <SensitiveWordTestForm ref="testFormRef" />
</template> </template>
<script setup lang="ts" name="SensitiveWord"> <script setup lang="ts" name="SensitiveWord">
import { DICT_TYPE, getDictOptions } from '@/utils/dict' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download' import download from '@/utils/download'
import * as SensitiveWordApi from '@/api/system/sensitiveWord' import * as SensitiveWordApi from '@/api/system/sensitiveWord'
import SensitiveWordForm from './form.vue' // TODO @blue-syd import SensitiveWordForm from './SensitiveWordForm.vue'
import SensitiveWordTestForm from './testForm.vue' import SensitiveWordTestForm from './SensitiveWordTestForm.vue'
const message = useMessage() // const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
@ -159,13 +166,13 @@ const queryParams = reactive({
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
const exportLoading = ref(false) // const exportLoading = ref(false) //
const tags = ref([]) const tagList = ref([]) //
/** 查询参数列表 */ /** 查询参数列表 */
const getList = async () => { const getList = async () => {
loading.value = true loading.value = true
try { try {
const data = await SensitiveWordApi.getSensitiveWordPage(queryParams) // TODO @blue-syd API const data = await SensitiveWordApi.getSensitiveWordPage(queryParams)
list.value = data.list list.value = data.list
total.value = data.total total.value = data.total
} finally { } finally {
@ -186,16 +193,15 @@ const resetQuery = () => {
} }
/** 添加/修改操作 */ /** 添加/修改操作 */
const modalRef = ref() const formRef = ref()
const openModal = (type: string, id?: number) => { const openForm = (type: string, id?: number) => {
modalRef.value.openModal(type, tags.value, id) formRef.value.open(type, id)
} }
// TODO @blue-syd http://dashboard.yudao.iocoder.cn/system/sensitive-word /** 测试敏感词按钮操作 */
/* 测试敏感词按钮操作 */ const testFormRef = ref()
const modalTestRef = ref() const openTestForm = () => {
const handleTest = () => { testFormRef.value.open()
modalTestRef.value.openModal(tags.value)
} }
/** 删除按钮操作 */ /** 删除按钮操作 */
@ -218,7 +224,7 @@ const handleExport = async () => {
await message.exportConfirm() await message.exportConfirm()
// //
exportLoading.value = true exportLoading.value = true
const data = await SensitiveWordApi.exportSensitiveWord(queryParams) // TODO @blue-syd API const data = await SensitiveWordApi.exportSensitiveWord(queryParams)
download.excel(data, '敏感词.xls') download.excel(data, '敏感词.xls')
} catch { } catch {
} finally { } finally {
@ -226,14 +232,10 @@ const handleExport = async () => {
} }
} }
/** 获得 Tag 标签列表 */
const getTags = async () => {
tags.value = await SensitiveWordApi.getSensitiveWordTags() // TODO @blue-syd API
}
/** 初始化 **/ /** 初始化 **/
onMounted(() => { onMounted(async () => {
getTags() await getList()
getList() // Tag
tagList.value = await SensitiveWordApi.getSensitiveWordTagList()
}) })
</script> </script>