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

feat(app): add referrerInfo

上级 bf33a6c7
...@@ -245,7 +245,8 @@ const third = [ ...@@ -245,7 +245,8 @@ const third = [
'preloadPage', 'preloadPage',
'unPreloadPage', 'unPreloadPage',
'loadSubPackage', 'loadSubPackage',
'sendHostEvent' 'sendHostEvent',
'navigateToMiniProgram'
] ]
const ad = [ const ad = [
......
...@@ -256,7 +256,8 @@ var serviceContext = (function () { ...@@ -256,7 +256,8 @@ var serviceContext = (function () {
'preloadPage', 'preloadPage',
'unPreloadPage', 'unPreloadPage',
'loadSubPackage', 'loadSubPackage',
'sendHostEvent' 'sendHostEvent',
'navigateToMiniProgram'
]; ];
const ad = [ const ad = [
...@@ -1702,13 +1703,17 @@ var serviceContext = (function () { ...@@ -1702,13 +1703,17 @@ var serviceContext = (function () {
"uni.chooseLocation.cancel": "取消" "uni.chooseLocation.cancel": "取消"
}; };
const messages = { const messages = {};
{
Object.assign(messages, {
en, en,
es, es,
fr, fr,
'zh-Hans': zhHans, 'zh-Hans': zhHans,
'zh-Hant': zhHant 'zh-Hant': zhHant
}; });
}
let locale; let locale;
...@@ -5802,7 +5807,7 @@ var serviceContext = (function () { ...@@ -5802,7 +5807,7 @@ var serviceContext = (function () {
animationDuration: 200, animationDuration: 200,
uniNView: { uniNView: {
path: `${(typeof process === 'object' && process.env && process.env.VUE_APP_TEMPLATE_PATH) || ''}/${url}.js`, path: `${(typeof process === 'object' && process.env && process.env.VUE_APP_TEMPLATE_PATH) || ''}/${url}.js`,
defaultFontSize: plus_.screen.resolutionWidth / 20, defaultFontSize: 16,
viewport: plus_.screen.resolutionWidth viewport: plus_.screen.resolutionWidth
} }
}; };
...@@ -9225,7 +9230,7 @@ var serviceContext = (function () { ...@@ -9225,7 +9230,7 @@ var serviceContext = (function () {
}); });
} }
function onWebviewPopGesture (webview) { function onWebviewPopGesture(webview) {
let popStartStatusBarStyle; let popStartStatusBarStyle;
webview.addEventListener('popGesture', e => { webview.addEventListener('popGesture', e => {
if (e.type === 'start') { if (e.type === 'start') {
...@@ -9242,16 +9247,49 @@ var serviceContext = (function () { ...@@ -9242,16 +9247,49 @@ var serviceContext = (function () {
const pages = getCurrentPages(); const pages = getCurrentPages();
const page = pages[pages.length - 1]; const page = pages[pages.length - 1];
page && page.$remove(); page && page.$remove();
setStatusBarStyle(); setStatusBarStyle();
if (page && isDirectPage(page)) {
reLaunchEntryPage();
} else {
UniServiceJSBridge.emit('onAppRoute', { UniServiceJSBridge.emit('onAppRoute', {
type: 'navigateBack' type: 'navigateBack'
}); });
} }
}
});
}
/**
* 是否处于直达页面
* @param page
* @returns
*/
function isDirectPage(page) {
return (
__uniConfig.realEntryPagePath &&
page.$page.route === __uniConfig.entryPagePath
)
}
/**
* 重新启动到首页
*/
function reLaunchEntryPage() {
__uniConfig.entryPagePath = __uniConfig.realEntryPagePath;
delete __uniConfig.realEntryPagePath;
uni.reLaunch({
url: addLeadingSlash(__uniConfig.entryPagePath),
}); });
} }
function hasLeadingSlash(str) {
return str.indexOf('/') === 0
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str
}
let preloadWebview; let preloadWebview;
let id$1 = 2; let id$1 = 2;
...@@ -9753,6 +9791,64 @@ var serviceContext = (function () { ...@@ -9753,6 +9791,64 @@ var serviceContext = (function () {
return pageVm return pageVm
} }
const extend = Object.assign;
function createLaunchOptions () {
return {
path: '',
query: {},
scene: 1001,
referrerInfo: {
appId: '',
extraData: {}
}
}
}
const enterOptions = createLaunchOptions();
const launchOptions = createLaunchOptions();
function initLaunchOptions ({
path,
query,
referrerInfo
}) {
extend(launchOptions, {
path,
query: query ? parseQuery(query) : {},
referrerInfo: referrerInfo || {}
});
extend(enterOptions, launchOptions);
return launchOptions
}
function parseRedirectInfo () {
const weexPlus = weex.requireModule('plus');
if (weexPlus.getRedirectInfo) {
const {
path,
query,
extraData,
userAction,
fromAppid
} =
weexPlus.getRedirectInfo() || {};
const referrerInfo = {
appId: fromAppid,
extraData: {}
};
if (extraData) {
referrerInfo.extraData = extraData;
}
return {
path: path || '',
query: query ? '?' + query : '',
referrerInfo,
userAction
}
}
}
let isInitEntryPage = false; let isInitEntryPage = false;
function initEntryPage () { function initEntryPage () {
...@@ -9767,9 +9863,16 @@ var serviceContext = (function () { ...@@ -9767,9 +9863,16 @@ var serviceContext = (function () {
const weexPlus = weex.requireModule('plus'); const weexPlus = weex.requireModule('plus');
if (weexPlus.getRedirectInfo) { if (weexPlus.getRedirectInfo) {
const info = weexPlus.getRedirectInfo() || {}; const {
entryPagePath = info.path; path,
entryPageQuery = info.query ? ('?' + info.query) : ''; query,
referrerInfo
} = parseRedirectInfo();
if (path) {
entryPagePath = path;
entryPageQuery = query;
}
__uniConfig.referrerInfo = referrerInfo;
} else { } else {
const argsJsonStr = plus.runtime.arguments; const argsJsonStr = plus.runtime.arguments;
if (!argsJsonStr) { if (!argsJsonStr) {
...@@ -21993,11 +22096,11 @@ var serviceContext = (function () { ...@@ -21993,11 +22096,11 @@ var serviceContext = (function () {
} }
function initAppLaunch (appVm) { function initAppLaunch (appVm) {
const args = { const args = initLaunchOptions({
path: __uniConfig.entryPagePath, path: __uniConfig.entryPagePath,
query: {}, query: __uniConfig.entryPageQuery,
scene: 1001 referrerInfo: __uniConfig.referrerInfo
}; });
callAppHook(appVm, 'onLaunch', args); callAppHook(appVm, 'onLaunch', args);
callAppHook(appVm, 'onShow', args); callAppHook(appVm, 'onShow', args);
......
...@@ -45,6 +45,10 @@ import { ...@@ -45,6 +45,10 @@ import {
backbuttonListener backbuttonListener
} from './backbutton' } from './backbutton'
import {
initLaunchOptions
} from './utils'
let appCtx let appCtx
const defaultApp = { const defaultApp = {
...@@ -143,11 +147,11 @@ function onPlusMessage (e) { ...@@ -143,11 +147,11 @@ function onPlusMessage (e) {
} }
function initAppLaunch (appVm) { function initAppLaunch (appVm) {
const args = { const args = initLaunchOptions({
path: __uniConfig.entryPagePath, path: __uniConfig.entryPagePath,
query: {}, query: __uniConfig.entryPageQuery,
scene: 1001 referrerInfo: __uniConfig.referrerInfo
} })
callAppHook(appVm, 'onLaunch', args) callAppHook(appVm, 'onLaunch', args)
callAppHook(appVm, 'onShow', args) callAppHook(appVm, 'onShow', args)
......
import {
parseRedirectInfo
} from './utils'
function parseRoutes (config) { function parseRoutes (config) {
__uniRoutes.length = 0 __uniRoutes.length = 0
/* eslint-disable no-mixed-operators */ /* eslint-disable no-mixed-operators */
...@@ -51,9 +55,16 @@ export function initEntryPage () { ...@@ -51,9 +55,16 @@ export function initEntryPage () {
const weexPlus = weex.requireModule('plus') const weexPlus = weex.requireModule('plus')
if (weexPlus.getRedirectInfo) { if (weexPlus.getRedirectInfo) {
const info = weexPlus.getRedirectInfo() || {} const {
entryPagePath = info.path path,
entryPageQuery = info.query ? ('?' + info.query) : '' query,
referrerInfo
} = parseRedirectInfo()
if (path) {
entryPagePath = path
entryPageQuery = query
}
__uniConfig.referrerInfo = referrerInfo
} else { } else {
const argsJsonStr = plus.runtime.arguments const argsJsonStr = plus.runtime.arguments
if (!argsJsonStr) { if (!argsJsonStr) {
......
import {
parseQuery
} from 'uni-shared'
const extend = Object.assign
function createLaunchOptions () {
return {
path: '',
query: {},
scene: 1001,
referrerInfo: {
appId: '',
extraData: {}
}
}
}
const enterOptions = createLaunchOptions()
const launchOptions = createLaunchOptions()
export function getLaunchOptions () {
return launchOptions
}
export function getEnterOptions () {
return enterOptions
}
export function initEnterOptions ({
path,
query,
referrerInfo
}) {
extend(enterOptions, {
path,
query: query ? parseQuery(query) : {},
referrerInfo: referrerInfo || {}
})
}
export function initLaunchOptions ({
path,
query,
referrerInfo
}) {
extend(launchOptions, {
path,
query: query ? parseQuery(query) : {},
referrerInfo: referrerInfo || {}
})
extend(enterOptions, launchOptions)
return launchOptions
}
export function parseRedirectInfo () {
const weexPlus = weex.requireModule('plus')
if (weexPlus.getRedirectInfo) {
const {
path,
query,
extraData,
userAction,
fromAppid
} =
weexPlus.getRedirectInfo() || {}
const referrerInfo = {
appId: fromAppid,
extraData: {}
}
if (extraData) {
referrerInfo.extraData = extraData
}
return {
path: path || '',
query: query ? '?' + query : '',
referrerInfo,
userAction
}
}
}
...@@ -19,12 +19,44 @@ export function onWebviewPopGesture (webview) { ...@@ -19,12 +19,44 @@ export function onWebviewPopGesture (webview) {
const pages = getCurrentPages() const pages = getCurrentPages()
const page = pages[pages.length - 1] const page = pages[pages.length - 1]
page && page.$remove() page && page.$remove()
setStatusBarStyle() setStatusBarStyle()
if (page && isDirectPage(page)) {
reLaunchEntryPage()
} else {
UniServiceJSBridge.emit('onAppRoute', { UniServiceJSBridge.emit('onAppRoute', {
type: 'navigateBack' type: 'navigateBack'
}) })
} }
}
}) })
} }
/**
* 是否处于直达页面
* @param page
* @returns
*/
function isDirectPage (page) {
return (
__uniConfig.realEntryPagePath &&
page.$page.route === __uniConfig.entryPagePath
)
}
/**
* 重新启动到首页
*/
function reLaunchEntryPage () {
__uniConfig.entryPagePath = __uniConfig.realEntryPagePath
delete __uniConfig.realEntryPagePath
uni.reLaunch({
url: addLeadingSlash(__uniConfig.entryPagePath)
})
}
function hasLeadingSlash (str) {
return str.indexOf('/') === 0
}
function addLeadingSlash (str) {
return hasLeadingSlash(str) ? str : '/' + str
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册