7 changed files with 285 additions and 256 deletions
@ -1,63 +0,0 @@
@@ -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 @@
@@ -1,73 +1,95 @@
|
||||
<template> |
||||
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit"> |
||||
<BasicForm @register="registerForm" /> |
||||
<BasicModal v-bind="$attrs" |
||||
width="720px" |
||||
@ok="handleSubmit" |
||||
@register="registerModal" |
||||
> |
||||
<BasicForm @register="registerForm"/> |
||||
</BasicModal> |
||||
</template> |
||||
<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 { BasicForm, useForm } from '/@/components/Form/index'; |
||||
import { accountFormSchema } from './user.data'; |
||||
import { departList } from '/@/api/system/dept'; |
||||
//import { set } from '/@/api/system/user'; |
||||
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index'; |
||||
import { userFormSchema } from './user.data'; |
||||
import { deptList } from '/@/api/system/dept'; |
||||
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({ |
||||
name: 'UserModal', |
||||
components: { BasicModal, BasicForm }, |
||||
emits: ['success', 'register'], |
||||
setup(_, { emit }) { |
||||
const isUpdate = ref(true); |
||||
const rowId = ref(''); |
||||
setup(props, { emit }) { |
||||
const tag = ref(''); |
||||
|
||||
const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({ |
||||
const [registerForm, {resetFields, setFieldsValue, updateSchema, validate, clearValidate}] = useForm({ |
||||
labelWidth: 100, |
||||
schemas: accountFormSchema, |
||||
schemas: userFormSchema, |
||||
showActionButtonGroup: false, |
||||
actionColOptions: { |
||||
span: 23, |
||||
}, |
||||
span: 24 |
||||
} |
||||
}); |
||||
|
||||
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 treeData = await departList(); |
||||
updateSchema([ |
||||
await resetFields(); |
||||
await clearValidate(); |
||||
tag.value = data._tag; |
||||
const userId = data.record?.id; |
||||
const props: Partial<ModalProps> = { confirmLoading: false }; |
||||
await updateSchema([ |
||||
{ |
||||
field: 'pwd', |
||||
show: !unref(isUpdate), |
||||
field: 'deptId', |
||||
componentProps: { treeData: listToTree(await deptList()) } |
||||
}, |
||||
{ |
||||
field: 'departId', |
||||
componentProps: { treeData }, |
||||
}, |
||||
field: 'password', |
||||
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() { |
||||
try { |
||||
const values = await validate(); |
||||
const formData = await validate(); |
||||
setModalProps({ confirmLoading: true }); |
||||
await set(values); |
||||
switch (unref(tag)) { |
||||
case 'add': |
||||
await addMenu(formData); |
||||
break; |
||||
case 'edit': |
||||
await editMenu(formData); |
||||
break; |
||||
} |
||||
closeModal(); |
||||
emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } }); |
||||
emit('success'); |
||||
} finally { |
||||
setModalProps({ confirmLoading: false }); |
||||
} |
||||
} |
||||
|
||||
return { registerModal, registerForm, getTitle, handleSubmit }; |
||||
}, |
||||
return { |
||||
registerModal, |
||||
registerForm, |
||||
handleSubmit |
||||
}; |
||||
} |
||||
}); |
||||
</script> |
||||
|
@ -1,155 +1,182 @@
@@ -1,155 +1,182 @@
|
||||
<template> |
||||
<PageWrapper dense contentFullHeight fixedHeight contentClass="flex"> |
||||
<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"> |
||||
<BasicTable class="w-3/4 xl:w-4/5" @register="registerTable"> |
||||
<template #toolbar> |
||||
<a-button type="primary" @click="handleCreate">新增用户</a-button> |
||||
<a-button v-auth="['role_edit']" |
||||
<a-button v-auth="['user_add']" |
||||
type="primary" |
||||
@click="handleAdd()" |
||||
>新增用户</a-button> |
||||
<a-button v-auth="['user_edit']" |
||||
type="primary" |
||||
:disabled="state.single" |
||||
@click="handleEdit()" |
||||
>修改用户</a-button> |
||||
<a-button v-auth="['role_del']" |
||||
<a-button v-auth="['user_del']" |
||||
type="primary" |
||||
:disabled="state.multiple" |
||||
@click="handleDel()" |
||||
>删除用户</a-button> |
||||
</template> |
||||
<template #action="{ record }"> |
||||
<TableAction |
||||
:actions="[ |
||||
{ |
||||
icon: 'clarity:lock-line', |
||||
tooltip: '修改密码', |
||||
onClick: handleSetPassword.bind(null, record), |
||||
}, |
||||
{ |
||||
icon: 'clarity:note-edit-line', |
||||
tooltip: '编辑用户资料', |
||||
onClick: handleEdit.bind(null, record), |
||||
}, |
||||
{ |
||||
icon: 'ant-design:delete-outlined', |
||||
color: 'error', |
||||
tooltip: '删除此账号', |
||||
popConfirm: { |
||||
title: '是否确认删除', |
||||
confirm: handleDelete.bind(null, record), |
||||
}, |
||||
}, |
||||
]" |
||||
<TableAction :actions="[ |
||||
{ |
||||
icon: 'clarity:lock-line', |
||||
tooltip: '修改密码', |
||||
onClick: handleUpdatePwd.bind(null, record), |
||||
}, |
||||
{ |
||||
label: '编辑', |
||||
icon: 'fa6-regular:pen-to-square', |
||||
auth: ['role_edit'], |
||||
onClick: handleEdit.bind(null, record) |
||||
}, |
||||
{ |
||||
label: '删除', |
||||
icon: 'ant-design:delete-outlined', |
||||
auth: ['role_del'], |
||||
color: 'error', |
||||
onClick: handleDel.bind(null, record) |
||||
}]" |
||||
/> |
||||
</template> |
||||
</BasicTable> |
||||
<UserModal @register="registerModal" @success="handleSuccess" /> |
||||
<PasswordModal @register="registerPasswordModal" @success="handlePasswordSuccess" /> |
||||
<UserModal @register="registerModal" @success="handleSuccess"/> |
||||
<PasswordModal @register="registerPasswordModal" @success="handleUpdatePwd"/> |
||||
</PageWrapper> |
||||
</template> |
||||
|
||||
<script lang="ts"> |
||||
import { defineComponent, reactive } from 'vue'; |
||||
import { defineComponent, reactive, toRaw } from 'vue'; |
||||
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 DeptTree from './DeptTree.vue'; |
||||
import { useModal } from '/@/components/Modal'; |
||||
import UserModal from './UserModal.vue'; |
||||
import PasswordModal from './PasswordModal.vue'; |
||||
import { columns, searchFormSchema } from './user.data'; |
||||
import { useGo } from '/@/hooks/web/usePage'; |
||||
import { useMessage } from '/@/hooks/web/useMessage'; |
||||
|
||||
const { createConfirm } = useMessage(); |
||||
const { createMessage } = useMessage(); |
||||
|
||||
export default defineComponent({ |
||||
name: 'UserManagement', |
||||
components: { BasicTable, PageWrapper, DeptTree, UserModal, TableAction, PasswordModal }, |
||||
components: { |
||||
BasicTable, |
||||
PageWrapper, |
||||
DeptTree, |
||||
TableAction, |
||||
UserModal, |
||||
PasswordModal |
||||
}, |
||||
setup() { |
||||
const go = useGo(); |
||||
const state = reactive({ |
||||
// 选中数组 |
||||
ids: [], |
||||
// 非单个禁用 |
||||
single: true, |
||||
// 非多个禁用 |
||||
multiple: true, |
||||
// 搜索信息 |
||||
searchInfo: {} as Recordable |
||||
}); |
||||
|
||||
const [registerModal, { openModal }] = useModal(); |
||||
const [registerPasswordModal, { openModal: openPasswordModal }] = useModal(); |
||||
const searchInfo = reactive<Recordable>({}); |
||||
const [registerTable, { reload, updateTableDataRecord }] = useTable({ |
||||
const [registerTable, { reload }] = useTable({ |
||||
title: '用户列表', |
||||
api: page, |
||||
api: listUser, |
||||
rowKey: 'id', |
||||
columns, |
||||
formConfig: { |
||||
labelWidth: 120, |
||||
schemas: searchFormSchema, |
||||
autoSubmitOnEnter: true, |
||||
autoSubmitOnEnter: true |
||||
}, |
||||
rowSelection: { type: 'checkbox' }, |
||||
useSearchForm: true, |
||||
showTableSetting: true, |
||||
bordered: true, |
||||
handleSearchInfoFn(info) { |
||||
console.log('handleSearchInfoFn', info); |
||||
return info; |
||||
}, |
||||
clickToRowSelect: false, |
||||
searchInfo: state.searchInfo, |
||||
actionColumn: { |
||||
width: 120, |
||||
title: '操作', |
||||
dataIndex: 'action', |
||||
slots: { customRender: 'action' }, |
||||
}, |
||||
slots: { customRender: 'action' } |
||||
} |
||||
}); |
||||
|
||||
function handleCreate() { |
||||
openModal(true, { |
||||
isUpdate: false, |
||||
}); |
||||
/** 处理多选框选中数据 */ |
||||
function handleSelectionChange(selection?: Recordable) { |
||||
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, { |
||||
record, |
||||
isUpdate: true, |
||||
}); |
||||
/** 新增按钮操作,行内新增与工具栏局域新增通用 */ |
||||
function handleAdd() { |
||||
openModal(true,{ _tag: 'add' }); |
||||
} |
||||
|
||||
async function handleDelete(record: Recordable) { |
||||
await del({ ids: record.id }); |
||||
createMessage.success('删除成功!'); |
||||
handleSuccess(); |
||||
/** 编辑按钮操作,行内编辑 */ |
||||
function handleEdit(record?: Recordable) { |
||||
record = record || { id: toRaw(state.ids) }; |
||||
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; |
||||
reload(); |
||||
} |
||||
|
||||
function handleSetPassword(record: Recordable) { |
||||
openPasswordModal(true, { |
||||
record, |
||||
isUpdate: true, |
||||
/** 删除按钮操作,行内删除 */ |
||||
async function handleDel(record?: Recordable) { |
||||
const ids = record?.id || toRaw(state.ids); |
||||
createConfirm({ |
||||
iconType: 'warning', |
||||
title: '警告', |
||||
content: `是否确认删除用户编号为${ids}用户吗?`, |
||||
onOk: async () => { |
||||
await delUser(ids); |
||||
createMessage.success('删除成功!'); |
||||
handleSuccess(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
function handleView(record: Recordable) { |
||||
go('/system/account_detail/' + record.id); |
||||
/** 处理表单提交成功 */ |
||||
function handleSuccess() { |
||||
reload(); |
||||
} |
||||
|
||||
function handlePasswordSuccess() { |
||||
/** 处理部门管理点击 */ |
||||
function handleSelect(departId = '') { |
||||
state.searchInfo.departId = departId; |
||||
reload(); |
||||
} |
||||
|
||||
return { |
||||
state, |
||||
registerTable, |
||||
registerModal, |
||||
handleCreate, |
||||
registerPasswordModal, |
||||
handleAdd, |
||||
handleEdit, |
||||
handleDelete, |
||||
handleDel, |
||||
handleSelectionChange, |
||||
handleSuccess, |
||||
handleSelect, |
||||
handleView, |
||||
searchInfo, |
||||
handleSetPassword, |
||||
registerPasswordModal, |
||||
handlePasswordSuccess, |
||||
handleUpdatePwd |
||||
}; |
||||
}, |
||||
} |
||||
}); |
||||
</script> |
||||
|
Loading…
Reference in new issue