admin-list.html 9.5 KB

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