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

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

上级 2240f7f3
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 => {
......
......@@ -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
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册