Jelajahi Sumber

添加权限控制

wangchao 3 tahun lalu
induk
melakukan
d0ab87044b

+ 34 - 0
common/directive.js

@@ -0,0 +1,34 @@
+import Vue from 'vue';
+const rolesList = []
+const permission = (el, binding) => {
+	const roles = getRoles();
+	if (!roles) {
+		return;
+	}
+	  let userPermissionList = Array.isArray(binding.value) ? binding.value : [binding.value];
+	  // 当前用户的权限列表
+	  if (!userPermissionList.some(e => roles.includes(e))) {
+	    el.parentNode && el.parentNode.removeChild(el);
+	  }
+}
+const getRoles = ()=>{
+	let _roles = uni.getStorageSync('jurisdiction');
+	return getUserAllRoles(_roles)
+}
+
+const getUserAllRoles = (item) => {
+	console.log(item)
+	for(let i = 0;i<item.length;i++){
+		rolesList.push(item[i].name)
+		console.log('用户权限',rolesList)
+		if(item[i].children&&item[i].children.length>0){
+			getUserAllRoles(item[i].children)
+		}
+	}
+	return rolesList;
+}
+Vue.directive('hasPermission', {
+		inserted: permission,
+		componentUpdated: permission
+	})
+

+ 15 - 1
common/helper.js

@@ -1,3 +1,4 @@
+import * as config from '../config'
 const selectContractNo = {}
 const detailData = {}
 const erpWarehouse={}
@@ -7,11 +8,24 @@ const now = Date.now || function () {
 const isArray = Array.isArray || function (obj) {  
     return obj instanceof Array;  
 };  
+const getListByUserId = function(){
+	let baseUrlNew = config.def().baseUrlNew
+	uni.request({
+	    url: baseUrlNew + '/roleMenu/query/getListByUserId',
+	    method: 'GET',
+	    success: (res) => {			
+	    	if (res.statusCode === 200) {
+				uni.setStorageSync("jurisdiction", res.data.data)
+	    	}
+	    }
+	})
+}
 
 export default {  
 	detailData,
 	selectContractNo,
     now,  
     isArray,
-	erpWarehouse
+	erpWarehouse,
+	getListByUserId
 }

+ 1 - 1
config/index.js

@@ -1,6 +1,6 @@
 const dev = {
 	baseUrl: 'https://www.zthymaoyi.com',
-	baseUrlNew: 'http://192.168.1.115:8090/',
+	baseUrlNew: 'http://192.168.1.102:8090/',
 	// baseUrlNew: 'http://api1.eliangeyun.com/',
 	h5Appid: 'wxb66b599f7f61b46f',
 	debug: false

+ 1 - 0
main.js

@@ -31,6 +31,7 @@ App.mpType = 'app'
 import * as filters from './filters' 
 import * as config from './config'
 import utils from '@/util/util.js'
+import '@/common/directive.js'
 
 let urlAddress = 'liangxin.zthymaoyi.com'
 

+ 4 - 0
pages/public/code.vue

@@ -41,6 +41,7 @@
 </template>
 
 <script>
+	import helper from '@/common/helper.js'; 
 	export default {
 		data() {
 			return {
@@ -175,15 +176,18 @@
 							veriCode: "123456",}).then(res1 => {
 								if(res1.data.code==200){
 									uni.setStorageSync('pcUserInfo', res1.data.data)
+									helper.getListByUserId()
 								}
 								else{
 									that.$api.doRequest('post','/commonUser/api/loginQuickly',{mobilePhone: '13333333333',
 									veriCode: "123456",}).then(res2 => {
 										uni.setStorageSync('pcUserInfo', res2.data.data)
+										helper.getListByUserId()
 									})
 								}
 							})
 							uni.setStorageSync('userInfo', res.data.data)
+							helper.getListByUserId()
 					        that.$store.commit('login', res.data.data)
 					        // that.liangxinLogin()
 					        uni.switchTab({

+ 4 - 0
pages/public/login_account_number.vue

@@ -35,6 +35,7 @@
 		mapMutations
 	} from 'vuex';
 	import { openFSqlite, createFSQL, selectFSQL, addFSQL } from '../../util/f.js'
+	import helper from '@/common/helper.js'; 
 	import { queryData, upData, initData } from '../../util/dbUtil.js'
 	import {
 		mapState
@@ -116,11 +117,14 @@
 							console.log("loginQuickly",res)
 							if(res1.data.code==200){
 								uni.setStorageSync('pcUserInfo', res1.data.data)
+								debugger
+								helper.getListByUserId()
 							}
 							else{
 								that.$api.doRequest('post','/commonUser/api/loginQuickly',{mobilePhone: '13333333333',
 								veriCode: "123456",}).then(res2 => {
 									uni.setStorageSync('pcUserInfo', res2.data.data)
+									helper.getListByUserId()
 								})
 							}
 							

+ 3 - 0
pages/public/register.vue

@@ -38,6 +38,7 @@
 		mapMutations
 	} from 'vuex';
 	import { openFSqlite, createFSQL, selectFSQL, addFSQL } from '../../util/f.js'
+    import helper from '@/common/helper.js'; 
 	import { queryData, upData, initData } from '../../util/dbUtil.js'
 	export default {
 		data() {
@@ -227,11 +228,13 @@
 							veriCode: "123456",}).then(res1 => {
 									if(res1.data.code==200){
 										uni.setStorageSync('pcUserInfo', res1.data.data)
+										helper.getListByUserId()
 									}
 									else{
 										that.$api.doRequest('post','/commonUser/api/loginQuickly',{mobilePhone: '13333333333',
 										veriCode: "123456",}).then(res2 => {
 											uni.setStorageSync('pcUserInfo', res2.data.data)
+											helper.getListByUserId()
 										})
 									}
 								})

+ 1 - 1
pages/task/my_task.vue

@@ -1,7 +1,7 @@
 <template name="task">
 	<view class="content">
 		<view class="cu-bar search bg-white">
-			<view class="search-form round">
+			<view class="search-form round" v-hasPermission="'acquisitionPay.view11'">
 				<u-search placeholder="请输入合同编号、车牌号或派车编号" v-model="keyword" @search="searchKeyWord()"
 					@custom="searchKeyWord()"></u-search>
 			</view>

+ 3 - 0
websocket_sdk.js

@@ -1,6 +1,7 @@
 import packetCode from './PacketCodeC.js'
 import store from './store/index.js'
 import * as config from './config'
+import helper from '@/common/helper.js'; 
 export default class Websocket {
     constructor({
         heartCheck,
@@ -276,6 +277,7 @@ export default class Websocket {
 					success: (res) => {						
 						if (res.statusCode === 200) {
 							uni.setStorageSync('pcUserInfo', res.data)
+							helper.getListByUserId()
 						}
 						else{
 							uni.request({
@@ -288,6 +290,7 @@ export default class Websocket {
 								success: (res) => {						
 									if (res.statusCode === 200) {
 										uni.setStorageSync('pcUserInfo', res.data)
+										helper.getListByUserId()
 									}
 								}
 							})