admin-list.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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="../../static/kj/vue.min.js"></script>
  11. <script src="../../static/kj/element-ui/index.js"></script>
  12. <script src="../../static/kj/httpVueLoader.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{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.sort_type">
  38. <el-radio :label="0">最近添加</el-radio>
  39. <el-radio :label="2">最近登录</el-radio>
  40. <el-radio :label="3">登录次数</el-radio>
  41. </el-radio-group>
  42. </sa-item>
  43. </el-form>
  44. <!-- ------------- 快捷按钮 ------------- -->
  45. <sa-item type="fast-btn" show="add,get,delete,reset"></sa-item>
  46. <!-- ------------- 数据列表 ------------- -->
  47. <el-table class="data-table" ref="data-table" :data="dataList">
  48. <sa-td type="selection"></sa-td>
  49. <sa-td type="user-avatar" name="昵称" prop="name,avatar" min-width="120px"></sa-td>
  50. <sa-td type="text" name="手机" prop="phone"></sa-td>
  51. <sa-td name="创建人" >
  52. <template slot-scope="s">
  53. <span v-if="s.row.createByAid == -1">无</span>
  54. <el-link v-else @click="sa.$page.openAdminInfo(s.row.createByAid, s.row.name)">{{s.row.createByAid}}</el-link>
  55. </template>
  56. </sa-td type="text">
  57. <sa-td type="text" name="所属角色" prop="roleName"></sa-td>
  58. <sa-td type="datetime" name="所属角色" prop="createTime" width="150px"></sa-td>
  59. <sa-td type="datetime" name="最后登录" prop="loginTime" width="150px"></sa-td>
  60. <sa-td type="text" name="登录次数" prop="loginCount" not="0" width="100px"></sa-td>
  61. <sa-td type="switch" name="账号状态" prop="status" :jv="{1: '正常', 2: '禁用[#ff4949]'}" @change="s => updateStatus(s.row)" width="120px"></sa-td>
  62. <el-table-column label="操作" fixed="right" width="450px">
  63. <template slot-scope="s">
  64. <span @click="getInfo(s.row)">
  65. <el-button type="success" class="c-btn" icon="el-icon-view">查看</el-button>
  66. </span>
  67. <span @click="updateName(s.row)">
  68. <el-button type="primary" class="c-btn" icon="el-icon-edit">改名称</el-button>
  69. </span>
  70. <span @click="updateAvatar(s.row)">
  71. <el-button type="primary" class="c-btn" icon="el-icon-edit">改头像</el-button>
  72. </span>
  73. <span @click="updatePassword(s.row)">
  74. <el-button type="primary" class="c-btn" icon="el-icon-edit">改密码</el-button>
  75. </span>
  76. <el-dropdown trigger="click" style="font-size: 0.85em;">
  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" @click="updateRoleId(s.row, role.id, role.name)">
  82. <el-dropdown-item :style=" s.row.roleId == role.id ? {color: 'blue'} : null ">{{role.name}}</el-dropdown-item>
  83. </span>
  84. </el-dropdown-menu>
  85. </el-dropdown>
  86. <span @click="del(s.row)">
  87. <el-button type="danger" class="c-btn" icon="el-icon-delete">删除</el-button>
  88. </span>
  89. </template>
  90. </el-table-column>
  91. </el-table>
  92. <!-- 分页 -->
  93. <sa-item type="page" :curr.sync="p.pageNo" :size.sync="p.pageSize" :total="dataCount" @change="f5()"></sa-item>
  94. </div>
  95. </div>
  96. <script>
  97. var app = new Vue({
  98. components: {
  99. "sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue'),
  100. "sa-td": httpVueLoader('../../sa-frame/com/sa-td.vue')
  101. },
  102. el: '.vue-box',
  103. data: {
  104. sa: sa, // 超级对象
  105. p: { // 查询参数
  106. id: '',
  107. name: '',
  108. roleId: '',
  109. sort_type: 0,
  110. pageNo: 1,
  111. pageSize: 10,
  112. },
  113. dataCount: 0,
  114. dataList: [], // 数据集合
  115. roleList: [], // 角色集合
  116. curr_m: null // 当前操作的 m
  117. },
  118. methods: {
  119. // 刷新
  120. f5: function(isPage){
  121. sa.ajax('/sp-admin/admin/getList', this.p, function(res){
  122. this.dataList = res.data; // 数据
  123. this.dataCount = res.dataCount;
  124. sa.f5TableHeight(); // 刷新表格高度
  125. }.bind(this));
  126. },
  127. // 新增
  128. add: function() {
  129. parent.sa_admin.showMenuById('admin-add');
  130. },
  131. // 查看详情
  132. getInfo: function(data) {
  133. //sa.showIframe('账号详情', 'admin-info.html?id=' + data.id, '700px', '80%');
  134. sa.$page.openAdminInfo(data.id, data.name);
  135. },
  136. // 查看 - 根据选中的
  137. getBySelect: function(data) {
  138. var selection = this.$refs['data-table'].selection;
  139. if(selection.length == 0) {
  140. return sa.msg('请选择一条数据')
  141. }
  142. this.getInfo(selection[0]);
  143. },
  144. // 修改名称
  145. updateName: function(data) {
  146. layer.prompt({title: '修改账号名称'}, function(pass, index){
  147. layer.close(index);
  148. sa.ajax('/sp-admin/admin/update', {id: data.id, name: pass}, function(res){
  149. data.name = pass;
  150. layer.msg('修改成功');
  151. })
  152. });
  153. },
  154. // 修改头像
  155. updateAvatar: function(data) {
  156. sa.uploadImage(function(src) {
  157. var p = {id: data.id, avatar: src};
  158. sa.ajax('/sp-admin/admin/updateAvatar', p, function(res) {
  159. sa.msg('上传成功');
  160. data.avatar = src;
  161. }.bind(this));
  162. })
  163. },
  164. // 修改密码
  165. updatePassword: function(data) {
  166. layer.prompt({title: '修改密码'}, function(pass, index){
  167. layer.close(index);
  168. if(pass.length < 4) {
  169. return layer.msg('新密码长度请不要低于4位');
  170. }
  171. sa.ajax('/sp-admin/admin/updatePassword', {id: data.id, password: pass}, function(res){
  172. layer.msg('修改成功');
  173. })
  174. });
  175. },
  176. // 修改角色
  177. updateRoleId: function(data, roleId, roleName) {
  178. if(data.id == sa.$sys.getCurrUser().id) {
  179. return sa.alert('不能自己修改自己的角色');
  180. }
  181. if(data.roleId == roleId) {
  182. return sa.alert('该用户已经是' + roleName + '了');
  183. }
  184. var str = '将此账号修改为 [' + roleName + '], 请确认?';
  185. layer.confirm(str, {title: '请确认'}, function() {
  186. sa.ajax('/sp-admin/admin/updateRole', {id: data.id, roleId: roleId}, function(res) {
  187. sa.msg('修改成功');
  188. data.roleId = roleId;
  189. data.roleName = roleName;
  190. }.bind(this));
  191. }.bind(this));
  192. },
  193. // 修改用户的状态
  194. updateStatus: function(data) {
  195. if(data.id == sa.$sys.getCurrUser().id) {
  196. data.status = 3 - data.status;
  197. return sa.alert('不能自己封禁自己');
  198. }
  199. var is_ok = false; // 记录是否成功
  200. var ajax = sa.ajax('/sp-admin/admin/updateStatus', {adminId: data.id, status: data.status}, function(res) {
  201. sa.msg('修改成功');
  202. is_ok = true;
  203. }.bind(this));
  204. // 如果未能修改成功, 则回滚
  205. $.when(ajax).done(function() {
  206. if(is_ok == false) {
  207. data.status = 3 - data.status;
  208. }
  209. })
  210. },
  211. // 删除
  212. del: function (data) {
  213. sa.confirm('是否删除,此操作不可撤销', function(){
  214. sa.ajax('/sp-admin/admin/delete', {id: data.id},function(res){
  215. sa.arrayDelete(app.dataList, data);
  216. sa.ok('删除成功');
  217. sa.f5TableHeight(); // 刷新表格高度
  218. })
  219. });
  220. },
  221. // 批量删除
  222. deleteByIds: function() {
  223. // 获取选中元素的id列表
  224. let selection = this.$refs['data-table'].selection;
  225. let ids = sa.getArrayField(selection, 'id');
  226. if(selection.length == 0) {
  227. return sa.msg('请至少选择一条数据')
  228. }
  229. // 提交删除
  230. sa.confirm('是否批量删除选中数据?此操作不可撤销', function() {
  231. sa.ajax('/sp-admin/admin/deleteByIds', {ids: ids.join(',')}, function(res) {
  232. sa.arrayDelete(this.dataList, selection);
  233. sa.ok('删除成功');
  234. sa.f5TableHeight(); // 刷新表格高度
  235. }.bind(this))
  236. }.bind(this));
  237. },
  238. },
  239. created: function(){
  240. this.f5();
  241. sa.onInputEnter(); // 监听回车执行查询
  242. // 加载角色
  243. sa.ajax('/sp-admin/role/getList', function(res){
  244. this.roleList = res.data; // 数据
  245. }.bind(this), {msg: null});
  246. }
  247. })
  248. </script>
  249. </body>
  250. </html>