5 changed files with 231 additions and 5 deletions
@ -0,0 +1,84 @@ |
|||||||
|
<template> |
||||||
|
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit"> |
||||||
|
<BasicForm @register="registerForm" /> |
||||||
|
</BasicModal> |
||||||
|
</template> |
||||||
|
<script lang="ts" setup name="PostModal"> |
||||||
|
import { ref, computed, unref } from 'vue' |
||||||
|
import { BasicModal, useModalInner } from '@/components/Modal' |
||||||
|
import { BasicForm, FormSchema, useForm } from '@/components/Form' |
||||||
|
|
||||||
|
const formSchema: FormSchema[] = [ |
||||||
|
{ |
||||||
|
field: 'name', |
||||||
|
label: '岗位名称', |
||||||
|
required: true, |
||||||
|
component: 'Input' |
||||||
|
}, |
||||||
|
{ |
||||||
|
field: 'code', |
||||||
|
label: '岗位编码', |
||||||
|
required: true, |
||||||
|
component: 'Input' |
||||||
|
}, |
||||||
|
{ |
||||||
|
field: 'status', |
||||||
|
label: '状态', |
||||||
|
component: 'RadioButtonGroup', |
||||||
|
defaultValue: '0', |
||||||
|
componentProps: { |
||||||
|
options: [ |
||||||
|
{ label: '启用', value: '0' }, |
||||||
|
{ label: '停用', value: '1' } |
||||||
|
] |
||||||
|
} |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '备注', |
||||||
|
field: 'remark', |
||||||
|
component: 'InputTextArea' |
||||||
|
} |
||||||
|
] |
||||||
|
|
||||||
|
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)) { |
||||||
|
rowId.value = data.record.id |
||||||
|
setFieldsValue({ |
||||||
|
...data.record |
||||||
|
}) |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增账号' : '编辑账号')) |
||||||
|
|
||||||
|
async function handleSubmit() { |
||||||
|
try { |
||||||
|
const values = await validate() |
||||||
|
setModalProps({ confirmLoading: true }) |
||||||
|
// TODO custom api |
||||||
|
console.log(values) |
||||||
|
closeModal() |
||||||
|
emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } }) |
||||||
|
} finally { |
||||||
|
setModalProps({ confirmLoading: false }) |
||||||
|
} |
||||||
|
} |
||||||
|
</script> |
@ -1,3 +1,144 @@ |
|||||||
<template> |
<template> |
||||||
<div>index</div> |
<div> |
||||||
|
<BasicTable @register="registerTable"> |
||||||
|
<template #toolbar> |
||||||
|
<a-button type="primary" @click="handleCreate"> 新增 </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> |
||||||
|
<PostModel @register="registerModal" @success="handleSuccess" /> |
||||||
|
</div> |
||||||
</template> |
</template> |
||||||
|
<script lang="ts" setup name="Post"> |
||||||
|
import { BasicTable, useTable, TableAction, BasicColumn, FormSchema } from '@/components/Table' |
||||||
|
import { getPostPageApi } from '@/api/system/post' |
||||||
|
import { useModal } from '@/components/Modal' |
||||||
|
import PostModel from './PostModel.vue' |
||||||
|
import dayjs from 'dayjs' |
||||||
|
|
||||||
|
const columns: BasicColumn[] = [ |
||||||
|
{ |
||||||
|
title: '岗位编号', |
||||||
|
dataIndex: 'id', |
||||||
|
width: 100 |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '岗位名称', |
||||||
|
dataIndex: 'name', |
||||||
|
width: 180 |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '岗位编码', |
||||||
|
dataIndex: 'code', |
||||||
|
width: 100 |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '岗位顺序', |
||||||
|
dataIndex: 'sort', |
||||||
|
width: 120 |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '状态', |
||||||
|
dataIndex: 'status', |
||||||
|
width: 180 |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '备注', |
||||||
|
dataIndex: 'remark' |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '创建时间', |
||||||
|
dataIndex: 'createTime', |
||||||
|
customRender: ({ text }) => { |
||||||
|
return dayjs(text).format('YYYY-MM-DD HH:mm:ss') |
||||||
|
} |
||||||
|
} |
||||||
|
] |
||||||
|
|
||||||
|
const searchFormSchema: FormSchema[] = [ |
||||||
|
{ |
||||||
|
field: 'name', |
||||||
|
label: '岗位名称', |
||||||
|
component: 'Input', |
||||||
|
colProps: { span: 8 } |
||||||
|
}, |
||||||
|
{ |
||||||
|
field: 'code', |
||||||
|
label: '岗位编码', |
||||||
|
component: 'Input' |
||||||
|
}, |
||||||
|
{ |
||||||
|
field: 'status', |
||||||
|
label: '状态', |
||||||
|
component: 'Select', |
||||||
|
componentProps: { |
||||||
|
options: [ |
||||||
|
{ label: '启用', value: '0' }, |
||||||
|
{ label: '停用', value: '1' } |
||||||
|
] |
||||||
|
}, |
||||||
|
colProps: { span: 8 } |
||||||
|
} |
||||||
|
] |
||||||
|
const [registerModal, { openModal }] = useModal() |
||||||
|
const [registerTable, { reload }] = useTable({ |
||||||
|
title: '岗位列表', |
||||||
|
api: getPostPageApi, |
||||||
|
columns, |
||||||
|
formConfig: { |
||||||
|
labelWidth: 120, |
||||||
|
schemas: searchFormSchema |
||||||
|
}, |
||||||
|
useSearchForm: true, |
||||||
|
showTableSetting: true, |
||||||
|
// bordered: 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 |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
function handleDelete(record: Recordable) { |
||||||
|
console.log(record) |
||||||
|
} |
||||||
|
|
||||||
|
function handleSuccess() { |
||||||
|
reload() |
||||||
|
} |
||||||
|
</script> |
||||||
|
Reference in new issue