Browse Source

账户管理内容

master
aBin 3 years ago
parent
commit
a4bb129700
  1. 34
      src/api/jurisdiction.js
  2. 170
      src/views/privilegeManagement/account/addEquipment.vue
  3. 166
      src/views/privilegeManagement/account/index.vue
  4. 273
      src/views/privilegeManagement/account/opiModel.vue

34
src/api/jurisdiction.js

@ -1,5 +1,6 @@
import request from '@/utils/request'
const admin = '/back/admin'
const role = '/back/role'
/**
@ -34,3 +35,36 @@ export function DELETE_ADMIN(params) {
data: params
}).then(res => res.data)
}
/**
* 修改管理员账户信息
*/
export function UPDATE_ADMIN(params) {
return request({
url: `${admin}/update`,
method: 'post',
data: params
}).then(res => res.data)
}
/**
* 添加管理员账户信息
*/
export function ADD_ADMIN(params) {
return request({
url: `${admin}/add`,
method: 'post',
data: params
}).then(res => res.data)
}
/**
* 获取所有角色列表
*/
export function GET_ROLE_ALL(params) {
return request({
url: `${role}/all`,
method: 'post',
data: params
}).then(res => res.data)
}

170
src/views/privilegeManagement/account/addEquipment.vue

@ -1,170 +0,0 @@
<template>
<div class="selector">
<div class="el-input1">
<el-input placeholder="搜索" @keyup.enter.native="onEnter" v-model="params.query" size="small" type="text"
class=""/>
</div>
<div class="selector-check" @scroll="scrollEvent">
<ul>
<li v-for="(item,index) in list" :key="index">
<el-checkbox @change="change(item.id,item.checked)" v-model="item.checked">
<div class="lis">
<div>
<p>{{item.name}}</p>
</div>
</div>
</el-checkbox>
</li>
</ul>
</div>
</div>
</template>
<script>
// import {
// GET_LOCATIONS
// } from '@/api/common'
export default {
name: "elTransfer",
data() {
return {
list: [],
params: {
size: 10,
from: 0,
query: ''
}
}
},
props: {
locationIds: Array
},
mounted() {
// this.getList();
console.log(this.locationIds);
},
watch: {
locationIds(val) {
console.log(val);
}
},
methods: {
getList() {
GET_LOCATIONS(this.params).then(res => {
res.map((item) => {
item.checked = false;
if (this.locationIds.includes(item.id)){
item.checked = true;
}
return item;
});
this.list = [...this.list, ...res];
})
},
change(id, checked) {
if (checked) {
let list = this.list.map((item) => {
if (id == item.id) {
item.checked = true
}
return item;
});
this.list = list;
} else {
let list = this.list.map((item) => {
if (id == item.id) {
item.checked = false
}
return item;
});
this.list = list;
}
},
scrollEvent(e) {
// if (e.srcElement.scrollTop + e.srcElement.offsetHeight > e.srcElement.scrollHeight) {
// this.params = {
// ...this.params,
// from: this.params.from + this.params.size,
// };
// this.getList()
// }
},
onEnter() {
// this.params = {
// ...this.params,
// query: this.params.query
// };
// this.getList()
}
},
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
* {
margin: 0;
padding: 0;
}
.selector {
margin-top: 10px;
border-radius: 4px;
height: 300px;
border: 1px solid #d9d9d9;
.el-input1 {
margin: 10px;
}
.selector-check {
height: calc(100% - 55px);
border-top: 1px solid #d9d9d9;
padding: 15px;
overflow: auto;
ul {
padding: 0;
margin: 0;
li {
list-style: none;
padding: 5px 0;
.el-checkbox__input {
vertical-align: super;
}
.lis {
display: flex;
img, div {
flex: 1;
}
img {
width: 80px;
height: 80px;
}
div {
margin-left: 10px;
}
}
}
}
}
}
.el-checkbox__input {
vertical-align: top;
}
</style>

166
src/views/privilegeManagement/account/index.vue

@ -5,7 +5,7 @@
<el-row>
<router-link :to="`/privilegeManagement/account/opiModel`">
<el-button type="primary">
新增
新增
</el-button>
</router-link>
</el-row>
@ -21,11 +21,11 @@
<span>{{ scope.row.userId }}</span>
</template>
</el-table-column>
<el-table-column prop="avatarUrl" label="头像">
<!-- <el-table-column prop="avatarUrl" label="头像">
<template slot-scope="scope">
<img :src="scope.row.avatarUrl" style="width:60px;height:60px;" alt="">
</template>
</el-table-column>
</el-table-column> -->
<el-table-column prop="userName" label="登录名">
<template slot-scope="scope">
<span>{{ scope.row.userName }}</span>
@ -56,20 +56,6 @@
</el-table-column>npm i element-ui -S
<el-table-column fixed="right" label="操作" align="center" width="290">
<template slot-scope="lists">
<!-- <el-popover
placement="top"
width="160"
:value="visible">
<p>确定重置密码吗</p>
<div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="visible = false">取消</el-button>
<el-button type="danger" size="mini" plain @click="reset(lists.row.userId)">确定</el-button>
</div>
<el-button slot="reference" icon="el-icon-refresh" size="mini" type="warning">重置密码</el-button>
</el-popover> -->
<!-- <el-popconfirm title="这是一段内容确定删除吗?">
<el-button slot="reference">删除</el-button>
</el-popconfirm> -->
<el-button icon="el-icon-edit" size="mini" type="primary" @click="showEidt(lists.row)">编辑</el-button>
<el-button icon="el-icon-refresh" size="mini" type="warning" @click="open(lists.row.userId,0)">重置密码</el-button>
<el-button icon="el-icon-delete" size="mini" type="danger" @click="open(lists.row.userId,1)">删除</el-button>
@ -90,21 +76,34 @@
<el-dialog
title="修改密码"
title="修改登录用户信息"
width="600px"
:visible.sync="showEidtDialog">
<el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">
<el-form-item label="密码" prop="password" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
<el-input type="password" v-model="ruleForm.password"></el-input>
<el-form :model="editRow" ref="editRow" label-width="100px">
<el-form-item label="登录名" prop="userName" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
<el-input v-model="editRow.userName"></el-input>
</el-form-item>
<el-form-item label="手机号" prop="phone">
<el-input v-model="editRow.phone"></el-input>
</el-form-item>
<el-form-item label="真实姓名" prop="realName">
<el-input v-model="editRow.realName"></el-input>
</el-form-item>
<el-form-item label="确认密码" prop="confirmPassword"
:rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
<el-input type="password" v-model="ruleForm.confirmPassword"></el-input>
<el-form-item label="关联角色" prop="roleIds" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
<!-- <el-input v-model="editRow.roleIds"></el-input> -->
<el-select v-model="editRow.roleIds" multiple placeholder="请选择">
<el-option
v-for="item in roleList"
:key="item.roleId"
:label="item.roleName"
:value="item.roleId">
</el-option>
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="showEidtDialog = false">取消</el-button>
<!-- <el-button type="primary" @click="determine('ruleForm')">确定</el-button> -->
<el-button type="primary" @click="updateData(editRow)">确定</el-button>
</div>
</el-dialog>
@ -112,7 +111,7 @@
</template>
<script>
import { GET_LIST,RESET_PASSWORD } from '@/api/jurisdiction'
import { GET_LIST,RESET_PASSWORD,DELETE_ADMIN,GET_ROLE_ALL,UPDATE_ADMIN } from '@/api/jurisdiction'
import Alert from "@/utils/alert";
const FormContainer = () => import('./form.vue');
export default {
@ -124,17 +123,25 @@
lists: [],
count: 0,
visible: false,
roleList: [],
params: {
pageNum: 1,
pageSize: 10,
phone: '',
name: '',
loginName: '',
realName: '',
},
ruleForm: {
password: '',
confirmPassword: '',
},
editRow: {
userId: '',
phone: '',
realName: '',
roleIds: [],
userName: '',
},
}
},
mounted() {
@ -144,10 +151,39 @@
FormContainer
},
methods: {
//
showEidt(item) {
console.log('item: ', item);
item.roleIds = []
this.getRoleList();
if(item.roles && item.roles.length) {
for(let i = 0; i < item.roles.length;i++) {
item.roleIds.push(item.roles[i].roleId)
}
}
this.editRow = {...item}
this.showEidtDialog = true;
},
//
updateData(data) {
const params = {
phone: data.phone,
realName: data.realName,
roleIds: data.roleIds,
userId: data.userId,
userName: data.userName,
}
UPDATE_ADMIN(params).then(res => {
if(res.code === 200) {
Alert.success('修改成功')
this.showEidtDialog = false;
this.getList()
} else {
Alert.fail(res.msg)
this.showEidtDialog = false;
}
})
},
// /
open(userId,type) {
let title = ''
@ -158,15 +194,27 @@
}
this.$alert(title, '请确认', {
confirmButtonText: '确定',
callback: () => {
if(type === 0) {
console.log('重置userId: ', userId);
} else if (type === 1) {
console.log('删除userId: ', userId);
callback: res => {
console.log('res: ', res);
if(res === 'confirm') {
if(type === 0) {
RESET_PASSWORD({ userId }).then(() => {
if(res.code === 200) {
Alert.success('重置密码成功');
} else {
Alert.fail(res.msg);
}
});
} else if (type === 1) {
DELETE_ADMIN({ userId }).then(() => {
if(res.code === 200) {
Alert.success('删除账户成功');
} else {
Alert.fail(res.msg);
}
});
}
}
// GET_LIST({ userId }).then(res => {
// Alert('');
// });
}
});
},
@ -175,9 +223,12 @@
*/
getList() {
GET_LIST(this.params).then(res => {
this.lists = res.data.list;
console.log('this.lists: ', this.lists);
this.count = res.data.total - 0;
if(res.code === 200) {
this.lists = res.data.list;
this.count = res.data.total - 0;
} else {
Alert.fail(res.msg);
}
});
},
@ -188,34 +239,41 @@
this.visible = false
const params = { userId }
RESET_PASSWORD(params).then(res => {
Alert.success('重置密码成功')
if(res.code === 200) {
Alert.success('重置密码成功')
} else {
Alert.fail(res.msg);
}
});
},
/**
* 删除管理员账户
*/
delete(userId) {
console.log('userId: ', userId);
// GET_LIST({ userId }).then(res => {
// Alert('');
// });
},
/**
* 查询
*/
submitForm(res) {
this.params = {
...this.params,
loginName: res.loginName,
realName: res.name,
userName: res.loginName,
name: res.name,
phone: res.phone
};
this.getList()
},
/**
* 查询所有角色列表
*/
getRoleList() {
GET_ROLE_ALL({}).then( res => {
if(res.code === 200) {
this.roleList = res.data;
} else {
Alert.fail(res.msg);
}
})
},
/**
* 翻页
*/
@ -228,10 +286,6 @@
this.getList()
},
changePassword(id) {
this.isPassword = true;
this.id = id
},
/**
* 取消弹层
*/

273
src/views/privilegeManagement/account/opiModel.vue

@ -1,174 +1,120 @@
<template>
<div class="form">
<el-form :model="ruleForm" ref="ruleForm" label-width="120px" class="demo-ruleForm">
<el-form-item label="姓名" prop="name" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
<el-input v-model="ruleForm.name"></el-input>
<el-form :model="addRole" ref="addRole" label-width="120px" class="demo-addRole">
<el-form-item label="登录名" prop="userName" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
<el-input v-model="addRole.userName"></el-input>
</el-form-item>
<el-form-item label="用户名" prop="username" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
<el-input v-model="ruleForm.username"></el-input>
<el-form-item label="手机号" prop="phone">
<el-input v-model="addRole.phone"></el-input>
</el-form-item>
<el-form-item label="手机号" prop="mobile" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
<el-input v-model="ruleForm.mobile"></el-input>
<el-form-item label="真实姓名" prop="realName">
<el-input v-model="addRole.realName"></el-input>
</el-form-item>
<el-form-item label="设为管理员" prop="admin">
<el-switch
v-model="ruleForm.admin"
active-color="#13ce66"
@change="isAdmin"
inactive-color="#ccc">
</el-switch>
</el-form-item>
<el-form-item v-if="!ruleForm.admin" label="角色" prop="roleId"
:rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
<!-- <el-select v-model="ruleForm.roleId" placeholder="">
<el-option v-for="item in roles" :label="item.name" :value="item.id"></el-option>
</el-select> -->
</el-form-item>
<el-form-item v-if="!ruleForm.admin" label="场地" prop="locationIds">
<span style="cursor: pointer;" v-if="!ruleForm.locationIds.length"
@click="addLocationIds=true,isSel=true">选择场地</span>
<span style="cursor: pointer;" v-else
@click="addLocationIds=true,isSel=true">{{ruleForm.locationIds.length}}个场地</span>
<div v-show="isLocationIds" class="el-form-item__error">
不能为空
</div>
</el-form-item>
<el-form-item v-if="!isView" label="密码" prop="password"
:rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
<el-input v-model="ruleForm.password" type="password"></el-input>
</el-form-item>
<el-form-item v-if="!isView" label="确认密码" prop="confirmPassword"
:rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
<el-input v-model="ruleForm.confirmPassword" type="password"></el-input>
<el-form-item label="关联角色" prop="roleIds" :rules="[{required: true, message: '不能为空', trigger: 'blur'}]">
<el-select v-model="addRole.roleIds" multiple placeholder="请选择">
<el-option
v-for="item in roleList"
:key="item.roleId"
:label="item.roleName"
:value="item.roleId">
</el-option>
</el-select>
</el-form-item>
<el-form-item style="text-align: center;">
<el-button type="primary" @click="submitForm('ruleForm')">{{submitInfo}}</el-button>
<el-button @click="resetForm('ruleForm')">重置</el-button>
<el-button type="primary" @click="submitForm('addRole')">{{submitInfo}}</el-button>
<el-button @click="resetForm">重置</el-button>
</el-form-item>
</el-form>
<el-dialog
width="300px"
:visible.sync="addLocationIds">
<add-equipment v-if="isSel" ref="transfer" :locationIds="ruleForm.locationIds"></add-equipment>
<div slot="footer" class="dialog-footer">
<el-button @click="addLocationIds = false,isSel=false">取消</el-button>
<el-button type="primary" @click="determine">确定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import Alert from "@/utils/alert";
import AddEquipment from "./addEquipment.vue"
// import {
// ADD_ACCOUNT_LIST,
// DETAIL_ACCOUNT_LIST,
// ROLES_SEL,
// UPDATE_ACCOUNT_LIST
// } from '@/api/privilegeManagement'
import { GET_ROLE_ALL,ADD_ADMIN } from '@/api/jurisdiction'
import {mapActions} from 'vuex'
export default {
data() {
return {
isLocationIds: false,
isSel: true,
isView: false,
submitInfo: '立即创建',
addLocationIds: false,
addSourceMaterial: false,
ruleForm: {
name: '',
username: '',
mobile: '',
roleId: '',
admin: false,
locationIds: [],
password: '',
confirmPassword: ''
submitInfo: '立即新增',
addRole: {
avatarUrl: '',
phone: '',
realName: '',
roleIds: [],
userName: '',
},
roles: []
roleList: []
};
},
components: {
AddEquipment
},
mounted() {
// this.getDetail();
// this.getRolesList();
this.getRoleList();
},
methods: {
...mapActions(["delVisitedView"]),
/**
* 获取列表数据
* 查询所有角色列表
*/
getDetail() {
let id = this.$route.query.id;
if (id != undefined) {
this.isView = true;
this.submitInfo = '立即更新';
let params = {
id
};
DETAIL_ACCOUNT_LIST(params).then(res => {
res.locationIds = res.locationIds == null ? [] : res.locationIds;
this.ruleForm = res
});
}
},
getRolesList() {
ROLES_SEL().then(res => {
this.roles = res
});
},
/**
* 是否管理员
*/
isAdmin(val) {
console.log(val);
getRoleList() {
GET_ROLE_ALL({}).then( res => {
if(res.code === 200) {
this.roleList = res.data;
} else {
Alert.fail('查询角色列表失败,请重试');
}
})
},
/**
* 确定
*/
submitForm(formName) {
let that = this;
let id = this.$route.query.id;
this.$refs[formName].validate((valid) => {
if (valid) {
if (!that.ruleForm.admin) {
if (!that.ruleForm.locationIds.length) {
that.isLocationIds = true;
return false;
}
}
if (id != undefined) {
that.UPDATE_ACCOUNT_LIST(that.ruleForm, id)
} else {
if (that.ruleForm.password.length < 6) {
Alert.fail('密码不能小于6位');
return false
}
if (that.ruleForm.password != that.ruleForm.confirmPassword) {
Alert.fail('密码不一致,请重新输入');
return false
const params = {...this.addRole}
this.$refs[formName].validate(res => {
if(!params.userName || !params.roleIds.length) {
return false
} else {
ADD_ADMIN(params).then(res => {
if(res.code === 200) {
Alert.success('添加成功')
} else {
Alert.fail(res.msg)
}
that.ADD_ACCOUNT_LIST(that.ruleForm)
}
})
}
});
})
// let that = this;
// let id = this.$route.query.id;
// this.$refs[formName].validate((valid) => {
// if (valid) {
// if (!that.ruleForm.admin) {
// if (!that.ruleForm.locationIds.length) {
// that.isLocationIds = true;
// return false;
// }
// }
// if (id != undefined) {
// that.UPDATE_ACCOUNT_LIST(that.ruleForm, id)
// } else {
// if (that.ruleForm.password.length < 6) {
// Alert.fail('6');
// return false
// }
// if (that.ruleForm.password != that.ruleForm.confirmPassword) {
// Alert.fail(',');
// return false
// }
// that.ADD_ACCOUNT_LIST(that.ruleForm)
// }
// }
// });
},
/**
@ -188,64 +134,19 @@
})
},
/**
* 更新角色
*/
UPDATE_ACCOUNT_LIST(ruleForm, id) {
let that = this;
console.log(ruleForm);
ruleForm.id = id;
UPDATE_ACCOUNT_LIST(ruleForm).then(res => {
Alert.success('更新成功');
setTimeout(() => {
that.delVisitedView(that.$route).then(res => {
that.$router.go(-1);
});
}, 1000)
})
},
/**
* 重置
*/
resetForm(formName) {
this.ruleForm = {
name: '',
username: '',
mobile: '',
roleId: '',
admin: false,
locationIds: [],
password: '',
confirmPassword: ''
resetForm() {
this.addRole = {
avatarUrl: '',
phone: '',
realName: '',
roleIds: [],
userName: '',
};
this.getDetail();
},
determine() {
let childList = [];
this.$refs.transfer.list.map((item) => {
if (item.checked) {
childList.push(item.id)
}
return item
});
this.addLocationIds = false;
this.isSel = false;
if (!this.ruleForm.admin) {
if (childList.length) {
this.isLocationIds = false
}
}
this.ruleForm = {
...this.ruleForm,
locationIds: childList
}
}
}
}
</script>

Loading…
Cancel
Save