|
|
@@ -4,20 +4,22 @@ 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 { getUserByPage } from '@/api/system/userApi'
|
|
|
+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
|
|
|
- isLeaf: boolean
|
|
|
groupId: number
|
|
|
children?: TreeNode[]
|
|
|
}
|
|
|
|
|
|
const state = reactive({
|
|
|
loading: false,
|
|
|
- keywords: '',
|
|
|
curGroupId: 0,
|
|
|
groups: [] as TreeNode[],
|
|
|
userList: [],
|
|
|
@@ -26,26 +28,15 @@ const state = reactive({
|
|
|
},
|
|
|
})
|
|
|
|
|
|
-const menu = ref([])
|
|
|
-const getGroupList = async () => {
|
|
|
- const { data } = await getGroupByList()
|
|
|
+const groupTreeRef = ref()
|
|
|
|
|
|
- menu.value = packageTreeData({
|
|
|
- data,
|
|
|
- id: 'groupId',
|
|
|
- })
|
|
|
- if (data && data.length > 0) {
|
|
|
- state.curGroupId = data[0].groupId
|
|
|
- const res = await getUserByPage({ groupId: state.curGroupId })
|
|
|
- state.userList = res.data
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-const getUserList = async () => {
|
|
|
+// 查询帐号列表
|
|
|
+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
|
|
|
@@ -54,77 +45,137 @@ const getUserList = async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 查询部门数据
|
|
|
+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(() => getUserList())
|
|
|
+ onSizeChange(size).then(() => getUserData())
|
|
|
}
|
|
|
|
|
|
// 当前页码切换(翻页)
|
|
|
function currentChange(page = 1) {
|
|
|
- onCurrentChange(page).then(() => getUserList())
|
|
|
+ onCurrentChange(page).then(() => getUserData())
|
|
|
}
|
|
|
|
|
|
+// 部门点击
|
|
|
const onTreeNodeClick = (node: TreeNode) => {
|
|
|
- if (node.isLeaf) {
|
|
|
- state.curGroupId = node.groupId
|
|
|
- getUserList()
|
|
|
- }
|
|
|
+ state.curGroupId = node.groupId
|
|
|
+ getUserData()
|
|
|
}
|
|
|
|
|
|
const groupRef = ref()
|
|
|
+
|
|
|
+// 新增部门
|
|
|
const onGroupAdd = (data: any) => {
|
|
|
- groupRef.value.showAddModel(data)
|
|
|
+ const { groupId, groupName } = data
|
|
|
+ groupRef.value.showAddModel(groupId, groupName)
|
|
|
}
|
|
|
|
|
|
+// 编辑部门
|
|
|
const onGroupEdit = (data?: any) => {
|
|
|
- groupRef.value.showAddModel(data)
|
|
|
+ const { groupId } = data
|
|
|
+ groupRef.value.showEditModel(groupId)
|
|
|
}
|
|
|
+
|
|
|
+// 删除部门
|
|
|
const onGroupDelete = (node: Node, data: any) => {
|
|
|
ElMessageBox.confirm(`确认删除「${data.label}」吗?`, '确认信息').then(async () => {
|
|
|
await deleteGroupById(data.groupId)
|
|
|
- await getGroupList()
|
|
|
+ await getGroupData()
|
|
|
ElMessage.success({
|
|
|
message: '删除成功',
|
|
|
center: true,
|
|
|
})
|
|
|
- })
|
|
|
+ }).catch(() => {})
|
|
|
}
|
|
|
|
|
|
+const accountTableRef = ref()
|
|
|
+const userRef = ref()
|
|
|
+
|
|
|
+// 查询
|
|
|
const onSearch = () => {
|
|
|
- getUserList()
|
|
|
+ getUserData()
|
|
|
}
|
|
|
|
|
|
-const accountTableRef = ref()
|
|
|
+// 新增账号
|
|
|
+const onUserAdd = () => {
|
|
|
+ userRef.value.showAddModel()
|
|
|
+}
|
|
|
|
|
|
-const onChangeStatus = (row: any) => {
|
|
|
- window.console.log(row)
|
|
|
+// 修改账号
|
|
|
+const onUserEdit = (row: any) => {
|
|
|
+ userRef.value.showEditModel(row.groupId, row.accountId)
|
|
|
}
|
|
|
+
|
|
|
+// 密码重置
|
|
|
+const onPasswordReset = (data?: any) => {
|
|
|
+ ElMessageBox.confirm('温馨提示:系统默认重置密码为 888888?', '确认').then(async () => {
|
|
|
+ await resetPassword(data.accountId)
|
|
|
+ ElMessage.success({
|
|
|
+ message: '密码重置成功',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ }).catch(() => {})
|
|
|
+}
|
|
|
+
|
|
|
+// 修改状态
|
|
|
+const onChangeStatus = async (row: any) => {
|
|
|
+ const status = row.status === 1 ? 0 : 1
|
|
|
+ await updateUserStatus(row.accountId, status)
|
|
|
+ ElMessage.success({
|
|
|
+ message: '修改成功',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 删除用户账号
|
|
|
+const onUserDelete = (row: any) => {
|
|
|
+ ElMessageBox.confirm('温馨提示:系统默认重置密码为 888888?', '确认').then(async () => {
|
|
|
+ await deleteUserById(row.accountId)
|
|
|
+ ElMessage.success({
|
|
|
+ message: '删除',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ }).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 userRef = ref('userRef')
|
|
|
-const onUserEdit = (row: any) => {
|
|
|
- window.console.log(row)
|
|
|
-}
|
|
|
-const onUserDelete = (row: any) => {
|
|
|
- window.console.log(row)
|
|
|
-}
|
|
|
-
|
|
|
-onMounted(() => {
|
|
|
- getGroupList()
|
|
|
-})
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
@@ -134,13 +185,10 @@ onMounted(() => {
|
|
|
<LayoutContainer left-side-width="300px" hide-left-side-toggle>
|
|
|
<template #leftSide>
|
|
|
<el-scrollbar class="tree">
|
|
|
- <ElTree ref="menuRef" :data="menu" default-expand-all @node-click="onTreeNodeClick">
|
|
|
+ <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">
|
|
|
- <el-icon v-if="data.isLeaf" size="16px" style="margin-right: 5px;">
|
|
|
- <svg-icon name="uim:box" />
|
|
|
- </el-icon>
|
|
|
<div class="text">
|
|
|
{{ data.groupName }}
|
|
|
</div>
|
|
|
@@ -154,6 +202,7 @@ onMounted(() => {
|
|
|
</el-icon>
|
|
|
</template>
|
|
|
</el-button>
|
|
|
+
|
|
|
<el-button type="info" plain size="small" @click.stop="onGroupEdit(data)">
|
|
|
<template #icon>
|
|
|
<el-icon>
|
|
|
@@ -161,7 +210,8 @@ onMounted(() => {
|
|
|
</el-icon>
|
|
|
</template>
|
|
|
</el-button>
|
|
|
- <el-button type="danger" plain size="small" @click.stop="onGroupDelete(node, data)">
|
|
|
+
|
|
|
+ <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" />
|
|
|
@@ -178,6 +228,10 @@ onMounted(() => {
|
|
|
|
|
|
<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">
|
|
|
@@ -187,13 +241,17 @@ onMounted(() => {
|
|
|
</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="70" />
|
|
|
+ <el-table-column type="index" align="center" label="序号" width="60" />
|
|
|
|
|
|
- <el-table-column align="center" header-align="center" label="头像" width="100">
|
|
|
+ <el-table-column align="center" header-align="center" label="头像" width="60">
|
|
|
<template #default="{ row }">
|
|
|
<el-avatar :size="30" :src="row.accountAvatar" />
|
|
|
</template>
|
|
|
@@ -205,19 +263,19 @@ onMounted(() => {
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
|
|
|
- <el-table-column align="center" width="100" label="姓名">
|
|
|
+ <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="100" label="工号">
|
|
|
+ <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="120" label="联系方式">
|
|
|
+ <el-table-column align="center" width="125" label="联系方式">
|
|
|
<template #default="{ row }">
|
|
|
<span>{{ row.accountPhone }}</span>
|
|
|
</template>
|
|
|
@@ -235,7 +293,7 @@ onMounted(() => {
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
|
|
|
- <el-table-column align="center" label="状态" width="140">
|
|
|
+ <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" :loading="scope.row.loading" inline-prompt active-text="启用" inactive-text="禁用" @before-change="() => onChangeStatus(scope.row)" />
|
|
|
@@ -243,9 +301,9 @@ onMounted(() => {
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
|
|
|
- <el-table-column label="操作" header-align="center" align="center" width="310">
|
|
|
+ <el-table-column label="操作" header-align="center" align="center" width="220">
|
|
|
<template #default="scope">
|
|
|
- <el-button size="small" @click="onUserEdit(scope.row)">
|
|
|
+ <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)">
|
|
|
@@ -253,7 +311,7 @@ onMounted(() => {
|
|
|
</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>
|