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

feat(mp-360): init

上级 4251ebf7
......@@ -3,3 +3,5 @@ src/platforms/app-plus-nvue/runtime
build/rollup-plugin-require-context
packages/*/packages
packages/*/template/**/*
qh-api.js
touch-emulator.js
......@@ -20,8 +20,8 @@
"build:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin rollup -c build/rollup.config.mp.js",
"build:mp-baidu": "cross-env UNI_PLATFORM=mp-baidu rollup -c build/rollup.config.mp.js",
"build:mp-alipay": "cross-env UNI_PLATFORM=mp-alipay rollup -c build/rollup.config.mp.js",
"build:mp-toutiao": "cross-env UNI_PLATFORM=mp-toutiao rollup -c build/rollup.config.mp.js",
"build:mp-weixin:mp": "npm run lint && cross-env UNI_PLATFORM=mp-weixin UNI_MP=true rollup -c build/rollup.config.mp.js",
"build:mp-toutiao": "cross-env UNI_PLATFORM=mp-toutiao rollup -c build/rollup.config.mp.js",
"build:mp-weixin:mp": "npm run lint && cross-env UNI_PLATFORM=mp-weixin UNI_MP=true rollup -c build/rollup.config.mp.js",
"build:mp-weixin:wxs": "rollup -c build/rollup.config.wxs.js",
"build:runtime": "npm run lint && npm run build:mp-weixin && npm run build:mp-qq && npm run build:mp-alipay && npm run build:mp-baidu && npm run build:mp-toutiao && npm run build:app-plus",
"build:stat": "npm run lint && rollup -c build/rollup.config.stat.js",
......@@ -30,7 +30,7 @@
"test:unit": "cross-env NODE_ENV=test UNI_PLATFORM=h5 mocha-webpack --require tests/unit/setup.js --webpack-config build/webpack.config.test.js tests/unit/**/*.spec.js",
"release": "npm run lint:cli && lerna publish --force-publish=*",
"release:alpha": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=alpha",
"release:next": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=next",
"release:next": "npm run lint:cli && lerna publish --force-publish=* --npm-tag=next",
"release:v3": "npm run lint:cli && lerna publish --no-git-tag-version --force-publish=* --npm-tag=v3"
},
"dependencies": {
......@@ -105,6 +105,7 @@
"my": true,
"swan": true,
"tt": true,
"qh": true,
"weex": true,
"__id__": true,
"__uniConfig": true,
......
......@@ -50,7 +50,11 @@ function getH5Options (manifestJson) {
h5.title = h5.title || manifestJson.name || ''
h5.router = Object.assign({}, defaultRouter, h5.router || {})
if (process.env.UNI_SUB_PLATFORM === 'mp-360') { // 360 小程序仅支持 hash 模式
h5.router = Object.assign({}, defaultRouter)
} else {
h5.router = Object.assign({}, defaultRouter, h5.router || {})
}
h5['async'] = Object.assign({}, defaultAsync, h5['async'] || {})
......@@ -59,7 +63,6 @@ function getH5Options (manifestJson) {
if (base.indexOf('/') !== 0) {
base = '/' + base
}
if (base.substr(-1) !== '/') {
base = base + '/'
}
......@@ -74,6 +77,11 @@ function getH5Options (manifestJson) {
}
} else { // 其他模式,启用 base
h5.publicPath = base
}
if (process.env.UNI_SUB_PLATFORM === 'mp-360') {
h5.router.base = '/'
h5.publicPath = '/'
}
/* eslint-disable no-mixed-operators */
......
......@@ -340,6 +340,10 @@ const PLATFORMS = {
}
}
// 解决 vue-cli-service lint 时 UNI_PLATFORM 不存在
if (process.env.UNI_PLATFORM === 'mp-360') {
process.env.UNI_PLATFORM = 'h5'
process.env.UNI_SUB_PLATFORM = 'mp-360'
}
process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5'
const platform = PLATFORMS[process.env.UNI_PLATFORM]
......@@ -375,6 +379,14 @@ if (process.env.UNI_PLATFORM.indexOf('app-') === 0) {
preprocessContext['APP'] = true
}
preprocessContext['MP-360'] = false
preprocessContext['MP_360'] = false
if (process.env.UNI_SUB_PLATFORM === 'mp-360') {
preprocessContext['H5'] = false
preprocessContext['MP-360'] = true
preprocessContext['MP_360'] = true
}
if (process.UNI_SCRIPT_DEFINE && Object.keys(process.UNI_SCRIPT_DEFINE).length) {
Object.keys(process.UNI_SCRIPT_DEFINE).forEach(name => {
preprocessContext[name] = process.UNI_SCRIPT_DEFINE[name]
......@@ -566,7 +578,7 @@ module.exports = {
orderedValues: false,
mergeLonghand: false,
mergeRules: false,
cssDeclarationSorter: false,
cssDeclarationSorter: false,
uniqueSelectors: false, // 标签排序影响头条小程序
discardComments: false,
discardDuplicates: false // 条件编译会导致重复
......
此差异已折叠。
......@@ -289,6 +289,14 @@
"/core/helpers/protocol/media/preview-image.js",
"previewImage"
],
[
"/core/view/components/swiper/index.vue",
"Swiper"
],
[
"/core/view/components/swiper-item/index.vue",
"SwiperItem"
],
[
"/platforms/h5/components/system-routes/preview-image/index.vue",
"PreviewImage"
......
......@@ -12,7 +12,7 @@ module.exports = {
warn
}) {
if (process.env.UNI_PLATFORM === 'app-plus' && el.tag === 'ad') {
warn("app-vue平台, <ad> 组件暂不支持非 V3 编译, 详见: https://ask.dcloud.net.cn/article/36599")
warn('app-vue平台, <ad> 组件暂不支持非 V3 编译, 详见: https://ask.dcloud.net.cn/article/36599')
}
if (el.tag === 'slot' && !el.attrsMap['name']) {
el.attrsList.push({
......
......@@ -104,7 +104,7 @@ async function build (args, api, options) {
log()
if (!runByHBuilderX && !runByAliIde) {
logWithSpinner(`开始编译当前项目至 ${process.env.UNI_PLATFORM} 平台...`)
logWithSpinner(`开始编译当前项目至 ${process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM} 平台...`)
}
const targetDir = api.resolve(options.outputDir)
......
......@@ -14,13 +14,15 @@ module.exports = (api, options, rootOptions) => {
'dev:mp-weixin': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch',
'dev:mp-baidu': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-baidu vue-cli-service uni-build --watch',
'dev:mp-alipay': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-alipay vue-cli-service uni-build --watch',
'dev:mp-toutiao': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-toutiao vue-cli-service uni-build --watch',
'dev:mp-toutiao': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-toutiao vue-cli-service uni-build --watch',
'dev:mp-360': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-360 vue-cli-service uni-build --watch',
'build:h5': 'cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build',
'build:mp-qq': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-qq vue-cli-service uni-build',
'build:mp-weixin': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build',
'build:mp-baidu': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-baidu vue-cli-service uni-build',
'build:mp-alipay': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-alipay vue-cli-service uni-build',
'build:mp-toutiao': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-toutiao vue-cli-service uni-build',
'build:mp-toutiao': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-toutiao vue-cli-service uni-build',
'build:mp-360': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-360 vue-cli-service uni-build',
'dev:custom': 'cross-env NODE_ENV=development uniapp-cli custom',
'build:custom': 'cross-env NODE_ENV=production uniapp-cli custom'
},
......
......@@ -3,6 +3,11 @@ const path = require('path')
const mkdirp = require('mkdirp')
const loaderUtils = require('loader-utils')
if (process.env.UNI_PLATFORM === 'mp-360') {
process.env.UNI_PLATFORM = 'h5'
process.env.UNI_SUB_PLATFORM = 'mp-360'
}
// 初始化环境变量
const defaultInputDir = '../../../../src'
const defaultOutputDir = '../../../../dist/' +
......@@ -21,6 +26,11 @@ process.env.VUE_APP_PLATFORM = process.env.UNI_PLATFORM
process.env.UNI_INPUT_DIR = process.env.UNI_INPUT_DIR || path.resolve(__dirname, defaultInputDir)
process.env.UNI_OUTPUT_DIR = process.env.UNI_OUTPUT_DIR || path.resolve(__dirname, defaultOutputDir)
if (process.env.UNI_SUB_PLATFORM === 'mp-360') {
const outputDir = process.env.UNI_OUTPUT_DIR
process.env.UNI_OUTPUT_DIR = path.resolve(outputDir.substr(0, outputDir.lastIndexOf('h5')), 'mp-360/dist')
}
if (process.env.UNI_PLATFORM === 'app-plus') {
process.env.UNI_OUTPUT_TMP_DIR = path.resolve(process.env.UNI_OUTPUT_DIR, '../.tmp/app-plus')
}
......
......@@ -102,13 +102,23 @@ module.exports = {
const beforeCode = (useBuiltIns === 'entry' ? `import '@babel/polyfill';` : '') +
`import 'uni-pages';import 'uni-${process.env.UNI_PLATFORM}';`
const qihooCode = process.env.UNI_SUB_PLATFORM === 'mp-360'
? `
import 'uni-touch-emulator';
import qh from 'uni-qh';
global.qh = qh;
global.onAppShow = function(){};
` : ''
return {
devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
resolve: {
extensions: ['.nvue'],
alias: {
'vue-router': resolve('packages/h5-vue-router'),
'uni-h5': require.resolve('@dcloudio/uni-h5')
'uni-h5': require.resolve('@dcloudio/uni-h5'),
'uni-qh': path.resolve(__dirname, 'qh-api.js'),
'uni-touch-emulator': path.resolve(__dirname, 'touch-emulator.js')
}
},
module: {
......@@ -118,7 +128,7 @@ module.exports = {
loader: 'wrap-loader',
options: {
before: [
beforeCode + statCode + getGlobalUsingComponentsCode()
qihooCode + beforeCode + statCode + getGlobalUsingComponentsCode()
]
}
}]
......
此差异已折叠。
(function (window, document, exportName, undefined) {
'use strict'
var isMultiTouch = false
var multiTouchStartPos
var eventTarget
var touchElements = {}
// polyfills
if (!document.createTouch) {
document.createTouch = function (view, target, identifier, pageX, pageY, screenX, screenY, clientX, clientY) {
// auto set
if (clientX == undefined || clientY == undefined) {
clientX = pageX - window.pageXOffset
clientY = pageY - window.pageYOffset
}
return new Touch(target, identifier, {
pageX: pageX,
pageY: pageY,
screenX: screenX,
screenY: screenY,
clientX: clientX,
clientY: clientY
})
}
}
if (!document.createTouchList) {
document.createTouchList = function () {
var touchList = new TouchList()
for (var i = 0; i < arguments.length; i++) {
touchList[i] = arguments[i]
}
touchList.length = arguments.length
return touchList
}
}
/**
* create an touch point
* @constructor
* @param target
* @param identifier
* @param pos
* @param deltaX
* @param deltaY
* @returns {Object} touchPoint
*/
function Touch (target, identifier, pos, deltaX, deltaY) {
deltaX = deltaX || 0
deltaY = deltaY || 0
this.identifier = identifier
this.target = target
this.clientX = pos.clientX + deltaX
this.clientY = pos.clientY + deltaY
this.screenX = pos.screenX + deltaX
this.screenY = pos.screenY + deltaY
this.pageX = pos.pageX + deltaX
this.pageY = pos.pageY + deltaY
}
/**
* create empty touchlist with the methods
* @constructor
* @returns touchList
*/
function TouchList () {
var touchList = []
touchList.item = function (index) {
return this[index] || null
}
// specified by Mozilla
touchList.identifiedTouch = function (id) {
return this[id + 1] || null
}
return touchList
}
/**
* Simple trick to fake touch event support
* this is enough for most libraries like Modernizr and Hammer
*/
function fakeTouchSupport () {
var objs = [window, document.documentElement]
var props = ['ontouchstart', 'ontouchmove', 'ontouchcancel', 'ontouchend']
for (var o = 0; o < objs.length; o++) {
for (var p = 0; p < props.length; p++) {
if (objs[o] && objs[o][props[p]] == undefined) {
objs[o][props[p]] = null
}
}
}
}
/**
* we don't have to emulate on a touch device
* @returns {boolean}
*/
function hasTouchSupport () {
return ('ontouchstart' in window) || // touch events
(window.Modernizr && window.Modernizr.touch) || // modernizr
(navigator.msMaxTouchPoints || navigator.maxTouchPoints) > 2 // pointer events
}
/**
* disable mouseevents on the page
* @param ev
*/
function preventMouseEvents (ev) {
ev.preventDefault()
ev.stopPropagation()
}
/**
* only trigger touches when the left mousebutton has been pressed
* @param touchType
* @returns {Function}
*/
function onMouse (touchType) {
return function (ev) {
// prevent mouse events
// 过滤 输入框 和 可编辑元素
// preventMouseEvents(ev);
ev.stopPropagation()
var computedStyle
var target = ev.target
if (target.tagName !== 'INPUT' && target.tagName !== 'TEXTAREA' && (computedStyle = window.getComputedStyle(target)) && (computedStyle['user-modify'] || computedStyle['-webkit-user-modify']).indexOf('write') < 0) {
ev.preventDefault()
}
if (ev.which !== 1) {
return
}
// The EventTarget on which the touch point started when it was first placed on the surface,
// even if the touch point has since moved outside the interactive area of that element.
// also, when the target doesnt exist anymore, we update it
if (ev.type == 'mousedown' || !eventTarget || (eventTarget && !eventTarget.dispatchEvent)) {
eventTarget = ev.target
}
// shiftKey has been lost, so trigger a touchend
if (isMultiTouch && !ev.shiftKey) {
triggerTouch('touchend', ev)
isMultiTouch = false
}
triggerTouch(touchType, ev)
// we're entering the multi-touch mode!
if (!isMultiTouch && ev.shiftKey) {
isMultiTouch = true
multiTouchStartPos = {
pageX: ev.pageX,
pageY: ev.pageY,
clientX: ev.clientX,
clientY: ev.clientY,
screenX: ev.screenX,
screenY: ev.screenY
}
triggerTouch('touchstart', ev)
}
// reset
if (ev.type == 'mouseup') {
multiTouchStartPos = null
isMultiTouch = false
eventTarget = null
}
}
}
/**
* trigger a touch event
* @param eventName
* @param mouseEv
*/
function triggerTouch (eventName, mouseEv) {
var touchEvent = document.createEvent('Event')
touchEvent.initEvent(eventName, true, true)
touchEvent.altKey = mouseEv.altKey
touchEvent.ctrlKey = mouseEv.ctrlKey
touchEvent.metaKey = mouseEv.metaKey
touchEvent.shiftKey = mouseEv.shiftKey
touchEvent.touches = getActiveTouches(mouseEv, eventName)
touchEvent.targetTouches = getActiveTouches(mouseEv, eventName)
touchEvent.changedTouches = getChangedTouches(mouseEv, eventName)
eventTarget.dispatchEvent(touchEvent)
}
/**
* create a touchList based on the mouse event
* @param mouseEv
* @returns {TouchList}
*/
function createTouchList (mouseEv) {
var touchList = new TouchList()
if (isMultiTouch) {
var f = TouchEmulator.multiTouchOffset
var deltaX = multiTouchStartPos.pageX - mouseEv.pageX
var deltaY = multiTouchStartPos.pageY - mouseEv.pageY
touchList.push(new Touch(eventTarget, 1, multiTouchStartPos, (deltaX * -1) - f, (deltaY * -1) + f))
touchList.push(new Touch(eventTarget, 2, multiTouchStartPos, deltaX + f, deltaY - f))
} else {
touchList.push(new Touch(eventTarget, 1, mouseEv, 0, 0))
}
return touchList
}
/**
* receive all active touches
* @param mouseEv
* @returns {TouchList}
*/
function getActiveTouches (mouseEv, eventName) {
// empty list
if (mouseEv.type == 'mouseup') {
return new TouchList()
}
var touchList = createTouchList(mouseEv)
if (isMultiTouch && mouseEv.type != 'mouseup' && eventName == 'touchend') {
touchList.splice(1, 1)
}
return touchList
}
/**
* receive a filtered set of touches with only the changed pointers
* @param mouseEv
* @param eventName
* @returns {TouchList}
*/
function getChangedTouches (mouseEv, eventName) {
var touchList = createTouchList(mouseEv)
// we only want to return the added/removed item on multitouch
// which is the second pointer, so remove the first pointer from the touchList
//
// but when the mouseEv.type is mouseup, we want to send all touches because then
// no new input will be possible
if (isMultiTouch && mouseEv.type != 'mouseup' &&
(eventName == 'touchstart' || eventName == 'touchend')) {
touchList.splice(0, 1)
}
return touchList
}
/**
* show the touchpoints on the screen
*/
function showTouches (ev) {
var touch, i, el, styles
// first all visible touches
for (i = 0; i < ev.touches.length; i++) {
touch = ev.touches[i]
el = touchElements[touch.identifier]
if (!el) {
el = touchElements[touch.identifier] = document.createElement('div')
document.body.appendChild(el)
}
styles = TouchEmulator.template(touch)
for (var prop in styles) {
el.style[prop] = styles[prop]
}
}
// remove all ended touches
if (ev.type == 'touchend' || ev.type == 'touchcancel') {
for (i = 0; i < ev.changedTouches.length; i++) {
touch = ev.changedTouches[i]
el = touchElements[touch.identifier]
if (el) {
el.parentNode.removeChild(el)
delete touchElements[touch.identifier]
}
}
}
}
/**
* TouchEmulator initializer
*/
function TouchEmulator () {
if (hasTouchSupport()) {
return
}
fakeTouchSupport()
window.addEventListener('mousedown', onMouse('touchstart'), true)
window.addEventListener('mousemove', onMouse('touchmove'), true)
window.addEventListener('mouseup', onMouse('touchend'), true)
window.addEventListener('mouseenter', preventMouseEvents, true)
window.addEventListener('mouseleave', preventMouseEvents, true)
window.addEventListener('mouseout', preventMouseEvents, true)
window.addEventListener('mouseover', preventMouseEvents, true)
// it uses itself!
// 关闭触摸显示
// window.addEventListener("touchstart", showTouches, false);
// window.addEventListener("touchmove", showTouches, false);
// window.addEventListener("touchend", showTouches, false);
// window.addEventListener("touchcancel", showTouches, false);
}
// start distance when entering the multitouch mode
TouchEmulator.multiTouchOffset = 75
/**
* css template for the touch rendering
* @param touch
* @returns object
*/
TouchEmulator.template = function (touch) {
var size = 30
var transform = 'translate(' + (touch.clientX - (size / 2)) + 'px, ' + (touch.clientY - (size / 2)) + 'px)'
return {
position: 'fixed',
left: 0,
top: 0,
background: '#fff',
border: 'solid 1px #999',
opacity: 0.6,
borderRadius: '100%',
height: size + 'px',
width: size + 'px',
padding: 0,
margin: 0,
display: 'block',
overflow: 'hidden',
pointerEvents: 'none',
webkitUserSelect: 'none',
mozUserSelect: 'none',
userSelect: 'none',
webkitTransform: transform,
mozTransform: transform,
transform: transform
}
}
// export
// 直接启用
// if (typeof define == "function" && define.amd) {
// define(function() {
// return TouchEmulator;
// });
// } else if (typeof module != "undefined" && module.exports) {
// module.exports = TouchEmulator;
// } else {
// window[exportName] = TouchEmulator;
// }
TouchEmulator()
})(window, document, 'TouchEmulator')
......@@ -5,7 +5,8 @@ const {
getPlatforms,
getH5Options,
getFlexDirection,
getNetworkTimeout
getNetworkTimeout,
normalizePath
} = require('@dcloudio/uni-cli-shared')
const {
......@@ -14,9 +15,6 @@ const {
const PLATFORMS = getPlatforms()
const isWin = /^win/.test(process.platform)
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
const removePlatformStyle = function (style) {
Object.keys(style).forEach(name => {
if (PLATFORMS.includes(name)) {
......@@ -60,11 +58,21 @@ const getPageComponents = function (inputDir, pagesJson) {
pagesJson.tabBar.borderStyle = pagesJson.tabBar.borderStyle || 'black'
}
const globalStyle = pagesJson.globalStyle || {}
const globalStyle = Object.assign({}, pagesJson.globalStyle || {})
Object.assign(
globalStyle,
globalStyle['app-plus'] || {},
globalStyle['h5'] || {}
)
if (process.env.UNI_SUB_PLATFORM === 'mp-360') {
Object.assign(globalStyle, globalStyle['mp-360'] || {})
}
process.UNI_H5_PAGES_JSON = {
pages: {},
globalStyle: Object.assign({}, globalStyle, globalStyle['app-plus'] || {}, globalStyle['h5'] || {})
globalStyle
}
removePlatformStyle(process.UNI_H5_PAGES_JSON.globalStyle)
......@@ -86,6 +94,10 @@ const getPageComponents = function (inputDir, pagesJson) {
// 解析 titleNView,pullToRefresh
const h5Options = Object.assign({}, props['app-plus'] || {}, props['h5'] || {})
if (process.env.UNI_SUB_PLATFORM === 'mp-360') {
Object.assign(h5Options, props['mp-360'] || {})
Object.assign(props, props['mp-360'] || {})
}
removePlatformStyle(h5Options)
if (h5Options.hasOwnProperty('titleNView')) {
......@@ -118,6 +130,7 @@ const getPageComponents = function (inputDir, pagesJson) {
// 删除 app-plus 平台配置
delete props['app-plus']
delete props['h5']
delete props['mp-360']
process.UNI_H5_PAGES_JSON.pages[page.path] = props
......@@ -348,4 +361,4 @@ global.__uniConfig.nvue = ${JSON.stringify({ 'flex-direction': getFlexDirection(
${genRegisterPageVueComponentsCode(pageComponents)}
global.__uniRoutes=[${genPageRoutes(pageComponents).concat(genSystemRoutes()).join(',')}]
`
}
}
......@@ -35,8 +35,8 @@ export class MapContext {
}
}
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) {
......
......@@ -144,14 +144,14 @@ function beforeEach (to, from, next, routes) {
/* eslint-disable no-undef */
if (__PLATFORM__ === 'h5') {
if (to.meta && to.meta.name) {
document.body.className = 'uni-body ' + to.meta.name
const nvueDirKey = 'nvue-dir-' + __uniConfig.nvue['flex-direction']
if (to.meta.isNVue) {
document.body.setAttribute('nvue', '')
document.body.setAttribute(nvueDirKey, '')
} else {
document.body.removeAttribute('nvue')
document.body.removeAttribute(nvueDirKey)
document.body.className = 'uni-body ' + to.meta.name
const nvueDirKey = 'nvue-dir-' + __uniConfig.nvue['flex-direction']
if (to.meta.isNVue) {
document.body.setAttribute('nvue', '')
document.body.setAttribute(nvueDirKey, '')
} else {
document.body.removeAttribute('nvue')
document.body.removeAttribute(nvueDirKey)
}
}
}
......@@ -199,9 +199,23 @@ function afterEach (to, from) {
if (to.type !== 'reLaunch') { // 因为 reLaunch 会重置 id,故不触发 onShow,switchTab 在 beforeRouteEnter 中触发
// 直接获取所有 pages,getCurrentPages 正常情况下仅返回页面栈内,传 true 则返回所有已存在(主要是 tabBar 页面)
const toVm = getCurrentPages(true).find(pageVm => pageVm.$page.id === toId) // 使用最新的 pages
if (toVm) { // 目标页面若已存在,则触发 onShow
if (toVm) { // 目标页面若已存在,则触发 onShow
// 延迟执行 onShow,防止与 UniServiceJSBridge.emit('onHidePopup') 冲突。
setTimeout(function () {
setTimeout(function () {
if (__PLATFORM__ === 'h5') {
const navigationBar = toVm.$parent.$parent.navigationBar
if (typeof qh !== 'undefined') {
qh.setNavigationBarTitle({
title: document.title
})
qh.setNavigationBarColor({
backgroundColor: navigationBar.backgroundColor
})
qh.setNavigationBarTextStyle({
textStyle: navigationBar.textColor === '#000' ? 'black' : 'white'
})
}
}
callPageHook(toVm, 'onShow')
}, 0)
if (__PLATFORM__ === 'h5') {
......@@ -219,4 +233,4 @@ export default function initRouterGuard (appVm, routes) {
appVm.$router.afterEach(function (to, from) {
afterEach.call(appVm, to, from)
})
}
}
......@@ -3,19 +3,17 @@
<page-head
v-if="navigationBar.type!=='none'"
v-bind="navigationBar" />
<page-refresh
v-if="enablePullDownRefresh"
ref="refresh"
:color="refreshOptions.color"
:offset="refreshOptions.offset"
/>
<page-body
v-if="enablePullDownRefresh"
@touchstart.native="_touchstart"
<page-refresh
v-if="enablePullDownRefresh"
ref="refresh"
:color="refreshOptions.color"
:offset="refreshOptions.offset" />
<page-body
v-if="enablePullDownRefresh"
@touchstart.native="_touchstart"
@touchmove.native="_touchmove"
@touchend.native="_touchend"
@touchcancel.native="_touchend"
>
@touchend.native="_touchend"
@touchcancel.native="_touchend">
<slot name="page" />
</page-body>
<page-body v-else>
......@@ -24,11 +22,11 @@
</uni-page>
</template>
<style>
uni-page {
display: block;
width: 100%;
height: 100%;
}
uni-page {
display: block;
width: 100%;
height: 100%;
}
</style>
<script>
import {
......@@ -210,8 +208,20 @@ export default {
},
created () {
if (__PLATFORM__ === 'h5') {
document.title = this.navigationBar.titleText
const navigationBar = this.navigationBar
document.title = navigationBar.titleText
if (typeof qh !== 'undefined') {
qh.setNavigationBarTitle({
title: document.title
})
qh.setNavigationBarColor({
backgroundColor: navigationBar.backgroundColor
})
qh.setNavigationBarTextStyle({
textStyle: navigationBar.textColor === '#000' ? 'black' : 'white'
})
}
}
}
}
</script>
</script>
......@@ -34,6 +34,11 @@ export default {
created () {
if (__PLATFORM__ === 'h5') {
document.title = this.$slots.default[0].text
if (typeof qh !== 'undefined') {
qh.setNavigationBarTitle({
title: document.title
})
}
}
},
methods: {
......
......@@ -9,18 +9,32 @@ function setNavigationBar (type, args) {
frontColor,
backgroundColor,
animation
} = args
const {
duration,
timingFunc
} = args
const {
duration,
timingFunc
} = animation
if (frontColor) {
page.navigationBar.textColor = frontColor === '#000000' ? 'black' : 'white'
if (__PLATFORM__ === 'h5') {
if (typeof qh !== 'undefined') {
qh.setNavigationBarTextStyle({
textStyle: page.navigationBar.textColor
})
}
}
}
if (backgroundColor) {
page.navigationBar.backgroundColor = backgroundColor
if (__PLATFORM__ === 'h5') {
if (typeof qh !== 'undefined') {
qh.setNavigationBarColor({
backgroundColor
})
}
}
}
page.navigationBar.duration = duration + 'ms'
page.navigationBar.timingFunc = timingFunc
......@@ -38,12 +52,17 @@ function setNavigationBar (type, args) {
page.navigationBar.titleText = title
if (__PLATFORM__ === 'h5') {
document.title = title
if (typeof qh !== 'undefined') {
qh.setNavigationBarTitle({
title: document.title
})
}
}
break
}
}
return {}
}
}
export function setNavigationBarColor (args) {
return setNavigationBar('setNavigationBarColor', args)
......@@ -59,4 +78,4 @@ export function hideNavigationBarLoading () {
export function setNavigationBarTitle (args) {
return setNavigationBar('setNavigationBarTitle', args)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册