feat: error code init
parent
8f33b3ff31
commit
fbb15cde59
|
@ -42,6 +42,7 @@ export const updateErrorCodeApi = (data: ErrorCodeVO) => {
|
|||
export const deleteErrorCodeApi = (id: number) => {
|
||||
return defHttp.delete({ url: '/system/error-code/delete?id=' + id })
|
||||
}
|
||||
|
||||
// 导出错误码
|
||||
export const excelErrorCodeApi = (params: ErrorCodePageReqVO) => {
|
||||
return defHttp.download({ url: '/system/error-code/export-excel', params })
|
||||
|
|
|
@ -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="ErrorCodeModal">
|
||||
import { ref, computed, unref } from 'vue'
|
||||
import { BasicModal, useModalInner } from '@/components/Modal'
|
||||
import { BasicForm, useForm } from '@/components/Form'
|
||||
import { formSchema } from './errorCode.data'
|
||||
import { createErrorCodeApi, getErrorCodeApi, updateErrorCodeApi } from '@/api/system/errorCode'
|
||||
|
||||
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 getErrorCodeApi(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 updateErrorCodeApi(values)
|
||||
} else {
|
||||
await createErrorCodeApi(values)
|
||||
}
|
||||
closeModal()
|
||||
emit('success')
|
||||
} finally {
|
||||
setModalProps({ confirmLoading: false })
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,114 @@
|
|||
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: 'type',
|
||||
width: 80,
|
||||
customRender: ({ text }) => {
|
||||
return useRender.renderDict(text, DICT_TYPE.SYSTEM_ERROR_CODE_TYPE)
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '应用名',
|
||||
dataIndex: 'applicationName',
|
||||
width: 200
|
||||
},
|
||||
{
|
||||
title: '错误码编码',
|
||||
dataIndex: 'code',
|
||||
width: 120
|
||||
},
|
||||
{
|
||||
title: '错误码提示',
|
||||
dataIndex: 'message',
|
||||
width: 300
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
dataIndex: 'memo',
|
||||
width: 200
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
width: 180,
|
||||
customRender: ({ text }) => {
|
||||
return useRender.renderDate(text)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
export const searchFormSchema: FormSchema[] = [
|
||||
{
|
||||
label: '错误码类型',
|
||||
field: 'type',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: getIntDictOptions(DICT_TYPE.SYSTEM_ERROR_CODE_TYPE)
|
||||
},
|
||||
colProps: { span: 8 }
|
||||
},
|
||||
{
|
||||
label: '应用名',
|
||||
field: 'applicationName',
|
||||
component: 'Input',
|
||||
colProps: { span: 8 }
|
||||
},
|
||||
{
|
||||
label: '错误码编码',
|
||||
field: 'code',
|
||||
component: 'Input',
|
||||
colProps: { span: 8 }
|
||||
},
|
||||
{
|
||||
label: '错误码提示',
|
||||
field: 'message',
|
||||
component: 'Input',
|
||||
colProps: { span: 8 }
|
||||
},
|
||||
{
|
||||
label: '创建时间',
|
||||
field: 'createTime',
|
||||
component: 'RangePicker',
|
||||
colProps: { span: 8 }
|
||||
}
|
||||
]
|
||||
|
||||
export const formSchema: FormSchema[] = [
|
||||
{
|
||||
label: '编号',
|
||||
field: 'id',
|
||||
show: false,
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
label: '应用名',
|
||||
field: 'applicationName',
|
||||
required: true,
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
label: '错误码编码',
|
||||
field: 'code',
|
||||
required: true,
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
label: '错误码提示',
|
||||
field: 'message',
|
||||
required: true,
|
||||
component: 'Input'
|
||||
},
|
||||
{
|
||||
label: '备注',
|
||||
field: 'memo',
|
||||
component: 'InputTextArea'
|
||||
}
|
||||
]
|
|
@ -1,3 +1,97 @@
|
|||
<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>
|
||||
<ErrorCodeModel @register="registerModal" @success="reload()" />
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup name="ErrorCode">
|
||||
import { BasicTable, useTable, TableAction } from '@/components/Table'
|
||||
import { ErrorCodePageReqVO, deleteErrorCodeApi, excelErrorCodeApi, getErrorCodePageApi } from '@/api/system/errorCode'
|
||||
import { useModal } from '@/components/Modal'
|
||||
import ErrorCodeModel from './ErrorCodeModel.vue'
|
||||
import { columns, searchFormSchema } from './errorCode.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: getErrorCodePageApi,
|
||||
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 excelErrorCodeApi(getForm().getFieldsValue() as ErrorCodePageReqVO)
|
||||
createMessage.success(t('common.exportSuccessText'))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function handleDelete(record: Recordable) {
|
||||
console.log(record)
|
||||
const res = await deleteErrorCodeApi(record.id)
|
||||
if (res) {
|
||||
createMessage.success('删除成功')
|
||||
reload()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue