customer-admin-list.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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="../../static/kj/element-ui/theme-chalk/index.css">
  10. <link rel="stylesheet" href="../../static/sa.css">
  11. <script src="../../static/kj/vue.min.js"></script>
  12. <script src="../../static/kj/element-ui/index.js"></script>
  13. <script src="../../static/kj/httpVueLoader.js"></script>
  14. <script src="../../static/kj/jquery.min.js"></script>
  15. <script src="../../static/kj/layer/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. <el-button type="primary" icon="el-icon-search" @click="p.pageNo = 1; f5()">查询</el-button>
  32. <!-- ------------- 快捷按钮 ------------- -->
  33. <el-button style="display: inline;" type="primary" icon="el-icon-plus" @click="add()"
  34. v-if="sa.isAuth('tb-partner-user-add')">新增
  35. </el-button>
  36. <el-button style="display: inline;" type="info" icon="el-icon-refresh" @click="sa.f5()">重置</el-button>
  37. </el-form>
  38. <!-- ------------- 数据列表 ------------- -->
  39. <el-table class="data-table" ref="data-table" :data="dataList">
  40. <sa-td type="selection"></sa-td>
  41. <sa-td type="text" name="登录名" prop="name" min-width="120px"></sa-td>
  42. <sa-td type="text" name="姓名" prop="nickname" min-width="120px"></sa-td>
  43. <sa-td type="datetime" name="创建时间" prop="createTime" width="150px"></sa-td>
  44. <sa-td type="datetime" name="最后登录" prop="loginTime" width="150px"></sa-td>
  45. <sa-td type="text" name="登录次数" prop="loginCount" not="0" width="100px"></sa-td>
  46. <sa-td type="switch" name="账号状态" prop="status" :jv="{1: '正常', 2: '禁用[#ff4949]'}"
  47. @change="s => updateStatus(s.row)" width="120px"></sa-td>
  48. <el-table-column label="操作" width="450px">
  49. <template slot-scope="s">
  50. <span @click="updateName(s.row)" v-if="sa.isAuth('tb-partner-user-edit')">
  51. <el-button type="primary" class="c-btn">改登录名</el-button>
  52. </span>
  53. <span @click="updateNickname(s.row)" v-if="sa.isAuth('tb-partner-user-edit')">
  54. <el-button type="primary" class="c-btn">改姓名</el-button>
  55. </span>
  56. <span @click="updateAvatar(s.row)" v-if="sa.isAuth('tb-partner-user-edit')">
  57. <el-button type="primary" class="c-btn">改头像</el-button>
  58. </span>
  59. <span @click="updatePassword(s.row)" v-if="sa.isAuth('tb-partner-user-edit')">
  60. <el-button type="primary" class="c-btn">改密码</el-button>
  61. </span>
  62. <span @click="roleFn(s.row)" v-if="sa.isAuth('tb-partner-user-edit')">
  63. <el-button type="primary" class="c-btn">角色</el-button>
  64. </span>
  65. <span @click="del(s.row)" v-if="sa.isAuth('tb-partner-user-del')">
  66. <el-button type="danger" class="c-btn">删除</el-button>
  67. </span>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <!-- 分页 -->
  72. <sa-item type="page" :curr.sync="p.pageNo" :size.sync="p.pageSize" :total="dataCount" @change="f5()"></sa-item>
  73. </div>
  74. <el-dialog
  75. :title="roleDialog.title"
  76. :visible.sync="roleDialog.visible"
  77. width="60%">
  78. <div>
  79. <el-checkbox @change="handleCheckAllChange">全选</el-checkbox>
  80. <div style="margin: 15px 0;"></div>
  81. <el-checkbox-group v-model="roleDialog.form.roleId">
  82. <el-checkbox v-for="role in roleList" :label="role.id+''" :key="role.id">{{role.name}}</el-checkbox>
  83. </el-checkbox-group>
  84. </div>
  85. <span slot="footer" class="dialog-footer">
  86. <el-button @click="roleDialog.visible = false">取 消</el-button>
  87. <el-button type="primary" @click="confirmSetRole">确 定</el-button>
  88. </span>
  89. </el-dialog>
  90. </div>
  91. <script>
  92. const numStr = "123456789";
  93. const numStrDesc = "987654321";
  94. const varStr = "abcdefghijklmnopkrstuvwxyz"
  95. const varStrDesc = "zyxwvutsrkpomnlkjihgfedcba"
  96. var app = new Vue({
  97. components: {
  98. "sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue'),
  99. "sa-td": httpVueLoader('../../sa-frame/com/sa-td.vue')
  100. },
  101. el: '.vue-box',
  102. data: {
  103. roleDialog: {
  104. visible: false,
  105. title: '',
  106. form: {
  107. id: '',
  108. roleId: [],
  109. }
  110. },
  111. sa: sa, // 超级对象
  112. p: { // 查询参数
  113. name: '',
  114. customerId: sa.p('customerId', ''),
  115. sort_type: 0,
  116. pageNo: 1,
  117. pageSize: 10,
  118. },
  119. dataCount: 0,
  120. dataList: [], // 数据集合
  121. roleList: [], // 角色集合
  122. },
  123. methods: {
  124. roleFn(data) {
  125. Object.assign(this.roleDialog, {
  126. visible: true,
  127. title: '设置[' + data.name + ']角色属性',
  128. form: {
  129. id: data.id,
  130. roleId: data.roleId.split(',')
  131. }
  132. })
  133. },
  134. handleCheckAllChange() {
  135. let roleId = this.roleDialog.form.roleId;
  136. let allIds = this.roleList.map(obj => obj.id + '');
  137. this.roleDialog.form.roleId = roleId.length != allIds.length ? allIds : [];
  138. },
  139. confirmSetRole() {
  140. let roleId = this.roleDialog.form.roleId;
  141. if (roleId.length == 0) {
  142. return sa.msg('请选择一个角色')
  143. }
  144. let o = {
  145. id: this.roleDialog.form.id,
  146. roleId: this.roleDialog.form.roleId.join(',')
  147. }
  148. sa.ajax('/admin/setRole', o, function (resp) {
  149. this.f5();
  150. this.roleDialog.visible = false;
  151. }.bind(this))
  152. },
  153. // 刷新
  154. f5: function (isPage) {
  155. sa.ajax('/admin/getCustomerAdminList', this.p, function (res) {
  156. this.dataList = res.data; // 数据
  157. this.dataCount = res.dataCount;
  158. sa.f5TableHeight(); // 刷新表格高度
  159. }.bind(this));
  160. },
  161. // 新增
  162. add: function () {
  163. sa.showIframe('新增用户', 'customer-admin-add.html?customerId=' + this.p.customerId, '550px', '75%');
  164. },
  165. // 查看详情
  166. getInfo: function (data) {
  167. sa.showIframe('账号详情', '../../sa-view-sp/sp-admin/admin-info.html?id=' + data.id, '700px', '80%');
  168. //sa.$page.openAdminInfo(data.id, data.name);
  169. },
  170. // 查看 - 根据选中的
  171. getBySelect: function (data) {
  172. var selection = this.$refs['data-table'].selection;
  173. if (selection.length == 0) {
  174. return sa.msg('请选择一条数据')
  175. }
  176. this.getInfo(selection[0]);
  177. },
  178. // 修改名称
  179. updateName: function (data) {
  180. layer.prompt({title: '修改账号'}, function (pass, index) {
  181. layer.close(index);
  182. sa.ajax('/admin/update', {id: data.id, name: pass}, function (res) {
  183. data.name = pass;
  184. layer.msg('修改成功');
  185. })
  186. });
  187. },
  188. updateNickname(data) {
  189. layer.prompt({title: '修改账号名称'}, function (pass, index) {
  190. layer.close(index);
  191. sa.ajax('/admin/updateNickname', {id: data.id, nickname: pass}, function (res) {
  192. data.nickname = pass;
  193. layer.msg('修改成功');
  194. }.bind(this))
  195. });
  196. },
  197. // 修改头像
  198. updateAvatar: function (data) {
  199. sa.uploadImage(function (src) {
  200. var p = {id: data.id, avatar: src};
  201. sa.ajax('/admin/updateAvatar', p, function (res) {
  202. sa.msg('上传成功');
  203. data.avatar = src;
  204. }.bind(this));
  205. })
  206. },
  207. // 修改密码
  208. updatePassword: function (data) {
  209. let that=this;
  210. layer.prompt({title: '修改密码'}, function (pass, index) {
  211. layer.close(index);
  212. if (pass.length < 4) {
  213. return layer.msg('新密码长度请不要低于4位');
  214. }
  215. let result = that.newPwdChange(pass);
  216. if (!result) {
  217. return;
  218. }
  219. sa.ajax('/admin/updatePassword', {id: data.id, password: pass}, function (res) {
  220. layer.msg('修改成功');
  221. })
  222. });
  223. },
  224. newPwdChange(v) {
  225. let len = v.length;
  226. if (!this.checkStong(v)) {
  227. layer.msg('密码长度8-16位,至少包含一个数字、一个大写字母、一个小写字母以及!@#$%^&*?之一')
  228. return false;
  229. }
  230. if (len >= 3) {
  231. let s = v.toLowerCase();
  232. for (let i = 0; i < len - 2; i++) {
  233. let charStr = s.substring(i, i + 3);
  234. if (this.checkStr(charStr)) {
  235. layer.msg('密码不应该采用连续升序或者连续降序');
  236. return false;
  237. }
  238. }
  239. }
  240. },
  241. checkStr(charStr) {
  242. return numStr.indexOf(charStr) != -1 || varStr.indexOf(charStr) != -1 || numStrDesc.indexOf(
  243. charStr) != -1 || varStrDesc.indexOf(charStr) != -1;
  244. },
  245. checkStong(v) {
  246. let pattern = /^.*(?=.{8,16})(?=.*\d)(?=.*[A-Z]{1,})(?=.*[a-z]{1,})(?=.*[!@#$%^&*?\(\)]).*$/;
  247. return pattern.test(v);
  248. },
  249. // 修改角色
  250. updateRoleId: function (data, roleId, roleName) {
  251. if (data.id == sa.$sys.getCurrUser().id) {
  252. return sa.alert('不能自己修改自己的角色');
  253. }
  254. if (data.roleId == roleId) {
  255. return sa.alert('该用户已经是' + roleName + '了');
  256. }
  257. var str = '将此账号修改为 [' + roleName + '], 请确认?';
  258. layer.confirm(str, {title: '请确认'}, function () {
  259. sa.ajax('/admin/updateRole', {id: data.id, roleId: roleId}, function (res) {
  260. sa.msg('修改成功');
  261. data.roleId = roleId;
  262. data.roleName = roleName;
  263. }.bind(this));
  264. }.bind(this));
  265. },
  266. // 修改用户的状态
  267. updateStatus: function (data) {
  268. if (data.id == sa.$sys.getCurrUser().id) {
  269. data.status = 3 - data.status;
  270. return sa.alert('不能自己封禁自己');
  271. }
  272. var is_ok = false; // 记录是否成功
  273. var ajax = sa.ajax('/admin/updateStatus', {adminId: data.id, status: data.status}, function (res) {
  274. sa.msg('修改成功');
  275. is_ok = true;
  276. }.bind(this));
  277. // 如果未能修改成功, 则回滚
  278. $.when(ajax).done(function () {
  279. if (is_ok == false) {
  280. data.status = 3 - data.status;
  281. }
  282. })
  283. },
  284. // 删除
  285. del: function (data) {
  286. sa.confirm('是否删除,此操作不可撤销', function () {
  287. sa.ajax('/admin/delete', {id: data.id}, function (res) {
  288. sa.arrayDelete(app.dataList, data);
  289. sa.ok('删除成功');
  290. sa.f5TableHeight(); // 刷新表格高度
  291. })
  292. });
  293. },
  294. // 批量删除
  295. deleteByIds: function () {
  296. // 获取选中元素的id列表
  297. let selection = this.$refs['data-table'].selection;
  298. let ids = sa.getArrayField(selection, 'id');
  299. if (selection.length == 0) {
  300. return sa.msg('请至少选择一条数据')
  301. }
  302. // 提交删除
  303. sa.confirm('是否批量删除选中数据?此操作不可撤销', function () {
  304. sa.ajax('/admin/deleteByIds', {ids: ids.join(',')}, function (res) {
  305. sa.arrayDelete(this.dataList, selection);
  306. sa.ok('删除成功');
  307. sa.f5TableHeight(); // 刷新表格高度
  308. }.bind(this))
  309. }.bind(this));
  310. },
  311. getRoleList() {
  312. // 加载角色
  313. sa.ajax('/role/getCustomerRoleList', {customerId: this.p.customerId}, function (res) {
  314. this.roleList = res.data; // 数据
  315. }.bind(this), {msg: null});
  316. }
  317. },
  318. created: function () {
  319. this.f5();
  320. sa.onInputEnter(); // 监听回车执行查询
  321. this.getRoleList();
  322. }
  323. })
  324. </script>
  325. </body>
  326. </html>