index.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. <template>
  2. <div class="p-2">
  3. <el-row :gutter="20">
  4. <!-- 科室树 -->
  5. <el-col :lg="4" :xs="24" style="">
  6. <el-card shadow="hover">
  7. <el-input v-model="deptName" placeholder="搜索科室" prefix-icon="Search" clearable />
  8. <el-tree
  9. ref="deptTreeRef"
  10. class="mt-2"
  11. node-key="id"
  12. :data="deptOptions"
  13. :props="{ label: 'label', children: 'children' } as any"
  14. :expand-on-click-node="false"
  15. :filter-node-method="filterNode"
  16. highlight-current
  17. default-expand-all
  18. @node-click="handleNodeClick"
  19. />
  20. </el-card>
  21. </el-col>
  22. <el-col :lg="20" :xs="24">
  23. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  24. <div v-show="showSearch" class="mb-[10px]">
  25. <el-card shadow="hover">
  26. <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="150px">
  27. <el-form-item label="角色" prop="roleId">
  28. <el-select v-model="queryParams.roleId" placeholder="请选择" clearable>
  29. <el-option v-for="dict in roleList" :key="dict.roleId" :label="dict.roleName" :value="dict.roleId" />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="登录名/姓名/工号" prop="userName">
  33. <el-input v-model="queryParams.userName" placeholder="请输入" clearable @keyup.enter="handleQuery" />
  34. </el-form-item>
  35. <!--<el-form-item label="用户昵称" prop="nickName">
  36. <el-input v-model="queryParams.nickName" placeholder="请输入用户昵称" clearable @keyup.enter="handleQuery" />
  37. </el-form-item>
  38. <el-form-item label="手机号码" prop="phonenumber">
  39. <el-input v-model="queryParams.phonenumber" placeholder="请输入手机号码" clearable @keyup.enter="handleQuery" />
  40. </el-form-item>
  41. <el-form-item label="创建时间" style="width: 308px">
  42. <el-date-picker
  43. v-model="dateRange"
  44. value-format="YYYY-MM-DD HH:mm:ss"
  45. type="daterange"
  46. range-separator="-"
  47. start-placeholder="开始日期"
  48. end-placeholder="结束日期"
  49. :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
  50. ></el-date-picker>
  51. </el-form-item> -->
  52. <el-form-item>
  53. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  54. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  55. </el-form-item>
  56. </el-form>
  57. </el-card>
  58. </div>
  59. </transition>
  60. <el-card shadow="hover">
  61. <template #header>
  62. <el-row :gutter="10">
  63. <el-col :span="1.5">
  64. <el-button v-has-permi="['system:user:add']" type="primary" plain icon="Plus" @click="handleAdd()">新增</el-button>
  65. </el-col>
  66. <!-- <el-col :span="1.5">
  67. <el-button v-has-permi="['system:user:edit']" type="success" plain :disabled="single" icon="Edit" @click="handleUpdate()">
  68. 修改
  69. </el-button>
  70. </el-col>
  71. <el-col :span="1.5">
  72. <el-button v-has-permi="['system:user:remove']" type="danger" plain :disabled="multiple" icon="Delete" @click="handleDelete()">
  73. 删除
  74. </el-button>
  75. </el-col>
  76. <el-col :span="1.5">
  77. <el-dropdown class="mt-[1px]">
  78. <el-button plain type="info">
  79. 更多
  80. <el-icon class="el-icon--right"><arrow-down /></el-icon
  81. ></el-button>
  82. <template #dropdown>
  83. <el-dropdown-menu>
  84. <el-dropdown-item icon="Download" @click="importTemplate">下载模板</el-dropdown-item>
  85. 注意 由于el-dropdown-item标签是延迟加载的 所以v-has-permi自定义标签不生效 需要使用v-if调用方法执行
  86. <el-dropdown-item v-if="checkPermi(['system:user:import'])" icon="Top" @click="handleImport">导入数据</el-dropdown-item>
  87. <el-dropdown-item v-if="checkPermi(['system:user:export'])" icon="Download" @click="handleExport">导出数据</el-dropdown-item>
  88. </el-dropdown-menu>
  89. </template>
  90. </el-dropdown>
  91. </el-col>-->
  92. <right-toolbar v-model:show-search="showSearch" :columns="columns" :search="true" @query-table="getList"></right-toolbar>
  93. </el-row>
  94. </template>
  95. <el-table v-loading="loading" stripe border :data="userList" @selection-change="handleSelectionChange">
  96. <el-table-column type="selection" width="50" align="center" />
  97. <!-- <el-table-column key="userId" label="用户编号" align="center" prop="userId" /> -->
  98. <el-table-column key="name" label="姓名" align="center" prop="name" :show-overflow-tooltip="true" />
  99. <el-table-column key="userName" label="登录名" align="center" prop="userName" :show-overflow-tooltip="true" width="130"/>
  100. <el-table-column key="jobNumber" label="工号" align="center" prop="jobNumber" :show-overflow-tooltip="true" width="130">
  101. <template #default="scope">
  102. {{scope.row.jobNumber?scope.row.jobNumber:'--'}}
  103. </template>
  104. </el-table-column>
  105. <el-table-column key="email" label="用户邮箱" align="center" prop="email" :show-overflow-tooltip="true" width="170" >
  106. <template #default="scope">
  107. {{scope.row.email?scope.row.email:'--'}}
  108. </template>
  109. </el-table-column>
  110. <el-table-column key="phonenumber" label="手机号码" align="center" prop="phonenumber" width="130" >
  111. <template #default="scope">
  112. {{scope.row.phonenumber?scope.row.phonenumber:'--'}}
  113. </template>
  114. </el-table-column>
  115. <el-table-column key="deptName" label="所属科室" align="center" prop="deptName" :show-overflow-tooltip="true" width="170"/>
  116. <el-table-column key="roleName" label="角色" align="center" prop="roleName" :show-overflow-tooltip="true" width="170" />
  117. <el-table-column key="loginDate" label="上次登录时间" align="center" prop="loginDate" width="170" />
  118. <el-table-column label="操作" fixed="right" width="430" class-name="small-padding fixed-width">
  119. <template #default="scope">
  120. <el-tooltip v-if="scope.row.userId !== 1" content="编辑" placement="top">
  121. <el-button v-hasPermi="['system:user:edit']" link type="primary" icon="Edit" @click="handleUpdate(false,scope.row)">编辑</el-button>
  122. </el-tooltip>
  123. <el-tooltip v-if="scope.row.userId !== 1" content="详情" placement="top">
  124. <el-button v-hasPermi="['system:user:edit']" link type="primary" icon="View" @click="handleUpdate(true,scope.row)">详情</el-button>
  125. </el-tooltip>
  126. <el-tooltip v-if="scope.row.userId !== 1" content="删除" placement="top">
  127. <el-button v-hasPermi="['system:user:remove']" link type="danger" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
  128. </el-tooltip>
  129. <el-tooltip v-if="scope.row.userId !== 1" content="重置密码" placement="top">
  130. <el-button v-hasPermi="['system:user:resetPwd']" link type="primary" icon="Key" @click="handleResetPwd(scope.row)">重置密码</el-button>
  131. </el-tooltip>
  132. <el-tooltip v-if="scope.row.userId !== 1" content="分配角色" placement="top">
  133. <el-button v-hasPermi="['system:user:edit']" link type="primary" icon="CircleCheck" @click="handleAuthRole(scope.row)">分配角色</el-button>
  134. </el-tooltip>
  135. </template>
  136. </el-table-column>
  137. </el-table>
  138. <pagination
  139. v-show="total > 0"
  140. v-model:page="queryParams.pageNum"
  141. v-model:limit="queryParams.pageSize"
  142. :total="total"
  143. @pagination="getList"
  144. />
  145. </el-card>
  146. </el-col>
  147. </el-row>
  148. <!-- 添加或修改用户配置对话框 -->
  149. <el-dialog ref="formDialogRef" v-model="dialog.visible" :title="dialog.title" width="800px" append-to-body @close="closeDialog">
  150. <el-form ref="userFormRef" :model="form" :rules="rules" label-width="100px">
  151. <el-row>
  152. <el-col :span="12">
  153. <el-form-item label="姓名" prop="name">
  154. <el-input v-model="form.name" placeholder="请输入姓名" maxlength="11" :disabled="dialog.disabled"/>
  155. </el-form-item>
  156. </el-col>
  157. <el-col :span="12">
  158. <el-form-item v-if="form.userId == undefined" label="用户密码" prop="password">
  159. <el-input v-model="form.password" placeholder="请输入用户密码" type="password" maxlength="20" show-password :disabled="dialog.disabled" />
  160. </el-form-item>
  161. </el-col>
  162. </el-row>
  163. <el-row>
  164. <el-col :span="12">
  165. <el-form-item label="别名" prop="alias">
  166. <el-input v-model="form.alias" placeholder="请输入别名" maxlength="30" :disabled="dialog.disabled" />
  167. </el-form-item>
  168. </el-col>
  169. <el-col :span="12">
  170. <el-form-item label="角色" prop="roleIds">
  171. <el-select v-model="form.roleIds" filterable placeholder="请选择" :disabled="dialog.disabled">
  172. <el-option
  173. v-for="item in roleOptions"
  174. :key="item.roleId"
  175. :label="item.roleName"
  176. :value="item.roleId"
  177. :disabled="item.status == '1'"
  178. ></el-option>
  179. </el-select>
  180. </el-form-item>
  181. </el-col>
  182. </el-row>
  183. <el-row>
  184. <el-col :span="12">
  185. <el-form-item label="性别" prop="sex">
  186. <el-select v-model="form.sex" placeholder="请选择" :disabled="dialog.disabled">
  187. <el-option v-for="dict in sys_user_sex" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
  188. </el-select>
  189. </el-form-item>
  190. </el-col>
  191. <el-col :span="12">
  192. <el-form-item label="所属科室" prop="deptId" >
  193. <el-tree-select :disabled="dialog.disabled"
  194. v-model="form.deptId"
  195. :data="enabledDeptOptions"
  196. :props="{ value: 'id', label: 'label', children: 'children' } as any"
  197. value-key="id"
  198. placeholder="请选择所属科室"
  199. check-strictly
  200. @change="handleDeptChange"
  201. />
  202. </el-form-item>
  203. </el-col>
  204. </el-row>
  205. <el-row>
  206. <el-col :span="12">
  207. <el-form-item label="登录名" prop="userName" >
  208. <el-input v-model="form.userName" placeholder="请输入登录名" maxlength="30" :disabled="dialog.disabled" />
  209. </el-form-item>
  210. </el-col>
  211. <el-col :span="12">
  212. <el-form-item label="所属科室编码" prop="deptCode">
  213. <el-input v-model="form.deptCode" placeholder="请输入" :disabled="true" />
  214. </el-form-item>
  215. </el-col>
  216. </el-row>
  217. <el-row>
  218. <el-col :span="12">
  219. <el-form-item label="工号" prop="jobNumber">
  220. <el-input v-model="form.jobNumber" placeholder="请输入工号" :disabled="dialog.disabled"/>
  221. </el-form-item>
  222. </el-col>
  223. <el-col :span="12">
  224. </el-col>
  225. </el-row>
  226. <el-divider />
  227. <el-row>
  228. <el-col :span="12">
  229. <el-form-item label="身份证号码" prop="idCard">
  230. <el-input v-model="form.idCard" placeholder="请输入身份证号码" :disabled="dialog.disabled" @input="handleIdCardChange"/>
  231. </el-form-item>
  232. </el-col>
  233. <el-col :span="12">
  234. <el-form-item label="现住地址" prop="address">
  235. <el-input v-model="form.address" placeholder="请输入现住地址" :disabled="dialog.disabled"/>
  236. </el-form-item>
  237. </el-col>
  238. </el-row>
  239. <el-row>
  240. <el-col :span="12">
  241. <el-form-item label="出生日期" prop="birthDate">
  242. <el-input v-model="form.birthDate" placeholder="请输入出生日期" :disabled="true"/>
  243. </el-form-item>
  244. </el-col>
  245. <el-col :span="12">
  246. <el-form-item label="户籍地址" prop="regAddress">
  247. <el-input v-model="form.regAddress" placeholder="请输入户籍地址" :disabled="dialog.disabled"/>
  248. </el-form-item>
  249. </el-col>
  250. </el-row>
  251. <el-row>
  252. <el-col :span="12">
  253. <el-form-item label="民族" prop="nation">
  254. <el-input v-model="form.nation" placeholder="请输入民族" :disabled="dialog.disabled"/>
  255. </el-form-item>
  256. </el-col>
  257. <el-col :span="12">
  258. <el-form-item label="政治面貌" prop="political">
  259. <el-input v-model="form.political" placeholder="请输入政治面貌" :disabled="dialog.disabled"/>
  260. </el-form-item>
  261. </el-col>
  262. </el-row>
  263. <el-row>
  264. <el-col :span="12">
  265. <el-form-item label="婚姻状况" prop="marital">
  266. <el-input v-model="form.marital" placeholder="请输入婚姻状况" :disabled="dialog.disabled"/>
  267. </el-form-item>
  268. </el-col>
  269. <el-col :span="12">
  270. <el-form-item label="职称" prop="title">
  271. <el-input v-model="form.title" placeholder="请输入职称" :disabled="dialog.disabled"/>
  272. </el-form-item>
  273. </el-col>
  274. </el-row>
  275. <el-row>
  276. <el-col :span="12">
  277. <el-form-item label="学历" prop="education">
  278. <el-input v-model="form.education" placeholder="请输入学历" :disabled="dialog.disabled" />
  279. </el-form-item>
  280. </el-col>
  281. <el-col :span="12">
  282. <el-form-item label="手机号码" prop="phonenumber">
  283. <el-input v-model="form.phonenumber" placeholder="请输入手机号码" maxlength="11" :disabled="dialog.disabled"/>
  284. </el-form-item>
  285. </el-col>
  286. </el-row>
  287. <el-row>
  288. <el-col :span="12">
  289. <el-form-item label="电子邮箱" prop="email">
  290. <el-input v-model="form.email" placeholder="请输入电子邮箱" :disabled="dialog.disabled"/>
  291. </el-form-item>
  292. </el-col>
  293. <el-col :span="12">
  294. <el-form-item label="职工简介" prop="intro">
  295. <el-input v-model="form.intro" placeholder="请输入" type="textarea" :rows="3" :disabled="dialog.disabled"/>
  296. </el-form-item>
  297. </el-col>
  298. </el-row>
  299. <el-row>
  300. <el-col :span="12">
  301. <el-form-item label="擅长疾病" prop="expertise">
  302. <el-input v-model="form.expertise" placeholder="请输入" type="textarea" :rows="6" :disabled="dialog.disabled"/>
  303. </el-form-item>
  304. </el-col>
  305. <el-col :span="12">
  306. <el-form-item label="签名图片" prop="signatureImg">
  307. <imageUpload v-model="form.signatureImg" :limit="1" :isShowTip="false" :disabled="dialog.disabled"/>
  308. <span style="font-size: 11px;color: red;">上传的签名图片将备用于复核管理的复核人签名</span>
  309. </el-form-item>
  310. </el-col>
  311. </el-row>
  312. </el-form>
  313. <template #footer>
  314. <div class="dialog-footer">
  315. <el-button type="primary" @click="submitForm">确 定</el-button>
  316. <el-button @click="cancel()">取 消</el-button>
  317. </div>
  318. </template>
  319. </el-dialog>
  320. <!-- 用户导入对话框 -->
  321. <el-dialog v-model="upload.open" :title="upload.title" width="400px" append-to-body>
  322. <el-upload
  323. ref="uploadRef"
  324. :limit="1"
  325. accept=".xlsx, .xls"
  326. :headers="upload.headers"
  327. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  328. :disabled="upload.isUploading"
  329. :on-progress="handleFileUploadProgress"
  330. :on-success="handleFileSuccess"
  331. :auto-upload="false"
  332. drag
  333. >
  334. <el-icon class="el-icon--upload">
  335. <i-ep-upload-filled />
  336. </el-icon>
  337. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  338. <template #tip>
  339. <div class="text-center el-upload__tip">
  340. <div class="el-upload__tip"><el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据</div>
  341. <span>仅允许导入xls、xlsx格式文件。</span>
  342. <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link>
  343. </div>
  344. </template>
  345. </el-upload>
  346. <template #footer>
  347. <div class="dialog-footer">
  348. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  349. <el-button @click="upload.open = false">取 消</el-button>
  350. </div>
  351. </template>
  352. </el-dialog>
  353. </div>
  354. </template>
  355. <script setup name="User" lang="ts">
  356. import api from '@/api/system/user';
  357. import { UserForm, UserQuery, UserVO } from '@/api/system/user/types';
  358. import { DeptTreeVO, DeptVO } from '@/api/system/dept/types';
  359. import { RoleVO ,RoleQuery} from '@/api/system/role/types';
  360. import { PostQuery, PostVO } from '@/api/system/post/types';
  361. import { treeselect } from '@/api/system/dept';
  362. import { globalHeaders } from '@/utils/request';
  363. import { to } from 'await-to-js';
  364. import { optionselect } from '@/api/system/post';
  365. import { hasPermi } from '@/directive/permission';
  366. import { checkPermi } from '@/utils/permission';
  367. import {listAllRole } from '@/api/system/role';
  368. const roleList=ref();
  369. const router = useRouter();
  370. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  371. const { sys_normal_disable, sys_user_sex } = toRefs<any>(proxy?.useDict('sys_normal_disable', 'sys_user_sex'));
  372. const userList = ref<UserVO[]>();
  373. const loading = ref(true);
  374. const showSearch = ref(true);
  375. const ids = ref<Array<number | string>>([]);
  376. const single = ref(true);
  377. const multiple = ref(true);
  378. const total = ref(0);
  379. const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
  380. const deptName = ref('');
  381. const deptOptions = ref<DeptTreeVO[]>([]);
  382. const enabledDeptOptions = ref<DeptTreeVO[]>([]);
  383. const initPassword = ref<string>('');
  384. const postOptions = ref<PostVO[]>([]);
  385. const roleOptions = ref<RoleVO[]>([]);
  386. /*** 用户导入参数 */
  387. const upload = reactive<ImportOption>({
  388. // 是否显示弹出层(用户导入)
  389. open: false,
  390. // 弹出层标题(用户导入)
  391. title: '',
  392. // 是否禁用上传
  393. isUploading: false,
  394. // 是否更新已经存在的用户数据
  395. updateSupport: 0,
  396. // 设置上传的请求头部
  397. headers: globalHeaders(),
  398. // 上传的地址
  399. url: import.meta.env.VITE_APP_BASE_API + '/system/user/importData'
  400. });
  401. // 列显隐信息
  402. const columns = ref<FieldOption[]>([
  403. { key: 0, label: `用户编号`, visible: false, children: [] },
  404. { key: 1, label: `用户名称`, visible: true, children: [] },
  405. { key: 2, label: `用户昵称`, visible: true, children: [] },
  406. { key: 3, label: `科室`, visible: true, children: [] },
  407. { key: 4, label: `手机号码`, visible: true, children: [] },
  408. { key: 5, label: `状态`, visible: true, children: [] },
  409. { key: 6, label: `创建时间`, visible: true, children: [] }
  410. ]);
  411. const deptTreeRef = ref<ElTreeInstance>();
  412. const queryFormRef = ref<ElFormInstance>();
  413. const userFormRef = ref<ElFormInstance>();
  414. const uploadRef = ref<ElUploadInstance>();
  415. const formDialogRef = ref<ElDialogInstance>();
  416. const dialog = reactive<DialogOption>({
  417. visible: false,
  418. disabled:false,
  419. title: ''
  420. });
  421. const initFormData: UserForm = {
  422. userId: undefined,
  423. deptId: undefined,
  424. userName: '',
  425. nickName: undefined,
  426. password: '',
  427. phonenumber: undefined,
  428. email: undefined,
  429. sex: undefined,
  430. status: '0',
  431. remark: '',
  432. postIds: [],
  433. roleIds: []
  434. };
  435. const initData: PageData<UserForm, UserQuery> = {
  436. form: { ...initFormData },
  437. queryParams: {
  438. pageNum: 1,
  439. pageSize: 10,
  440. userName: '',
  441. phonenumber: '',
  442. status: '',
  443. deptId: '',
  444. roleId: ''
  445. },
  446. rules: {
  447. userName: [
  448. { required: true, message: '用户名称不能为空', trigger: 'blur' },
  449. {
  450. min: 2,
  451. max: 20,
  452. message: '用户名称长度必须介于 2 和 20 之间',
  453. trigger: 'blur'
  454. }
  455. ],
  456. sex: [{ required: true, message: '请选择性别', trigger: 'blur' }],
  457. password: [
  458. { required: true, message: '用户密码不能为空', trigger: 'blur' },
  459. {
  460. min: 5,
  461. max: 20,
  462. message: '用户密码长度必须介于 5 和 20 之间',
  463. trigger: 'blur'
  464. },
  465. { pattern: /^[^<>"'|\\]+$/, message: '不能包含非法字符:< > " \' \\ |', trigger: 'blur' }
  466. ],
  467. email: [
  468. {
  469. type: 'email',
  470. message: '请输入正确的邮箱地址',
  471. trigger: ['blur', 'change']
  472. }
  473. ],
  474. name: [
  475. { required: true, message: '姓名不能为空', trigger: 'blur' }
  476. ],
  477. deptId: [
  478. { required: true, message: '请选择所属科室', trigger: 'blur' }
  479. ],
  480. roleIds: [{ required: true, message: '用户角色不能为空', trigger: 'blur' }]
  481. }
  482. };
  483. const data = reactive<PageData<UserForm, UserQuery>>(initData);
  484. const { queryParams, form, rules } = toRefs<PageData<UserForm, UserQuery>>(data);
  485. /** 通过条件过滤节点 */
  486. const filterNode = (value: string, data: any) => {
  487. if (!value) return true;
  488. return data.label.indexOf(value) !== -1;
  489. };
  490. /** 根据名称筛选科室树 */
  491. watchEffect(
  492. () => {
  493. deptTreeRef.value?.filter(deptName.value);
  494. },
  495. {
  496. flush: 'post' // watchEffect会在DOM挂载或者更新之前就会触发,此属性控制在DOM元素更新后运行
  497. }
  498. );
  499. /** 查询用户列表 */
  500. const getList = async () => {
  501. loading.value = true;
  502. const res = await api.listUser(proxy?.addDateRange(queryParams.value, dateRange.value));
  503. loading.value = false;
  504. userList.value = res.rows;
  505. total.value = res.total;
  506. };
  507. /** 查询科室下拉树结构 */
  508. const getDeptTree = async () => {
  509. const res = await api.deptTreeSelect();
  510. deptOptions.value = res.data;
  511. enabledDeptOptions.value = filterDisabledDept(res.data);
  512. };
  513. const deptJson= ref({});
  514. /** 过滤禁用的科室 */
  515. const filterDisabledDept = (deptList: DeptTreeVO[]) => {
  516. return deptList.filter((dept) => {
  517. deptJson.value[dept.id.toString()]=dept;
  518. if (dept.disabled) {
  519. return false;
  520. }
  521. if (dept.children && dept.children.length) {
  522. dept.children = filterDisabledDept(dept.children);
  523. }
  524. return true;
  525. });
  526. };
  527. /** 节点单击事件 */
  528. const handleNodeClick = (data: DeptVO) => {
  529. queryParams.value.deptId = data.id;
  530. handleQuery();
  531. };
  532. /** 搜索按钮操作 */
  533. const handleQuery = () => {
  534. queryParams.value.pageNum = 1;
  535. getList();
  536. };
  537. const handleIdCardChange=(val:string)=>{
  538. if(val&&val.length>6){
  539. let birth=val.substring(6,6+Math.min(val.length,8))
  540. if(birth.length>=4){
  541. birth=birth.substring(0,4)+'-'+birth.substring(4,val.length);
  542. }
  543. if(birth.length>=6){
  544. birth=birth.substring(0,7)+'-'+birth.substring(7,val.length);
  545. }
  546. form.value.birthDate=birth;
  547. }
  548. }
  549. /** 重置按钮操作 */
  550. const resetQuery = () => {
  551. dateRange.value = ['', ''];
  552. queryFormRef.value?.resetFields();
  553. queryParams.value.pageNum = 1;
  554. queryParams.value.deptId = undefined;
  555. deptTreeRef.value?.setCurrentKey(undefined);
  556. handleQuery();
  557. };
  558. /** 删除按钮操作 */
  559. const handleDelete = async (row?: UserVO) => {
  560. const userIds = row?.userId || ids.value;
  561. const [err] = await to(proxy?.$modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项?') as any);
  562. if (!err) {
  563. await api.delUser(userIds);
  564. await getList();
  565. proxy?.$modal.msgSuccess('删除成功');
  566. }
  567. };
  568. /** 用户状态修改 */
  569. const handleStatusChange = async (row: UserVO) => {
  570. const text = row.status === '0' ? '启用' : '停用';
  571. try {
  572. await proxy?.$modal.confirm('确认要"' + text + '""' + row.userName + '"用户吗?');
  573. await api.changeUserStatus(row.userId, row.status);
  574. proxy?.$modal.msgSuccess(text + '成功');
  575. } catch (err) {
  576. row.status = row.status === '0' ? '1' : '0';
  577. }
  578. };
  579. /** 跳转角色分配 */
  580. const handleAuthRole = (row: UserVO) => {
  581. const userId = row.userId;
  582. router.push('/system/user-auth/role/' + userId);
  583. };
  584. /** 重置密码按钮操作 */
  585. const handleResetPwd = async (row: UserVO) => {
  586. const [err, res] = await to(
  587. ElMessageBox.prompt('请输入"' + row.userName + '"的新密码', '提示', {
  588. confirmButtonText: '确定',
  589. cancelButtonText: '取消',
  590. closeOnClickModal: false,
  591. inputPattern: /^.{5,20}$/,
  592. inputErrorMessage: '用户密码长度必须介于 5 和 20 之间',
  593. inputValidator: (value) => {
  594. if (/<|>|"|'|\||\\/.test(value)) {
  595. return '不能包含非法字符:< > " \' \\ |';
  596. }
  597. }
  598. })
  599. );
  600. if (!err && res) {
  601. await api.resetUserPwd(row.userId, res.value);
  602. proxy?.$modal.msgSuccess('修改成功,新密码是:' + res.value);
  603. }
  604. };
  605. /** 选择条数 */
  606. const handleSelectionChange = (selection: UserVO[]) => {
  607. ids.value = selection.map((item) => item.userId);
  608. single.value = selection.length != 1;
  609. multiple.value = !selection.length;
  610. };
  611. /** 导入按钮操作 */
  612. const handleImport = () => {
  613. upload.title = '用户导入';
  614. upload.open = true;
  615. };
  616. /** 导出按钮操作 */
  617. const handleExport = () => {
  618. proxy?.download(
  619. 'system/user/export',
  620. {
  621. ...queryParams.value
  622. },
  623. `user_${new Date().getTime()}.xlsx`
  624. );
  625. };
  626. /** 下载模板操作 */
  627. const importTemplate = () => {
  628. proxy?.download('system/user/importTemplate', {}, `user_template_${new Date().getTime()}.xlsx`);
  629. };
  630. /**文件上传中处理 */
  631. const handleFileUploadProgress = () => {
  632. upload.isUploading = true;
  633. };
  634. /** 文件上传成功处理 */
  635. const handleFileSuccess = (response: any, file: UploadFile) => {
  636. upload.open = false;
  637. upload.isUploading = false;
  638. uploadRef.value?.handleRemove(file);
  639. ElMessageBox.alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + '</div>', '导入结果', {
  640. dangerouslyUseHTMLString: true
  641. });
  642. getList();
  643. };
  644. /** 提交上传文件 */
  645. function submitFileForm() {
  646. uploadRef.value?.submit();
  647. }
  648. /** 重置操作表单 */
  649. const reset = () => {
  650. form.value = { ...initFormData };
  651. userFormRef.value?.resetFields();
  652. };
  653. /** 取消按钮 */
  654. const cancel = () => {
  655. dialog.visible = false;
  656. reset();
  657. };
  658. /** 新增按钮操作 */
  659. const handleAdd = async () => {
  660. reset();
  661. const { data } = await api.getUser();
  662. dialog.visible = true;
  663. dialog.title = '新增用户';
  664. postOptions.value = data.posts;
  665. dialog.disabled = false;
  666. roleOptions.value = data.roles;
  667. form.value.password = initPassword.value.toString();
  668. };
  669. /** 修改按钮操作 */
  670. const handleUpdate = async (disabled:boolean,row?: UserForm ) => {
  671. reset();
  672. const userId = row?.userId || ids.value[0];
  673. const { data } = await api.getUser(userId);
  674. dialog.visible = true;
  675. dialog.title = '修改用户';
  676. dialog.disabled = disabled;
  677. Object.assign(form.value, data.user);
  678. postOptions.value = data.posts;
  679. roleOptions.value = data.roles;
  680. form.value.postIds = data.postIds;
  681. form.value.roleIds = data.roleIds;
  682. form.value.password = '';
  683. };
  684. /** 提交按钮 */
  685. const submitForm = () => {
  686. userFormRef.value?.validate(async (valid: boolean) => {
  687. if (valid) {
  688. form.value.userId ? await api.updateUser(form.value) : await api.addUser(form.value);
  689. proxy?.$modal.msgSuccess('操作成功');
  690. dialog.visible = false;
  691. await getList();
  692. }
  693. });
  694. };
  695. /**
  696. * 关闭用户弹窗
  697. */
  698. const closeDialog = () => {
  699. dialog.visible = false;
  700. resetForm();
  701. };
  702. /**
  703. * 重置表单
  704. */
  705. const resetForm = () => {
  706. userFormRef.value?.resetFields();
  707. userFormRef.value?.clearValidate();
  708. form.value.id = undefined;
  709. form.value.status = '1';
  710. };
  711. onMounted(() => {
  712. getDeptTree(); // 初始化科室数据
  713. getList(); // 初始化列表数据
  714. proxy?.getConfigKey('sys.user.initPassword').then((response) => {
  715. initPassword.value = response.data;
  716. });
  717. listAllRole().then((res) => {
  718. roleList.value = res.rows;
  719. });
  720. });
  721. async function handleDeptChange(value: number | string) {
  722. let dept=deptJson.value[value.toString()]
  723. form.value.deptCode=dept.deptCategory;
  724. }
  725. </script>