diff --git a/packages/uni-mp-weixin/dist/index.js b/packages/uni-mp-weixin/dist/index.js index eccdb0b225a4ae0f4074e391c809741d0f918b08..13c559ea50dc66e9a3298eb2b16761ed2dca0281 100644 --- a/packages/uni-mp-weixin/dist/index.js +++ b/packages/uni-mp-weixin/dist/index.js @@ -1,5 +1,55 @@ import Vue from 'vue'; +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 = ( wx).getStorageSync('uni_id_token') || ''; + const tokenArr = token.split('.'); + if (!token || tokenArr.length !== 3) { + return { + uid: null, + role: [], + permission: [], + tokenExpired: 0 + } + } + let userInfo; + try { + userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1])); + } catch (error) { + throw new Error('获取当前用户信息出错,详细错误信息为:' + error.message) + } + userInfo.tokenExpired = userInfo.exp * 1000; + delete userInfo.exp; + delete userInfo.iat; + return userInfo +} + +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 + }; + Vue.prototype.uniIDTokenValid = function () { + const { + tokenExpired + } = getCurrentUserInfo(); + return tokenExpired > Date.now() + }; +} + const _toString = Object.prototype.toString; const hasOwnProperty = Object.prototype.hasOwnProperty; @@ -422,37 +472,37 @@ var previewImage = { } }; -const UUID_KEY = '__DC_STAT_UUID'; -let deviceId; -function addUuid (result) { - deviceId = deviceId || wx.getStorageSync(UUID_KEY); - if (!deviceId) { - deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7); - wx.setStorage({ - key: UUID_KEY, - data: deviceId - }); - } - result.deviceId = deviceId; -} - -function addSafeAreaInsets (result) { - if (result.safeArea) { - const safeArea = result.safeArea; - result.safeAreaInsets = { - top: safeArea.top, - left: safeArea.left, - right: result.windowWidth - safeArea.right, - bottom: result.windowHeight - safeArea.bottom - }; - } -} - -var getSystemInfo = { - returnValue: function (result) { - addUuid(result); - addSafeAreaInsets(result); - } +const UUID_KEY = '__DC_STAT_UUID'; +let deviceId; +function addUuid (result) { + deviceId = deviceId || wx.getStorageSync(UUID_KEY); + if (!deviceId) { + deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7); + wx.setStorage({ + key: UUID_KEY, + data: deviceId + }); + } + result.deviceId = deviceId; +} + +function addSafeAreaInsets (result) { + if (result.safeArea) { + const safeArea = result.safeArea; + result.safeAreaInsets = { + top: safeArea.top, + left: safeArea.left, + right: result.windowWidth - safeArea.right, + bottom: result.windowHeight - safeArea.bottom + }; + } +} + +var getSystemInfo = { + returnValue: function (result) { + addUuid(result); + addSafeAreaInsets(result); + } }; // import navigateTo from 'uni-helpers/navigate-to' @@ -919,6 +969,11 @@ function initProperties (props, isBehavior = false, file = '') { type: Object, value: null }; + // scopedSlotsCompiler auto + properties.scopedSlotsCompiler = { + type: String, + value: '' + }; properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots type: null, value: [], @@ -1314,11 +1369,14 @@ function initScopedSlotsParams () { }; Vue.prototype.$setScopedSlotsParams = function (name, value) { - const vueId = this.$options.propsData.vueId; - const object = center[vueId] = center[vueId] || {}; - object[name] = value; - if (parents[vueId]) { - parents[vueId].$forceUpdate(); + const vueIds = this.$options.propsData.vueId; + if (vueIds) { + const vueId = vueIds.split(',')[0]; + const object = center[vueId] = center[vueId] || {}; + object[name] = value; + if (parents[vueId]) { + parents[vueId].$forceUpdate(); + } } }; @@ -1345,6 +1403,7 @@ function parseBaseApp (vm, { if (vm.$options.store) { Vue.prototype.$store = vm.$options.store; } + uniIdMixin(Vue); Vue.prototype.mpHost = "mp-weixin"; @@ -1718,11 +1777,12 @@ function createComponent (vueOptions) { } } -function createSubpackageApp (vm) { +function createSubpackageApp(vm) { const appOptions = parseApp(vm); const app = getApp({ allowDefault: true }); + vm.$scope = app; const globalData = app.globalData; if (globalData) { Object.keys(appOptions.globalData).forEach(name => { @@ -1737,39 +1797,39 @@ function createSubpackageApp (vm) { } }); if (isFn(appOptions.onShow) && wx.onAppShow) { - wx.onAppShow((...args) => { - appOptions.onShow.apply(app, args); + wx.onAppShow((...args) => { + vm.__call_hook('onShow', args); }); } if (isFn(appOptions.onHide) && wx.onAppHide) { - wx.onAppHide((...args) => { - appOptions.onHide.apply(app, args); + wx.onAppHide((...args) => { + vm.__call_hook('onHide', args); }); } if (isFn(appOptions.onLaunch)) { const args = wx.getLaunchOptionsSync && wx.getLaunchOptionsSync(); - appOptions.onLaunch.call(app, args); + vm.__call_hook('onLaunch', args); } return vm } -function createPlugin (vm) { - const appOptions = parseApp(vm); - if (isFn(appOptions.onShow) && wx.onAppShow) { - wx.onAppShow((...args) => { - appOptions.onShow.apply(vm, args); - }); - } - if (isFn(appOptions.onHide) && wx.onAppHide) { - wx.onAppHide((...args) => { - appOptions.onHide.apply(vm, args); - }); - } - if (isFn(appOptions.onLaunch)) { - const args = wx.getLaunchOptionsSync && wx.getLaunchOptionsSync(); - appOptions.onLaunch.call(vm, args); - } - return vm +function createPlugin (vm) { + const appOptions = parseApp(vm); + if (isFn(appOptions.onShow) && wx.onAppShow) { + wx.onAppShow((...args) => { + appOptions.onShow.apply(vm, args); + }); + } + if (isFn(appOptions.onHide) && wx.onAppHide) { + wx.onAppHide((...args) => { + appOptions.onHide.apply(vm, args); + }); + } + if (isFn(appOptions.onLaunch)) { + const args = wx.getLaunchOptionsSync && wx.getLaunchOptionsSync(); + appOptions.onLaunch.call(vm, args); + } + return vm } todos.forEach(todoApi => { diff --git a/packages/webpack-uni-mp-loader/lib/plugin/generate-json.js b/packages/webpack-uni-mp-loader/lib/plugin/generate-json.js index 2d5be4c68034d5727510745dc8a860544fa36b43..80655b696119f29dd645ca8bd064ac72f799911e 100644 --- a/packages/webpack-uni-mp-loader/lib/plugin/generate-json.js +++ b/packages/webpack-uni-mp-loader/lib/plugin/generate-json.js @@ -102,7 +102,7 @@ function normalizeUsingComponents (file, usingComponents) { } file = path.dirname('/' + file) names.forEach(name => { - usingComponents[name] = path.relative(file, usingComponents[name]) + usingComponents[name] = normalizePath(path.relative(file, usingComponents[name])) }) return usingComponents }