提交 57ed3bf5 编写于 作者: D DCloud_LXH

fix(mp): 修复 混合分包usingComponents在windows上路径问题

上级 2240f7f3
import Vue from 'vue'; 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 _toString = Object.prototype.toString;
const hasOwnProperty = Object.prototype.hasOwnProperty; const hasOwnProperty = Object.prototype.hasOwnProperty;
...@@ -422,37 +472,37 @@ var previewImage = { ...@@ -422,37 +472,37 @@ var previewImage = {
} }
}; };
const UUID_KEY = '__DC_STAT_UUID'; const UUID_KEY = '__DC_STAT_UUID';
let deviceId; let deviceId;
function addUuid (result) { function addUuid (result) {
deviceId = deviceId || wx.getStorageSync(UUID_KEY); deviceId = deviceId || wx.getStorageSync(UUID_KEY);
if (!deviceId) { if (!deviceId) {
deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7); deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7);
wx.setStorage({ wx.setStorage({
key: UUID_KEY, key: UUID_KEY,
data: deviceId data: deviceId
}); });
} }
result.deviceId = deviceId; result.deviceId = deviceId;
} }
function addSafeAreaInsets (result) { function addSafeAreaInsets (result) {
if (result.safeArea) { if (result.safeArea) {
const safeArea = result.safeArea; const safeArea = result.safeArea;
result.safeAreaInsets = { result.safeAreaInsets = {
top: safeArea.top, top: safeArea.top,
left: safeArea.left, left: safeArea.left,
right: result.windowWidth - safeArea.right, right: result.windowWidth - safeArea.right,
bottom: result.windowHeight - safeArea.bottom bottom: result.windowHeight - safeArea.bottom
}; };
} }
} }
var getSystemInfo = { var getSystemInfo = {
returnValue: function (result) { returnValue: function (result) {
addUuid(result); addUuid(result);
addSafeAreaInsets(result); addSafeAreaInsets(result);
} }
}; };
// import navigateTo from 'uni-helpers/navigate-to' // import navigateTo from 'uni-helpers/navigate-to'
...@@ -919,6 +969,11 @@ function initProperties (props, isBehavior = false, file = '') { ...@@ -919,6 +969,11 @@ function initProperties (props, isBehavior = false, file = '') {
type: Object, type: Object,
value: null value: null
}; };
// scopedSlotsCompiler auto
properties.scopedSlotsCompiler = {
type: String,
value: ''
};
properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
type: null, type: null,
value: [], value: [],
...@@ -1314,11 +1369,14 @@ function initScopedSlotsParams () { ...@@ -1314,11 +1369,14 @@ function initScopedSlotsParams () {
}; };
Vue.prototype.$setScopedSlotsParams = function (name, value) { Vue.prototype.$setScopedSlotsParams = function (name, value) {
const vueId = this.$options.propsData.vueId; const vueIds = this.$options.propsData.vueId;
const object = center[vueId] = center[vueId] || {}; if (vueIds) {
object[name] = value; const vueId = vueIds.split(',')[0];
if (parents[vueId]) { const object = center[vueId] = center[vueId] || {};
parents[vueId].$forceUpdate(); object[name] = value;
if (parents[vueId]) {
parents[vueId].$forceUpdate();
}
} }
}; };
...@@ -1345,6 +1403,7 @@ function parseBaseApp (vm, { ...@@ -1345,6 +1403,7 @@ function parseBaseApp (vm, {
if (vm.$options.store) { if (vm.$options.store) {
Vue.prototype.$store = vm.$options.store; Vue.prototype.$store = vm.$options.store;
} }
uniIdMixin(Vue);
Vue.prototype.mpHost = "mp-weixin"; Vue.prototype.mpHost = "mp-weixin";
...@@ -1718,11 +1777,12 @@ function createComponent (vueOptions) { ...@@ -1718,11 +1777,12 @@ function createComponent (vueOptions) {
} }
} }
function createSubpackageApp (vm) { function createSubpackageApp(vm) {
const appOptions = parseApp(vm); const appOptions = parseApp(vm);
const app = getApp({ const app = getApp({
allowDefault: true allowDefault: true
}); });
vm.$scope = app;
const globalData = app.globalData; const globalData = app.globalData;
if (globalData) { if (globalData) {
Object.keys(appOptions.globalData).forEach(name => { Object.keys(appOptions.globalData).forEach(name => {
...@@ -1737,39 +1797,39 @@ function createSubpackageApp (vm) { ...@@ -1737,39 +1797,39 @@ function createSubpackageApp (vm) {
} }
}); });
if (isFn(appOptions.onShow) && wx.onAppShow) { if (isFn(appOptions.onShow) && wx.onAppShow) {
wx.onAppShow((...args) => { wx.onAppShow((...args) => {
appOptions.onShow.apply(app, args); vm.__call_hook('onShow', args);
}); });
} }
if (isFn(appOptions.onHide) && wx.onAppHide) { if (isFn(appOptions.onHide) && wx.onAppHide) {
wx.onAppHide((...args) => { wx.onAppHide((...args) => {
appOptions.onHide.apply(app, args); vm.__call_hook('onHide', args);
}); });
} }
if (isFn(appOptions.onLaunch)) { if (isFn(appOptions.onLaunch)) {
const args = wx.getLaunchOptionsSync && wx.getLaunchOptionsSync(); const args = wx.getLaunchOptionsSync && wx.getLaunchOptionsSync();
appOptions.onLaunch.call(app, args); vm.__call_hook('onLaunch', args);
} }
return vm return vm
} }
function createPlugin (vm) { function createPlugin (vm) {
const appOptions = parseApp(vm); const appOptions = parseApp(vm);
if (isFn(appOptions.onShow) && wx.onAppShow) { if (isFn(appOptions.onShow) && wx.onAppShow) {
wx.onAppShow((...args) => { wx.onAppShow((...args) => {
appOptions.onShow.apply(vm, args); appOptions.onShow.apply(vm, args);
}); });
} }
if (isFn(appOptions.onHide) && wx.onAppHide) { if (isFn(appOptions.onHide) && wx.onAppHide) {
wx.onAppHide((...args) => { wx.onAppHide((...args) => {
appOptions.onHide.apply(vm, args); appOptions.onHide.apply(vm, args);
}); });
} }
if (isFn(appOptions.onLaunch)) { if (isFn(appOptions.onLaunch)) {
const args = wx.getLaunchOptionsSync && wx.getLaunchOptionsSync(); const args = wx.getLaunchOptionsSync && wx.getLaunchOptionsSync();
appOptions.onLaunch.call(vm, args); appOptions.onLaunch.call(vm, args);
} }
return vm return vm
} }
todos.forEach(todoApi => { todos.forEach(todoApi => {
......
...@@ -102,7 +102,7 @@ function normalizeUsingComponents (file, usingComponents) { ...@@ -102,7 +102,7 @@ function normalizeUsingComponents (file, usingComponents) {
} }
file = path.dirname('/' + file) file = path.dirname('/' + file)
names.forEach(name => { names.forEach(name => {
usingComponents[name] = path.relative(file, usingComponents[name]) usingComponents[name] = normalizePath(path.relative(file, usingComponents[name]))
}) })
return usingComponents return usingComponents
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册