| 123456789101112131415161718192021222324252627282930313233343536373839 | 
							- // const update = function(el, binding, vnode) {
 
- // 	/** 从binding中获取dom元素的value值 */
 
- // 	const {
 
- // 		value
 
- // 	} = binding
 
- // 	/** 存放value值 */
 
- // 	const btn_permission = value;
 
- // 	/** 拿到所有具备权限按钮的集合,通过传入的按钮id进行匹配 */
 
- // 	const permissions = uni.getStorageSync('permissions');
 
- // 	/** 利用some查询,只要有一个元素满足条件就返回true,全部不满足返回false */
 
- // 	var hasPermissions = permissions.some(permission => {
 
- // 		return btn_permission == permission
 
- // 	})
 
- // 	console.log(hasPermissions, btn_permission);
 
- // 	/** 传入的按钮id不存在集合里面就移除该节点 */
 
- // 	if (!hasPermissions) {
 
- // 		el.parentNode && el.parentNode.removeChild(el)
 
- // 	}
 
- // }
 
- // //注册的一般写法,循环遍历directives,通过vue.directive注册
 
- // export default {
 
- // 	install(Vue) {
 
- // 		Vue.directive('permission', update);
 
- // 		// if (window.Vue) {
 
- // 		// 	window['permission'] = inserted
 
- // 		// 	Vue.use(install); // eslint-disable-line
 
- // 		// }
 
- // 	}
 
- // }
 
- export function permission(key) {
 
- 	const permissions = uni.getStorageSync('permissions') ?? [];
 
- 	if(permissions.indexOf(key) !== -1) {
 
- 		return true;
 
- 	} else {
 
- 		return false;
 
- 	}
 
- }
 
 
  |