Vue3 重构:Review 敏感词管理
parent
45058a9a48
commit
cf959599c6
|
@ -48,6 +48,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
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'
|
||||||
|
|
||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
const message = useMessage() // 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
|
@ -56,11 +57,10 @@ const modelVisible = ref(false) // 弹窗的是否展示
|
||||||
const modelTitle = ref('') // 弹窗的标题
|
const modelTitle = ref('') // 弹窗的标题
|
||||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||||
const tags = ref([])
|
|
||||||
const formData = ref({
|
const formData = ref({
|
||||||
id: undefined,
|
id: undefined,
|
||||||
name: '',
|
name: '',
|
||||||
status: true,
|
status: CommonStatusEnum.ENABLE,
|
||||||
description: '',
|
description: '',
|
||||||
tags: []
|
tags: []
|
||||||
})
|
})
|
||||||
|
@ -69,6 +69,7 @@ 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([]) // todo @blue-syd:在 openModal 里加载下
|
||||||
|
|
||||||
/** 打开弹窗 */
|
/** 打开弹窗 */
|
||||||
const openModal = async (type: string, id?: number) => {
|
const openModal = async (type: string, id?: number) => {
|
||||||
|
@ -101,10 +102,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.createSensitiveWordApi(data)
|
await SensitiveWordApi.createSensitiveWordApi(data) // TODO @blue-syd:去掉 API 后缀
|
||||||
message.success(t('common.createSuccess'))
|
message.success(t('common.createSuccess'))
|
||||||
} else {
|
} else {
|
||||||
await SensitiveWordApi.updateSensitiveWordApi(data)
|
await SensitiveWordApi.updateSensitiveWordApi(data) // TODO @blue-syd:去掉 API 后缀
|
||||||
message.success(t('common.updateSuccess'))
|
message.success(t('common.updateSuccess'))
|
||||||
}
|
}
|
||||||
modelVisible.value = false
|
modelVisible.value = false
|
||||||
|
@ -120,7 +121,7 @@ const resetForm = () => {
|
||||||
formData.value = {
|
formData.value = {
|
||||||
id: undefined,
|
id: undefined,
|
||||||
name: '',
|
name: '',
|
||||||
status: true,
|
status: CommonStatusEnum.ENABLE,
|
||||||
description: '',
|
description: '',
|
||||||
tags: []
|
tags: []
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
: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')]"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
|
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
|
||||||
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
||||||
|
@ -82,9 +81,11 @@
|
||||||
:key="index"
|
:key="index"
|
||||||
v-for="(tag, index) in scope.row.tags"
|
v-for="(tag, index) in scope.row.tags"
|
||||||
:index="index"
|
:index="index"
|
||||||
|
class="mr-5px"
|
||||||
>
|
>
|
||||||
{{ tag }}
|
{{ tag }}
|
||||||
</el-tag>
|
</el-tag>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column
|
<el-table-column
|
||||||
|
@ -132,14 +133,13 @@ import { DICT_TYPE, getDictOptions } 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 ConfigForm from './form.vue'
|
import ConfigForm from './form.vue' // TODO @blue-syd:组件名不对
|
||||||
const message = useMessage() // 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
|
|
||||||
const loading = ref(true) // 列表的加载中
|
const loading = ref(true) // 列表的加载中
|
||||||
const total = ref(0) // 列表的总页数
|
const total = ref(0) // 列表的总页数
|
||||||
const list = ref([]) // 列表的数据
|
const list = ref([]) // 列表的数据
|
||||||
const tags = ref([])
|
|
||||||
const queryParams = reactive({
|
const queryParams = reactive({
|
||||||
pageNo: 1,
|
pageNo: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
|
@ -150,12 +150,13 @@ const queryParams = reactive({
|
||||||
})
|
})
|
||||||
const queryFormRef = ref() // 搜索的表单
|
const queryFormRef = ref() // 搜索的表单
|
||||||
const exportLoading = ref(false) // 导出的加载中
|
const exportLoading = ref(false) // 导出的加载中
|
||||||
|
const tags = ref([])
|
||||||
|
|
||||||
/** 查询参数列表 */
|
/** 查询参数列表 */
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const data = await SensitiveWordApi.getSensitiveWordPageApi(queryParams)
|
const data = await SensitiveWordApi.getSensitiveWordPageApi(queryParams) // TODO @blue-syd:去掉 API 后缀哈
|
||||||
list.value = data.list
|
list.value = data.list
|
||||||
total.value = data.total
|
total.value = data.total
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -163,12 +164,6 @@ const getList = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 初始化标签select*/
|
|
||||||
const getTags = async () => {
|
|
||||||
const data = await SensitiveWordApi.getSensitiveWordTagsApi()
|
|
||||||
tags.value = data
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 搜索按钮操作 */
|
/** 搜索按钮操作 */
|
||||||
const handleQuery = () => {
|
const handleQuery = () => {
|
||||||
queryParams.pageNo = 1
|
queryParams.pageNo = 1
|
||||||
|
@ -187,6 +182,8 @@ const openModal = (type: string, id?: number) => {
|
||||||
modalRef.value.openModal(type, id)
|
modalRef.value.openModal(type, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @blue-syd:还少一个【测试】按钮的功能,参见 http://dashboard.yudao.iocoder.cn/system/sensitive-word
|
||||||
|
|
||||||
/** 删除按钮操作 */
|
/** 删除按钮操作 */
|
||||||
const handleDelete = async (id: number) => {
|
const handleDelete = async (id: number) => {
|
||||||
try {
|
try {
|
||||||
|
@ -207,7 +204,7 @@ const handleExport = async () => {
|
||||||
await message.exportConfirm()
|
await message.exportConfirm()
|
||||||
// 发起导出
|
// 发起导出
|
||||||
exportLoading.value = true
|
exportLoading.value = true
|
||||||
const data = await SensitiveWordApi.exportSensitiveWordApi(queryParams)
|
const data = await SensitiveWordApi.exportSensitiveWordApi(queryParams) // TODO @blue-syd:去掉 API 后缀哈
|
||||||
download.excel(data, '敏感词.xls')
|
download.excel(data, '敏感词.xls')
|
||||||
} catch {
|
} catch {
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -215,6 +212,11 @@ const handleExport = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 获得 Tag 标签列表 */
|
||||||
|
const getTags = async () => {
|
||||||
|
tags.value = await SensitiveWordApi.getSensitiveWordTagsApi() // TODO @blue-syd:去掉 API 后缀哈
|
||||||
|
}
|
||||||
|
|
||||||
/** 初始化 **/
|
/** 初始化 **/
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getTags()
|
getTags()
|
||||||
|
|
Loading…
Reference in New Issue