admin-list.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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" not='-'></sa-td>
  66. <sa-td type="datetime" name="创建日期" prop="createTime" width="150px"></sa-td>
  67. <sa-td type="datetime" name="最后登录" prop="loginTime" width="150px" not='-'></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)">
  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.form.deptId">
  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. form: {
  153. id: '',
  154. deptId: ''
  155. }
  156. },
  157. dataCount: 0,
  158. dataList: [], // 数据集合
  159. roleList: [], // 角色集合
  160. },
  161. methods: {
  162. updateDept(data) {
  163. Object.assign(this.modal,{
  164. visible:true,
  165. form:{
  166. id:data.id,
  167. deptId:data.deptId
  168. }
  169. })
  170. },
  171. sureFn(){
  172. let data=this.modal.form;
  173. let deptId=data.deptId;
  174. if(!deptId){
  175. sa.error('请选择组织');
  176. return;
  177. }
  178. data.deptId=deptId;
  179. sa.ajax('/admin/updateDept', data, function(res) {
  180. this.modal.visible=false;
  181. this.f5();
  182. }.bind(this));
  183. },
  184. getDeptList() {
  185. sa.ajax('/TbDept/getList', {
  186. pageNo: 1,
  187. pageSize: 100
  188. }, function(resp) {
  189. let list = resp.data;
  190. this.deptList = list;
  191. }.bind(this))
  192. },
  193. // 刷新
  194. f5: function(isPage) {
  195. sa.ajax('/admin/getList', this.p, function(res) {
  196. this.dataList = res.data; // 数据
  197. this.dataCount = res.dataCount;
  198. sa.f5TableHeight(); // 刷新表格高度
  199. }.bind(this));
  200. },
  201. // 新增
  202. add: function() {
  203. sa.showIframe('添加用户', 'admin-add.html', '600px', '80%');
  204. },
  205. // 查看详情
  206. getInfo: function(data) {
  207. //sa.showIframe('账号详情', 'admin-info.html?id=' + data.id, '700px', '80%');
  208. sa.$page.openAdminInfo(data.id, data.name);
  209. },
  210. // 查看登录日志
  211. getAdminLogin: function(data) {
  212. sa.showIframe('登录日志', '../sp-admin-login/sp-admin-login-list.html?accId=' + data.id, '90%',
  213. '90%');
  214. },
  215. // 查看 - 根据选中的
  216. getBySelect: function(data) {
  217. var selection = this.$refs['data-table'].selection;
  218. if (selection.length == 0) {
  219. return sa.msg('请选择一条数据')
  220. }
  221. this.getInfo(selection[0]);
  222. },
  223. updateNickName: function(data) {
  224. layer.prompt({
  225. title: '修改姓名'
  226. }, function(pass, index) {
  227. layer.close(index);
  228. sa.ajax('/admin/updateNickName', {
  229. id: data.id,
  230. nickname: pass
  231. }, function(res) {
  232. data.nickname = pass;
  233. layer.msg('修改成功');
  234. })
  235. });
  236. },
  237. // 修改名称
  238. updateName: function(data) {
  239. layer.prompt({
  240. title: '请输入新的手机号'
  241. }, function(pass, index) {
  242. layer.close(index);
  243. sa.ajax('/admin/update', {
  244. id: data.id,
  245. name: pass
  246. }, function(res) {
  247. data.name = pass;
  248. layer.msg('修改成功');
  249. })
  250. });
  251. },
  252. // 修改头像
  253. updateAvatar: function(data) {
  254. sa.uploadImage(function(src) {
  255. var p = {
  256. id: data.id,
  257. avatar: src
  258. };
  259. sa.ajax('/admin/updateAvatar', p, function(res) {
  260. sa.msg('上传成功');
  261. data.avatar = src;
  262. }.bind(this));
  263. })
  264. },
  265. // 修改密码
  266. updatePassword: function(data) {
  267. layer.prompt({
  268. title: '修改密码'
  269. }, function(pass, index) {
  270. layer.close(index);
  271. if (pass.length < 4) {
  272. return layer.msg('新密码长度请不要低于4位');
  273. }
  274. sa.ajax('/admin/updatePassword', {
  275. id: data.id,
  276. password: pass
  277. }, function(res) {
  278. layer.msg('修改成功');
  279. })
  280. });
  281. },
  282. // 修改角色
  283. updateRoleId: function(data, roleId, roleName) {
  284. if (data.id == sa.$sys.getCurrUser().id) {
  285. return sa.alert('不能自己修改自己的角色');
  286. }
  287. if (data.roleId == roleId) {
  288. return sa.alert('该用户已经是' + roleName + '了');
  289. }
  290. var str = '将此账号修改为 [' + roleName + '], 请确认?';
  291. layer.confirm(str, {
  292. title: '请确认'
  293. }, function() {
  294. sa.ajax('/admin/updateRole', {
  295. id: data.id,
  296. roleId: roleId
  297. }, function(res) {
  298. sa.msg('修改成功');
  299. data.roleId = roleId;
  300. data.roleName = roleName;
  301. }.bind(this));
  302. }.bind(this));
  303. },
  304. // 修改用户的状态
  305. updateStatus: function(data) {
  306. if (data.id == sa.$sys.getCurrUser().id) {
  307. data.status = 3 - data.status;
  308. return sa.alert('不能自己封禁自己');
  309. }
  310. var is_ok = false; // 记录是否成功
  311. var ajax = sa.ajax('/admin/updateStatus', {
  312. id: data.id,
  313. status: data.status
  314. }, function(res) {
  315. sa.msg('修改成功');
  316. is_ok = true;
  317. }.bind(this));
  318. // 如果未能修改成功, 则回滚
  319. $.when(ajax).done(function() {
  320. if (is_ok == false) {
  321. data.status = 3 - data.status;
  322. }
  323. })
  324. },
  325. // 模拟登陆
  326. runAs: function(data) {
  327. // 提交删除
  328. sa.confirm('将要以账号 [ ' + data.name + ' ] 模拟登录,是否确认?', function() {
  329. sa.ajax('/admin/runAs?adminId=' + data.id, function(res) {
  330. sa.ok('登录成功,即将刷新页面');
  331. sessionStorage.runAsToken = res.data;
  332. setTimeout(function() {
  333. top.location.reload(true);
  334. }, 1000)
  335. }.bind(this))
  336. }.bind(this));
  337. },
  338. // 删除
  339. del: function(data) {
  340. sa.confirm('是否删除,此操作不可撤销', function() {
  341. sa.ajax('/admin/delete', {
  342. id: data.id
  343. }, function(res) {
  344. sa.arrayDelete(app.dataList, data);
  345. sa.ok('删除成功');
  346. sa.f5TableHeight(); // 刷新表格高度
  347. })
  348. });
  349. },
  350. // 批量删除
  351. deleteByIds: function() {
  352. // 获取选中元素的id列表
  353. let selection = this.$refs['data-table'].selection;
  354. let ids = sa.getArrayField(selection, 'id');
  355. if (selection.length == 0) {
  356. return sa.msg('请至少选择一条数据')
  357. }
  358. // 提交删除
  359. sa.confirm('是否批量删除选中数据?此操作不可撤销', function() {
  360. sa.ajax('/admin/deleteByIds', {
  361. ids: ids.join(',')
  362. }, function(res) {
  363. sa.arrayDelete(this.dataList, selection);
  364. sa.ok('删除成功');
  365. sa.f5TableHeight(); // 刷新表格高度
  366. }.bind(this))
  367. }.bind(this));
  368. },
  369. },
  370. created: function() {
  371. this.f5();
  372. this.getDeptList();
  373. sa.onInputEnter(); // 监听回车执行查询
  374. // 加载角色
  375. sa.ajax('/role/getList', function(res) {
  376. this.roleList = res.data; // 数据
  377. }.bind(this), {
  378. msg: null
  379. });
  380. }
  381. })
  382. </script>
  383. </body>
  384. </html>