提交 eb5c684c 编写于 作者: fxy060608's avatar fxy060608

feat(runtime): add exists for redirectTo

上级 cf87a142
......@@ -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')
}, {
......@@ -77,4 +80,4 @@ module.exports = {
})
],
external: ['vue']
}
}
......@@ -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))
}
......@@ -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])));
}
});
}
......@@ -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
......@@ -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
......
......@@ -130,7 +130,8 @@ var serviceContext = (function () {
'stopBeaconDiscovery',
'checkIsSupportSoterAuthentication',
'checkIsSoterEnrolledInDevice',
'startSoterAuthentication',
'startSoterAuthentication',
'onThemeChange',
'onUIStyleChange'
];
......@@ -3573,85 +3574,6 @@ var serviceContext = (function () {
return data
}
const DEVICE_FREQUENCY = 200;
const NETWORK_TYPES = ['unknown', 'none', 'ethernet', 'wifi', '2g', '3g', '4g'];
const MAP_ID = '__UNIAPP_MAP';
const TEMP_PATH_BASE = '_doc/uniapp_temp';
const TEMP_PATH = `${TEMP_PATH_BASE}_${Date.now()}`;
/**
* 5+错误对象转换为错误消息
* @param {*} error 5+错误对象
*/
function toErrMsg (error) {
var msg = 'base64ToTempFilePath:fail';
if (error && error.message) {
msg += ` ${error.message}`;
} else if (error) {
msg += ` ${error}`;
}
return msg
}
function base64ToTempFilePath ({
base64Data,
x,
y,
width,
height,
destWidth,
destHeight,
canvasId,
fileType,
quality
} = {}, callbackId) {
var id = Date.now();
var bitmap = new plus.nativeObj.Bitmap(`bitmap${id}`);
bitmap.loadBase64Data(base64Data, function () {
var formats = ['jpg', 'png'];
var format = String(fileType).toLowerCase();
if (formats.indexOf(format) < 0) {
format = 'png';
}
/**
* 保存配置
*/
var saveOption = {
overwrite: true,
quality: typeof quality === 'number' ? quality * 100 : 100,
format
};
/**
* 保存文件路径
*/
var tempFilePath = `${TEMP_PATH}/canvas/${id}.${format}`;
bitmap.save(tempFilePath, saveOption, function () {
clear();
invoke$1(callbackId, {
tempFilePath,
errMsg: 'base64ToTempFilePath:ok'
});
}, function (error) {
clear();
invoke$1(callbackId, {
errMsg: toErrMsg(error)
});
});
}, function (error) {
clear();
invoke$1(callbackId, {
errMsg: toErrMsg(error)
});
});
function clear () {
bitmap.clear();
}
}
function operateMapPlayer (mapId, pageVm, type, data) {
const pageId = pageVm.$page.id;
UniServiceJSBridge.publishHandler(pageId + '-map-' + mapId, {
......@@ -3934,6 +3856,14 @@ var serviceContext = (function () {
return createLivePusherContext(id, vm)
}
const DEVICE_FREQUENCY = 200;
const NETWORK_TYPES = ['unknown', 'none', 'ethernet', 'wifi', '2g', '3g', '4g'];
const MAP_ID = '__UNIAPP_MAP';
const TEMP_PATH_BASE = '_doc/uniapp_temp';
const TEMP_PATH = `${TEMP_PATH_BASE}_${Date.now()}`;
let watchAccelerationId = false;
let isWatchAcceleration = false;
......@@ -6579,7 +6509,7 @@ var serviceContext = (function () {
};
const cookiesPrase = header => {
let cookiesStr = header['Set-Cookie'];
let cookiesStr = header['Set-Cookie'] || header['set-cookie'];
let cookiesArr = [];
if (!cookiesStr) {
return []
......@@ -8755,6 +8685,7 @@ var serviceContext = (function () {
meta: routeOptions.meta,
path,
route,
fullPath: url,
openType
},
$remove () {
......@@ -8923,13 +8854,47 @@ var serviceContext = (function () {
});
}
function hasLifecycleHook (vueOptions = {}, hook) {
return Array.isArray(vueOptions[hook]) && vueOptions[hook].length
}
function findExistsPageIndex (url) {
const pages = getCurrentPages();
let len = pages.length;
while (len--) {
const page = pages[len];
if (page.$page && page.$page.fullPath === url) {
return len
}
}
return -1
}
function _redirectTo ({
url,
path,
query
query,
exists
}, callbackId) {
const pages = getCurrentPages();
const lastPage = pages[pages.length - 1];
const len = pages.length - 1;
if (exists === 'back') {
const existsPageIndex = findExistsPageIndex(url);
if (existsPageIndex !== -1) {
const delta = len - existsPageIndex;
if (delta > 0) {
navigateBack$1({
delta
});
invoke$1(callbackId, {
errMsg: 'redirectTo:ok'
});
return
}
}
}
const lastPage = pages[len];
lastPage && lastPage.$remove();
......@@ -8959,7 +8924,8 @@ var serviceContext = (function () {
setStatusBarStyle();
}
function redirectTo$1 ({
url
url,
exists
}, callbackId) {
const urls = url.split('?');
const path = urls[0];
......@@ -8968,7 +8934,8 @@ var serviceContext = (function () {
_redirectTo({
url,
path,
query
query,
exists
}, callbackId);
});
}
......@@ -9840,6 +9807,7 @@ var serviceContext = (function () {
};
});
this._preload = options.preload !== undefined ? options.preload : true;
this._isLoad = false;
this._adError = '';
this._loadPromiseResolve = null;
......@@ -9849,8 +9817,8 @@ var serviceContext = (function () {
const rewardAd = this._rewardAd = plus.ad.createRewardedVideoAd(options);
rewardAd.onLoad((e) => {
this._isLoad = true;
this._dispatchEvent('load', {});
this._lastLoadTime = Date.now();
this._dispatchEvent('load', {});
if (this._loadPromiseResolve != null) {
this._loadPromiseResolve();
......@@ -9858,7 +9826,9 @@ var serviceContext = (function () {
}
});
rewardAd.onClose((e) => {
this._loadAd();
if (this._preload) {
this._loadAd();
}
this._dispatchEvent('close', { isEnded: e.isEnded });
});
rewardAd.onVerify && rewardAd.onVerify((e) => {
......@@ -9878,11 +9848,14 @@ var serviceContext = (function () {
this._loadPromiseReject = null;
}
});
this._loadAd();
if (this._preload) {
this._loadAd();
}
}
get isExpired () {
return (Math.abs(Date.now() - this._lastLoadTime) > EXPIRED_TIME)
return (this._lastLoadTime !== 0 && (Math.abs(Date.now() - this._lastLoadTime) > EXPIRED_TIME))
}
load () {
......@@ -9961,7 +9934,6 @@ var serviceContext = (function () {
setBackgroundAudioState: setBackgroundAudioState,
operateBackgroundAudio: operateBackgroundAudio,
getBackgroundAudioState: getBackgroundAudioState,
base64ToTempFilePath: base64ToTempFilePath,
operateMapPlayer: operateMapPlayer$2,
operateVideoPlayer: operateVideoPlayer$2,
createLivePusherContext: createLivePusherContext$1,
......@@ -11145,37 +11117,20 @@ var serviceContext = (function () {
});
return
}
const cId = canvasEventCallbacks.push(function ({
base64
}) {
if (!base64 || !base64.length) {
invoke$1(callbackId, {
errMsg: 'canvasToTempFilePath:fail'
});
}
invokeMethod('base64ToTempFilePath', {
base64Data: base64,
x,
y,
width,
height,
destWidth,
destHeight,
canvasId,
fileType,
qualit
}, callbackId);
const cId = canvasEventCallbacks.push(function (res) {
invoke$1(callbackId, res);
});
operateCanvas(canvasId, pageId, 'getDataUrl', {
const dirname = `${TEMP_PATH}/canvas`;
operateCanvas(canvasId, pageId, 'toTempFilePath', {
x,
y,
width,
height,
destWidth,
destHeight,
hidpi: false,
fileType,
qualit,
dirname,
callbackId: cId
});
}
......@@ -11198,8 +11153,8 @@ var serviceContext = (function () {
data
}) => {
callback.invoke(callbackId, data);
});
});
const methods = ['getCenterLocation', 'moveToLocation', 'getScale', 'getRegion', 'includePoints', 'translateMarker'];
class MapContext {
......@@ -11207,18 +11162,20 @@ var serviceContext = (function () {
this.id = id;
this.pageVm = pageVm;
}
}
MapContext.prototype.$getAppMap = function () {
return plus.maps.getMapById(this.pageVm.$page.id + '-map-' + this.id)
};
}
MapContext.prototype.$getAppMap = function () {
{
return plus.maps.getMapById(this.pageVm.$page.id + '-map-' + this.id)
}
};
methods.forEach(function (method) {
MapContext.prototype[method] = callback.warp(function (options, callbackId) {
MapContext.prototype[method] = callback.warp(function (options, callbackId) {
options.callbackId = callbackId;
operateMapPlayer$3(this.id, this.pageVm, method, options);
});
});
});
function createMapContext$1 (id, context) {
if (context) {
......@@ -11681,6 +11638,17 @@ var serviceContext = (function () {
const callbacks$9 = [];
onMethod('onThemeChange', function (res) {
callbacks$9.forEach(callbackId => {
invoke$1(callbackId, res);
});
});
function onThemeChange (callbackId) {
callbacks$9.push(callbackId);
}
// 旧版本 API,后期文档更新后考虑移除
onMethod('onUIStyleChange', function (res) {
callbacks$9.forEach(callbackId => {
invoke$1(callbackId, res);
......@@ -11689,10 +11657,12 @@ var serviceContext = (function () {
function onUIStyleChange (callbackId) {
callbacks$9.push(callbackId);
console.log('API uni.onUIStyleChange 已过时,请使用 uni.onThemeChange,详情:https://uniapp.dcloud.net.cn/api/system/theme');
}
var require_context_module_1_15 = /*#__PURE__*/Object.freeze({
__proto__: null,
onThemeChange: onThemeChange,
onUIStyleChange: onUIStyleChange
});
......@@ -12954,8 +12924,15 @@ var serviceContext = (function () {
callCurrentPageHook('onHide');
}
function onAppEnterForeground () {
callAppHook(getApp(), 'onShow');
function onAppEnterForeground () {
const pages = getCurrentPages();
const page = pages[pages.length - 1];
const args = {
path: page.route,
query: page.options
};
callAppHook(getApp(), 'onShow', args);
callCurrentPageHook('onShow');
}
......@@ -13274,9 +13251,17 @@ var serviceContext = (function () {
});
});
globalEvent.addEventListener('uistylechange', function (event) {
publish('onUIStyleChange', {
style: event.uistyle
globalEvent.addEventListener('uistylechange', function (event) {
const args = {
theme: event.uistyle
};
callAppHook(appCtx, 'onThemeChange', args);
publish('onThemeChange', args);
// 兼容旧版本 API
publish('onUIStyleChange', {
style: event.uistyle
});
});
......@@ -13386,6 +13371,33 @@ var serviceContext = (function () {
}
}
function clearTempFile () {
// 统一处理路径
function getPath (path) {
path = path.replace(/\/$/, '');
return path.indexOf('_') === 0 ? plus.io.convertLocalFileSystemURL(path) : path
}
var basePath = getPath(TEMP_PATH_BASE);
var tempPath = getPath(TEMP_PATH);
// 获取父目录
var dirPath = tempPath.split('/');
dirPath.pop();
dirPath = dirPath.join('/');
plus.io.resolveLocalFileSystemURL(plus.io.convertAbsoluteFileSystem(dirPath), entry => {
var reader = entry.createReader();
reader.readEntries(function (entries) {
if (entries && entries.length) {
entries.forEach(function (entry) {
if (entry.isDirectory && entry.fullPath.indexOf(basePath) === 0 && entry.fullPath
.indexOf(tempPath) !== 0) {
entry.removeRecursively();
}
});
}
});
});
}
function registerApp (appVm) {
if (process.env.NODE_ENV !== 'production') {
console.log('[uni-app] registerApp');
......@@ -13415,13 +13427,21 @@ var serviceContext = (function () {
initAppLaunch(appVm);
// 10s后清理临时文件
setTimeout(clearTempFile, 10000);
__uniConfig.ready = true;
process.env.NODE_ENV !== 'production' && perf('registerApp');
}
var tags = [
'uni-app',
'uni-app',
'uni-layout',
'uni-content',
'uni-main',
'uni-left-window',
'uni-right-window',
'uni-tabbar',
'uni-page',
'uni-page-head',
......@@ -13477,20 +13497,17 @@ var serviceContext = (function () {
'uni-web-view'
];
function hasLifecycleHook (vueOptions = {}, hook) {
return Array.isArray(vueOptions[hook]) && vueOptions[hook].length
}
// 使用白名单过滤(前期有一批自定义组件使用了 uni-)
function initVue (Vue) {
Vue.config.errorHandler = function (err, vm, info) {
Vue.util.warn(`Error in ${info}: "${err.toString()}"`, vm);
const errType = toRawType(err);
Vue.util.warn(`Error in ${info}: "${errType === 'Error' ? err.toString() : err}"`, vm);
const app = typeof getApp === 'function' && getApp();
if (app && hasLifecycleHook(app.$options, 'onError')) {
app.__call_hook('onError', err);
} else {
if ( process.env.NODE_ENV !== 'production') {
if ( process.env.NODE_ENV !== 'production' && errType === 'Error') {
console.error(`
${err.message}
${err.stack}
......@@ -13615,11 +13632,9 @@ var serviceContext = (function () {
const isAndroid = plus.os.name.toLowerCase() === 'android';
const FOCUS_TIMEOUT = isAndroid ? 300 : 700;
const HIDE_TIMEOUT = isAndroid ? 800 : 300;
let keyboardHeight = 0;
let onKeyboardShow;
let focusTimer;
let hideKeyboardTimeout;
function hookKeyboardEvent (event, callback) {
onKeyboardShow = null;
......@@ -13647,19 +13662,6 @@ var serviceContext = (function () {
keyboardHeight = res.height;
if (keyboardHeight > 0) {
onKeyboardShow && onKeyboardShow();
if (hideKeyboardTimeout) {
clearTimeout(hideKeyboardTimeout);
hideKeyboardTimeout = null;
}
} else {
// 安卓/iOS13收起键盘时通知view层失去焦点
if (isAndroid || parseInt(plus.os.version) >= 13) {
hideKeyboardTimeout = setTimeout(function () {
hideKeyboardTimeout = null;
var pageId = getCurrentPageId();
UniServiceJSBridge.publishHandler('hideKeyboard', {}, pageId);
}, HIDE_TIMEOUT);
}
}
});
......
此差异已折叠。
......@@ -451,6 +451,10 @@
"/core/service/api/device/bluetooth.js",
[]
],
"onThemeChange": [
"/core/service/api/device/theme.js",
[]
],
"onUIStyleChange": [
"/core/service/api/device/theme.js",
[]
......@@ -780,10 +784,6 @@
"createCanvasContext": [
"/core/service/api/context/canvas.js",
[
[
"/platforms/h5/service/api/context/canvas.js",
"base64ToTempFilePath"
],
[
"/core/helpers/protocol/context/context.js",
"createCanvasContext"
......@@ -793,10 +793,6 @@
"canvasToTempFilePath": [
"/core/service/api/context/canvas.js",
[
[
"/platforms/h5/service/api/context/canvas.js",
"base64ToTempFilePath"
],
[
"/core/helpers/protocol/context/canvas.js",
"canvasToTempFilePath"
......@@ -806,10 +802,6 @@
"canvasPutImageData": [
"/core/service/api/context/canvas.js",
[
[
"/platforms/h5/service/api/context/canvas.js",
"base64ToTempFilePath"
],
[
"/core/helpers/protocol/context/canvas.js",
"canvasPutImageData"
......@@ -819,10 +811,6 @@
"canvasGetImageData": [
"/core/service/api/context/canvas.js",
[
[
"/platforms/h5/service/api/context/canvas.js",
"base64ToTempFilePath"
],
[
"/core/helpers/protocol/context/canvas.js",
"canvasGetImageData"
......
......@@ -356,6 +356,38 @@ var baseApi = /*#__PURE__*/Object.freeze({
interceptors: interceptors
});
function findExistsPageIndex (url) {
const pages = getCurrentPages();
let len = pages.length;
while (len--) {
const page = pages[len];
if (page.$page && page.$page.fullPath === url) {
return len
}
}
return -1
}
var redirectTo = {
name (fromArgs) {
if (fromArgs.exists === 'back' && fromArgs.delta) {
return 'navigateBack'
}
return 'redirectTo'
},
args (fromArgs) {
if (fromArgs.exists === 'back' && fromArgs.url) {
const existsPageIndex = findExistsPageIndex(fromArgs.url);
if (existsPageIndex !== -1) {
const delta = getCurrentPages().length - 1 - existsPageIndex;
if (delta > 0) {
fromArgs.delta = delta;
}
}
}
}
};
// 不支持的 API 列表
const todos = [
'preloadPage',
......@@ -434,6 +466,7 @@ function _handleSystemInfo (result) {
}
const protocols = { // 需要做转换的 API 列表
redirectTo,
returnValue (methodName, res = {}) { // 通用 returnValue 解析
if (res.error || res.errorMessage) {
res.errMsg = `${methodName}:fail ${res.errorMessage || res.error}`;
......@@ -466,7 +499,8 @@ const protocols = { // 需要做转换的 API 列表
},
data (data) {
// 钉钉小程序在content-type为application/json时需上传字符串形式data,使用my.dd在真机运行钉钉小程序时不能正确判断
if (my.canIUse('saveFileToDingTalk') && method.toUpperCase() === 'POST' && headers['content-type'].indexOf('application/json') === 0 && isPlainObject(data)) {
if (my.canIUse('saveFileToDingTalk') && method.toUpperCase() === 'POST' && headers['content-type'].indexOf(
'application/json') === 0 && isPlainObject(data)) {
return {
name: 'data',
value: JSON.stringify(data)
......@@ -641,17 +675,17 @@ const protocols = { // 需要做转换的 API 列表
args: {
filePath: 'apFilePath'
}
},
getSavedFileList: {
returnValue (result) {
if (result.fileList && result.fileList.length) {
result.fileList.forEach(file => {
file.filePath = file.apFilePath;
delete file.apFilePath;
});
}
return {}
}
},
getSavedFileList: {
returnValue (result) {
if (result.fileList && result.fileList.length) {
result.fileList.forEach(file => {
file.filePath = file.apFilePath;
delete file.apFilePath;
});
}
return {}
}
},
removeSavedFile: {
args: {
......@@ -895,12 +929,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 = my[options.name || methodName].apply(my, args);
if (isFn(options.name)) {
methodName = options.name(arg1);
} else if (isStr(options.name)) {
methodName = options.name;
}
const returnValue = my[methodName].apply(my, args);
if (isSyncApi(methodName)) { // 同步 api
return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
}
......@@ -1626,10 +1665,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])));
}
});
}
......@@ -2046,6 +2085,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}` : ''
}
const hooks$1 = [
'onShow',
'onHide',
......@@ -2064,7 +2146,7 @@ function parsePage (vuePageOptions) {
const pageOptions = {
mixins: initBehaviors(vueOptions, initBehavior),
data: initData(vueOptions, Vue.prototype),
onLoad (args) {
onLoad (query) {
const properties = this.props;
const options = {
......@@ -2075,14 +2157,19 @@ function parsePage (vuePageOptions) {
// 初始化 vue 实例
this.$vm = new VueComponent(options);
initSpecialMethods(this);
initSpecialMethods(this);
// 触发首次 setData
this.$vm.$mount();
this.$vm.$mp.query = args; // 兼容 mpvue
this.$vm.__call_hook('onLoad', args);
this.$page = {
fullPath: '/' + this.route + stringifyQuery(query)
};
this.options = query;
this.$vm.$mp.query = query; // 兼容 mpvue
this.$vm.__call_hook('onLoad', query);
},
onReady () {
initChildVues(this);
......@@ -2093,12 +2180,12 @@ function parsePage (vuePageOptions) {
onUnload () {
this.$vm.__call_hook('onUnload');
this.$vm.$destroy();
},
events: {
// 支付宝小程序有些页面事件只能放在events下
onBack () {
this.$vm.__call_hook('onBackPress');
}
},
events: {
// 支付宝小程序有些页面事件只能放在events下
onBack () {
this.$vm.__call_hook('onBackPress');
}
},
__r: handleRef,
__e: handleEvent,
......@@ -2106,14 +2193,14 @@ function parsePage (vuePageOptions) {
};
initHooks(pageOptions, hooks$1, vuePageOptions);
if (Array.isArray(vueOptions.wxsCallMethods)) {
vueOptions.wxsCallMethods.forEach(callMethod => {
pageOptions[callMethod] = function (args) {
return this.$vm[callMethod](args)
};
});
}
if (Array.isArray(vueOptions.wxsCallMethods)) {
vueOptions.wxsCallMethods.forEach(callMethod => {
pageOptions[callMethod] = function (args) {
return this.$vm[callMethod](args)
};
});
}
return pageOptions
}
......
......@@ -356,6 +356,38 @@ var baseApi = /*#__PURE__*/Object.freeze({
interceptors: interceptors
});
function findExistsPageIndex (url) {
const pages = getCurrentPages();
let len = pages.length;
while (len--) {
const page = pages[len];
if (page.$page && page.$page.fullPath === url) {
return len
}
}
return -1
}
var redirectTo = {
name (fromArgs) {
if (fromArgs.exists === 'back' && fromArgs.delta) {
return 'navigateBack'
}
return 'redirectTo'
},
args (fromArgs) {
if (fromArgs.exists === 'back' && fromArgs.url) {
const existsPageIndex = findExistsPageIndex(fromArgs.url);
if (existsPageIndex !== -1) {
const delta = getCurrentPages().length - 1 - existsPageIndex;
if (delta > 0) {
fromArgs.delta = delta;
}
}
}
}
};
var previewImage = {
args (fromArgs) {
let currentIndex = parseInt(fromArgs.current);
......@@ -467,7 +499,8 @@ const protocols = {
args: {
method: false
}
},
},
redirectTo,
previewImage,
getRecorderManager: {
returnValue (fromRet) {
......@@ -571,12 +604,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);
}
if (isFn(options.name)) {
methodName = options.name(arg1);
} else if (isStr(options.name)) {
methodName = options.name;
}
const returnValue = swan[options.name || methodName].apply(swan, args);
const returnValue = swan[methodName].apply(swan, args);
if (isSyncApi(methodName)) { // 同步 api
return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
}
......@@ -1289,10 +1327,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])));
}
});
}
......@@ -1484,6 +1522,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
......@@ -1637,9 +1718,13 @@ function parseBasePage (vuePageOptions, {
initHooks(pageOptions.methods, hooks$1, 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
......
......@@ -356,6 +356,38 @@ var baseApi = /*#__PURE__*/Object.freeze({
interceptors: interceptors
});
function findExistsPageIndex (url) {
const pages = getCurrentPages();
let len = pages.length;
while (len--) {
const page = pages[len];
if (page.$page && page.$page.fullPath === url) {
return len
}
}
return -1
}
var redirectTo = {
name (fromArgs) {
if (fromArgs.exists === 'back' && fromArgs.delta) {
return 'navigateBack'
}
return 'redirectTo'
},
args (fromArgs) {
if (fromArgs.exists === 'back' && fromArgs.url) {
const existsPageIndex = findExistsPageIndex(fromArgs.url);
if (existsPageIndex !== -1) {
const delta = getCurrentPages().length - 1 - existsPageIndex;
if (delta > 0) {
fromArgs.delta = delta;
}
}
}
}
};
var previewImage = {
args (fromArgs) {
let currentIndex = parseInt(fromArgs.current);
......@@ -390,7 +422,8 @@ var previewImage = {
}
};
const protocols = {
const protocols = {
redirectTo,
previewImage
};
const todos = [
......@@ -532,12 +565,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))
}
......@@ -1205,10 +1243,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])));
}
});
}
......@@ -1401,6 +1439,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
......@@ -1527,9 +1608,13 @@ function parseBasePage (vuePageOptions, {
initHooks(pageOptions.methods, hooks$1, 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
......
......@@ -356,6 +356,38 @@ var baseApi = /*#__PURE__*/Object.freeze({
interceptors: interceptors
});
function findExistsPageIndex (url) {
const pages = getCurrentPages();
let len = pages.length;
while (len--) {
const page = pages[len];
if (page.$page && page.$page.fullPath === url) {
return len
}
}
return -1
}
var redirectTo = {
name (fromArgs) {
if (fromArgs.exists === 'back' && fromArgs.delta) {
return 'navigateBack'
}
return 'redirectTo'
},
args (fromArgs) {
if (fromArgs.exists === 'back' && fromArgs.url) {
const existsPageIndex = findExistsPageIndex(fromArgs.url);
if (existsPageIndex !== -1) {
const delta = getCurrentPages().length - 1 - existsPageIndex;
if (delta > 0) {
fromArgs.delta = delta;
}
}
}
}
};
var previewImage = {
args (fromArgs) {
let currentIndex = parseInt(fromArgs.current);
......@@ -488,7 +520,8 @@ const protocols = {
args: {
sizeType: false
}
},
},
redirectTo,
previewImage,
connectSocket: {
args: {
......@@ -624,12 +657,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);
}
if (isFn(options.name)) {
methodName = options.name(arg1);
} else if (isStr(options.name)) {
methodName = options.name;
}
const returnValue = tt[options.name || methodName].apply(tt, args);
const returnValue = tt[methodName].apply(tt, args);
if (isSyncApi(methodName)) { // 同步 api
return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
}
......@@ -1297,10 +1335,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])));
}
});
}
......@@ -1573,6 +1611,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
......@@ -1719,9 +1800,13 @@ function parseBasePage (vuePageOptions, {
initHooks(pageOptions.methods, hooks$1, 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
......
......@@ -356,6 +356,38 @@ var baseApi = /*#__PURE__*/Object.freeze({
interceptors: interceptors
});
function findExistsPageIndex (url) {
const pages = getCurrentPages();
let len = pages.length;
while (len--) {
const page = pages[len];
if (page.$page && page.$page.fullPath === url) {
return len
}
}
return -1
}
var redirectTo = {
name (fromArgs) {
if (fromArgs.exists === 'back' && fromArgs.delta) {
return 'navigateBack'
}
return 'redirectTo'
},
args (fromArgs) {
if (fromArgs.exists === 'back' && fromArgs.url) {
const existsPageIndex = findExistsPageIndex(fromArgs.url);
if (existsPageIndex !== -1) {
const delta = getCurrentPages().length - 1 - existsPageIndex;
if (delta > 0) {
fromArgs.delta = delta;
}
}
}
}
};
var previewImage = {
args (fromArgs) {
let currentIndex = parseInt(fromArgs.current);
......@@ -402,6 +434,7 @@ function addSafeAreaInsets (result) {
}
}
const protocols = {
redirectTo,
previewImage,
getSystemInfo: {
returnValue: addSafeAreaInsets
......@@ -484,12 +517,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))
}
......@@ -1162,10 +1200,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])));
}
});
}
......@@ -1354,6 +1392,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
......@@ -1476,9 +1557,13 @@ function parseBasePage (vuePageOptions, {
initHooks(pageOptions.methods, hooks$1, 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
......
......@@ -356,6 +356,38 @@ var baseApi = /*#__PURE__*/Object.freeze({
interceptors: interceptors
});
function findExistsPageIndex (url) {
const pages = getCurrentPages();
let len = pages.length;
while (len--) {
const page = pages[len];
if (page.$page && page.$page.fullPath === url) {
return len
}
}
return -1
}
var redirectTo = {
name (fromArgs) {
if (fromArgs.exists === 'back' && fromArgs.delta) {
return 'navigateBack'
}
return 'redirectTo'
},
args (fromArgs) {
if (fromArgs.exists === 'back' && fromArgs.url) {
const existsPageIndex = findExistsPageIndex(fromArgs.url);
if (existsPageIndex !== -1) {
const delta = getCurrentPages().length - 1 - existsPageIndex;
if (delta > 0) {
fromArgs.delta = delta;
}
}
}
}
};
var previewImage = {
args (fromArgs) {
let currentIndex = parseInt(fromArgs.current);
......@@ -390,7 +422,8 @@ var previewImage = {
}
};
const protocols = {
const protocols = {
redirectTo,
previewImage
};
const todos = [
......@@ -466,12 +499,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 = qa[options.name || methodName].apply(qa, args);
if (isFn(options.name)) {
methodName = options.name(arg1);
} else if (isStr(options.name)) {
methodName = options.name;
}
const returnValue = qa[methodName].apply(qa, args);
if (isSyncApi(methodName)) { // 同步 api
return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
}
......@@ -1147,10 +1185,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])));
}
});
}
......@@ -1404,6 +1442,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
......@@ -1550,9 +1631,13 @@ function parseBasePage (vuePageOptions, {
initHooks(pageOptions.methods, hooks$1, 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
......
......@@ -41,4 +41,16 @@ export function upx2px (str) {
return uni.upx2px(parseInt(str) || 0)
}
return parseInt(str) || 0
}
export function findExistsPageIndex (url) {
const pages = getCurrentPages()
let len = pages.length
while (len--) {
const page = pages[len]
if (page.$page && page.$page.fullPath === url) {
return len
}
}
return -1
}
......@@ -10,7 +10,9 @@ import {
isContextApi
} from '../helpers/promise'
import { protocols } from 'uni-platform/runtime/api/protocols'
import {
protocols
} from 'uni-platform/runtime/api/protocols'
const CALLBACKS = ['success', 'fail', 'cancel', 'complete']
......@@ -78,12 +80,17 @@ export default 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)
}
if (isFn(options.name)) {
methodName = options.name(arg1)
} else if (isStr(options.name)) {
methodName = options.name
}
const returnValue = __GLOBAL__[options.name || methodName].apply(__GLOBAL__, args)
const returnValue = __GLOBAL__[methodName].apply(__GLOBAL__, args)
if (isSyncApi(methodName)) { // 同步 api
return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
}
......
......@@ -27,5 +27,5 @@ onMethod('onUIStyleChange', function (res) {
export function onUIStyleChange (callbackId) {
callbacks.push(callbackId)
console.log("API uni.onUIStyleChange 已过时,请使用 uni.onThemeChange,详情:https://uniapp.dcloud.net.cn/api/system/theme")
console.log('API uni.onUIStyleChange 已过时,请使用 uni.onThemeChange,详情:https://uniapp.dcloud.net.cn/api/system/theme')
}
......@@ -14,6 +14,7 @@ export default function createPage (pageVm, options) {
id,
path: $route.path,
route: $route.meta.pagePath,
fullPath: $route.meta.isEntry ? $route.meta.pagePath : $route.fullPath,
options: options,
meta: Object.assign({}, $route.meta)
}
......
<template>
<uni-navigator
v-if="hoverClass && hoverClass !== 'none'"
:class="[hovering ? hoverClass : '']"
<uni-navigator
v-if="hoverClass && hoverClass !== 'none'"
:class="[hovering ? hoverClass : '']"
@touchstart="_hoverTouchStart"
@touchend="_hoverTouchEnd"
@touchcancel="_hoverTouchCancel"
@click="_onClick"
@touchend="_hoverTouchEnd"
@touchcancel="_hoverTouchCancel"
@click="_onClick"
v-on="$listeners"
>
<slot />
</uni-navigator>
<uni-navigator
v-else
@click="_onClick"
<uni-navigator
v-else
@click="_onClick"
v-on="$listeners"
>
<slot />
......@@ -55,13 +55,18 @@ export default {
hoverStayTime: {
type: [Number, String],
default: 600
},
exists: {
type: String,
default: ''
}
},
methods: {
_onClick ($event) {
if (this.openType !== 'navigateBack' && !this.url) {
console.error('<navigator/> should have url attribute when using navigateTo, redirectTo, reLaunch or switchTab')
console.error(
'<navigator/> should have url attribute when using navigateTo, redirectTo, reLaunch or switchTab')
return
}
......@@ -73,7 +78,8 @@ export default {
break
case 'redirect':
uni.redirectTo({
url: this.url
url: this.url,
exists: this.exists
})
break
case 'switchTab':
......@@ -114,4 +120,4 @@ export default {
background-color: rgba(0, 0, 0, 0.1);
opacity: 0.7;
}
</style>
</style>
......@@ -2,6 +2,10 @@ import {
parseQuery
} from 'uni-shared'
import {
findExistsPageIndex
} from 'uni-helpers/index'
import {
showWebview
} from './util'
......@@ -20,13 +24,35 @@ import {
navigate
} from '../../framework/navigator'
import {
navigateBack
} from './navigate-back'
function _redirectTo ({
url,
path,
query
query,
exists
}, callbackId) {
const pages = getCurrentPages()
const lastPage = pages[pages.length - 1]
const len = pages.length - 1
if (exists === 'back') {
const existsPageIndex = findExistsPageIndex(url)
if (existsPageIndex !== -1) {
const delta = len - existsPageIndex
if (delta > 0) {
navigateBack({
delta
})
invoke(callbackId, {
errMsg: 'redirectTo:ok'
})
return
}
}
}
const lastPage = pages[len]
lastPage && lastPage.$remove()
......@@ -56,7 +82,8 @@ function _redirectTo ({
setStatusBarStyle()
}
export function redirectTo ({
url
url,
exists
}, callbackId) {
const urls = url.split('?')
const path = urls[0]
......@@ -65,7 +92,8 @@ export function redirectTo ({
_redirectTo({
url,
path,
query
query,
exists
}, callbackId)
})
}
......@@ -152,6 +152,7 @@ export function registerPage ({
meta: routeOptions.meta,
path,
route,
fullPath: url,
openType
},
$remove () {
......@@ -209,4 +210,4 @@ export function registerPage ({
}
return webview
}
}
import {
hasLifecycleHook
hasLifecycleHook,
findExistsPageIndex
} from 'uni-helpers/index'
const {
......@@ -9,6 +10,7 @@ const {
function onAppRoute (type, {
url,
delta,
exists,
animationType,
animationDuration,
from = 'navigateBack',
......@@ -17,6 +19,17 @@ function onAppRoute (type, {
const router = getApp().$router
switch (type) {
case 'redirectTo':
if (exists === 'back') {
const existsPageIndex = findExistsPageIndex(url)
if (existsPageIndex !== -1) {
const delta = (getCurrentPages().length - 1) - existsPageIndex
if (delta > 0) {
return onAppRoute('navigateBack', {
delta
})
}
}
}
router.replace({
type,
path: url
......
import {
isPlainObject
} from 'uni-shared'
import redirectTo from '../../../mp-weixin/helpers/redirect-to'
// 不支持的 API 列表
const todos = [
'preloadPage',
......@@ -79,6 +80,7 @@ function _handleSystemInfo (result) {
}
const protocols = { // 需要做转换的 API 列表
redirectTo,
returnValue (methodName, res = {}) { // 通用 returnValue 解析
if (res.error || res.errorMessage) {
res.errMsg = `${methodName}:fail ${res.errorMessage || res.error}`
......@@ -111,7 +113,8 @@ const protocols = { // 需要做转换的 API 列表
},
data (data) {
// 钉钉小程序在content-type为application/json时需上传字符串形式data,使用my.dd在真机运行钉钉小程序时不能正确判断
if (my.canIUse('saveFileToDingTalk') && method.toUpperCase() === 'POST' && headers['content-type'].indexOf('application/json') === 0 && isPlainObject(data)) {
if (my.canIUse('saveFileToDingTalk') && method.toUpperCase() === 'POST' && headers['content-type'].indexOf(
'application/json') === 0 && isPlainObject(data)) {
return {
name: 'data',
value: JSON.stringify(data)
......@@ -286,17 +289,17 @@ const protocols = { // 需要做转换的 API 列表
args: {
filePath: 'apFilePath'
}
},
getSavedFileList: {
returnValue (result) {
if (result.fileList && result.fileList.length) {
result.fileList.forEach(file => {
file.filePath = file.apFilePath
delete file.apFilePath
})
}
return {}
}
},
getSavedFileList: {
returnValue (result) {
if (result.fileList && result.fileList.length) {
result.fileList.forEach(file => {
file.filePath = file.apFilePath
delete file.apFilePath
})
}
return {}
}
},
removeSavedFile: {
args: {
......@@ -478,4 +481,4 @@ export {
protocols,
todos,
canIUses
}
}
import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
// 不支持的 API 列表
const todos = [
......@@ -76,7 +77,8 @@ const protocols = {
args: {
method: false
}
},
},
redirectTo,
previewImage,
getRecorderManager: {
returnValue (fromRet) {
......
此差异已折叠。
import redirectTo from '../../../mp-weixin/helpers/redirect-to'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
export const protocols = {
export const protocols = {
redirectTo,
previewImage
}
export const todos = [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册