作者 朱兆平

用户岗位/角色配置属性结构完毕

... ... @@ -30,8 +30,8 @@ module.exports = {
assetsPublicPath: '/',
proxyTable: {
'/api':{
// target: 'http://192.168.1.53:12343',//设置你调用的接口域名和端口号 别忘了加http
target: 'http://localhost:12343',//设置你调用的接口域名和端口号 别忘了加http
target: 'http://192.168.1.53:12343',//设置你调用的接口域名和端口号 别忘了加http
// target: 'http://localhost:12343',//设置你调用的接口域名和端口号 别忘了加http
changeOrigin: true,
pathRewrite: {
'^/api/': '/'//这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可
... ...
... ... @@ -4,12 +4,12 @@ export const getUserList = params => { return http.get(`${baseUrl}/list`, param
export const getUserListPage = params => { return http.get(`/user/list`,params) };
export const removeUser = params => { return http.del(`/user/del`,params)};
export const removeUser = params => { return http.del(`${baseUrl}/del`,params)};
export const batchRemoveUser = params => { return http.del(`/user/batchremove`, { params: params }); };
export const batchRemoveUser = params => { return http.del(`${baseUrl}/batchremove`, { params: params }); };
export const editUser = params => { return http.put(`/user/edit`,params)};
export const editUser = params => { return http.put(`${baseUrl}/edit`,params)};
export const addUser = params => { return http.post(`/user/add`,params)};
export const addUser = params => { return http.post(`${baseUrl}/add`,params)};
export const setUserRole = params => { return http.put(`/user/roleset`,params)};
export const setUserRole = params => { return http.put(`${baseUrl}/roleset`,params)};
... ...
var SIGN_REGEXP = /([yMdhsm])(\1*)/g;
var DEFAULT_PATTERN = 'yyyy-MM-dd';
/**
* 根据数组 元素的“值” 来删除或者获取数据
* 使用方法arrList.splice(arrList.contains('c'),1)
*/
Array.prototype.contains = function(obj) {
var i = this.length;
while (i--) {
if (this[i] === obj) {
return i; // 返回的这个 i 就是元素的索引下标,
}
}
return false;
},
function padding(s, len) {
var len = len - (s + '').length;
len = len - (s + '').length;
for (var i = 0; i < len; i++) { s = '0' + s; }
return s;
};
}
export default {
getQueryStringByName: function (name) {
... ...
... ... @@ -118,8 +118,10 @@ axios.interceptors.response.use(
});
}
if (error.response.status === 404) {
router.push({
path: "/error/404"
message({
// 饿了么的消息弹窗组件
message: error.message,
type: "error"
});
}
}
... ...
... ... @@ -168,7 +168,7 @@
<el-form-item label="账号">
<span>{{roleEditForm.username}}</span>
</el-form-item>
<el-tree :data="roles" :props="treeDefaultProps" show-checkbox node-key="roleId" ref="tree">
<el-tree :data="roles" :props="treeDefaultProps" show-checkbox highlight-current node-key="roleId" ref="tree" @check-change="treeHandleCheckChange">
</el-tree>
</el-form>
... ... @@ -321,16 +321,24 @@
this.editForm = Object.assign({}, row);
},
roleEdit: function (index, row) {
this.roleFormVisible = true;
this.getRoles();
var _this = this;
_this.roleIds = [];
this.roleEditForm = Object.assign({}, row);
let userRoles = this.roleEditForm.roles;
if (util.checkNull(userRoles)){
userRoles.forEach(function (role,v_index,v_arr) {
let roles = this.roleEditForm.roles;
if (util.checkNull(roles)){
roles.forEach(function (role,v_index,v_arr) {
if (util.checkNull(role)) {
_this.roleIds[v_index] = role.roleId;
}
});
}
this.getRoles();
this.$nextTick(() => {
//反向适配
this.$refs.tree.setCheckedKeys(this.roleIds);
});
},
getRoles() {
let para = {
... ... @@ -340,7 +348,6 @@
NProgress.start();
getList(para).then((res) => {
this.roles = res.data.list;
this.roleFormVisible = true;
NProgress.done();
}).catch((error) => {
if(null!= error.response && error.response!==undefined){
... ... @@ -352,6 +359,7 @@
}
});
},
//显示新增界面,每次点开初始化数据
handleAdd: function () {
... ... @@ -463,7 +471,10 @@
let para = {userId,roleIds};
setUserRole(para).then((res) => {
if (res.status ===200) {
alert("ok");
this.$message({
message: '岗位设置成功',
type: 'success'
});
}
this.getUsers();
this.roleFormVisible = false;
... ... @@ -478,6 +489,15 @@
},
beforeAvatarUpload: function () {
},
treeHandleCheckChange: function (data, checked, indeterminate) {
if(checked) {
this.roleIds.push(data.roleId);
}else {
this.roleIds.splice(this.roleIds.contains(data.roleId),1);
}
// console.log(data, checked, indeterminate);
console.log(this.roleIds);
}
},
mounted() {
... ...