作者 朱兆平

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

@@ -30,8 +30,8 @@ module.exports = { @@ -30,8 +30,8 @@ module.exports = {
30 assetsPublicPath: '/', 30 assetsPublicPath: '/',
31 proxyTable: { 31 proxyTable: {
32 '/api':{ 32 '/api':{
33 - // target: 'http://192.168.1.53:12343',//设置你调用的接口域名和端口号 别忘了加http  
34 - target: 'http://localhost:12343',//设置你调用的接口域名和端口号 别忘了加http 33 + target: 'http://192.168.1.53:12343',//设置你调用的接口域名和端口号 别忘了加http
  34 + // target: 'http://localhost:12343',//设置你调用的接口域名和端口号 别忘了加http
35 changeOrigin: true, 35 changeOrigin: true,
36 pathRewrite: { 36 pathRewrite: {
37 '^/api/': '/'//这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可 37 '^/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 @@ -4,12 +4,12 @@ export const getUserList = params => { return http.get(`${baseUrl}/list`, param
4 4
5 export const getUserListPage = params => { return http.get(`/user/list`,params) }; 5 export const getUserListPage = params => { return http.get(`/user/list`,params) };
6 6
7 -export const removeUser = params => { return http.del(`/user/del`,params)}; 7 +export const removeUser = params => { return http.del(`${baseUrl}/del`,params)};
8 8
9 -export const batchRemoveUser = params => { return http.del(`/user/batchremove`, { params: params }); }; 9 +export const batchRemoveUser = params => { return http.del(`${baseUrl}/batchremove`, { params: params }); };
10 10
11 -export const editUser = params => { return http.put(`/user/edit`,params)}; 11 +export const editUser = params => { return http.put(`${baseUrl}/edit`,params)};
12 12
13 -export const addUser = params => { return http.post(`/user/add`,params)}; 13 +export const addUser = params => { return http.post(`${baseUrl}/add`,params)};
14 14
15 -export const setUserRole = params => { return http.put(`/user/roleset`,params)}; 15 +export const setUserRole = params => { return http.put(`${baseUrl}/roleset`,params)};
1 var SIGN_REGEXP = /([yMdhsm])(\1*)/g; 1 var SIGN_REGEXP = /([yMdhsm])(\1*)/g;
2 var DEFAULT_PATTERN = 'yyyy-MM-dd'; 2 var DEFAULT_PATTERN = 'yyyy-MM-dd';
3 - 3 +/**
  4 + * 根据数组 元素的“值” 来删除或者获取数据
  5 + * 使用方法arrList.splice(arrList.contains('c'),1)
  6 + */
  7 +Array.prototype.contains = function(obj) {
  8 + var i = this.length;
  9 + while (i--) {
  10 + if (this[i] === obj) {
  11 + return i; // 返回的这个 i 就是元素的索引下标,
  12 + }
  13 + }
  14 + return false;
  15 +},
4 function padding(s, len) { 16 function padding(s, len) {
5 - var len = len - (s + '').length; 17 + len = len - (s + '').length;
6 for (var i = 0; i < len; i++) { s = '0' + s; } 18 for (var i = 0; i < len; i++) { s = '0' + s; }
7 return s; 19 return s;
8 -}; 20 +}
9 21
10 export default { 22 export default {
11 getQueryStringByName: function (name) { 23 getQueryStringByName: function (name) {
@@ -118,8 +118,10 @@ axios.interceptors.response.use( @@ -118,8 +118,10 @@ axios.interceptors.response.use(
118 }); 118 });
119 } 119 }
120 if (error.response.status === 404) { 120 if (error.response.status === 404) {
121 - router.push({  
122 - path: "/error/404" 121 + message({
  122 + // 饿了么的消息弹窗组件
  123 + message: error.message,
  124 + type: "error"
123 }); 125 });
124 } 126 }
125 } 127 }
@@ -168,7 +168,7 @@ @@ -168,7 +168,7 @@
168 <el-form-item label="账号"> 168 <el-form-item label="账号">
169 <span>{{roleEditForm.username}}</span> 169 <span>{{roleEditForm.username}}</span>
170 </el-form-item> 170 </el-form-item>
171 - <el-tree :data="roles" :props="treeDefaultProps" show-checkbox node-key="roleId" ref="tree"> 171 + <el-tree :data="roles" :props="treeDefaultProps" show-checkbox highlight-current node-key="roleId" ref="tree" @check-change="treeHandleCheckChange">
172 </el-tree> 172 </el-tree>
173 </el-form> 173 </el-form>
174 174
@@ -321,16 +321,24 @@ @@ -321,16 +321,24 @@
321 this.editForm = Object.assign({}, row); 321 this.editForm = Object.assign({}, row);
322 }, 322 },
323 roleEdit: function (index, row) { 323 roleEdit: function (index, row) {
  324 + this.roleFormVisible = true;
  325 + this.getRoles();
324 var _this = this; 326 var _this = this;
325 _this.roleIds = []; 327 _this.roleIds = [];
326 this.roleEditForm = Object.assign({}, row); 328 this.roleEditForm = Object.assign({}, row);
327 - let userRoles = this.roleEditForm.roles;  
328 - if (util.checkNull(userRoles)){  
329 - userRoles.forEach(function (role,v_index,v_arr) {  
330 - _this.roleIds[v_index] = role.roleId; 329 + let roles = this.roleEditForm.roles;
  330 +
  331 + if (util.checkNull(roles)){
  332 + roles.forEach(function (role,v_index,v_arr) {
  333 + if (util.checkNull(role)) {
  334 + _this.roleIds[v_index] = role.roleId;
  335 + }
331 }); 336 });
332 } 337 }
333 - this.getRoles(); 338 + this.$nextTick(() => {
  339 + //反向适配
  340 + this.$refs.tree.setCheckedKeys(this.roleIds);
  341 + });
334 }, 342 },
335 getRoles() { 343 getRoles() {
336 let para = { 344 let para = {
@@ -340,7 +348,6 @@ @@ -340,7 +348,6 @@
340 NProgress.start(); 348 NProgress.start();
341 getList(para).then((res) => { 349 getList(para).then((res) => {
342 this.roles = res.data.list; 350 this.roles = res.data.list;
343 - this.roleFormVisible = true;  
344 NProgress.done(); 351 NProgress.done();
345 }).catch((error) => { 352 }).catch((error) => {
346 if(null!= error.response && error.response!==undefined){ 353 if(null!= error.response && error.response!==undefined){
@@ -352,6 +359,7 @@ @@ -352,6 +359,7 @@
352 } 359 }
353 }); 360 });
354 361
  362 +
355 }, 363 },
356 //显示新增界面,每次点开初始化数据 364 //显示新增界面,每次点开初始化数据
357 handleAdd: function () { 365 handleAdd: function () {
@@ -463,7 +471,10 @@ @@ -463,7 +471,10 @@
463 let para = {userId,roleIds}; 471 let para = {userId,roleIds};
464 setUserRole(para).then((res) => { 472 setUserRole(para).then((res) => {
465 if (res.status ===200) { 473 if (res.status ===200) {
466 - alert("ok"); 474 + this.$message({
  475 + message: '岗位设置成功',
  476 + type: 'success'
  477 + });
467 } 478 }
468 this.getUsers(); 479 this.getUsers();
469 this.roleFormVisible = false; 480 this.roleFormVisible = false;
@@ -478,6 +489,15 @@ @@ -478,6 +489,15 @@
478 }, 489 },
479 beforeAvatarUpload: function () { 490 beforeAvatarUpload: function () {
480 491
  492 + },
  493 + treeHandleCheckChange: function (data, checked, indeterminate) {
  494 + if(checked) {
  495 + this.roleIds.push(data.roleId);
  496 + }else {
  497 + this.roleIds.splice(this.roleIds.contains(data.roleId),1);
  498 + }
  499 +// console.log(data, checked, indeterminate);
  500 + console.log(this.roleIds);
481 } 501 }
482 }, 502 },
483 mounted() { 503 mounted() {