admin-list.html 11 KB

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