index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--部门数据-->
  5. <el-col :span="4" :xs="24">
  6. <dtree v-model="queryParams.deptId" @handleQuery="handleQuery"></dtree>
  7. </el-col>
  8. <!--用户数据-->
  9. <el-col :span="20" :xs="24">
  10. <el-form :model="queryParams" ref="queryForm" :inline="true">
  11. <el-form-item label="账号" prop="userName">
  12. <el-input v-model="queryParams.userName" placeholder="请输入账号" clearable @keyup.enter.native="handleQuery" class="se" />
  13. </el-form-item>
  14. <el-form-item label="姓名" prop="nickName">
  15. <el-input v-model="queryParams.nickName" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" class="se" />
  16. </el-form-item>
  17. <el-form-item label="创建时间">
  18. <el-date-picker v-model="dateRange" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  22. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  23. </el-form-item>
  24. </el-form>
  25. <el-row :gutter="10" class="mb8">
  26. <el-col :span="1.5"><el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-hasPermi="['system:user:add']">新增</el-button></el-col>
  27. <el-col :span="1.5">
  28. <el-button type="success" icon="el-icon-edit" :disabled="single" @click="handleUpdate" v-hasPermi="['system:user:edit']">修改</el-button>
  29. </el-col>
  30. <el-col :span="1.5">
  31. <el-button type="danger" icon="el-icon-delete" :disabled="multiple" @click="handleDelete" v-hasPermi="['system:user:remove']">删除</el-button>
  32. </el-col>
  33. <el-col :span="1.5"><el-button type="info" icon="el-icon-upload2" @click="handleImport" v-hasPermi="['system:user:import']">导入</el-button></el-col>
  34. <el-col :span="1.5"><el-button type="warning" icon="el-icon-download" @click="handleExport" v-hasPermi="['system:user:export']">导出</el-button></el-col>
  35. </el-row>
  36. <el-table border :data="userList" @selection-change="handleSelectionChange" height="calc(100vh - 273px)">
  37. <el-table-column type="selection" align="center" width="50" />
  38. <el-table-column label="登录账号" align="center" key="userName" prop="userName" :show-overflow-tooltip="true" width="110" />
  39. <el-table-column label="姓名" align="center" key="nickName" prop="nickName" :show-overflow-tooltip="true" width="110" />
  40. <el-table-column label="所属科室" align="center" key="deptName" prop="dept.deptName" :show-overflow-tooltip="true" />
  41. <el-table-column label="角色" align="center" width="170">
  42. <template slot-scope="scope">
  43. <el-tag type="danger" size="mini" style="margin-top: 2px" v-if="scope.row.userName == 'admin'">超级管理员</el-tag>
  44. <div v-else>
  45. <span v-for="(item, index) in scope.row.rolesGroup.split(',')" style="padding-right: 5px">{{ item }}</span>
  46. </div>
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="状态" align="center" key="status" width="100">
  50. <template slot-scope="scope">
  51. <div class="switch">
  52. <el-switch v-model="scope.row.status" active-value="0" :width="50" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
  53. <span class="zc" v-if="scope.row.status == 0">正常</span>
  54. <span class="ty" v-else>停用</span>
  55. </div>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="创建时间" align="center" prop="createTime">
  59. <template slot-scope="scope">
  60. <span>{{ parseTime(scope.row.createTime) }}</span>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="操作" align="center" width="160">
  64. <template slot-scope="scope" v-if="scope.row.userId !== 1">
  65. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:user:edit']">修改</el-button>
  66. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:user:remove']">删除</el-button>
  67. <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)" v-hasPermi="['system:user:resetPwd', 'system:user:edit']">
  68. <span class="el-dropdown-link">
  69. <i class="el-icon-d-arrow-right el-icon--right"></i>
  70. 更多
  71. </span>
  72. <el-dropdown-menu slot="dropdown">
  73. <el-dropdown-item command="handleResetPwd" icon="el-icon-key" v-hasPermi="['system:user:resetPwd']">重置密码</el-dropdown-item>
  74. <el-dropdown-item command="handleAuthRole" icon="el-icon-circle-check" v-hasPermi="['system:user:edit']">分配角色</el-dropdown-item>
  75. </el-dropdown-menu>
  76. </el-dropdown>
  77. </template>
  78. </el-table-column>
  79. <template slot="empty">
  80. <el-empty></el-empty>
  81. </template>
  82. </el-table>
  83. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  84. </el-col>
  85. </el-row>
  86. <!-- 用户导入对话框 -->
  87. <el-dialog :title="upload.title" :visible.sync="upload.open" :close-on-click-modal="false" width="400px" append-to-body>
  88. <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
  89. <i class="el-icon-upload"></i>
  90. <div class="el-upload__text">
  91. 将文件拖到此处,或
  92. <em>点击上传</em>
  93. </div>
  94. <div class="el-upload__tip text-center" slot="tip">
  95. <div class="el-upload__tip" slot="tip">
  96. <el-checkbox v-model="upload.updateSupport" />
  97. 是否更新已经存在的用户数据
  98. </div>
  99. <span>仅允许导入xls、xlsx格式文件。</span>
  100. <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link>
  101. </div>
  102. </el-upload>
  103. <div slot="footer" class="dialog-footer">
  104. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  105. <el-button @click="upload.open = false">取 消</el-button>
  106. </div>
  107. </el-dialog>
  108. </div>
  109. </template>
  110. <script>
  111. import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus, deptTreeSelect } from '@/api/system/user';
  112. import { getToken } from '@/utils/auth';
  113. import edit from './edit';
  114. export default {
  115. name: 'User',
  116. data() {
  117. return {
  118. // 非单个禁用
  119. single: true,
  120. // 非多个禁用
  121. multiple: true,
  122. // 总条数
  123. total: 0,
  124. // 用户表格数据
  125. userList: null,
  126. // 日期范围
  127. dateRange: [],
  128. // 表单参数
  129. form: {},
  130. // 用户导入参数
  131. upload: {
  132. // 是否显示弹出层(用户导入)
  133. open: false,
  134. // 弹出层标题(用户导入)
  135. title: '',
  136. // 是否禁用上传
  137. isUploading: false,
  138. // 是否更新已经存在的用户数据
  139. updateSupport: 0,
  140. // 设置上传的请求头部
  141. headers: { Authorization: 'Bearer ' + getToken() },
  142. // 上传的地址
  143. url: process.env.VUE_APP_BASE_API + '/system/user/importData'
  144. },
  145. // 查询参数
  146. queryParams: {
  147. pageNum: 1,
  148. pageSize: 10,
  149. userName: undefined,
  150. phonenumber: undefined,
  151. status: undefined,
  152. deptId: undefined,
  153. orderByColumn: 'userId',
  154. isAsc: 'desc'
  155. }
  156. };
  157. },
  158. created() {
  159. this.getList();
  160. this.getConfigKey('sys.user.initPassword').then((response) => {
  161. this.initPassword = response.msg;
  162. });
  163. },
  164. methods: {
  165. /** 查询用户列表 */
  166. getList() {
  167. listUser(this.addDateRange(this.queryParams, this.dateRange)).then((response) => {
  168. this.userList = response.rows;
  169. this.total = response.total;
  170. });
  171. },
  172. // 用户状态修改
  173. handleStatusChange(row) {
  174. let text = row.status === '0' ? '启用' : '停用';
  175. this.$modal
  176. .confirm('确认要' + text + '"' + row.userName + '"用户吗?')
  177. .then(function () {
  178. return changeUserStatus(row.userId, row.status);
  179. })
  180. .then(() => {
  181. this.$modal.msgSuccess(text + '成功');
  182. })
  183. .catch(function () {
  184. row.status = row.status === '0' ? '1' : '0';
  185. });
  186. },
  187. /** 搜索按钮操作 */
  188. handleQuery() {
  189. this.queryParams.pageNum = 1;
  190. this.getList();
  191. },
  192. /** 重置按钮操作 */
  193. resetQuery() {
  194. this.dateRange = [];
  195. this.resetForm('queryForm');
  196. this.handleQuery();
  197. },
  198. // 多选框选中数据
  199. handleSelectionChange(selection) {
  200. this.ids = selection.map((item) => item.userId);
  201. this.single = selection.length != 1;
  202. this.multiple = !selection.length;
  203. },
  204. // 更多操作触发
  205. handleCommand(command, row) {
  206. switch (command) {
  207. case 'handleResetPwd':
  208. this.handleResetPwd(row);
  209. break;
  210. case 'handleAuthRole':
  211. this.handleAuthRole(row);
  212. break;
  213. default:
  214. break;
  215. }
  216. },
  217. /** 新增按钮操作 */
  218. handleAdd() {
  219. this.iframe({ obj: edit, param: {}, title: '新增管理员/医生', width: '55%', height: '78%' });
  220. },
  221. /** 修改按钮操作 */
  222. handleUpdate(row) {
  223. const userId = row.userId || this.ids;
  224. this.iframe({ obj: edit, param: { id: userId }, title: '编辑管理员/医生', width: '55%', height: '78%' });
  225. },
  226. /** 重置密码按钮操作 */
  227. handleResetPwd(row) {
  228. this.$prompt('请输入"' + row.userName + '"的新密码', '提示', {
  229. confirmButtonText: '确定',
  230. cancelButtonText: '取消',
  231. closeOnClickModal: false,
  232. inputPattern: /^.{5,20}$/,
  233. inputErrorMessage: '用户密码长度必须介于 5 和 20 之间'
  234. })
  235. .then(({ value }) => {
  236. resetUserPwd(row.userId, value).then((response) => {
  237. this.$modal.msgSuccess('修改成功,新密码是:' + value);
  238. });
  239. })
  240. .catch(() => {});
  241. },
  242. /** 分配角色操作 */
  243. handleAuthRole: function (row) {
  244. const userId = row.userId;
  245. this.$router.push('/system/user-auth/role/' + userId);
  246. },
  247. /** 删除按钮操作 */
  248. handleDelete(row) {
  249. const userIds = row.userId || this.ids;
  250. this.$modal
  251. .confirm('是否确认删除用户编号为"' + userIds + '"的数据项?')
  252. .then(function () {
  253. return delUser(userIds);
  254. })
  255. .then(() => {
  256. this.getList();
  257. this.$modal.msgSuccess('删除成功');
  258. })
  259. .catch(() => {});
  260. },
  261. /** 导出按钮操作 */
  262. handleExport() {
  263. this.download(
  264. 'system/user/export',
  265. {
  266. ...this.queryParams
  267. },
  268. `user_${new Date().getTime()}.xlsx`
  269. );
  270. },
  271. /** 导入按钮操作 */
  272. handleImport() {
  273. this.upload.title = '用户导入';
  274. this.upload.open = true;
  275. },
  276. /** 下载模板操作 */
  277. importTemplate() {
  278. this.download('system/user/importTemplate', {}, `user_template_${new Date().getTime()}.xlsx`);
  279. },
  280. // 文件上传中处理
  281. handleFileUploadProgress(event, file, fileList) {
  282. this.upload.isUploading = true;
  283. },
  284. // 文件上传成功处理
  285. handleFileSuccess(response, file, fileList) {
  286. this.upload.open = false;
  287. this.upload.isUploading = false;
  288. this.$refs.upload.clearFiles();
  289. this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + '</div>', '导入结果', {
  290. dangerouslyUseHTMLString: true
  291. });
  292. this.getList();
  293. },
  294. // 提交上传文件
  295. submitFileForm() {
  296. this.$refs.upload.submit();
  297. }
  298. }
  299. };
  300. </script>