Vue3 重构:Review 敏感词管理

This commit is contained in:
YunaiV 2023-03-19 21:30:53 +08:00
parent 45058a9a48
commit cf959599c6
2 changed files with 19 additions and 16 deletions

View File

@ -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) // 12 const formLoading = ref(false) // 12
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: []
} }

View File

@ -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>
&nbsp; &nbsp;
</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()