提交 0f4b1e3d 编写于 作者: 雪洛's avatar 雪洛

feat: uni-id mixin

上级 a8cb6790
......@@ -24,6 +24,10 @@ import {
getTabBarScrollPosition
} from './app/router-guard'
import {
uniIdMixin
} from 'uni-shared'
function getMinId (routes) {
let minId = 0
routes.forEach(route => {
......@@ -74,6 +78,8 @@ export default {
lifecycleMixin(Vue)
uniIdMixin(Vue)
/* eslint-disable no-undef */
if (typeof __UNI_ROUTER_BASE__ !== 'undefined') {
__uniConfig.router.base = __UNI_ROUTER_BASE__
......
......@@ -22,6 +22,10 @@ import {
vdSyncCallbacks
} from '../subscribe-handlers/on-vd-sync-callback'
import {
uniIdMixin
} from 'uni-shared'
export default {
install (Vue, options) {
initVue(Vue)
......@@ -31,6 +35,8 @@ export default {
initPolyfill(Vue)
uniIdMixin(Vue)
Vue.prototype.getOpenerEventChannel = function () {
if (!this.$root.$scope.eventChannel) {
this.$root.$scope.eventChannel = new EventChannel()
......@@ -94,4 +100,4 @@ export default {
return callback ? undefined : result
}
}
}
}
......@@ -11,6 +11,10 @@ import {
getEventChannel
} from 'uni-helpers/navigate-to'
import {
uniIdMixin
} from 'uni-shared'
const hooks = [
'onShow',
'onHide',
......@@ -101,6 +105,7 @@ export default function parseBaseApp (vm, {
if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store
}
uniIdMixin(Vue)
Vue.prototype.mpHost = __PLATFORM__
......
function b64DecodeUnicode (str) {
return decodeURIComponent(atob(str).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
}).join(''))
}
function getCurrentUserInfo () {
const token = (__PLATFORM__ === 'h5' || __PLATFORM__ === 'app-plus' ? uni : __GLOBAL__).getStorageSync('uni_id_token') || ''
const tokenArr = token.split('.')
if (!token || tokenArr.length !== 3) {
return {
uid: null,
role: [],
permission: []
}
}
let userInfo
try {
userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1]))
} catch (error) {
throw new Error('获取当前用户信息出错,详细错误信息为:' + error.message)
}
return userInfo
}
export function uniIdMixin (Vue) {
Vue.prototype.uniIDHasRole = function (roleId) {
const {
role
} = getCurrentUserInfo()
return role.indexOf(roleId) > -1
}
Vue.prototype.uniIDHasPermission = function (permissionId) {
const {
permission
} = getCurrentUserInfo()
return this.uniIDHasRole('admin') || permission.indexOf(permissionId) > -1
}
}
......@@ -193,3 +193,5 @@ export function deepClone (vnodes, createElement) {
return vnodes.map(cloneVNode)
}
export * from './uni-id-mixin'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册