4 changed files with 357 additions and 1 deletions
@ -0,0 +1,37 @@
|
||||
<template> |
||||
<div class="m-4 mr-0 overflow-hidden bg-white"> |
||||
<BasicTree |
||||
title="部门列表" |
||||
toolbar |
||||
search |
||||
treeWrapperClassName="h-[calc(100%-35px)] overflow-auto" |
||||
:clickRowToExpand="false" |
||||
:treeData="treeData" |
||||
:fieldNames="{ key: 'id', title: 'name' }" |
||||
@select="handleSelect" |
||||
/> |
||||
</div> |
||||
</template> |
||||
<script lang="ts" setup name="DeptTree"> |
||||
import { onMounted, ref } from 'vue' |
||||
|
||||
import { BasicTree, TreeItem } from '@/components/Tree' |
||||
import { listSimpleDeptApi } from '@/api/system/dept' |
||||
import { handleTree } from '@/utils/tree' |
||||
|
||||
const emit = defineEmits(['select']) |
||||
const treeData = ref<TreeItem[]>([]) |
||||
|
||||
async function fetch() { |
||||
const res = await listSimpleDeptApi() |
||||
treeData.value = handleTree(res, 'id') |
||||
} |
||||
|
||||
function handleSelect(keys) { |
||||
emit('select', keys[0]) |
||||
} |
||||
|
||||
onMounted(() => { |
||||
fetch() |
||||
}) |
||||
</script> |
@ -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="UserModal"> |
||||
import { ref, computed, unref } from 'vue' |
||||
import { BasicModal, useModalInner } from '@/components/Modal' |
||||
import { BasicForm, useForm } from '@/components/Form' |
||||
import { formSchema } from './user.data' |
||||
import { createUserApi, getUserApi, updateUserApi } from '@/api/system/user' |
||||
|
||||
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 getUserApi(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 updateUserApi(values) |
||||
} else { |
||||
await createUserApi(values) |
||||
} |
||||
closeModal() |
||||
emit('success') |
||||
} finally { |
||||
setModalProps({ confirmLoading: false }) |
||||
} |
||||
} |
||||
</script> |
@ -1,3 +1,101 @@
|
||||
<template> |
||||
<div>开发中</div> |
||||
<PageWrapper dense contentFullHeight fixedHeight contentClass="flex"> |
||||
<DeptTree class="w-1/4 xl:w-1/5" @select="handleSelect" /> |
||||
<BasicTable @register="registerTable" class="w-3/4 xl:w-4/5" :searchInfo="searchInfo"> |
||||
<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', |
||||
tooltip: '编辑用户资料', |
||||
onClick: handleEdit.bind(null, record) |
||||
}, |
||||
{ |
||||
icon: 'ant-design:delete-outlined', |
||||
color: 'error', |
||||
tooltip: '删除此账号', |
||||
popConfirm: { |
||||
title: '是否确认删除', |
||||
placement: 'left', |
||||
confirm: handleDelete.bind(null, record) |
||||
} |
||||
} |
||||
]" |
||||
/> |
||||
</template> |
||||
</template> |
||||
</BasicTable> |
||||
<UserModel @register="registerModal" @success="handleSuccess" /> |
||||
</PageWrapper> |
||||
</template> |
||||
<script lang="ts" setup name="User"> |
||||
import { reactive } from 'vue' |
||||
import { BasicTable, useTable, TableAction } from '@/components/Table' |
||||
import { useModal } from '@/components/Modal' |
||||
import UserModel from './UserModel.vue' |
||||
import { PageWrapper } from '@/components/Page' |
||||
import DeptTree from './DeptTree.vue' |
||||
import { columns, searchFormSchema } from './user.data' |
||||
import { getUserPageApi } from '@/api/system/user' |
||||
|
||||
const [registerModal, { openModal }] = useModal() |
||||
const searchInfo = reactive<Recordable>({}) |
||||
|
||||
const [registerTable, { reload, updateTableDataRecord }] = useTable({ |
||||
title: '账号列表', |
||||
api: getUserPageApi, |
||||
columns, |
||||
formConfig: { |
||||
labelWidth: 120, |
||||
schemas: searchFormSchema, |
||||
autoSubmitOnEnter: true |
||||
}, |
||||
useSearchForm: true, |
||||
showTableSetting: true, |
||||
showIndexColumn: false, |
||||
actionColumn: { |
||||
width: 120, |
||||
title: '操作', |
||||
dataIndex: 'action', |
||||
fixed: 'right' |
||||
} |
||||
}) |
||||
|
||||
function handleCreate() { |
||||
openModal(true, { |
||||
isUpdate: false |
||||
}) |
||||
} |
||||
|
||||
function handleEdit(record: Recordable) { |
||||
console.log(record) |
||||
openModal(true, { |
||||
record, |
||||
isUpdate: true |
||||
}) |
||||
} |
||||
|
||||
function handleDelete(record: Recordable) { |
||||
console.log(record) |
||||
} |
||||
|
||||
function handleSuccess({ isUpdate, values }) { |
||||
if (isUpdate) { |
||||
// 演示不刷新表格直接更新内部数据。 |
||||
// 注意:updateTableDataRecord要求表格的rowKey属性为string并且存在于每一行的record的keys中 |
||||
const result = updateTableDataRecord(values.id, values) |
||||
console.log(result) |
||||
} else { |
||||
reload() |
||||
} |
||||
} |
||||
|
||||
function handleSelect(deptId = '') { |
||||
searchInfo.deptId = deptId |
||||
reload() |
||||
} |
||||
</script> |
||||
|
@ -0,0 +1,163 @@
|
||||
import { listSimpleDeptApi } from '@/api/system/dept' |
||||
import { listSimplePostsApi } from '@/api/system/post' |
||||
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: 'username', |
||||
width: 180 |
||||
}, |
||||
{ |
||||
title: '用户昵称', |
||||
dataIndex: 'nickname', |
||||
width: 100 |
||||
}, |
||||
{ |
||||
title: '部门', |
||||
dataIndex: 'dept.name', |
||||
width: 120 |
||||
}, |
||||
{ |
||||
title: '手机号码', |
||||
dataIndex: 'mobile', |
||||
width: 120 |
||||
}, |
||||
{ |
||||
title: '状态', |
||||
dataIndex: 'status', |
||||
width: 180, |
||||
customRender: ({ text }) => { |
||||
return useRender.renderDict(text, DICT_TYPE.COMMON_STATUS) |
||||
} |
||||
}, |
||||
{ |
||||
title: '创建时间', |
||||
dataIndex: 'createTime', |
||||
width: 180, |
||||
customRender: ({ text }) => { |
||||
return useRender.renderDate(text) |
||||
} |
||||
} |
||||
] |
||||
|
||||
export const searchFormSchema: FormSchema[] = [ |
||||
{ |
||||
label: '用户名称', |
||||
field: 'username', |
||||
component: 'Input', |
||||
colProps: { span: 8 } |
||||
}, |
||||
{ |
||||
label: '手机号码', |
||||
field: 'mobile', |
||||
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: 'nickname', |
||||
required: true, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '归属部门', |
||||
field: 'deptId', |
||||
required: true, |
||||
component: 'ApiTreeSelect', |
||||
componentProps: { |
||||
api: () => listSimpleDeptApi(), |
||||
fieldNames: { |
||||
label: 'name', |
||||
key: 'id', |
||||
value: 'id' |
||||
}, |
||||
handleTree: 'id' |
||||
} |
||||
}, |
||||
{ |
||||
label: '手机号码', |
||||
field: 'mobile', |
||||
required: true, |
||||
component: 'InputNumber' |
||||
}, |
||||
{ |
||||
label: '邮箱', |
||||
field: 'email', |
||||
required: true, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '用户名称', |
||||
field: 'username', |
||||
component: 'Input', |
||||
ifShow: ({ values }) => values.id === undefined |
||||
}, |
||||
{ |
||||
label: '用户密码', |
||||
field: 'password', |
||||
component: 'InputPassword', |
||||
ifShow: ({ values }) => values.id === undefined |
||||
}, |
||||
{ |
||||
label: '用户性别', |
||||
field: 'sex', |
||||
component: 'Select', |
||||
componentProps: { |
||||
options: getIntDictOptions(DICT_TYPE.SYSTEM_USER_SEX) |
||||
} |
||||
}, |
||||
{ |
||||
label: '岗位', |
||||
field: 'postIds', |
||||
component: 'ApiSelect', |
||||
componentProps: { |
||||
api: () => listSimplePostsApi(), |
||||
labelField: 'name', |
||||
valueField: 'id' |
||||
} |
||||
}, |
||||
{ |
||||
label: '状态', |
||||
field: 'status', |
||||
component: 'Select', |
||||
componentProps: { |
||||
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS) |
||||
} |
||||
}, |
||||
{ |
||||
label: '备注', |
||||
field: 'remark', |
||||
component: 'InputTextArea' |
||||
} |
||||
] |
Reference in new issue