admin-list.html 13 KB

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