Browse Source

feat: post

main
xingyuv 2 years ago
parent
commit
198772973a
  1. 54
      src/views/system/post/PostModel.vue
  2. 92
      src/views/system/post/index.vue
  3. 109
      src/views/system/post/post.data.ts

54
src/views/system/post/PostModel.vue

@ -6,43 +6,13 @@
<script lang="ts" setup name="PostModal"> <script lang="ts" setup name="PostModal">
import { ref, computed, unref } from 'vue' import { ref, computed, unref } from 'vue'
import { BasicModal, useModalInner } from '@/components/Modal' import { BasicModal, useModalInner } from '@/components/Modal'
import { BasicForm, FormSchema, useForm } from '@/components/Form' import { BasicForm, useForm } from '@/components/Form'
import { formSchema } from './post.data'
const formSchema: FormSchema[] = [ import { createPostApi, getPostApi, updatePostApi } from '@/api/system/post'
{
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 emit = defineEmits(['success', 'register'])
const isUpdate = ref(true) const isUpdate = ref(true)
const rowId = ref('') const rowId = ref()
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({ const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
labelWidth: 100, labelWidth: 100,
@ -60,23 +30,27 @@ const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data
isUpdate.value = !!data?.isUpdate isUpdate.value = !!data?.isUpdate
if (unref(isUpdate)) { if (unref(isUpdate)) {
rowId.value = data.record.id const res = await getPostApi(data.record.id)
rowId.value = res.id
setFieldsValue({ setFieldsValue({
...data.record ...res
}) })
} }
}) })
const getTitle = computed(() => (!unref(isUpdate) ? '新增账号' : '编辑账号')) const getTitle = computed(() => (!unref(isUpdate) ? '新增岗位' : '编辑岗位'))
async function handleSubmit() { async function handleSubmit() {
try { try {
const values = await validate() const values = await validate()
setModalProps({ confirmLoading: true }) setModalProps({ confirmLoading: true })
// TODO custom api if (unref(isUpdate)) {
console.log(values) await updatePostApi(values)
} else {
await createPostApi(values)
}
closeModal() closeModal()
emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } }) emit('success')
} finally { } finally {
setModalProps({ confirmLoading: false }) setModalProps({ confirmLoading: false })
} }

92
src/views/system/post/index.vue

@ -26,84 +26,18 @@
</template> </template>
</template> </template>
</BasicTable> </BasicTable>
<PostModel @register="registerModal" @success="handleSuccess" /> <PostModel @register="registerModal" @success="reload()" />
</div> </div>
</template> </template>
<script lang="ts" setup name="Post"> <script lang="ts" setup name="Post">
import { BasicTable, useTable, useRender, TableAction, BasicColumn, FormSchema } from '@/components/Table' import { BasicTable, useTable, TableAction } from '@/components/Table'
import { getPostPageApi } from '@/api/system/post' import { deletePostApi, getPostPageApi } from '@/api/system/post'
import { useModal } from '@/components/Modal' import { useModal } from '@/components/Modal'
import PostModel from './PostModel.vue' import PostModel from './PostModel.vue'
import { DICT_TYPE } from '@/utils/dict' import { columns, searchFormSchema } from './post.data'
import { useMessage } from '@/hooks/web/useMessage'
const columns: BasicColumn[] = [ const { createMessage } = useMessage()
{
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,
customRender: ({ text }) => {
return useRender.renderDict(text, DICT_TYPE.COMMON_STATUS)
}
},
{
title: '备注',
dataIndex: 'remark'
},
{
title: '创建时间',
dataIndex: 'createTime',
customRender: ({ text }) => {
return useRender.renderDate(text)
}
}
]
const searchFormSchema: FormSchema[] = [
{
field: 'name',
label: '岗位名称',
component: 'Input',
colProps: { span: 8 }
},
{
field: 'code',
label: '岗位编码',
component: 'Input',
colProps: { span: 8 }
},
{
field: 'status',
label: '状态',
component: 'Select',
componentProps: {
options: [
{ label: '启用', value: '0' },
{ label: '停用', value: '1' }
]
},
colProps: { span: 8 }
}
]
const [registerModal, { openModal }] = useModal() const [registerModal, { openModal }] = useModal()
const [registerTable, { reload }] = useTable({ const [registerTable, { reload }] = useTable({
title: '岗位列表', title: '岗位列表',
@ -115,8 +49,7 @@ const [registerTable, { reload }] = useTable({
}, },
useSearchForm: true, useSearchForm: true,
showTableSetting: true, showTableSetting: true,
// bordered: true, showIndexColumn: false,
// showIndexColumn: false,
actionColumn: { actionColumn: {
width: 120, width: 120,
title: '操作', title: '操作',
@ -138,11 +71,12 @@ function handleEdit(record: Recordable) {
}) })
} }
function handleDelete(record: Recordable) { async function handleDelete(record: Recordable) {
console.log(record) console.log(record)
} const res = await deletePostApi(record.id)
if (res) {
function handleSuccess() { createMessage.success('删除成功')
reload() reload()
}
} }
</script> </script>

109
src/views/system/post/post.data.ts

@ -0,0 +1,109 @@
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: 'code',
width: 100
},
{
title: '岗位顺序',
dataIndex: 'sort',
width: 120
},
{
title: '状态',
dataIndex: 'status',
width: 180,
customRender: ({ text }) => {
return useRender.renderDict(text, DICT_TYPE.COMMON_STATUS)
}
},
{
title: '备注',
dataIndex: 'remark'
},
{
title: '创建时间',
dataIndex: 'createTime',
customRender: ({ text }) => {
return useRender.renderDate(text)
}
}
]
export const searchFormSchema: FormSchema[] = [
{
field: 'name',
label: '岗位名称',
component: 'Input',
colProps: { span: 8 }
},
{
field: 'code',
label: '岗位编码',
component: 'Input',
colProps: { span: 8 }
},
{
field: 'status',
label: '状态',
component: 'Select',
componentProps: {
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS)
},
colProps: { span: 8 }
}
]
export const formSchema: FormSchema[] = [
{
field: 'id',
label: '编号',
show: false,
component: 'Input'
},
{
field: 'name',
label: '岗位名称',
required: true,
component: 'Input'
},
{
field: 'code',
label: '岗位编码',
required: true,
component: 'Input'
},
{
field: 'sort',
label: '岗位顺序',
required: true,
component: 'InputNumber'
},
{
field: 'status',
label: '状态',
component: 'Select',
defaultValue: 0,
componentProps: {
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS)
}
},
{
label: '备注',
field: 'remark',
component: 'InputTextArea'
}
]
Loading…
Cancel
Save