admin-list.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>管理员列表</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <meta name="viewport"
  7. content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  8. <!-- 所有的 css & js 资源 -->
  9. <link rel="stylesheet" href="../../static/kj/element-ui/theme-chalk/index.css">
  10. <link rel="stylesheet" href="../../static/sa.css">
  11. <script src="../../static/kj/vue.min.js"></script>
  12. <script src="../../static/kj/element-ui/index.js"></script>
  13. <script src="../../static/kj/jquery.min.js"></script>
  14. <script src="../../static/kj/layer/layer.js"></script>
  15. <script src="../../static/sa.js"></script>
  16. <script src="../../static/kj/upload-util.js"></script>
  17. <style type="text/css">
  18. .el-radio {
  19. margin-right: 10px;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div class="vue-box" style="display: none;" :style="'display: block;'">
  25. <div class="c-panel">
  26. <!-- ------------- 检索参数 ------------- -->
  27. <h4 class="c-title">检索参数</h4>
  28. <el-form>
  29. <sa-item type="text" name="名称" v-model="p.name"></sa-item>
  30. <sa-item name="角色">
  31. <el-select v-model="p.roleId">
  32. <el-option label="全部" value=""></el-option>
  33. <el-option v-for="role in roleList" :key="role.id" :label="role.name" :value="role.id">
  34. </el-option>
  35. </el-select>
  36. </sa-item>
  37. <el-button type="primary" icon="el-icon-search" @click="p.pageNo = 1; f5()">查询</el-button>
  38. <br>
  39. <sa-item name="综合排序" class="s-radio-text">
  40. <el-radio-group v-model="p.sortType">
  41. <el-radio label="id">最近添加</el-radio>
  42. <el-radio label="loginTime">最近登录</el-radio>
  43. <el-radio label="loginCount">登录次数</el-radio>
  44. </el-radio-group>
  45. </sa-item>
  46. </el-form>
  47. <!-- ------------- 快捷按钮 ------------- -->
  48. <div class="fast-btn">
  49. <el-button type="primary" icon="el-icon-plus" @click="add" v-if="sa.isAuth('sp-admin-add')">新增
  50. </el-button>
  51. <el-button type="info" icon="el-icon-refresh" @click="f5">重置</el-button>
  52. </div>
  53. <!-- ------------- 数据列表 ------------- -->
  54. <el-table class="data-table" ref="data-table" :data="dataList">
  55. <sa-td type="selection"></sa-td>
  56. <sa-td type="text" name="姓名" prop="nickname"></sa-td>
  57. <sa-td type="text" name="账号" prop="name" width="140"></sa-td>
  58. <sa-td type="text" name="手机" prop="phone" min-width="120px">
  59. <template slot-scope="s">
  60. <span v-if="s.row.phone">{{s.row.phone}}</span>
  61. <span v-else>{{s.row.name}}</span>
  62. </template>
  63. </sa-td>
  64. <sa-td type="text" name="所属单位" prop="departmentName" not='-' width="130"></sa-td>
  65. <sa-td type="text" name="所属角色" prop="roleName" not='-'></sa-td>
  66. <sa-td type="datetime" name="创建日期" prop="createTime" width="150px"></sa-td>
  67. <sa-td type="datetime" name="最后登录" prop="loginTime" width="150px" not='-'></sa-td>
  68. <sa-td type="text" name="登录次数" prop="loginCount" not="0" width="100px"></sa-td>
  69. <sa-td type="switch" name="账号状态" prop="status" :jv="{1: '正常', 2: '禁用[#ff4949]'}"
  70. @change="s => updateStatus(s.row)" width="120px"></sa-td>
  71. <el-table-column label="操作" fixed="right" width="330px">
  72. <template slot-scope="s">
  73. <span @click="getInfo(s.row)">
  74. <el-button type="success" class="c-btn" icon="el-icon-view">查看</el-button>
  75. </span>
  76. <el-dropdown trigger="click" style="font-size: 0.85em;" v-if="sa.isAuth('sp-admin-edit')">
  77. <el-button type="primary" class="c-btn">
  78. 修改资料 <i class="el-icon-arrow-down el-icon--right"></i>
  79. </el-button>
  80. <el-dropdown-menu slot="dropdown">
  81. <span @click="updateDept(s.row)">
  82. <el-dropdown-item>修改单位</el-dropdown-item>
  83. </span>
  84. <span @click="updateName(s.row)">
  85. <el-dropdown-item>修改账号</el-dropdown-item>
  86. </span>
  87. <span @click="updatePhone(s.row)">
  88. <el-dropdown-item>改手机号</el-dropdown-item>
  89. </span>
  90. <span @click="updateNickName(s.row)">
  91. <el-dropdown-item>改姓名</el-dropdown-item>
  92. </span>
  93. <span @click="updatePassword(s.row)">
  94. <el-dropdown-item>改密码</el-dropdown-item>
  95. </span>
  96. </el-dropdown-menu>
  97. </el-dropdown>
  98. <el-dropdown trigger="click" style="font-size: 0.85em;" v-if="sa.isAuth('sp-admin-role-edit')">
  99. <el-button type="primary" class="c-btn">
  100. 修改角色为 <i class="el-icon-arrow-down el-icon--right"></i>
  101. </el-button>
  102. <el-dropdown-menu slot="dropdown">
  103. <span v-for="role in roleList" :key="role.id"
  104. @click="updateRoleId(s.row, role.id, role.name)">
  105. <el-dropdown-item :style=" s.row.roleId == role.id ? {color: 'blue'} : null ">
  106. {{role.name}}</el-dropdown-item>
  107. </span>
  108. </el-dropdown-menu>
  109. </el-dropdown>
  110. <span @click="del(s.row)">
  111. <el-button v-if="sa.isAuth('sp-admin-del')" type="danger" class="c-btn"
  112. icon="el-icon-delete">删除</el-button>
  113. </span>
  114. </template>
  115. </el-table-column>
  116. </el-table>
  117. <!-- 分页 -->
  118. <sa-item type="page" :curr.sync="p.pageNo" :size.sync="p.pageSize" :total="dataCount" @change="f5()">
  119. </sa-item>
  120. </div>
  121. <el-dialog title="修改单位" :modal="false" :visible.sync="modal.visible" width="400px">
  122. <div class="c-item">
  123. <label class="c-label"><span style="color: red;">*</span>单位:</label>
  124. <el-select v-model="modal.form.departmentId">
  125. <el-option label="请选择" v-for="(item,index) in deptList" :key="item.id" :label="item.name"
  126. :value="item.id"></el-option>
  127. </el-select>
  128. </div>
  129. <span slot="footer" class="dialog-footer">
  130. <el-button @click="modal.visible=false">取 消</el-button>
  131. <el-button type="primary" @click="sureFn">确 定</el-button>
  132. </span>
  133. </el-dialog>
  134. </div>
  135. <script>
  136. var app = new Vue({
  137. components: {
  138. "sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue'),
  139. "sa-td": httpVueLoader('../../sa-frame/com/sa-td.vue')
  140. },
  141. el: '.vue-box',
  142. data: {
  143. sa: sa, // 超级对象
  144. p: { // 查询参数
  145. id: '',
  146. name: '',
  147. roleId: '',
  148. sortType: 'id',
  149. pageNo: 1,
  150. pageSize: 10,
  151. },
  152. deptList:[],
  153. modal: {
  154. visible:false,
  155. form: {
  156. id: '',
  157. departmentId: ''
  158. }
  159. },
  160. dataCount: 0,
  161. dataList: [], // 数据集合
  162. roleList: [], // 角色集合
  163. },
  164. methods: {
  165. updateDept(data) {
  166. Object.assign(this.modal,{
  167. visible:true,
  168. form:{
  169. id:data.id,
  170. departmentId:data.departmentId
  171. }
  172. })
  173. },
  174. sureFn(){
  175. let data=this.modal.form;
  176. let departmentId=data.departmentId;
  177. if(!departmentId){
  178. sa.error('请选择组织');
  179. return;
  180. }
  181. data.departmentId=departmentId;
  182. sa.ajax('/admin/updateDepartment', data, function(res) {
  183. this.modal.visible=false;
  184. this.f5();
  185. }.bind(this));
  186. },
  187. getDeptList() {
  188. sa.ajax('/TbDepartment/getList', {
  189. pageNo: 1,
  190. pageSize: 100
  191. }, function(resp) {
  192. let list = resp.data;
  193. this.deptList = list;
  194. }.bind(this))
  195. },
  196. // 刷新
  197. f5: function(isPage) {
  198. sa.ajax('/admin/getList', this.p, function(res) {
  199. this.dataList = res.data; // 数据
  200. this.dataCount = res.dataCount;
  201. sa.f5TableHeight(); // 刷新表格高度
  202. }.bind(this));
  203. },
  204. // 新增
  205. add: function() {
  206. sa.showIframe('添加用户', 'admin-add.html', '600px', '80%');
  207. },
  208. // 查看详情
  209. getInfo: function(data) {
  210. //sa.showIframe('账号详情', 'admin-info.html?id=' + data.id, '700px', '80%');
  211. sa.$page.openAdminInfo(data.id, data.name);
  212. },
  213. // 查看登录日志
  214. getAdminLogin: function(data) {
  215. sa.showIframe('登录日志', '../sp-admin-login/sp-admin-login-list.html?accId=' + data.id, '90%',
  216. '90%');
  217. },
  218. // 查看 - 根据选中的
  219. getBySelect: function(data) {
  220. var selection = this.$refs['data-table'].selection;
  221. if (selection.length == 0) {
  222. return sa.msg('请选择一条数据')
  223. }
  224. this.getInfo(selection[0]);
  225. },
  226. updateNickName: function(data) {
  227. layer.prompt({
  228. title: '修改姓名'
  229. }, function(pass, index) {
  230. layer.close(index);
  231. sa.ajax('/admin/updateNickName', {
  232. id: data.id,
  233. nickname: pass
  234. }, function(res) {
  235. data.nickname = pass;
  236. layer.msg('修改成功');
  237. })
  238. });
  239. },
  240. updatePhone: function(data) {
  241. layer.prompt({
  242. title: '请输入新的手机号'
  243. }, function(pass, index) {
  244. layer.close(index);
  245. sa.ajax('/admin/updatePhone', {
  246. id: data.id,
  247. phone: pass
  248. }, function(res) {
  249. data.phone = pass;
  250. layer.msg('修改成功');
  251. })
  252. });
  253. },
  254. // 修改名称
  255. updateName: function(data) {
  256. layer.prompt({
  257. title: '请输入新账号'
  258. }, function(pass, index) {
  259. layer.close(index);
  260. sa.ajax('/admin/updateName', {
  261. id: data.id,
  262. name: pass
  263. }, function(res) {
  264. data.name = pass;
  265. layer.msg('修改成功');
  266. })
  267. });
  268. },
  269. // 修改头像
  270. updateAvatar: function(data) {
  271. sa.uploadImage(function(src) {
  272. var p = {
  273. id: data.id,
  274. avatar: src
  275. };
  276. sa.ajax('/admin/updateAvatar', p, function(res) {
  277. sa.msg('上传成功');
  278. data.avatar = src;
  279. }.bind(this));
  280. })
  281. },
  282. // 修改密码
  283. updatePassword: function(data) {
  284. layer.prompt({
  285. title: '修改密码'
  286. }, function(pass, index) {
  287. layer.close(index);
  288. if (pass.length < 4) {
  289. return layer.msg('新密码长度请不要低于4位');
  290. }
  291. sa.ajax('/admin/updatePassword', {
  292. id: data.id,
  293. password: pass
  294. }, function(res) {
  295. layer.msg('修改成功');
  296. })
  297. });
  298. },
  299. // 修改角色
  300. updateRoleId: function(data, roleId, roleName) {
  301. if (data.id == sa.$sys.getCurrUser().id) {
  302. return sa.alert('不能自己修改自己的角色');
  303. }
  304. if (data.roleId == roleId) {
  305. return sa.alert('该用户已经是' + roleName + '了');
  306. }
  307. var str = '将此账号修改为 [' + roleName + '], 请确认?';
  308. layer.confirm(str, {
  309. title: '请确认'
  310. }, function() {
  311. sa.ajax('/admin/updateRole', {
  312. id: data.id,
  313. roleId: roleId
  314. }, function(res) {
  315. sa.msg('修改成功');
  316. data.roleId = roleId;
  317. data.roleName = roleName;
  318. }.bind(this));
  319. }.bind(this));
  320. },
  321. // 修改用户的状态
  322. updateStatus: function(data) {
  323. if (data.id == sa.$sys.getCurrUser().id) {
  324. data.status = 3 - data.status;
  325. return sa.alert('不能自己封禁自己');
  326. }
  327. var is_ok = false; // 记录是否成功
  328. var ajax = sa.ajax('/admin/updateStatus', {
  329. id: data.id,
  330. status: data.status
  331. }, function(res) {
  332. sa.msg('修改成功');
  333. is_ok = true;
  334. }.bind(this));
  335. // 如果未能修改成功, 则回滚
  336. $.when(ajax).done(function() {
  337. if (is_ok == false) {
  338. data.status = 3 - data.status;
  339. }
  340. })
  341. },
  342. // 模拟登陆
  343. runAs: function(data) {
  344. // 提交删除
  345. sa.confirm('将要以账号 [ ' + data.name + ' ] 模拟登录,是否确认?', function() {
  346. sa.ajax('/admin/runAs?adminId=' + data.id, function(res) {
  347. sa.ok('登录成功,即将刷新页面');
  348. sessionStorage.runAsToken = res.data;
  349. setTimeout(function() {
  350. top.location.reload(true);
  351. }, 1000)
  352. }.bind(this))
  353. }.bind(this));
  354. },
  355. // 删除
  356. del: function(data) {
  357. sa.confirm('是否删除,此操作不可撤销', function() {
  358. sa.ajax('/admin/delete', {
  359. id: data.id
  360. }, function(res) {
  361. sa.arrayDelete(app.dataList, data);
  362. sa.ok('删除成功');
  363. sa.f5TableHeight(); // 刷新表格高度
  364. })
  365. });
  366. },
  367. // 批量删除
  368. deleteByIds: function() {
  369. // 获取选中元素的id列表
  370. let selection = this.$refs['data-table'].selection;
  371. let ids = sa.getArrayField(selection, 'id');
  372. if (selection.length == 0) {
  373. return sa.msg('请至少选择一条数据')
  374. }
  375. // 提交删除
  376. sa.confirm('是否批量删除选中数据?此操作不可撤销', function() {
  377. sa.ajax('/admin/deleteByIds', {
  378. ids: ids.join(',')
  379. }, function(res) {
  380. sa.arrayDelete(this.dataList, selection);
  381. sa.ok('删除成功');
  382. sa.f5TableHeight(); // 刷新表格高度
  383. }.bind(this))
  384. }.bind(this));
  385. },
  386. },
  387. created: function() {
  388. this.f5();
  389. this.getDeptList();
  390. sa.onInputEnter(); // 监听回车执行查询
  391. // 加载角色
  392. sa.ajax('/role/getList', function(res) {
  393. this.roleList = res.data; // 数据
  394. }.bind(this), {
  395. msg: null
  396. });
  397. }
  398. })
  399. </script>
  400. </body>
  401. </html>