Vue3 重构:REVIEW 敏感词
This commit is contained in:
parent
7f8f43aff5
commit
9c869dee5f
@ -10,27 +10,13 @@ export interface SensitiveWordVO {
|
||||
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 {
|
||||
text: string
|
||||
tag: string[]
|
||||
}
|
||||
|
||||
// 查询敏感词列表
|
||||
export const getSensitiveWordPage = (params: SensitiveWordPageReqVO) => {
|
||||
export const getSensitiveWordPage = (params: PageParam) => {
|
||||
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 })
|
||||
}
|
||||
|
||||
// 获取所有敏感词的标签数组
|
||||
export const getSensitiveWordTags = () => {
|
||||
export const getSensitiveWordTagList = () => {
|
||||
return request.get({ url: '/system/sensitive-word/get-tags' })
|
||||
}
|
||||
|
||||
|
4
src/types/auto-components.d.ts
vendored
4
src/types/auto-components.d.ts
vendored
@ -54,11 +54,13 @@ declare module '@vue/runtime-core' {
|
||||
ElIcon: typeof import('element-plus/es')['ElIcon']
|
||||
ElImageViewer: typeof import('element-plus/es')['ElImageViewer']
|
||||
ElInput: typeof import('element-plus/es')['ElInput']
|
||||
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']
|
||||
ElLink: typeof import('element-plus/es')['ElLink']
|
||||
ElOption: typeof import('element-plus/es')['ElOption']
|
||||
ElPagination: typeof import('element-plus/es')['ElPagination']
|
||||
ElPopover: typeof import('element-plus/es')['ElPopover']
|
||||
ElRadio: typeof import('element-plus/es')['ElRadio']
|
||||
ElRadioButton: typeof import('element-plus/es')['ElRadioButton']
|
||||
ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
|
||||
ElRow: typeof import('element-plus/es')['ElRow']
|
||||
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
|
||||
@ -72,6 +74,8 @@ declare module '@vue/runtime-core' {
|
||||
ElTag: typeof import('element-plus/es')['ElTag']
|
||||
ElTooltip: typeof import('element-plus/es')['ElTooltip']
|
||||
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']
|
||||
Error: typeof import('./../components/Error/src/Error.vue')['default']
|
||||
FlowCondition: typeof import('./../components/bpmnProcessDesigner/package/penal/flow-condition/FlowCondition.vue')['default']
|
||||
|
@ -133,7 +133,6 @@
|
||||
import type { FormExpose } from '@/components/Form'
|
||||
// 业务相关的 import
|
||||
import * as ClientApi from '@/api/system/oauth2/client'
|
||||
import { rules, allSchemas } from './client.data'
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
@ -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) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
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>
|
@ -33,7 +33,7 @@
|
||||
placeholder="请选择文章标签"
|
||||
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-form-item>
|
||||
</el-form>
|
||||
@ -47,7 +47,6 @@
|
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
import * as SensitiveWordApi from '@/api/system/sensitiveWord'
|
||||
import { CommonStatusEnum } from '@/utils/constants'
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
@ -67,11 +66,10 @@ const formRules = reactive({
|
||||
tags: [{ required: true, message: '标签不能为空', trigger: 'blur' }]
|
||||
})
|
||||
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) => {
|
||||
tags.value = paramTags
|
||||
const open = async (type: string, id?: number) => {
|
||||
modelVisible.value = true
|
||||
modelTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
@ -81,13 +79,14 @@ const openModal = async (type: string, paramTags: string[], id?: number) => {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await SensitiveWordApi.getSensitiveWord(id)
|
||||
console.log(formData.value)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
// 获得 Tag 标签列表
|
||||
tagList.value = await SensitiveWordApi.getSensitiveWordTagList()
|
||||
}
|
||||
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
@ -101,10 +100,10 @@ const submitForm = async () => {
|
||||
try {
|
||||
const data = formData.value as unknown as SensitiveWordApi.SensitiveWordVO
|
||||
if (formType.value === 'create') {
|
||||
await SensitiveWordApi.createSensitiveWord(data) // TODO @blue-syd:去掉 API 后缀
|
||||
await SensitiveWordApi.createSensitiveWord(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await SensitiveWordApi.updateSensitiveWord(data) // TODO @blue-syd:去掉 API 后缀
|
||||
await SensitiveWordApi.updateSensitiveWord(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
modelVisible.value = false
|
@ -1,6 +1,5 @@
|
||||
<template>
|
||||
<!-- 对话框(测试敏感词) -->
|
||||
<Dialog :title="modelTitle" v-model="modelVisible">
|
||||
<Dialog title="检测敏感词" v-model="modelVisible">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
@ -17,10 +16,10 @@
|
||||
multiple
|
||||
filterable
|
||||
allow-create
|
||||
placeholder="请选择文章标签"
|
||||
placeholder="请选择标签"
|
||||
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-form-item>
|
||||
</el-form>
|
||||
@ -34,13 +33,10 @@
|
||||
</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: []
|
||||
@ -50,14 +46,16 @@ const formRules = reactive({
|
||||
tags: [{ required: true, message: '标签不能为空', trigger: 'blur' }]
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
const tagList = ref([]) // 标签数组
|
||||
|
||||
/** 打开弹窗 */
|
||||
const openModal = async (paramTags: string[]) => {
|
||||
tags.value = paramTags
|
||||
const open = async () => {
|
||||
modelVisible.value = true
|
||||
resetForm()
|
||||
// 获得 Tag 标签列表
|
||||
tagList.value = await SensitiveWordApi.getSensitiveWordTagList()
|
||||
}
|
||||
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 提交表单 */
|
||||
const submitForm = async () => {
|
@ -1,13 +1,20 @@
|
||||
<template>
|
||||
<!-- 搜索 -->
|
||||
<content-wrap>
|
||||
<el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true">
|
||||
<!-- 搜索工作栏 -->
|
||||
<ContentWrap>
|
||||
<el-form
|
||||
class="-mb-15px"
|
||||
:model="queryParams"
|
||||
ref="queryFormRef"
|
||||
:inline="true"
|
||||
label-width="68px"
|
||||
>
|
||||
<el-form-item label="敏感词" prop="name">
|
||||
<el-input
|
||||
v-model="queryParams.name"
|
||||
placeholder="请输入敏感词"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="标签" prop="tag">
|
||||
@ -16,17 +23,19 @@
|
||||
placeholder="请选择标签"
|
||||
clearable
|
||||
@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-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="queryParams.status" placeholder="请选择启用状态" clearable>
|
||||
<el-option
|
||||
v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
|
||||
:key="parseInt(dict.value)"
|
||||
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="parseInt(dict.value)"
|
||||
:value="dict.value"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
@ -38,6 +47,7 @@
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
@ -46,13 +56,13 @@
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
@click="openModal('create')"
|
||||
@click="openForm('create')"
|
||||
v-hasPermi="['system:sensitive-word:create']"
|
||||
>
|
||||
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||
</el-button>
|
||||
<el-button
|
||||
type="warning"
|
||||
type="success"
|
||||
plain
|
||||
@click="handleExport"
|
||||
:loading="exportLoading"
|
||||
@ -60,15 +70,15 @@
|
||||
>
|
||||
<Icon icon="ep:download" class="mr-5px" /> 导出
|
||||
</el-button>
|
||||
<el-button type="success" plain @click="handleTest">
|
||||
<el-button type="warning" plain @click="openTestForm">
|
||||
<Icon icon="ep:document-checked" class="mr-5px" /> 测试
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</content-wrap>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 列表 -->
|
||||
<content-wrap>
|
||||
<ContentWrap>
|
||||
<el-table v-loading="loading" :data="list">
|
||||
<el-table-column label="编号" align="center" prop="id" />
|
||||
<el-table-column label="敏感词" align="center" prop="name" />
|
||||
@ -81,15 +91,13 @@
|
||||
<el-table-column label="标签" align="center" prop="tags">
|
||||
<template #default="scope">
|
||||
<el-tag
|
||||
:disable-transitions="true"
|
||||
:key="index"
|
||||
v-for="(tag, index) in scope.row.tags"
|
||||
:index="index"
|
||||
class="mr-5px"
|
||||
v-for="tag in scope.row.tags"
|
||||
:key="tag"
|
||||
:disable-transitions="true"
|
||||
>
|
||||
{{ tag }}
|
||||
</el-tag>
|
||||
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
@ -104,7 +112,7 @@
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openModal('update', scope.row.id)"
|
||||
@click="openForm('update', scope.row.id)"
|
||||
v-hasPermi="['infra:config:update']"
|
||||
>
|
||||
编辑
|
||||
@ -127,22 +135,21 @@
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</content-wrap>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<SensitiveWordForm ref="modalRef" @success="getList" />
|
||||
<SensitiveWordForm ref="formRef" @success="getList" />
|
||||
|
||||
<!-- 表单弹窗:测试敏感词 -->
|
||||
<SensitiveWordTestForm ref="modalTestRef" />
|
||||
<SensitiveWordTestForm ref="testFormRef" />
|
||||
</template>
|
||||
<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 download from '@/utils/download'
|
||||
import * as SensitiveWordApi from '@/api/system/sensitiveWord'
|
||||
import SensitiveWordForm from './form.vue' // TODO @blue-syd:组件名不对
|
||||
import SensitiveWordTestForm from './testForm.vue'
|
||||
|
||||
import SensitiveWordForm from './SensitiveWordForm.vue'
|
||||
import SensitiveWordTestForm from './SensitiveWordTestForm.vue'
|
||||
const message = useMessage() // 消息弹窗
|
||||
const { t } = useI18n() // 国际化
|
||||
|
||||
@ -159,13 +166,13 @@ const queryParams = reactive({
|
||||
})
|
||||
const queryFormRef = ref() // 搜索的表单
|
||||
const exportLoading = ref(false) // 导出的加载中
|
||||
const tags = ref([])
|
||||
const tagList = ref([]) // 标签数组
|
||||
|
||||
/** 查询参数列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await SensitiveWordApi.getSensitiveWordPage(queryParams) // TODO @blue-syd:去掉 API 后缀哈
|
||||
const data = await SensitiveWordApi.getSensitiveWordPage(queryParams)
|
||||
list.value = data.list
|
||||
total.value = data.total
|
||||
} finally {
|
||||
@ -186,16 +193,15 @@ const resetQuery = () => {
|
||||
}
|
||||
|
||||
/** 添加/修改操作 */
|
||||
const modalRef = ref()
|
||||
const openModal = (type: string, id?: number) => {
|
||||
modalRef.value.openModal(type, tags.value, id)
|
||||
const formRef = ref()
|
||||
const openForm = (type: string, id?: number) => {
|
||||
formRef.value.open(type, id)
|
||||
}
|
||||
|
||||
// TODO @blue-syd:还少一个【测试】按钮的功能,参见 http://dashboard.yudao.iocoder.cn/system/sensitive-word
|
||||
/* 测试敏感词按钮操作 */
|
||||
const modalTestRef = ref()
|
||||
const handleTest = () => {
|
||||
modalTestRef.value.openModal(tags.value)
|
||||
/** 测试敏感词按钮操作 */
|
||||
const testFormRef = ref()
|
||||
const openTestForm = () => {
|
||||
testFormRef.value.open()
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
@ -218,7 +224,7 @@ const handleExport = async () => {
|
||||
await message.exportConfirm()
|
||||
// 发起导出
|
||||
exportLoading.value = true
|
||||
const data = await SensitiveWordApi.exportSensitiveWord(queryParams) // TODO @blue-syd:去掉 API 后缀哈
|
||||
const data = await SensitiveWordApi.exportSensitiveWord(queryParams)
|
||||
download.excel(data, '敏感词.xls')
|
||||
} catch {
|
||||
} finally {
|
||||
@ -226,14 +232,10 @@ const handleExport = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** 获得 Tag 标签列表 */
|
||||
const getTags = async () => {
|
||||
tags.value = await SensitiveWordApi.getSensitiveWordTags() // TODO @blue-syd:去掉 API 后缀哈
|
||||
}
|
||||
|
||||
/** 初始化 **/
|
||||
onMounted(() => {
|
||||
getTags()
|
||||
getList()
|
||||
onMounted(async () => {
|
||||
await getList()
|
||||
// 获得 Tag 标签列表
|
||||
tagList.value = await SensitiveWordApi.getSensitiveWordTagList()
|
||||
})
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user