123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- <!DOCTYPE html>
- <html>
- <head>
- <title>管理员列表</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <meta name="viewport"
- content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
- <!-- 所有的 css & js 资源 -->
- <link rel="stylesheet" href="../../static/kj/element-ui/theme-chalk/index.css">
- <link rel="stylesheet" href="../../static/sa.css">
- <script src="../../static/kj/vue.min.js"></script>
- <script src="../../static/kj/element-ui/index.js"></script>
- <script src="../../static/kj/httpVueLoader.js"></script>
- <script src="../../static/kj/jquery.min.js"></script>
- <script src="../../static/kj/layer/layer.js"></script>
- <script src="../../static/sa.js"></script>
- <script src="../../static/kj/upload-util.js"></script>
- <style type="text/css">
- .el-radio {
- margin-right: 10px;
- }
- </style>
- </head>
- <body>
- <div class="vue-box" style="display: none;" :style="'display: block;'">
- <div class="c-panel">
- <!-- ------------- 检索参数 ------------- -->
- <h4 class="c-title">检索参数</h4>
- <el-form>
- <sa-item type="text" name="账号" v-model="p.name"></sa-item>
- <el-button type="primary" icon="el-icon-search" @click="p.pageNo = 1; f5()">查询</el-button>
- <el-button type="primary" icon="el-icon-plus" @click="add" v-if="sa.isAuth('sp-admin-add')">新增
- </el-button>
- <el-button type="info" icon="el-icon-refresh" @click="p.name='';f5()">重置</el-button>
- </el-form>
- <!-- ------------- 数据列表 ------------- -->
- <el-table class="data-table" ref="data-table" :data="dataList">
- <sa-td type="text" name="姓名" prop="nickname"></sa-td>
- <sa-td type="text" name="账号" prop="name"></sa-td>
- <sa-td type="text" name="手机" prop="phone" min-width="120px">
- <template slot-scope="s">
- <span v-if="s.row.phone">{{s.row.phone}}</span>
- <span v-else>{{s.row.name}}</span>
- </template>
- </sa-td>
- <sa-td type="text" name="所属角色" prop="roleName" not='-'></sa-td>
- <sa-td type="datetime" name="创建日期" prop="createTime" width="150px"></sa-td>
- <sa-td type="datetime" name="最后登录" prop="loginTime" width="150px" not='-'></sa-td>
- <sa-td type="text" name="登录次数" prop="loginCount" not="0" width="100px"></sa-td>
- <sa-td type="switch" name="账号状态" prop="status" :jv="{1: '正常', 2: '禁用[#ff4949]'}"
- @change="s => updateStatus(s.row)" width="120px"></sa-td>
- <el-table-column label="操作" fixed="right" width="330px">
- <template slot-scope="s">
- <span @click="getInfo(s.row)">
- <el-button type="success" class="c-btn" icon="el-icon-view">查看</el-button>
- </span>
- <el-dropdown trigger="click" style="font-size: 0.85em;" v-if="sa.isAuth('sp-admin-edit')">
- <el-button type="primary" class="c-btn">
- 修改资料 <i class="el-icon-arrow-down el-icon--right"></i>
- </el-button>
- <el-dropdown-menu slot="dropdown">
- <span @click="updateName(s.row)">
- <el-dropdown-item>修改账号</el-dropdown-item>
- </span>
- <span @click="updatePhone(s.row)">
- <el-dropdown-item>改手机号</el-dropdown-item>
- </span>
- <span @click="updateNickName(s.row)">
- <el-dropdown-item>改姓名</el-dropdown-item>
- </span>
- <span @click="updatePassword(s.row)">
- <el-dropdown-item>改密码</el-dropdown-item>
- </span>
- </el-dropdown-menu>
- </el-dropdown>
- <el-dropdown trigger="click" style="font-size: 0.85em;" v-if="sa.isAuth('sp-admin-edit')">
- <el-button type="primary" class="c-btn">
- 修改角色为 <i class="el-icon-arrow-down el-icon--right"></i>
- </el-button>
- <el-dropdown-menu slot="dropdown">
- <span v-for="role in roleList" :key="role.id"
- @click="updateRoleId(s.row, role.id, role.name)">
- <el-dropdown-item :style=" s.row.roleId == role.id ? {color: 'blue'} : null ">
- {{role.name}}
- </el-dropdown-item>
- </span>
- </el-dropdown-menu>
- </el-dropdown>
- <span @click="del(s.row)">
- <el-button v-if="sa.isAuth('sp-admin-del')" type="danger" class="c-btn"
- icon="el-icon-delete">删除</el-button>
- </span>
- </template>
- </el-table-column>
- </el-table>
- <!-- 分页 -->
- <sa-item type="page" :curr.sync="p.pageNo" :size.sync="p.pageSize" :total="dataCount" @change="f5()">
- </sa-item>
- </div>
- </div>
- <script>
- var app = new Vue({
- components: {
- "sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue'),
- "sa-td": httpVueLoader('../../sa-frame/com/sa-td.vue')
- },
- el: '.vue-box',
- data: {
- sa: sa, // 超级对象
- p: { // 查询参数
- id: '',
- name: '',
- roleId: '',
- customerId: sa.p('customerId', '-2'),
- sortType: 'id',
- pageNo: 1,
- pageSize: 10,
- },
- deptList: [],
- modal: {
- visible: false,
- form: {
- id: '',
- deptId: ''
- }
- },
- dataCount: 0,
- dataList: [], // 数据集合
- roleList: [], // 角色集合
- },
- methods: {
- // 刷新
- f5: function(isPage) {
- sa.ajax('/admin/getCustomerList', sa.removeNull(this.p), function(res) {
- this.dataList = res.data; // 数据
- this.dataCount = res.dataCount;
- sa.f5TableHeight(); // 刷新表格高度
- }.bind(this));
- },
- // 新增
- add: function() {
- sa.showIframe('添加用户', 'admin-add.html?customerId=' + this.p.customerId, '600px', '80%');
- },
- // 查看详情
- getInfo: function(data) {
- //sa.showIframe('账号详情', 'admin-info.html?id=' + data.id, '700px', '80%');
- sa.$page.openAdminInfo(data.id, data.name);
- },
- // 查看登录日志
- getAdminLogin: function(data) {
- sa.showIframe('登录日志', '../sp-admin-login/sp-admin-login-list.html?accId=' + data.id, '90%',
- '90%');
- },
- // 查看 - 根据选中的
- getBySelect: function(data) {
- var selection = this.$refs['data-table'].selection;
- if (selection.length == 0) {
- return sa.msg('请选择一条数据')
- }
- this.getInfo(selection[0]);
- },
- updateNickName: function(data) {
- layer.prompt({
- title: '修改姓名'
- }, function(pass, index) {
- layer.close(index);
- sa.ajax('/admin/updateNickName', {
- id: data.id,
- nickname: pass
- }, function(res) {
- data.nickname = pass;
- layer.msg('修改成功');
- })
- });
- },
- updatePhone: function(data) {
- layer.prompt({
- title: '请输入新的手机号'
- }, function(pass, index) {
- layer.close(index);
- sa.ajax('/admin/updatePhone', {
- id: data.id,
- phone: pass
- }, function(res) {
- data.phone = pass;
- layer.msg('修改成功');
- })
- });
- },
- // 修改名称
- updateName: function(data) {
- layer.prompt({
- title: '请输入新账号'
- }, function(pass, index) {
- layer.close(index);
- sa.ajax('/admin/updateName', {
- id: data.id,
- name: pass
- }, function(res) {
- data.name = pass;
- layer.msg('修改成功');
- })
- });
- },
- // 修改头像
- updateAvatar: function(data) {
- sa.uploadImage(function(src) {
- var p = {
- id: data.id,
- avatar: src
- };
- sa.ajax('/admin/updateAvatar', p, function(res) {
- sa.msg('上传成功');
- data.avatar = src;
- }.bind(this));
- })
- },
- // 修改密码
- updatePassword: function(data) {
- layer.prompt({
- title: '修改密码'
- }, function(pass, index) {
- layer.close(index);
- if (pass.length < 4) {
- return layer.msg('新密码长度请不要低于4位');
- }
- sa.ajax('/admin/updatePassword', {
- id: data.id,
- password: pass
- }, function(res) {
- layer.msg('修改成功');
- })
- });
- },
- // 修改角色
- updateRoleId: function(data, roleId, roleName) {
- if (data.id == sa.$sys.getCurrUser().id) {
- return sa.alert('不能自己修改自己的角色');
- }
- if (data.roleId == roleId) {
- return sa.alert('该用户已经是' + roleName + '了');
- }
- var str = '将此账号修改为 [' + roleName + '], 请确认?';
- layer.confirm(str, {
- title: '请确认'
- }, function() {
- sa.ajax('/admin/updateRole', {
- id: data.id,
- roleId: roleId
- }, function(res) {
- sa.msg('修改成功');
- data.roleId = roleId;
- data.roleName = roleName;
- }.bind(this));
- }.bind(this));
- },
- // 修改用户的状态
- updateStatus: function(data) {
- if (data.id == sa.$sys.getCurrUser().id) {
- data.status = 3 - data.status;
- return sa.alert('不能自己封禁自己');
- }
- var is_ok = false; // 记录是否成功
- var ajax = sa.ajax('/admin/updateStatus', {
- id: data.id,
- status: data.status
- }, function(res) {
- sa.msg('修改成功');
- is_ok = true;
- }.bind(this));
- // 如果未能修改成功, 则回滚
- $.when(ajax).done(function() {
- if (is_ok == false) {
- data.status = 3 - data.status;
- }
- })
- },
- // 模拟登陆
- runAs: function(data) {
- // 提交删除
- sa.confirm('将要以账号 [ ' + data.name + ' ] 模拟登录,是否确认?', function() {
- sa.ajax('/admin/runAs?adminId=' + data.id, function(res) {
- sa.ok('登录成功,即将刷新页面');
- sessionStorage.runAsToken = res.data;
- setTimeout(function() {
- top.location.reload(true);
- }, 1000)
- }.bind(this))
- }.bind(this));
- },
- // 删除
- del: function(data) {
- sa.confirm('是否删除,此操作不可撤销', function() {
- sa.ajax('/admin/delete', {
- id: data.id
- }, function(res) {
- sa.arrayDelete(app.dataList, data);
- sa.ok('删除成功');
- sa.f5TableHeight(); // 刷新表格高度
- })
- });
- },
- getRoleList() {
- sa.ajax('/role/getCustomerRoleList', {
- customerId: this.p.customerId
- }, function(res) {
- this.roleList = res.data; // 数据
- }.bind(this), {
- msg: null
- });
- },
- // 批量删除
- deleteByIds: function() {
- // 获取选中元素的id列表
- let selection = this.$refs['data-table'].selection;
- let ids = sa.getArrayField(selection, 'id');
- if (selection.length == 0) {
- return sa.msg('请至少选择一条数据')
- }
- // 提交删除
- sa.confirm('是否批量删除选中数据?此操作不可撤销', function() {
- sa.ajax('/admin/deleteByIds', {
- ids: ids.join(',')
- }, function(res) {
- sa.arrayDelete(this.dataList, selection);
- sa.ok('删除成功');
- sa.f5TableHeight(); // 刷新表格高度
- }.bind(this))
- }.bind(this));
- },
- },
- created: function() {
- this.f5();
- this.getRoleList();
- sa.onInputEnter(); // 监听回车执行查询
- }
- })
- </script>
- </body>
- </html>
|