7 changed files with 285 additions and 256 deletions
@ -1,63 +0,0 @@ |
|||||||
<template> |
|
||||||
<PageWrapper |
|
||||||
:title="`用户` + userId + `的资料`" |
|
||||||
content="这是用户资料详情页面。本页面仅用于演示相同路由在tab中打开多个页面并且显示不同的数据" |
|
||||||
contentBackground |
|
||||||
@back="goBack" |
|
||||||
> |
|
||||||
<template #extra> |
|
||||||
<a-button type="primary" danger> 禁用账号 </a-button> |
|
||||||
<a-button type="primary"> 修改密码 </a-button> |
|
||||||
</template> |
|
||||||
<template #footer> |
|
||||||
<a-tabs default-active-key="detail" v-model:activeKey="currentKey"> |
|
||||||
<a-tab-pane key="detail" tab="用户资料" /> |
|
||||||
<a-tab-pane key="logs" tab="操作日志" /> |
|
||||||
</a-tabs> |
|
||||||
</template> |
|
||||||
<div class="pt-4 m-4 desc-wrap"> |
|
||||||
<template v-if="currentKey == 'detail'"> |
|
||||||
<div v-for="i in 10" :key="i">这是用户{{ userId }}资料Tab</div> |
|
||||||
</template> |
|
||||||
<template v-if="currentKey == 'logs'"> |
|
||||||
<div v-for="i in 10" :key="i">这是用户{{ userId }}操作日志Tab</div> |
|
||||||
</template> |
|
||||||
</div> |
|
||||||
</PageWrapper> |
|
||||||
</template> |
|
||||||
|
|
||||||
<script> |
|
||||||
import { defineComponent, ref } from 'vue'; |
|
||||||
import { useRoute } from 'vue-router'; |
|
||||||
import { PageWrapper } from '/@/components/Page'; |
|
||||||
import { useGo } from '/@/hooks/web/usePage'; |
|
||||||
import { useTabs } from '/@/hooks/web/useTabs'; |
|
||||||
import { Tabs } from 'ant-design-vue'; |
|
||||||
|
|
||||||
export default defineComponent({ |
|
||||||
name: 'AccountDetail', |
|
||||||
components: { PageWrapper, ATabs: Tabs, ATabPane: Tabs.TabPane }, |
|
||||||
setup() { |
|
||||||
const route = useRoute(); |
|
||||||
const go = useGo(); |
|
||||||
// 此处可以得到用户ID |
|
||||||
const userId = ref(route.params?.id); |
|
||||||
const currentKey = ref('detail'); |
|
||||||
const { setTitle } = useTabs(); |
|
||||||
// TODO |
|
||||||
// 本页代码仅作演示,实际应当通过userId从接口获得用户的相关资料 |
|
||||||
|
|
||||||
// 设置Tab的标题(不会影响页面标题) |
|
||||||
setTitle('详情:用户' + userId.value); |
|
||||||
|
|
||||||
// 页面左侧点击返回链接时的操作 |
|
||||||
function goBack() { |
|
||||||
// 本例的效果时点击返回始终跳转到账号列表页,实际应用时可返回上一页 |
|
||||||
go('/system/account'); |
|
||||||
} |
|
||||||
return { userId, currentKey, goBack }; |
|
||||||
}, |
|
||||||
}); |
|
||||||
</script> |
|
||||||
|
|
||||||
<style></style> |
|
@ -1,73 +1,95 @@ |
|||||||
<template> |
<template> |
||||||
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit"> |
<BasicModal v-bind="$attrs" |
||||||
|
width="720px" |
||||||
|
@ok="handleSubmit" |
||||||
|
@register="registerModal" |
||||||
|
> |
||||||
<BasicForm @register="registerForm"/> |
<BasicForm @register="registerForm"/> |
||||||
</BasicModal> |
</BasicModal> |
||||||
</template> |
</template> |
||||||
<script lang="ts"> |
<script lang="ts"> |
||||||
import { defineComponent, ref, computed, unref } from 'vue'; |
/** |
||||||
|
* Copyright © 2020-2022 <a href="http://www.entfrm.com/">entfrm</a> All rights reserved. |
||||||
|
* author entfrm开发团队-王翔 |
||||||
|
*/ |
||||||
|
import { defineComponent, ref, computed, unref, reactive } from 'vue'; |
||||||
import { BasicModal, useModalInner } from '/@/components/Modal'; |
import { BasicModal, useModalInner } from '/@/components/Modal'; |
||||||
import { BasicForm, useForm } from '/@/components/Form/index'; |
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index'; |
||||||
import { accountFormSchema } from './user.data'; |
import { userFormSchema } from './user.data'; |
||||||
import { departList } from '/@/api/system/dept'; |
import { deptList } from '/@/api/system/dept'; |
||||||
//import { set } from '/@/api/system/user'; |
import { addUser, editUser, getUser } from '/@/api/system/user'; |
||||||
|
import { listToTree } from "/@/utils/helper/treeHelper"; |
||||||
|
import { addMenu, editMenu, getMenu, getRoleMenuIds, listMenu } from "/@/api/system/menu"; |
||||||
|
import { ModalProps } from "/@/components/Modal"; |
||||||
|
|
||||||
export default defineComponent({ |
export default defineComponent({ |
||||||
name: 'UserModal', |
name: 'UserModal', |
||||||
components: { BasicModal, BasicForm }, |
components: { BasicModal, BasicForm }, |
||||||
emits: ['success', 'register'], |
emits: ['success', 'register'], |
||||||
setup(_, { emit }) { |
setup(props, { emit }) { |
||||||
const isUpdate = ref(true); |
const tag = ref(''); |
||||||
const rowId = ref(''); |
|
||||||
|
|
||||||
const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({ |
const [registerForm, {resetFields, setFieldsValue, updateSchema, validate, clearValidate}] = useForm({ |
||||||
labelWidth: 100, |
labelWidth: 100, |
||||||
schemas: accountFormSchema, |
schemas: userFormSchema, |
||||||
showActionButtonGroup: false, |
showActionButtonGroup: false, |
||||||
actionColOptions: { |
actionColOptions: { |
||||||
span: 23, |
span: 24 |
||||||
}, |
} |
||||||
}); |
}); |
||||||
|
|
||||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { |
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { |
||||||
resetFields(); |
await resetFields(); |
||||||
setModalProps({ confirmLoading: false }); |
await clearValidate(); |
||||||
isUpdate.value = !!data?.isUpdate; |
tag.value = data._tag; |
||||||
|
const userId = data.record?.id; |
||||||
if (unref(isUpdate)) { |
const props: Partial<ModalProps> = { confirmLoading: false }; |
||||||
rowId.value = data.record.id; |
await updateSchema([ |
||||||
setFieldsValue({ |
|
||||||
...data.record, |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
const treeData = await departList(); |
|
||||||
updateSchema([ |
|
||||||
{ |
{ |
||||||
field: 'pwd', |
field: 'deptId', |
||||||
show: !unref(isUpdate), |
componentProps: { treeData: listToTree(await deptList()) } |
||||||
}, |
}, |
||||||
{ |
{ |
||||||
field: 'departId', |
field: 'password', |
||||||
componentProps: { treeData }, |
show: tag.value == 'add' |
||||||
}, |
} |
||||||
]); |
]); |
||||||
|
switch (tag.value) { |
||||||
|
case 'add': |
||||||
|
props.title = '新增用户'; |
||||||
|
break; |
||||||
|
case 'edit': |
||||||
|
props.title = '编辑用户'; |
||||||
|
await setFieldsValue(await getUser(userId) || {}); |
||||||
|
break; |
||||||
|
} |
||||||
|
setModalProps(props); |
||||||
}); |
}); |
||||||
|
|
||||||
const getTitle = computed(() => (!unref(isUpdate) ? '新增用户' : '编辑用户')); |
|
||||||
|
|
||||||
async function handleSubmit() { |
async function handleSubmit() { |
||||||
try { |
try { |
||||||
const values = await validate(); |
const formData = await validate(); |
||||||
setModalProps({ confirmLoading: true }); |
setModalProps({ confirmLoading: true }); |
||||||
await set(values); |
switch (unref(tag)) { |
||||||
|
case 'add': |
||||||
|
await addMenu(formData); |
||||||
|
break; |
||||||
|
case 'edit': |
||||||
|
await editMenu(formData); |
||||||
|
break; |
||||||
|
} |
||||||
closeModal(); |
closeModal(); |
||||||
emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } }); |
emit('success'); |
||||||
} finally { |
} finally { |
||||||
setModalProps({ confirmLoading: false }); |
setModalProps({ confirmLoading: false }); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
return { registerModal, registerForm, getTitle, handleSubmit }; |
return { |
||||||
}, |
registerModal, |
||||||
|
registerForm, |
||||||
|
handleSubmit |
||||||
|
}; |
||||||
|
} |
||||||
}); |
}); |
||||||
</script> |
</script> |
||||||
|
@ -1,155 +1,182 @@ |
|||||||
<template> |
<template> |
||||||
<PageWrapper dense contentFullHeight fixedHeight contentClass="flex"> |
<PageWrapper dense |
||||||
|
contentFullHeight |
||||||
|
fixedHeight |
||||||
|
contentClass="flex" |
||||||
|
> |
||||||
<DeptTree class="w-1/4 xl:w-1/5" @select="handleSelect"/> |
<DeptTree class="w-1/4 xl:w-1/5" @select="handleSelect"/> |
||||||
<BasicTable @register="registerTable" class="w-3/4 xl:w-4/5" :searchInfo="searchInfo"> |
<BasicTable class="w-3/4 xl:w-4/5" @register="registerTable"> |
||||||
<template #toolbar> |
<template #toolbar> |
||||||
<a-button type="primary" @click="handleCreate">新增用户</a-button> |
<a-button v-auth="['user_add']" |
||||||
<a-button v-auth="['role_edit']" |
type="primary" |
||||||
|
@click="handleAdd()" |
||||||
|
>新增用户</a-button> |
||||||
|
<a-button v-auth="['user_edit']" |
||||||
type="primary" |
type="primary" |
||||||
:disabled="state.single" |
:disabled="state.single" |
||||||
@click="handleEdit()" |
@click="handleEdit()" |
||||||
>修改用户</a-button> |
>修改用户</a-button> |
||||||
<a-button v-auth="['role_del']" |
<a-button v-auth="['user_del']" |
||||||
type="primary" |
type="primary" |
||||||
:disabled="state.multiple" |
:disabled="state.multiple" |
||||||
@click="handleDel()" |
@click="handleDel()" |
||||||
>删除用户</a-button> |
>删除用户</a-button> |
||||||
</template> |
</template> |
||||||
<template #action="{ record }"> |
<template #action="{ record }"> |
||||||
<TableAction |
<TableAction :actions="[ |
||||||
:actions="[ |
|
||||||
{ |
{ |
||||||
icon: 'clarity:lock-line', |
icon: 'clarity:lock-line', |
||||||
tooltip: '修改密码', |
tooltip: '修改密码', |
||||||
onClick: handleSetPassword.bind(null, record), |
onClick: handleUpdatePwd.bind(null, record), |
||||||
}, |
}, |
||||||
{ |
{ |
||||||
icon: 'clarity:note-edit-line', |
label: '编辑', |
||||||
tooltip: '编辑用户资料', |
icon: 'fa6-regular:pen-to-square', |
||||||
onClick: handleEdit.bind(null, record), |
auth: ['role_edit'], |
||||||
|
onClick: handleEdit.bind(null, record) |
||||||
}, |
}, |
||||||
{ |
{ |
||||||
|
label: '删除', |
||||||
icon: 'ant-design:delete-outlined', |
icon: 'ant-design:delete-outlined', |
||||||
|
auth: ['role_del'], |
||||||
color: 'error', |
color: 'error', |
||||||
tooltip: '删除此账号', |
onClick: handleDel.bind(null, record) |
||||||
popConfirm: { |
}]" |
||||||
title: '是否确认删除', |
|
||||||
confirm: handleDelete.bind(null, record), |
|
||||||
}, |
|
||||||
}, |
|
||||||
]" |
|
||||||
/> |
/> |
||||||
</template> |
</template> |
||||||
</BasicTable> |
</BasicTable> |
||||||
<UserModal @register="registerModal" @success="handleSuccess"/> |
<UserModal @register="registerModal" @success="handleSuccess"/> |
||||||
<PasswordModal @register="registerPasswordModal" @success="handlePasswordSuccess" /> |
<PasswordModal @register="registerPasswordModal" @success="handleUpdatePwd"/> |
||||||
</PageWrapper> |
</PageWrapper> |
||||||
</template> |
</template> |
||||||
|
|
||||||
<script lang="ts"> |
<script lang="ts"> |
||||||
import { defineComponent, reactive } from 'vue'; |
import { defineComponent, reactive, toRaw } from 'vue'; |
||||||
import { BasicTable, useTable, TableAction } from '/@/components/Table'; |
import { BasicTable, useTable, TableAction } from '/@/components/Table'; |
||||||
//import { del, page } from '/@/api/system/user'; |
import { listUser, delUser, updatePwd } from '/@/api/system/user'; |
||||||
import { PageWrapper } from '/@/components/Page'; |
import { PageWrapper } from '/@/components/Page'; |
||||||
import DeptTree from './DeptTree.vue'; |
import DeptTree from './DeptTree.vue'; |
||||||
import { useModal } from '/@/components/Modal'; |
import { useModal } from '/@/components/Modal'; |
||||||
import UserModal from './UserModal.vue'; |
import UserModal from './UserModal.vue'; |
||||||
import PasswordModal from './PasswordModal.vue'; |
import PasswordModal from './PasswordModal.vue'; |
||||||
import { columns, searchFormSchema } from './user.data'; |
import { columns, searchFormSchema } from './user.data'; |
||||||
import { useGo } from '/@/hooks/web/usePage'; |
|
||||||
import { useMessage } from '/@/hooks/web/useMessage'; |
import { useMessage } from '/@/hooks/web/useMessage'; |
||||||
|
|
||||||
|
const { createConfirm } = useMessage(); |
||||||
const { createMessage } = useMessage(); |
const { createMessage } = useMessage(); |
||||||
|
|
||||||
export default defineComponent({ |
export default defineComponent({ |
||||||
name: 'UserManagement', |
name: 'UserManagement', |
||||||
components: { BasicTable, PageWrapper, DeptTree, UserModal, TableAction, PasswordModal }, |
components: { |
||||||
|
BasicTable, |
||||||
|
PageWrapper, |
||||||
|
DeptTree, |
||||||
|
TableAction, |
||||||
|
UserModal, |
||||||
|
PasswordModal |
||||||
|
}, |
||||||
setup() { |
setup() { |
||||||
const go = useGo(); |
const state = reactive({ |
||||||
|
// 选中数组 |
||||||
|
ids: [], |
||||||
|
// 非单个禁用 |
||||||
|
single: true, |
||||||
|
// 非多个禁用 |
||||||
|
multiple: true, |
||||||
|
// 搜索信息 |
||||||
|
searchInfo: {} as Recordable |
||||||
|
}); |
||||||
|
|
||||||
const [registerModal, { openModal }] = useModal(); |
const [registerModal, { openModal }] = useModal(); |
||||||
const [registerPasswordModal, { openModal: openPasswordModal }] = useModal(); |
const [registerPasswordModal, { openModal: openPasswordModal }] = useModal(); |
||||||
const searchInfo = reactive<Recordable>({}); |
const [registerTable, { reload }] = useTable({ |
||||||
const [registerTable, { reload, updateTableDataRecord }] = useTable({ |
|
||||||
title: '用户列表', |
title: '用户列表', |
||||||
api: page, |
api: listUser, |
||||||
rowKey: 'id', |
rowKey: 'id', |
||||||
columns, |
columns, |
||||||
formConfig: { |
formConfig: { |
||||||
labelWidth: 120, |
labelWidth: 120, |
||||||
schemas: searchFormSchema, |
schemas: searchFormSchema, |
||||||
autoSubmitOnEnter: true, |
autoSubmitOnEnter: true |
||||||
}, |
}, |
||||||
|
rowSelection: { type: 'checkbox' }, |
||||||
useSearchForm: true, |
useSearchForm: true, |
||||||
showTableSetting: true, |
showTableSetting: true, |
||||||
bordered: true, |
bordered: true, |
||||||
handleSearchInfoFn(info) { |
clickToRowSelect: false, |
||||||
console.log('handleSearchInfoFn', info); |
searchInfo: state.searchInfo, |
||||||
return info; |
|
||||||
}, |
|
||||||
actionColumn: { |
actionColumn: { |
||||||
width: 120, |
width: 120, |
||||||
title: '操作', |
title: '操作', |
||||||
dataIndex: 'action', |
dataIndex: 'action', |
||||||
slots: { customRender: 'action' }, |
slots: { customRender: 'action' } |
||||||
}, |
} |
||||||
}); |
}); |
||||||
|
|
||||||
function handleCreate() { |
/** 处理多选框选中数据 */ |
||||||
openModal(true, { |
function handleSelectionChange(selection?: Recordable) { |
||||||
isUpdate: false, |
const rawRows = toRaw(selection?.rows) || []; |
||||||
}); |
state.ids = rawRows.map(item => item.id); |
||||||
|
state.single = rawRows.length != 1; |
||||||
|
state.multiple = !rawRows.length; |
||||||
} |
} |
||||||
|
|
||||||
function handleEdit(record: Recordable) { |
/** 新增按钮操作,行内新增与工具栏局域新增通用 */ |
||||||
openModal(true, { |
function handleAdd() { |
||||||
record, |
openModal(true,{ _tag: 'add' }); |
||||||
isUpdate: true, |
|
||||||
}); |
|
||||||
} |
} |
||||||
|
|
||||||
async function handleDelete(record: Recordable) { |
/** 编辑按钮操作,行内编辑 */ |
||||||
await del({ ids: record.id }); |
function handleEdit(record?: Recordable) { |
||||||
createMessage.success('删除成功!'); |
record = record || { id: toRaw(state.ids) }; |
||||||
handleSuccess(); |
openModal(true, { _tag: 'edit', record }); |
||||||
} |
} |
||||||
|
|
||||||
function handleSuccess() { |
/** 处理修改用户密码 */ |
||||||
reload(); |
function handleUpdatePwd(record: Recordable) { |
||||||
|
record = record || { id: toRaw(state.ids) }; |
||||||
|
openPasswordModal(true, { _tag: 'edit', record }); |
||||||
} |
} |
||||||
|
|
||||||
function handleSelect(departId = '') { |
/** 删除按钮操作,行内删除 */ |
||||||
searchInfo.departId = departId; |
async function handleDel(record?: Recordable) { |
||||||
reload(); |
const ids = record?.id || toRaw(state.ids); |
||||||
|
createConfirm({ |
||||||
|
iconType: 'warning', |
||||||
|
title: '警告', |
||||||
|
content: `是否确认删除用户编号为${ids}用户吗?`, |
||||||
|
onOk: async () => { |
||||||
|
await delUser(ids); |
||||||
|
createMessage.success('删除成功!'); |
||||||
|
handleSuccess(); |
||||||
} |
} |
||||||
|
|
||||||
function handleSetPassword(record: Recordable) { |
|
||||||
openPasswordModal(true, { |
|
||||||
record, |
|
||||||
isUpdate: true, |
|
||||||
}); |
}); |
||||||
} |
} |
||||||
|
|
||||||
function handleView(record: Recordable) { |
/** 处理表单提交成功 */ |
||||||
go('/system/account_detail/' + record.id); |
function handleSuccess() { |
||||||
|
reload(); |
||||||
} |
} |
||||||
|
|
||||||
function handlePasswordSuccess() { |
/** 处理部门管理点击 */ |
||||||
|
function handleSelect(departId = '') { |
||||||
|
state.searchInfo.departId = departId; |
||||||
reload(); |
reload(); |
||||||
} |
} |
||||||
|
|
||||||
return { |
return { |
||||||
|
state, |
||||||
registerTable, |
registerTable, |
||||||
registerModal, |
registerModal, |
||||||
handleCreate, |
registerPasswordModal, |
||||||
|
handleAdd, |
||||||
handleEdit, |
handleEdit, |
||||||
handleDelete, |
handleDel, |
||||||
|
handleSelectionChange, |
||||||
handleSuccess, |
handleSuccess, |
||||||
handleSelect, |
handleSelect, |
||||||
handleView, |
handleUpdatePwd |
||||||
searchInfo, |
|
||||||
handleSetPassword, |
|
||||||
registerPasswordModal, |
|
||||||
handlePasswordSuccess, |
|
||||||
}; |
}; |
||||||
}, |
} |
||||||
}); |
}); |
||||||
</script> |
</script> |
||||||
|
Loading…
Reference in new issue