admin-list.html 9.6 KB

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