index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <div class="system-user-container layout-padding">
  3. <div class="layout-padding-auto layout-padding-view pd20">
  4. <splitpanes class="h100" Vertical>
  5. <pane min-size="16" max-size="25" size="16">
  6. <el-input v-model="filterOrg" placeholder="请输入部门名称" class="input-with-select mb10" clearable @input="onQueryChanged"> </el-input>
  7. <el-scrollbar style="height: calc(100% - 40px);'" ref="scrollBarRef">
  8. <el-skeleton :loading="state.loading" animated :rows="10">
  9. <template #default>
  10. <el-tree-v2
  11. :data="state.orgData"
  12. :filter-method="filterNodeOrg"
  13. ref="treRef"
  14. highlight-current
  15. :expand-on-click-node="false"
  16. @node-click="handleNodeClick"
  17. :item-size="40"
  18. :height="treeHeight"
  19. empty-text="暂无组织数据"
  20. :props="{ label: 'name', value: 'id' }"
  21. >
  22. <template #default="{ node }">
  23. <span>{{ node.label }}</span>
  24. </template>
  25. </el-tree-v2>
  26. </template>
  27. </el-skeleton>
  28. </el-scrollbar>
  29. </pane>
  30. <pane>
  31. <el-scrollbar class="pr10 scrollbar__view" ref="rightScrollRef">
  32. <el-form :model="state.queryParams" ref="ruleFormRef" inline @submit.native.prevent>
  33. <el-form-item label="关键字" prop="Keyword">
  34. <el-input
  35. v-model="state.queryParams.Keyword"
  36. placeholder="姓名/电话号码/账号"
  37. clearable
  38. @keyup.enter="handleQuery"
  39. class="keyword-input"
  40. />
  41. </el-form-item>
  42. <el-form-item label="角色" prop="Role">
  43. <el-select-v2
  44. v-model="state.queryParams.Role"
  45. filterable
  46. :options="state.roleOptions"
  47. :props="{
  48. label: 'displayName',
  49. value: 'id',
  50. }"
  51. placeholder="请选择角色"
  52. clearable
  53. />
  54. </el-form-item>
  55. <el-form-item>
  56. <el-button type="primary" @click="handleQuery" :loading="state.tableLoading">
  57. <SvgIcon name="ele-Search" class="mr5" />查询
  58. </el-button>
  59. <el-button @click="resetQuery(ruleFormRef)" class="default-button" :loading="state.tableLoading">
  60. <SvgIcon name="ele-Refresh" class="mr5" />重置
  61. </el-button>
  62. </el-form-item>
  63. </el-form>
  64. <ProTable
  65. ref="proTableRef"
  66. :columns="columns"
  67. :data="state.tableData"
  68. @updateTable="queryList"
  69. :loading="state.tableLoading"
  70. :total="state.total"
  71. v-model:page-index="state.queryParams.PageIndex"
  72. v-model:page-size="state.queryParams.PageSize"
  73. >
  74. <!-- 表格 header 按钮 -->
  75. <template #tableHeader="scope">
  76. <el-button type="primary" @click="onOpenAddUser" v-auth="'system:user:add'"> <SvgIcon name="ele-Plus" class="mr5" />新增 </el-button>
  77. </template>
  78. <!-- 表格操作 -->
  79. <template #operation="{ row }">
  80. <el-button link type="primary" @click="onOpenEditUser(row)" v-auth="'system:user:edit'" title="修改" v-if="!row.isDeleted">
  81. 修改
  82. </el-button>
  83. <el-button link type="warning" @click="onRestPwd(row)" title="重置密码" v-auth="'system:user:resetPwd'" v-if="!row.isDeleted">
  84. 重置密码
  85. </el-button>
  86. <el-button link type="danger" @click="onRowDel(row)" v-auth="'system:user:delete'" title="删除" v-if="!row.isDeleted">
  87. 删除
  88. </el-button>
  89. </template>
  90. </ProTable>
  91. <el-backtop target=".scrollbar__view > div" />
  92. </el-scrollbar>
  93. </pane>
  94. </splitpanes>
  95. </div>
  96. <user-add
  97. ref="userAddRef"
  98. @updateList="queryList"
  99. :roles="state.roleOptions"
  100. :baseOrg="state.orgData"
  101. :baseData="state.baseData"
  102. :telsList="state.telsList"
  103. />
  104. <user-edit
  105. ref="userEditRef"
  106. @updateList="queryList"
  107. :roles="state.roleOptions"
  108. :baseOrg="state.orgData"
  109. :baseData="state.baseData"
  110. :telsList="state.telsList"
  111. />
  112. </div>
  113. </template>
  114. <script lang="tsx" setup name="systemUser">
  115. import { defineAsyncComponent, nextTick, onActivated, onMounted, reactive, ref } from 'vue';
  116. import type { FormInstance } from 'element-plus';
  117. import { ElButton, ElMessage, ElMessageBox } from 'element-plus';
  118. import { formatDate } from '@/utils/formatTime';
  119. import { throttle } from '@/utils/tools';
  120. import { delUser, getBaseData, getCanUseOrg, getRoles, getUserListPaged, restPwd } from '@/api/system/user';
  121. import { getTelList } from '@/api/public/wex';
  122. import { Splitpanes, Pane } from 'splitpanes';
  123. import 'splitpanes/dist/splitpanes.css';
  124. // 引入组件
  125. const UserAdd = defineAsyncComponent(() => import('@/views/system/user/component/User-add.vue')); // 新增用户组件
  126. const UserEdit = defineAsyncComponent(() => import('@/views/system/user/component/User-edit.vue')); // 修改用户组件
  127. const proTableRef = ref<RefType>(); // 表格ref
  128. // 表格配置项
  129. const columns = ref<any[]>([
  130. { prop: 'name', label: '姓名', width: 170 },
  131. { prop: 'userName', label: '账号', width: 170 },
  132. { prop: 'organization.name', label: '所属部门', width: 190 },
  133. { prop: 'organization.orgTypeText', label: '部门类别', width: 190 },
  134. { prop: 'roleNames', label: '角色', width: 300 },
  135. { prop: 'phoneNo', label: '电话号码', width: 130 },
  136. { prop: 'staffNo', label: '工号', width: 120 },
  137. { prop: 'userTypeText', label: '用户类型' },
  138. { prop: 'genderText', label: '性别', width: 80 },
  139. {
  140. prop: 'creationTime',
  141. label: '创建时间',
  142. width: 170,
  143. render: (scope) => {
  144. return <span>{formatDate(scope.row.creationTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
  145. },
  146. },
  147. { prop: 'state', label: '状态', width: 80 },
  148. { prop: 'operation', label: '操作', fixed: 'right', width: 180, align: 'center' },
  149. ]);
  150. // 定义变量内容
  151. const state = reactive<any>({
  152. queryParams: {
  153. PageIndex: 1, // 当前页
  154. PageSize: 10, // 每页条数
  155. Keyword: null, // 关键字
  156. Role: null, // 角色id
  157. OrgCode: null, // 组织code
  158. },
  159. tableData: [], // 表格数据
  160. total: 0, // 总条数
  161. loading: false, // 加载状态
  162. tableLoading: false, // 表格加载状态
  163. orgData: [], // 组织结构数据
  164. roleOptions: [], // 角色数据
  165. baseData: [], // 基础数据
  166. telsList: [], // 分机数据
  167. });
  168. const ruleFormRef = ref<FormInstance>(); //表单ref
  169. const filterOrg = ref(''); // 搜索部门名称
  170. const treRef = ref<RefType>(); // 树形组件ref
  171. const onQueryChanged = (query: string) => {
  172. if (query) {
  173. treRef.value!.filter(query);
  174. } else {
  175. treRef.value!.filter(query);
  176. treRef.value?.setExpandedKeys([]);
  177. }
  178. };
  179. // 搜索部门名称
  180. const filterNodeOrg = (query: string, data: any) => {
  181. return data.name!.includes(query);
  182. };
  183. /** 搜索按钮操作 节流操作 */
  184. const handleQuery = throttle(() => {
  185. state.queryParams.PageIndex = 1;
  186. queryList();
  187. }, 300);
  188. // 获取所有组织结构
  189. const getOrgListApi = () => {
  190. state.loading = true;
  191. getCanUseOrg()
  192. .then((res: any) => {
  193. state.orgData = res?.result ?? [];
  194. state.loading = false;
  195. })
  196. .catch(() => {
  197. state.loading = false;
  198. });
  199. };
  200. /** 获取用户列表 */
  201. const rightScrollRef = ref<RefType>();
  202. const queryList = () => {
  203. state.tableLoading = true;
  204. getUserListPaged(state.queryParams)
  205. .then((response: any) => {
  206. state.tableData = response?.result.items ?? [];
  207. state.total = response?.result.total;
  208. rightScrollRef.value.setScrollTop(0); //滚动倒顶部
  209. state.tableLoading = false;
  210. })
  211. .catch(() => {
  212. state.tableLoading = false;
  213. });
  214. };
  215. // 获取角色
  216. const getRolesFn = () => {
  217. getRoles({ PageIndex: 1, PageSize: 999, IsDeleted: false }).then((res: any) => {
  218. state.roleOptions = res?.result.items ?? [];
  219. });
  220. };
  221. // 查询页面基础信息
  222. const getBaseDataFn = () => {
  223. getBaseData().then((res: any) => {
  224. state.baseData = res?.result ?? [];
  225. });
  226. };
  227. // 获取分机列表
  228. const getTelsListFn = async (object?: object) => {
  229. const res: any = await getTelList(object);
  230. state.telsList = res?.result ?? [];
  231. };
  232. // 点击节点
  233. const handleNodeClick = (data: any) => {
  234. state.queryParams.OrgCode = data.id;
  235. queryList();
  236. };
  237. // 打开新增用户弹窗
  238. const userAddRef = ref<RefType>(); //新增用户
  239. const onOpenAddUser = () => {
  240. userAddRef.value.openDialog();
  241. };
  242. /** 重置按钮操作 */
  243. const resetQuery = throttle((formEl: FormInstance | undefined) => {
  244. if (!formEl) return;
  245. formEl.resetFields();
  246. state.queryParams.OrgCode = '';
  247. treRef.value?.setCurrentKey(null);
  248. handleQuery();
  249. }, 300);
  250. // 打开修改用户弹窗
  251. const userEditRef = ref<RefType>(); //修改用户信息
  252. const onOpenEditUser = (row: any) => {
  253. userEditRef.value.openDialog(row);
  254. };
  255. // 重置密码
  256. const onRestPwd = (row: any) => {
  257. ElMessageBox.confirm(`此操作将:“${row.name}的密码重置为Fwkj@789”,是否继续?`, '提示', {
  258. confirmButtonText: '确认',
  259. cancelButtonText: '取消',
  260. type: 'warning',
  261. draggable: true,
  262. cancelButtonClass: 'default-button',
  263. })
  264. .then(() => {
  265. restPwd(row.id).then(() => {
  266. ElMessage.success('操作成功');
  267. queryList();
  268. state.queryParams.OrgCode = '';
  269. getOrgListApi();
  270. });
  271. })
  272. .catch(() => {});
  273. };
  274. // 删除用户
  275. const onRowDel = (row: any) => {
  276. ElMessageBox.confirm(`此操作将永久删除账户名称:“${row.name}”,是否继续?`, '提示', {
  277. confirmButtonText: '确认',
  278. cancelButtonText: '取消',
  279. draggable: true,
  280. cancelButtonClass: 'default-button',
  281. type: 'warning',
  282. })
  283. .then(() => {
  284. delUser(row.id).then(() => {
  285. ElMessage.success('删除成功');
  286. queryList();
  287. state.queryParams.OrgCode = '';
  288. getOrgListApi();
  289. });
  290. })
  291. .catch(() => {});
  292. };
  293. onMounted(() => {
  294. getRolesFn();
  295. getBaseDataFn();
  296. getTelsListFn();
  297. getOrgListApi();
  298. queryList();
  299. });
  300. const scrollBarRef = ref<RefType>(); // 滚动条ref
  301. const treeHeight = ref(0);
  302. onMounted(async () => {
  303. await nextTick();
  304. treeHeight.value = scrollBarRef.value.wrapRef.clientHeight;
  305. window.addEventListener('resize', () => {
  306. treeHeight.value = scrollBarRef.value.wrapRef.clientHeight;
  307. });
  308. });
  309. onActivated(() => {
  310. treRef.value.setData(state.orgData);
  311. });
  312. </script>
  313. <style lang="scss" scoped>
  314. .system-user-container {
  315. .orgTree {
  316. border-right: 1px solid var(--el-border-color);
  317. height: 100%;
  318. }
  319. :deep(.el-tree-node__content) {
  320. line-height: 40px;
  321. }
  322. }
  323. </style>