feat: SensitiveWord init
parent
91163752f3
commit
bb9ef8bd3f
|
@ -21,6 +21,15 @@ export const useRender = {
|
|||
return h('span', text)
|
||||
}
|
||||
},
|
||||
renderTags: (texts: string[]) => {
|
||||
if (texts) {
|
||||
return h('div', null, [
|
||||
texts.map((text) => {
|
||||
return h(Tag, null, () => text)
|
||||
})
|
||||
])
|
||||
}
|
||||
},
|
||||
renderDate: (text, format?) => {
|
||||
if (!format) {
|
||||
return dayjs(text).format('YYYY-MM-DD HH:mm:ss')
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
<template>
|
||||
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
|
||||
<BasicForm @register="registerForm" />
|
||||
</BasicModal>
|
||||
</template>
|
||||
<script lang="ts" setup name="SensitiveWordModal">
|
||||
import { ref, computed, unref } from 'vue'
|
||||
import { BasicModal, useModalInner } from '@/components/Modal'
|
||||
import { BasicForm, useForm } from '@/components/Form'
|
||||
import { formSchema } from './sensitiveWord.data'
|
||||
import { createSensitiveWordApi, getSensitiveWordApi, updateSensitiveWordApi } from '@/api/system/sensitiveWord'
|
||||
|
||||
const emit = defineEmits(['success', 'register'])
|
||||
const isUpdate = ref(true)
|
||||
const rowId = ref()
|
||||
|
||||
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
|
||||
labelWidth: 100,
|
||||
baseColProps: { span: 24 },
|
||||
schemas: formSchema,
|
||||
showActionButtonGroup: false,
|
||||
actionColOptions: {
|
||||
span: 23
|
||||
}
|
||||
})
|
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
||||
resetFields()
|
||||
setModalProps({ confirmLoading: false })
|
||||
isUpdate.value = !!data?.isUpdate
|
||||
|
||||
if (unref(isUpdate)) {
|
||||
const res = await getSensitiveWordApi(data.record.id)
|
||||
rowId.value = res.id
|
||||
setFieldsValue({
|
||||
...res
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const getTitle = computed(() => (!unref(isUpdate) ? '新增敏感词' : '编辑敏感词'))
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
const values = await validate()
|
||||
setModalProps({ confirmLoading: true })
|
||||
if (unref(isUpdate)) {
|
||||
await updateSensitiveWordApi(values)
|
||||
} else {
|
||||
await createSensitiveWordApi(values)
|
||||
}
|
||||
closeModal()
|
||||
emit('success')
|
||||
} finally {
|
||||
setModalProps({ confirmLoading: false })
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -1,3 +1,102 @@
|
|||
<template>
|
||||
<div>index</div>
|
||||
<div>
|
||||
<BasicTable @register="registerTable">
|
||||
<template #toolbar>
|
||||
<a-button type="primary" @click="handleCreate"> 新增 </a-button>
|
||||
<a-button type="warning" @click="handleExport"> 导出 </a-button>
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'action'">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
icon: 'clarity:note-edit-line',
|
||||
onClick: handleEdit.bind(null, record)
|
||||
},
|
||||
{
|
||||
icon: 'ant-design:delete-outlined',
|
||||
color: 'error',
|
||||
popConfirm: {
|
||||
title: '是否确认删除',
|
||||
placement: 'left',
|
||||
confirm: handleDelete.bind(null, record)
|
||||
}
|
||||
}
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<SensitiveWordModel @register="registerModal" @success="reload()" />
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup name="SensitiveWord">
|
||||
import { BasicTable, useTable, TableAction } from '@/components/Table'
|
||||
import {
|
||||
SensitiveWordExportReqVO,
|
||||
deleteSensitiveWordApi,
|
||||
exportSensitiveWordApi,
|
||||
getSensitiveWordPageApi
|
||||
} from '@/api/system/sensitiveWord'
|
||||
import { useModal } from '@/components/Modal'
|
||||
import SensitiveWordModel from './SensitiveWordModel.vue'
|
||||
import { columns, searchFormSchema } from './sensitiveWord.data'
|
||||
import { useI18n } from '@/hooks/web/useI18n'
|
||||
import { useMessage } from '@/hooks/web/useMessage'
|
||||
|
||||
const { t } = useI18n()
|
||||
const { createConfirm, createMessage } = useMessage()
|
||||
const [registerModal, { openModal }] = useModal()
|
||||
const [registerTable, { getForm, reload }] = useTable({
|
||||
title: '敏感词列表',
|
||||
api: getSensitiveWordPageApi,
|
||||
columns,
|
||||
formConfig: {
|
||||
labelWidth: 120,
|
||||
schemas: searchFormSchema
|
||||
},
|
||||
useSearchForm: true,
|
||||
showTableSetting: true,
|
||||
showIndexColumn: false,
|
||||
actionColumn: {
|
||||
width: 120,
|
||||
title: '操作',
|
||||
dataIndex: 'action',
|
||||
fixed: 'right'
|
||||
}
|
||||
})
|
||||
|
||||
function handleCreate() {
|
||||
openModal(true, {
|
||||
isUpdate: false
|
||||
})
|
||||
}
|
||||
|
||||
function handleEdit(record: Recordable) {
|
||||
openModal(true, {
|
||||
record,
|
||||
isUpdate: true
|
||||
})
|
||||
}
|
||||
|
||||
async function handleExport() {
|
||||
createConfirm({
|
||||
title: '导出',
|
||||
iconType: 'warning',
|
||||
content: '是否要导出数据?',
|
||||
async onOk() {
|
||||
await exportSensitiveWordApi(getForm().getFieldsValue() as SensitiveWordExportReqVO)
|
||||
createMessage.success(t('common.exportSuccessText'))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function handleDelete(record: Recordable) {
|
||||
console.log(record)
|
||||
const res = await deleteSensitiveWordApi(record.id)
|
||||
if (res) {
|
||||
createMessage.success('删除成功')
|
||||
reload()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
import { BasicColumn, FormSchema, useRender } from '@/components/Table'
|
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
|
||||
export const columns: BasicColumn[] = [
|
||||
{
|
||||
title: '编号',
|
||||
dataIndex: 'id',
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
title: '敏感词',
|
||||
dataIndex: 'name',
|
||||
width: 180
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 180,
|
||||
customRender: ({ text }) => {
|
||||
return useRender.renderDict(text, DICT_TYPE.COMMON_STATUS)
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'description',
|
||||
width: 200
|
||||
},
|
||||
{
|
||||
title: '标签',
|
||||
dataIndex: 'tags',
|
||||
width: 180,
|
||||
customRender: ({ text }) => {
|
||||
return useRender.renderTags(text)
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
width: 180,
|
||||
customRender: ({ text }) => {
|
||||
return useRender.renderDate(text)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
export const searchFormSchema: FormSchema[] = [
|
||||
{
|
||||
label: '敏感词',
|
||||
field: 'name',
|
||||
component: 'Input',
|
||||
colProps: { span: 8 }
|
||||
},
|
||||
{
|
||||
label: '标签',
|
||||
field: 'tag',
|
||||
component: 'Input',
|
||||
colProps: { span: 8 }
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS)
|
||||
},
|
||||
colProps: { span: 8 }
|
||||
},
|
||||
{
|
||||
label: '创建时间',
|
||||
field: 'createTime',
|
||||
component: 'RangePicker',
|
||||
colProps: { span: 8 }
|
||||
}
|
||||
]
|
||||
|
||||
export const formSchema: FormSchema[] = [
|
||||
{
|
||||
label: '编号',
|
||||
field: 'id',
|
||||
show: false,
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
label: '敏感词',
|
||||
field: 'name',
|
||||
required: true,
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
field: 'status',
|
||||
component: 'Select',
|
||||
defaultValue: 0,
|
||||
componentProps: {
|
||||
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS)
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '备注',
|
||||
field: 'remark',
|
||||
component: 'InputTextArea'
|
||||
},
|
||||
{
|
||||
label: '标签',
|
||||
field: 'tags',
|
||||
required: true,
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
mode: 'tags',
|
||||
options: []
|
||||
}
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue