admin-list.html 13 KB

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