admin-list.html 11 KB

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