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

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

@ -26,84 +26,18 @@
</template>
</template>
</BasicTable>
<PostModel @register="registerModal" @success="handleSuccess" />
<PostModel @register="registerModal" @success="reload()" />
</div>
</template>
<script lang="ts" setup name="Post">
import { BasicTable, useTable, useRender, TableAction, BasicColumn, FormSchema } from '@/components/Table'
import { getPostPageApi } from '@/api/system/post'
import { BasicTable, useTable, TableAction } from '@/components/Table'
import { deletePostApi, getPostPageApi } from '@/api/system/post'
import { useModal } from '@/components/Modal'
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[] = [
{
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 { createMessage } = useMessage()
const [registerModal, { openModal }] = useModal()
const [registerTable, { reload }] = useTable({
title: '岗位列表',
@ -115,8 +49,7 @@ const [registerTable, { reload }] = useTable({
},
useSearchForm: true,
showTableSetting: true,
// bordered: true,
// showIndexColumn: false,
showIndexColumn: false,
actionColumn: {
width: 120,
title: '操作',
@ -138,11 +71,12 @@ function handleEdit(record: Recordable) {
})
}
function handleDelete(record: Recordable) {
async function handleDelete(record: Recordable) {
console.log(record)
}
function handleSuccess() {
reload()
const res = await deletePostApi(record.id)
if (res) {
createMessage.success('删除成功')
reload()
}
}
</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