index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <div class="system-user-container layout-padding">
  3. <div class="layout-padding-auto layout-padding-view pd20">
  4. <el-row :gutter="20" class="h100">
  5. <!-- 左侧组织树 -->
  6. <el-col :xs="6" :sm="6" :md="6" :lg="4" :xl="4" class="orgTree">
  7. <div class="h100 pr10">
  8. <el-input v-model="filterOrg" placeholder="请输入部门名称" class="input-with-select mt10 mb10" clearable> </el-input>
  9. <el-scrollbar style="height: calc(100% - 40px);'">
  10. <template v-if="state.orgData.length">
  11. <el-tree
  12. :data="state.orgData"
  13. highlight-current
  14. :expand-on-click-node="false"
  15. :props="{ children: 'children', label: 'orgName' }"
  16. @node-click="handleNodeClick"
  17. ref="treRef"
  18. v-loading="state.loading"
  19. node-key="orgCode"
  20. style="min-width: 100%; display: inline-block"
  21. :filter-node-method="filterNodeOrg"
  22. :default-expanded-keys="state.defaultExpandedKeys"
  23. >
  24. </el-tree>
  25. </template>
  26. <template v-else>
  27. <Empty description="暂无组织数据" />
  28. </template>
  29. </el-scrollbar>
  30. </div>
  31. </el-col>
  32. <!-- 右侧表格 -->
  33. <el-col :xs="18" :sm="18" :md="18" :lg="20" :xl="20" class="rightContent">
  34. <el-scrollbar class="pr10" ref="rightScrollRef">
  35. <el-form :model="state.queryParams" ref="ruleFormRef" :inline="true" @submit.native.prevent>
  36. <el-form-item label="关键字" prop="Keyword">
  37. <el-input v-model="state.queryParams.Keyword" placeholder="姓名/电话号码" clearable @keyup.enter="handleQuery" />
  38. </el-form-item>
  39. <el-form-item label="角色" prop="Role">
  40. <el-select-v2 v-model="state.queryParams.Role" filterable :options="state.options" placeholder="请选择角色" clearable />
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button type="primary" @click="handleQuery" :loading="state.tableLoading">
  44. <SvgIcon name="ele-Search" class="mr5" />查询
  45. </el-button>
  46. <el-button @click="resetQuery(ruleFormRef)" class="default-button"> <SvgIcon name="ele-Refresh" class="mr5" />重置 </el-button>
  47. </el-form-item>
  48. </el-form>
  49. <div class="flex-center-between mb20">
  50. <p class="table-title"></p>
  51. <div>
  52. <el-button type="primary" @click="onOpenAddUser" v-auth="'system:user:add'">
  53. <SvgIcon name="ele-Plus" class="mr5" />新增
  54. </el-button>
  55. </div>
  56. </div>
  57. <!-- 表格 -->
  58. <el-table :data="state.tableData" v-loading="state.tableLoading" row-key="id">
  59. <el-table-column type="index" width="60" label="序号" />
  60. <el-table-column prop="name" label="姓名" show-overflow-tooltip width="170"></el-table-column>
  61. <el-table-column prop="userName" label="账号" show-overflow-tooltip width="170"></el-table-column>
  62. <el-table-column prop="organization.orgName" label="所属部门" show-overflow-tooltip width="190"></el-table-column>
  63. <el-table-column prop="organization.orgTypeText" label="部门类别" show-overflow-tooltip width="190"></el-table-column>
  64. <el-table-column prop="roleNames" label="角色" show-overflow-tooltip width="300"></el-table-column>
  65. <el-table-column prop="phoneNo" label="电话号码" show-overflow-tooltip width="130"></el-table-column>
  66. <el-table-column prop="staffNo" label="工号" show-overflow-tooltip width="120"></el-table-column>
  67. <el-table-column prop="genderText" label="性别" show-overflow-tooltip width="80"></el-table-column>
  68. <el-table-column prop="creationTime" label="更新时间" show-overflow-tooltip width="170">
  69. <template #default="{row}">
  70. <span>{{ formatDate(row.creationTime, 'YYYY-mm-dd HH:MM:SS') }}</span>
  71. </template>
  72. </el-table-column>
  73. <el-table-column prop="state" label="状态" show-overflow-tooltip width="80"></el-table-column>
  74. <el-table-column label="操作" width="180" fixed="right" align="center">
  75. <template #default="{ row }">
  76. <el-button link type="primary" @click="onOpenEditUser(row)" v-auth="'system:user:edit'" title="修改" v-if="!row.isDeleted">
  77. 修改
  78. </el-button>
  79. <el-button link type="warning" @click="onRestPwd(row)" title="重置密码" v-auth="'system:user:resetPwd'" v-if="!row.isDeleted">
  80. 重置密码
  81. </el-button>
  82. <el-button link type="danger" @click="onRowDel(row)" v-auth="'system:user:delete'" title="删除" v-if="!row.isDeleted">
  83. 删除
  84. </el-button>
  85. </template>
  86. </el-table-column>
  87. <template #empty>
  88. <Empty />
  89. </template>
  90. </el-table>
  91. <!-- 分页 -->
  92. <pagination
  93. :total="state.total"
  94. v-model:page="state.queryParams.PageIndex"
  95. v-model:limit="state.queryParams.PageSize"
  96. @pagination="getList"
  97. />
  98. </el-scrollbar>
  99. </el-col>
  100. </el-row>
  101. </div>
  102. <user-add ref="userAddRef" @updateList="getList" />
  103. <user-edit ref="userEditRef" @updateList="getList" />
  104. </div>
  105. </template>
  106. <script lang="ts" setup name="systemUser">
  107. import { defineAsyncComponent, ref, reactive, onMounted, watch, onActivated } from 'vue';
  108. import { ElMessageBox, ElMessage } from 'element-plus';
  109. import type { FormInstance } from 'element-plus';
  110. import { formatDate } from '/@/utils/formatTime';
  111. import { auth } from '/@/utils/authFunction';
  112. import { throttle } from '/@/utils/tools';
  113. import { delUser, getUserListPaged, restPwd, getRoles } from '/@/api/system/user';
  114. import { getOrgList } from '/@/api/system/organize';
  115. // 引入组件
  116. const UserAdd = defineAsyncComponent(() => import('/@/views/system/user/component/User-add.vue'));
  117. const UserEdit = defineAsyncComponent(() => import('/@/views/system/user/component/User-edit.vue'));
  118. // 定义变量内容
  119. const state = reactive<any>({
  120. queryParams: {
  121. PageIndex: 1,
  122. PageSize: 10,
  123. Keyword: '',
  124. Role: null, // 角色id
  125. OrgCode: null, // 组织code
  126. },
  127. tableData: [],
  128. total: 0,
  129. loading: false,
  130. tableLoading: false,
  131. orgData: [],
  132. options: [],
  133. defaultExpandedKeys: [],
  134. });
  135. const ruleFormRef = ref<FormInstance>(); //表单ref
  136. const userAddRef = ref<RefType>(); //新增用户
  137. const userEditRef = ref<RefType>(); //修改用户信息
  138. const rightScrollRef = ref<RefType>();
  139. const filterOrg = ref('');
  140. const treRef = ref<RefType>();
  141. watch(filterOrg, (val) => {
  142. treRef.value!.filter(val);
  143. });
  144. // 搜索部门名称
  145. const filterNodeOrg = (value: string, data: any) => {
  146. if (!value) return true;
  147. return data.orgName.includes(value);
  148. };
  149. /** 搜索按钮操作 节流操作 */
  150. const handleQuery = throttle(() => {
  151. state.queryParams.PageIndex = 1;
  152. getList();
  153. }, 500);
  154. // 获取所有组织结构
  155. const getOrgListApi = () => {
  156. if (!auth('system:organize:query')) ElMessage.error('抱歉,您没有权限获取组织架构!');
  157. else {
  158. state.loading = true;
  159. getOrgList()
  160. .then((res: any) => {
  161. state.orgData = res?.result ?? [];
  162. state.defaultExpandedKeys = state.orgData.map((v: any) => {
  163. return v.children.map((i: any) => {
  164. return i.orgCode;
  165. });
  166. });
  167. state.defaultExpandedKeys.push(state.orgData[0].orgCode); //默认展开一级部门
  168. state.loading = false;
  169. })
  170. .catch(() => {
  171. state.loading = false;
  172. });
  173. }
  174. };
  175. /** 获取用户列表 */
  176. const getList = () => {
  177. if (!auth('system:user:query')) ElMessage.error('抱歉,您没有权限获取用户列表!');
  178. else {
  179. state.tableLoading = true;
  180. getUserListPaged(state.queryParams)
  181. .then((response: any) => {
  182. state.tableData = response?.result.items ?? [];
  183. state.total = response?.result.total;
  184. rightScrollRef.value.setScrollTop(0); //滚动倒顶部
  185. state.tableLoading = false;
  186. })
  187. .catch(() => {
  188. state.tableLoading = false;
  189. });
  190. }
  191. };
  192. // 获取角色
  193. const getRolesFn = () => {
  194. if (!auth('system:role:query')) ElMessage.error('抱歉,您没有权限获取角色列表!');
  195. else {
  196. getRoles({ PageIndex: 1, PageSize: 999 }).then((res: any) => {
  197. state.options = res?.result.items ?? [];
  198. state.options = state.options.map((item: any) => ({
  199. value: item.id,
  200. label: item.displayName,
  201. }));
  202. });
  203. }
  204. };
  205. // 点击节点
  206. const handleNodeClick = (data: any) => {
  207. state.queryParams.OrgCode = data.orgCode;
  208. getList();
  209. };
  210. // 打开新增用户弹窗
  211. const onOpenAddUser = () => {
  212. userAddRef.value.openDialog();
  213. };
  214. /** 重置按钮操作 */
  215. const resetQuery = throttle((formEl: FormInstance | undefined) => {
  216. if (!formEl) return;
  217. formEl.resetFields();
  218. state.queryParams.OrgCode = '';
  219. treRef.value?.setCurrentKey(null);
  220. handleQuery();
  221. }, 500);
  222. // 打开修改用户弹窗
  223. const onOpenEditUser = (row: any) => {
  224. userEditRef.value.openDialog(row);
  225. };
  226. // 重置密码
  227. const onRestPwd = (row: any) => {
  228. ElMessageBox.confirm(`此操作将:“${row.name}的密码重置为Fwkj@789”,是否继续?`, '提示', {
  229. confirmButtonText: '确认',
  230. cancelButtonText: '取消',
  231. type: 'warning',
  232. draggable: true,
  233. cancelButtonClass: 'default-button',
  234. })
  235. .then(() => {
  236. restPwd(row.id).then(() => {
  237. ElMessage.success('操作成功');
  238. getList();
  239. state.queryParams.OrgCode = '';
  240. getOrgListApi();
  241. });
  242. })
  243. .catch(() => {});
  244. };
  245. // 删除用户
  246. const onRowDel = (row: any) => {
  247. ElMessageBox.confirm(`此操作将永久删除账户名称:“${row.name}”,是否继续?`, '提示', {
  248. confirmButtonText: '确认',
  249. cancelButtonText: '取消',
  250. draggable: true,
  251. cancelButtonClass: 'default-button',
  252. type: 'warning',
  253. })
  254. .then(() => {
  255. delUser(row.id).then(() => {
  256. ElMessage.success('删除成功');
  257. getList();
  258. state.queryParams.OrgCode = '';
  259. getOrgListApi();
  260. });
  261. })
  262. .catch(() => {});
  263. };
  264. onMounted(() => {
  265. getRolesFn();
  266. getList();
  267. getOrgListApi();
  268. });
  269. onActivated(() => {});
  270. </script>
  271. <style lang="scss" scoped>
  272. .system-user-container {
  273. .orgTree {
  274. border-right: 1px solid var(--el-border-color);
  275. height: 100%;
  276. }
  277. .rightContent {
  278. height: 100%;
  279. }
  280. :deep(.el-tree-node__content) {
  281. height: 40px;
  282. }
  283. }
  284. </style>