| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- <script lang="ts" setup>
- import { ElMessage, ElMessageBox } from 'element-plus'
- import type Node from 'element-plus/es/components/tree/src/model/node'
- import Group from './components/Group.vue'
- import User from './components/User.vue'
- import { deleteGroupById, getGroupByList } from '@/api/system/groupApi'
- import { deleteUserById, getUserByPage, resetPassword, updateUserStatus } from '@/api/system/userApi'
- import { packageTreeData } from '@/utils/tool'
- import useUserStore from '@/store/modules/user'
- const userStore = useUserStore()
- const { pagination, getParams, onSizeChange, onCurrentChange } = usePagination()
- const userData = userStore.getUserData()
- interface TreeNode {
- label: string
- groupId: number
- children?: TreeNode[]
- }
- const state = reactive({
- loading: false,
- curGroupId: 0,
- groups: [] as TreeNode[],
- userList: [],
- search: {
- keywords: '',
- },
- })
- const groupTreeRef = ref()
- // 查询帐号列表
- const getUserData = async () => {
- const params = getParams()
- const curGroupId = state.curGroupId
- if (curGroupId > 0) {
- params.groupId = curGroupId
- params.keywords = state.search.keywords
- state.loading = true
- const { data } = await getUserByPage(params)
- state.loading = false
- state.userList = data.data
- state.loading = false
- }
- }
- // 查询部门数据
- const getGroupData = async () => {
- const { data } = await getGroupByList()
- state.groups = packageTreeData({
- data,
- id: 'groupId',
- })
- if (data && data.length > 0) {
- state.curGroupId = data[0].groupId
- await getUserData()
- }
- }
- onMounted(() => {
- getGroupData()
- })
- // 每页数量切换
- function sizeChange(size: number) {
- onSizeChange(size).then(() => getUserData())
- }
- // 当前页码切换(翻页)
- function currentChange(page = 1) {
- onCurrentChange(page).then(() => getUserData())
- }
- // 部门点击
- const onTreeNodeClick = (node: TreeNode) => {
- state.curGroupId = node.groupId
- getUserData()
- }
- const groupRef = ref()
- // 新增部门
- const onGroupAdd = (data: any) => {
- const { groupId, groupName } = data
- groupRef.value.showAddModel(groupId, groupName)
- }
- // 编辑部门
- const onGroupEdit = (data?: any) => {
- const { groupId } = data
- groupRef.value.showEditModel(groupId)
- }
- // 删除部门
- const onGroupDelete = (node: Node, data: any) => {
- ElMessageBox.confirm(`确认删除「${data.label}」吗?`, '确认信息').then(async () => {
- const { msg } = await deleteGroupById(data.groupId)
- ElMessage.success(msg)
- await getGroupData()
- }).catch(() => {})
- }
- const accountTableRef = ref()
- const userRef = ref()
- // 查询
- const onSearch = () => {
- getUserData()
- }
- // 新增账号
- const onUserAdd = () => {
- userRef.value.showAddModel()
- }
- // 修改账号
- const onUserEdit = (row: any) => {
- userRef.value.showEditModel(row.groupId, row.accountId)
- }
- // 密码重置
- const onPasswordReset = (data?: any) => {
- ElMessageBox.confirm('温馨提示:系统默认重置密码为 888888?', '确认').then(async () => {
- const { msg } = await resetPassword(data.accountId)
- ElMessage.success(msg)
- }).catch(() => {})
- }
- // 修改状态
- const onChangeStatus = async (status: number, row: any) => {
- const { msg } = await updateUserStatus(row.accountId, status)
- ElMessage.success(msg)
- }
- // 删除用户账号
- const onUserDelete = (row: any) => {
- ElMessageBox.confirm('温馨提示:系统默认重置密码为 888888?', '确认').then(async () => {
- const { msg } = await deleteUserById(row.accountId)
- ElMessage.success(msg)
- }).catch(() => {})
- }
- // "更多"处理
- const onCommand = (command: string, row: any) => {
- switch (command) {
- case 'GrantGroupAdd':
- window.console.log(row)
- break
- case 'GrantGroupEdit':
- break
- case 'GrantGroupDelete':
- break
- case 'ResetPwd':
- onPasswordReset(row)
- break
- case 'Permit':
- break
- }
- }
- const getUserList = () => {}
- const getGroupList = () => {}
- </script>
- <template>
- <div class="absolute-container">
- <page-header title="帐号管理" content="维护组织部门及账号信息" />
- <div class="page-main">
- <LayoutContainer left-side-width="300px" hide-left-side-toggle>
- <template #leftSide>
- <el-scrollbar class="tree">
- <ElTree ref="groupTreeRef" :data="state.groups" :current-node-key="state.curGroupId" default-expand-all @node-click="onTreeNodeClick">
- <template #default="{ node, data }">
- <div class="custom-tree-node">
- <div class="label" :title="node.label">
- <div class="text">
- {{ data.groupName }}
- </div>
- </div>
- <div class="actions">
- <el-button-group>
- <el-button type="primary" plain size="small" @click.stop="onGroupAdd(data)">
- <template #icon>
- <el-icon>
- <svg-icon name="i-ep:plus" />
- </el-icon>
- </template>
- </el-button>
- <el-button type="info" plain size="small" @click.stop="onGroupEdit(data)">
- <template #icon>
- <el-icon>
- <svg-icon name="i-ep:edit" />
- </el-icon>
- </template>
- </el-button>
- <el-button v-if="data.groupId !== userData.ocId" type="danger" plain size="small" @click.stop="onGroupDelete(node, data)">
- <template #icon>
- <el-icon>
- <svg-icon name="i-ep:delete" />
- </el-icon>
- </template>
- </el-button>
- </el-button-group>
- </div>
- </div>
- </template>
- </ElTree>
- </el-scrollbar>
- </template>
- <div class="container">
- <tool-bar>
- <template #left>
- <span />
- </template>
- <template #right>
- <el-input v-model="state.search.keywords" placeholder="请输入名称,支持模糊查询" style="padding-right: 10px;" clearable />
- <el-button type="primary" @click="onSearch">
- <template #icon>
- <el-icon>
- <svg-icon name="i-ep:search" />
- </el-icon>
- </template>
- </el-button>
- <el-button type="primary" @click="onUserAdd">
- 新增用户
- </el-button>
- </template>
- </tool-bar>
- <el-table ref="accountTableRef" v-loading="state.loading" class="list-table" :data="state.userList" border stripe highlight-current-row>
- <el-table-column type="index" align="center" label="序号" width="60" />
- <el-table-column align="center" header-align="center" label="头像" width="60">
- <template #default="{ row }">
- <el-avatar :size="30" :src="row.accountAvatar" />
- </template>
- </el-table-column>
- <el-table-column align="center" width="100" label="账号">
- <template #default="{ row }">
- <span>{{ row.accountName }}</span>
- </template>
- </el-table-column>
- <el-table-column align="center" width="90" label="姓名">
- <template #default="{ row }">
- <span>{{ row.accountRealName }}</span>
- </template>
- </el-table-column>
- <el-table-column align="center" width="80" label="工号">
- <template #default="{ row }">
- <span>{{ row.accountStaffNo }}</span>
- </template>
- </el-table-column>
- <el-table-column align="center" width="125" label="联系方式">
- <template #default="{ row }">
- <span>{{ row.accountPhone }}</span>
- </template>
- </el-table-column>
- <el-table-column align="center" label="所在部门">
- <template #default="{ row }">
- <span>{{ row.groupName }}</span>
- </template>
- </el-table-column>
- <el-table-column align="center" width="100" label="岗位">
- <template #default="{ row }">
- <span>{{ row.positionName }}</span>
- </template>
- </el-table-column>
- <el-table-column align="center" label="状态" width="80">
- <template #default="scope">
- <div v-if="scope.row.isFixed !== 1">
- <el-switch
- v-model="scope.row.status"
- :active-value="1"
- :inactive-value="2"
- :loading="scope.row.loading"
- inline-prompt
- active-text="启用"
- inactive-text="禁用"
- @change="(status) => onChangeStatus(scope.row.status, scope.row)"
- />
- </div>
- </template>
- </el-table-column>
- <el-table-column label="操作" header-align="center" align="center" width="220">
- <template #default="scope">
- <el-button size="small" type="primary" @click="onUserEdit(scope.row)">
- 修改
- </el-button>
- <el-button v-if="scope.row.isFixed !== 1" size="small" type="danger" @click="onUserDelete(scope.row)">
- 删除
- </el-button>
- <el-dropdown v-if="scope.row.isFixed !== 1" @command="onCommand($event, scope.row)">
- <el-button size="small">
- 更多
- <el-icon class="el-icon--right">
- <svg-icon name="i-ep:arrow-down" />
- </el-icon>
- </el-button>
- <template #dropdown="{ row }">
- <el-dropdown-menu>
- <template v-if="row && row.grantGroupId > 0">
- <el-dropdown-item command="GrantGroupEdit">
- 编辑授权
- </el-dropdown-item>
- <el-dropdown-item command="GrantGroupDelete">
- 解除授权
- </el-dropdown-item>
- </template>
- <template v-else>
- <el-dropdown-item command="GrantGroupAdd">
- 添加授权
- </el-dropdown-item>
- </template>
- <el-dropdown-item command="ResetPwd">
- 重置密码
- </el-dropdown-item>
- <el-dropdown-item command="Permit">
- 权限配置
- </el-dropdown-item>
- </el-dropdown-menu>
- </template>
- </el-dropdown>
- </template>
- </el-table-column>
- </el-table>
- <el-pagination :current-page="pagination.page" :total="pagination.total" :page-size="pagination.size" :page-sizes="pagination.sizes" :layout="pagination.layout" :hide-on-single-page="false" class="pagination" background @current-change="currentChange" @size-change="sizeChange" />
- </div>
- </LayoutContainer>
- </div>
- <Group ref="groupRef" @success="getGroupList" />
- <User ref="userRef" @success="getUserList" />
- </div>
- </template>
- <style lang="scss" scoped>
- .absolute-container {
- position: absolute;
- width: 100%;
- height: 100%;
- display: flex;
- flex-direction: column;
- .page-header {
- margin-bottom: 0;
- }
- .page-main {
- flex: 1;
- overflow: auto;
- display: flex;
- flex-direction: column;
- .flex-container {
- position: static;
- }
- }
- }
- .flex-container {
- :deep(.left-side) {
- display: flex;
- flex-direction: column;
- height: 100%;
- .btns {
- display: inline-flex;
- width: 100%;
- margin-bottom: var(--container-padding);
- .add {
- width: 100%;
- }
- }
- .tree {
- flex: 1;
- overflow-y: auto;
- .el-tree {
- .el-tree-node__content {
- height: 40px;
- }
- .is-current > .el-tree-node__content {
- background-color: var(--el-color-primary-light-9);
- }
- .custom-tree-node {
- flex: 1;
- position: relative;
- width: 0;
- height: 100%;
- display: flex;
- flex-direction: column;
- justify-content: center;
- .label {
- display: inline-flex;
- align-items: center;
- width: calc(100% - 10px);
- color: var(--el-text-color-primary);
- .text {
- @include text-overflow;
- }
- }
- &:hover {
- .actions {
- display: block;
- }
- }
- .actions {
- display: none;
- position: absolute;
- right: 10px;
- top: 50%;
- transform: translateY(-50%);
- .el-button {
- padding: 5px 8px;
- }
- }
- }
- }
- }
- }
- :deep(.main) {
- .main-container {
- width: 100%;
- height: 100%;
- }
- }
- .empty {
- flex: 1;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 32px;
- color: var(--el-text-color-placeholder);
- }
- }
- </style>
|