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

feat(app): add referrerInfo

上级 bf33a6c7
...@@ -244,8 +244,9 @@ const third = [ ...@@ -244,8 +244,9 @@ const third = [
'sendNativeEvent', 'sendNativeEvent',
'preloadPage', 'preloadPage',
'unPreloadPage', 'unPreloadPage',
'loadSubPackage', 'loadSubPackage',
'sendHostEvent' 'sendHostEvent',
'navigateToMiniProgram'
] ]
const ad = [ const ad = [
...@@ -272,4 +273,4 @@ const apis = [ ...@@ -272,4 +273,4 @@ const apis = [
...ad ...ad
] ]
module.exports = apis module.exports = apis
...@@ -255,8 +255,9 @@ var serviceContext = (function () { ...@@ -255,8 +255,9 @@ var serviceContext = (function () {
'sendNativeEvent', 'sendNativeEvent',
'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 = {};
en,
es, {
fr, Object.assign(messages, {
'zh-Hans': zhHans, en,
'zh-Hant': zhHant es,
}; fr,
'zh-Hans': zhHans,
'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,31 +9230,64 @@ var serviceContext = (function () { ...@@ -9225,31 +9230,64 @@ 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') {
// 设置下一个页面的 statusBarStyle // 设置下一个页面的 statusBarStyle
const pages = getCurrentPages(); const pages = getCurrentPages();
const page = pages[pages.length - 2]; const page = pages[pages.length - 2];
popStartStatusBarStyle = lastStatusBarStyle; popStartStatusBarStyle = lastStatusBarStyle;
const statusBarStyle = page && page.$page.meta.statusBarStyle; const statusBarStyle = page && page.$page.meta.statusBarStyle;
statusBarStyle && setStatusBarStyle(statusBarStyle); statusBarStyle && setStatusBarStyle(statusBarStyle);
} else if (e.type === 'end' && !e.result) { } else if (e.type === 'end' && !e.result) {
// 拖拽未完成,设置为当前状态栏前景色 // 拖拽未完成,设置为当前状态栏前景色
setStatusBarStyle(popStartStatusBarStyle); setStatusBarStyle(popStartStatusBarStyle);
} else if (e.type === 'end' && e.result) { } else if (e.type === 'end' && e.result) {
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)) {
UniServiceJSBridge.emit('onAppRoute', { reLaunchEntryPage();
type: 'navigateBack' } else {
}); UniServiceJSBridge.emit('onAppRoute', {
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;
...@@ -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) {
...@@ -90,4 +101,4 @@ export function initEntryPage () { ...@@ -90,4 +101,4 @@ export function initEntryPage () {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
console.log(`[uni-app] entryPagePath(${entryPagePath + entryPageQuery})`) console.log(`[uni-app] entryPagePath(${entryPagePath + entryPageQuery})`)
} }
} }
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
}
}
}
import { import {
lastStatusBarStyle, lastStatusBarStyle,
setStatusBarStyle setStatusBarStyle
} from '../../bridge' } from '../../bridge'
export function onWebviewPopGesture (webview) { export function onWebviewPopGesture (webview) {
let popStartStatusBarStyle let popStartStatusBarStyle
webview.addEventListener('popGesture', e => { webview.addEventListener('popGesture', e => {
if (e.type === 'start') { if (e.type === 'start') {
// 设置下一个页面的 statusBarStyle // 设置下一个页面的 statusBarStyle
const pages = getCurrentPages() const pages = getCurrentPages()
const page = pages[pages.length - 2] const page = pages[pages.length - 2]
popStartStatusBarStyle = lastStatusBarStyle popStartStatusBarStyle = lastStatusBarStyle
const statusBarStyle = page && page.$page.meta.statusBarStyle const statusBarStyle = page && page.$page.meta.statusBarStyle
statusBarStyle && setStatusBarStyle(statusBarStyle) statusBarStyle && setStatusBarStyle(statusBarStyle)
} else if (e.type === 'end' && !e.result) { } else if (e.type === 'end' && !e.result) {
// 拖拽未完成,设置为当前状态栏前景色 // 拖拽未完成,设置为当前状态栏前景色
setStatusBarStyle(popStartStatusBarStyle) setStatusBarStyle(popStartStatusBarStyle)
} else if (e.type === 'end' && e.result) { } else if (e.type === 'end' && e.result) {
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)) {
UniServiceJSBridge.emit('onAppRoute', { reLaunchEntryPage()
type: 'navigateBack' } else {
}) UniServiceJSBridge.emit('onAppRoute', {
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.
先完成此消息的编辑!
想要评论请 注册