Skip to content

Commit

Permalink
feat(runtime): add exists for redirectTo
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Aug 19, 2020
1 parent cf87a14 commit eb5c684
Show file tree
Hide file tree
Showing 33 changed files with 1,019 additions and 339 deletions.
5 changes: 4 additions & 1 deletion build/rollup.config.mp.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ module.exports = {
plugins: [
alias({
entries: [{
find: 'uni-shared/query',
replacement: path.resolve(__dirname, '../src/shared/query.js')
}, {
find: 'uni-shared',
replacement: path.resolve(__dirname, '../src/shared/util.js')
}, {
Expand All @@ -77,4 +80,4 @@ module.exports = {
})
],
external: ['vue']
}
}
72 changes: 62 additions & 10 deletions packages/uni-app-plus/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,17 @@ function wrapper (methodName, method) {
}

arg1 = processArgs(methodName, arg1, options.args, options.returnValue);

const args = [arg1];
if (typeof arg2 !== 'undefined') {
args.push(arg2);

const args = [arg1];
if (typeof arg2 !== 'undefined') {
args.push(arg2);
}
const returnValue = wx[options.name || methodName].apply(wx, args);
if (isFn(options.name)) {
methodName = options.name(arg1);
} else if (isStr(options.name)) {
methodName = options.name;
}
const returnValue = wx[methodName].apply(wx, args);
if (isSyncApi(methodName)) { // 同步 api
return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
}
Expand Down Expand Up @@ -1147,10 +1152,10 @@ function handleEvent (event) {
eventArray[2],
isCustom,
methodName
) || [];
);
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
// eslint-disable-next-line no-sparse-arrays
ret.push(handler.apply(handlerCtx, params.concat([, , , , , , , , , , event])));
ret.push(handler.apply(handlerCtx, (Array.isArray(params) ? params : []).concat([, , , , , , , , , , event])));
}
});
}
Expand Down Expand Up @@ -1346,6 +1351,49 @@ function createApp (vm) {
return vm
}

const encodeReserveRE = /[!'()*]/g;
const encodeReserveReplacer = c => '%' + c.charCodeAt(0).toString(16);
const commaRE = /%2C/g;

// fixed encodeURIComponent which is more conformant to RFC3986:
// - escapes [!'()*]
// - preserve commas
const encode = str => encodeURIComponent(str)
.replace(encodeReserveRE, encodeReserveReplacer)
.replace(commaRE, ',');

function stringifyQuery (obj, encodeStr = encode) {
const res = obj ? Object.keys(obj).map(key => {
const val = obj[key];

if (val === undefined) {
return ''
}

if (val === null) {
return encodeStr(key)
}

if (Array.isArray(val)) {
const result = [];
val.forEach(val2 => {
if (val2 === undefined) {
return
}
if (val2 === null) {
result.push(encodeStr(key));
} else {
result.push(encodeStr(key) + '=' + encodeStr(val2));
}
});
return result.join('&')
}

return encodeStr(key) + '=' + encodeStr(val)
}).filter(x => x.length > 0).join('&') : null;
return res ? `?${res}` : ''
}

function parseBaseComponent (vueComponentOptions, {
isPage,
initRelation
Expand Down Expand Up @@ -1470,9 +1518,13 @@ function parseBasePage (vuePageOptions, {

initHooks(pageOptions.methods, hooks$2, vuePageOptions);

pageOptions.methods.onLoad = function (args) {
this.$vm.$mp.query = args; // 兼容 mpvue
this.$vm.__call_hook('onLoad', args);
pageOptions.methods.onLoad = function (query) {
this.options = query;
this.$page = {
fullPath: '/' + this.route + stringifyQuery(query)
};
this.$vm.$mp.query = query; // 兼容 mpvue
this.$vm.__call_hook('onLoad', query);
};

return pageOptions
Expand Down
Loading

0 comments on commit eb5c684

Please sign in to comment.