提交 d9c3f76b 编写于 作者: Q qiang

Merge branch 'dev' into v3

# Conflicts:
#	packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js
#	packages/vue-cli-plugin-uni/lib/env.js
#	packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js
......@@ -13,7 +13,7 @@ const {
} = require('./manifest.js')
const {
getMainEntry,
getMainEntry,
getNVueMainEntry,
parseEntry,
parsePages,
......@@ -29,36 +29,37 @@ const {
camelize,
hyphenate,
removeExt,
normalizePath,
normalizePath,
getComponentName,
convertStaticStyle
convertStaticStyle,
getTemplatePath
} = require('./util')
const {
getFlexDirection,
getPlatformProject,
const {
getFlexDirection,
getPlatformProject,
isSupportSubPackages,
getPlatforms,
getPlatforms,
getPlatformGlobal,
getPlatformScss,
getPlatformScss,
getPlatformSass,
runByHBuilderX,
isInHBuilderX,
runByHBuilderX,
isInHBuilderX,
isInHBuilderXAlpha,
getPlatformExts,
getPlatformTarget,
getPlatformVue,
getPlatformCompiler,
getPlatformCompiler,
getShadowCss,
getPlatformCssVars,
getPlatformCssnano,
getPlatformCssVars,
getPlatformCssnano,
getShadowTemplate,
jsPreprocessOptions,
cssPreprocessOptions,
htmlPreprocessOptions,
nvueJsPreprocessOptions,
nvueJsPreprocessOptions,
nvueCssPreprocessOptions,
nvueHtmlPreprocessOptions,
nvueHtmlPreprocessOptions,
devtoolModuleFilenameTemplate
} = require('./platform')
......@@ -77,38 +78,39 @@ module.exports = {
parseEntry,
parsePages,
getH5Options,
getMainEntry,
getMainEntry,
getNVueMainEntry,
getPagesJson,
getManifestJson,
getNetworkTimeout,
runByHBuilderX,
isInHBuilderX,
isInHBuilderXAlpha,
runByHBuilderX,
isInHBuilderX,
isInHBuilderXAlpha,
isSupportSubPackages,
getPlatforms,
getPlatforms,
getFlexDirection,
getPlatformScss,
getPlatformScss,
getPlatformSass,
getPlatformExts,
getPlatformTarget,
getPlatformTarget,
getPlatformProject,
getPlatformVue,
getPlatformGlobal,
getPlatformVue,
getPlatformGlobal,
getShadowCss,
getPlatformCssVars,
getPlatformCssVars,
getPlatformCssnano,
getPlatformCompiler,
getPlatformCompiler,
getShadowTemplate,
parsePagesJson,
parseManifestJson,
parseManifestJson,
getComponentName,
convertStaticStyle,
getTemplatePath,
jsPreprocessOptions,
cssPreprocessOptions,
htmlPreprocessOptions,
nvueJsPreprocessOptions,
nvueJsPreprocessOptions,
nvueCssPreprocessOptions,
nvueHtmlPreprocessOptions,
nvueHtmlPreprocessOptions,
devtoolModuleFilenameTemplate
}
......@@ -115,5 +115,8 @@ module.exports = {
return str.replace('wx-', 'weixin-')
}
return str
})
}
}),
getTemplatePath () {
return path.join(__dirname, '../template')
}
}
......@@ -8,7 +8,8 @@ const {
getNVueMainEntry,
nvueJsPreprocessOptions,
nvueHtmlPreprocessOptions,
devtoolModuleFilenameTemplate
devtoolModuleFilenameTemplate,
getTemplatePath
} = require('@dcloudio/uni-cli-shared')
const WebpackAppPlusNVuePlugin = require('../packages/webpack-app-plus-nvue-plugin')
......@@ -37,14 +38,12 @@ const uniPath = process.env.UNI_USING_V8
const provide = {}
if (!process.env.UNI_USING_V3) { // v3 不需要
if (!process.env.UNI_USING_NATIVE) {
provide['uni'] = [path.resolve(__dirname, uniPath), 'default']
}
if (!process.env.UNI_USING_NATIVE) {
provide['uni'] = [path.resolve(__dirname, uniPath), 'default']
}
if (process.env.UNI_USING_V8) {
provide['plus'] = [path.resolve(__dirname, uniPath), 'weexPlus']
}
if (process.env.UNI_USING_V8) {
provide['plus'] = [path.resolve(__dirname, uniPath), 'weexPlus']
}
if (
......@@ -97,7 +96,7 @@ const rules = [{
babelrc: false
}
},
jsPreprocessorLoader
jsPreprocessorLoader
],
exclude (modulePath) {
return excludeModuleReg.test(modulePath) && modulePath.indexOf('@dcloudio') === -1
......@@ -163,35 +162,56 @@ rules.unshift({
if (process.env.UNI_USING_NATIVE) {
plugins.push(new WebpackUniMPPlugin())
let nativeTemplatePath = path.resolve(__dirname, '../../uni-cli-shared/template/common')
if (!fs.existsSync(nativeTemplatePath)) { // 兼容旧版本
nativeTemplatePath = path.resolve(
process.env.UNI_HBUILDERX_PLUGINS,
'weapp-tools/template/v8'
)
}
plugins.push(new CopyWebpackPlugin([{
const array = [{
from: path.resolve(process.env.UNI_INPUT_DIR, 'static'),
to: 'static'
}, {
from: nativeTemplatePath,
to: process.env.UNI_OUTPUT_DIR
}, {
from: path.resolve(
process.env.UNI_HBUILDERX_PLUGINS,
'weapp-tools/template/common'
),
to: process.env.UNI_OUTPUT_DIR,
ignore: [
'*.js',
'*.json',
'__uniapppicker.html',
'__uniappview.html'
]
}]))
}]
if (process.env.UNI_USING_NVUE_COMPILER) {
array.push({
from: path.resolve(getTemplatePath(), 'common'),
to: process.env.UNI_OUTPUT_DIR
}, {
from: path.resolve(
process.env.UNI_HBUILDERX_PLUGINS,
'weapp-tools/template/common'
),
to: process.env.UNI_OUTPUT_DIR,
ignore: [
'*.js',
'*.json',
'__uniapppicker.html',
'__uniappview.html',
'__uniappmarker@3x.png',
'__uniappopenlocation.html',
'__uniapppicker.html'
]
})
} else {
let nativeTemplatePath = path.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'weapp-tools/template/v8-native')
if (!fs.existsSync(nativeTemplatePath)) { // 兼容旧版本
nativeTemplatePath = path.resolve(
process.env.UNI_HBUILDERX_PLUGINS,
'weapp-tools/template/v8'
)
}
array.push({
from: nativeTemplatePath,
to: process.env.UNI_OUTPUT_DIR
}, {
from: path.resolve(
process.env.UNI_HBUILDERX_PLUGINS,
'weapp-tools/template/common'
),
to: process.env.UNI_OUTPUT_DIR,
ignore: [
'*.js',
'*.json',
'__uniapppicker.html',
'__uniappview.html'
]
})
}
plugins.push(new CopyWebpackPlugin(array))
}
module.exports = function () {
......@@ -295,4 +315,4 @@ module.exports = function () {
zlib: false
}
}
}
}
......@@ -600,6 +600,7 @@ var PROP_NAME_GROUPS = {
},
common: {
opacity: NUMBER_VALIDATOR,
boxShadow: ANYTHING_VALIDATOR,
backgroundColor: COLOR_VALIDATOR,
backgroundImage: ANYTHING_VALIDATOR
},
......
......@@ -70,7 +70,7 @@ process.UNI_STAT_CONFIG = {
let usingComponentsAbsent = false
if (!platformOptions.hasOwnProperty('usingComponents')) {
usingComponentsAbsent = true
}
}
platformOptions.usingComponents = true
// }
......@@ -109,8 +109,11 @@ if (process.env.UNI_PLATFORM === 'mp-qq') { // QQ小程序 强制自定义组件
platformOptions.usingComponents = true
}
let isNVueCompiler = false
let isNVueCompiler = true
if (process.env.UNI_PLATFORM === 'app-plus') {
if (platformOptions.nvueCompiler === 'weex') {
isNVueCompiler = false
}
if (platformOptions.renderer !== 'native' && // 非 native
(
platformOptions.compilerVersion === '3' ||
......@@ -119,13 +122,9 @@ if (process.env.UNI_PLATFORM === 'app-plus') {
) {
process.env.UNI_USING_V3 = true
platformOptions.usingComponents = true
process.env.UNI_OUTPUT_TMP_DIR = ''
process.env.UNI_OUTPUT_TMP_DIR = ''
isNVueCompiler = true // v3 目前仅支持 uni-app 模式
}
if (platformOptions.nvueCompiler === 'uni-app') {
isNVueCompiler = true
}
if (platformOptions.renderer === 'native') {
process.env.UNI_USING_NATIVE = true
process.env.UNI_USING_V8 = true
......@@ -134,9 +133,9 @@ if (process.env.UNI_PLATFORM === 'app-plus') {
} else { // 其他平台,待确认配置方案
if (
manifestJsonObj['app-plus'] &&
manifestJsonObj['app-plus']['nvueCompiler'] === 'uni-app'
manifestJsonObj['app-plus']['nvueCompiler'] === 'weex'
) {
isNVueCompiler = true
isNVueCompiler = false
}
}
......@@ -265,9 +264,9 @@ if (runByHBuilderX) {
}
}
}
console.log(`正在编译中...`)
console.log(`正在编译中...`)
module.exports = {
manifestPlatformOptions: platformOptions
}
}
......@@ -216,8 +216,6 @@ module.exports = function (pagesJson, userManifestJson) {
if (process.env.UNI_USING_NVUE_COMPILER) {
appJson.nvueCompiler = 'uni-app'
flexDir = getFlexDirection(manifestJson.plus)
} else {
appJson.nvueCompiler = 'weex'
}
if (manifestJson.plus.renderer === 'native') {
......@@ -485,8 +483,8 @@ module.exports = function (pagesJson, userManifestJson) {
'description': 'UniNView原生渲染'
}
// TODO 需要考虑 condition
manifestJson.plus.launchwebview.id = '1' // 首页 id 固定 为 1
// 删除首页 style 中的 uni-app 配置(不注入 app-view.js)
manifestJson.plus.launchwebview.id = '1' // 首页 id 固定 为 1
// 删除首页 style 中的 uni-app 配置(不注入 app-view.js)
delete manifestJson.plus.launchwebview['uni-app']
if (appJson.page[appJson.entryPagePath].nvue) { // 首页是 nvue
......@@ -507,4 +505,4 @@ module.exports = function (pagesJson, userManifestJson) {
return [manifest, definePages(appJson), appConfigService(appJson)]
}
return [app, manifest]
}
}
......@@ -58,6 +58,9 @@ export function pageScrollTo ({
// bodyStyle.webkitTransform = `translateY(${documentElement.scrollTop}px) translateZ(0)`
}
let testReachBottomTimer
let lastScrollHeight = 0
export function createScrollListener (pageId, {
enablePageScroll,
enablePageReachBottom,
......@@ -72,14 +75,16 @@ export function createScrollListener (pageId, {
function isReachBottom () {
const {
clientHeight,
scrollHeight
} = document.documentElement
// 部分浏览器窗口高度变化后document.documentelement.clientheight不会变化,采用window.innerHeight
const windowHeight = window.innerHeight
const scrollY = window.scrollY
let isBottom = scrollY > 0 && scrollHeight > clientHeight && (scrollY + clientHeight + onReachBottomDistance) >=
scrollHeight
if (isBottom && !hasReachBottom) {
let isBottom = scrollY > 0 && scrollHeight > windowHeight && (scrollY + windowHeight + onReachBottomDistance) >= scrollHeight
// 兼容部分浏览器滚动时scroll事件不触发
const heightChanged = Math.abs(scrollHeight - lastScrollHeight) > onReachBottomDistance
if (isBottom && (!hasReachBottom || heightChanged)) {
lastScrollHeight = scrollHeight
hasReachBottom = true
return true
}
......@@ -108,18 +113,28 @@ export function createScrollListener (pageId, {
scrollTop
})
}
if (enablePageReachBottom && onReachBottom && isReachBottom()) {
publishHandler('onReachBottom', {}, pageId)
onReachBottom = false
setTimeout(function () {
onReachBottom = true
}, 350)
function testReachBottom () {
if (isReachBottom()) {
publishHandler('onReachBottom', {}, pageId)
onReachBottom = false
setTimeout(function () {
onReachBottom = true
}, 350)
return true
}
}
if (enablePageReachBottom && onReachBottom) {
if (testReachBottom()) {
} else {
// 解决部分浏览器滚动中js获取窗口高度不准确导致的问题
testReachBottomTimer = setTimeout(testReachBottom, 300)
}
}
ticking = false
}
return function onScroll () {
clearTimeout(testReachBottomTimer)
if (!ticking) {
requestAnimationFrame(trigger)
}
......
import {
getStatusBarStyle
} from '../util'
import {
invoke
} from '../../bridge'
import {
ANI_SHOW,
ANI_DURATION
} from '../../constants'
import {
registerPlusMessage,
consumePlusMessage
} from '../../framework/plus-message'
export const SCAN_ID = '__UNIAPP_SCAN'
export const SCAN_PATH = '_www/__uniappscan.html'
const MESSAGE_TYPE = 'scanCode'
export function scanCode ({
onlyFromCamera = false,
scanType
}, callbackId) {
const barcode = plus.barcode
const SCAN_TYPES = {
'qrCode': [
barcode.QR,
barcode.AZTEC,
barcode.MAXICODE
],
'barCode': [
barcode.EAN13,
barcode.EAN8,
barcode.UPCA,
barcode.UPCE,
barcode.CODABAR,
barcode.CODE128,
barcode.CODE39,
barcode.CODE93,
barcode.ITF,
barcode.RSS14,
barcode.RSSEXPANDED
],
'datamatrix': [barcode.DATAMATRIX],
'pdf417': [barcode.PDF417]
}
const SCAN_MAPS = {
[barcode.QR]: 'QR_CODE',
[barcode.EAN13]: 'EAN_13',
[barcode.EAN8]: 'EAN_8',
[barcode.DATAMATRIX]: 'DATA_MATRIX',
[barcode.UPCA]: 'UPC_A',
[barcode.UPCE]: 'UPC_E',
[barcode.CODABAR]: 'CODABAR',
[barcode.CODE39]: 'CODE_39',
[barcode.CODE93]: 'CODE_93',
[barcode.CODE128]: 'CODE_128',
[barcode.ITF]: 'CODE_25',
[barcode.PDF417]: 'PDF_417',
[barcode.AZTEC]: 'AZTEC',
[barcode.RSS14]: 'RSS_14',
[barcode.RSSEXPANDED]: 'RSSEXPANDED'
}
const statusBarStyle = getStatusBarStyle()
const isDark = statusBarStyle !== 'light'
let result
let filters = []
if (Array.isArray(scanType) && scanType.length) {
scanType.forEach(type => { // 暂不考虑去重
const types = SCAN_TYPES[type]
if (types) {
filters = filters.concat(types)
}
})
}
if (!filters.length) {
filters = filters.concat(SCAN_TYPES['qrCode']).concat(SCAN_TYPES['barCode']).concat(SCAN_TYPES['datamatrix']).concat(
SCAN_TYPES['pdf417'])
}
const buttons = []
if (!onlyFromCamera) {
buttons.push({
float: 'right',
text: '相册',
fontSize: '17px',
width: '60px',
onclick: function () {
plus.gallery.pick(file => {
barcode.scan(file, (type, code) => {
if (isDark) {
plus.navigator.setStatusBarStyle('isDark')
}
result = {
type,
code
}
webview.close('auto')
}, () => {
plus.nativeUI.toast('识别失败')
}, filters)
}, err => {
if (err.code !== 12) {
plus.nativeUI.toast('选择失败')
}
}, {
multiple: false,
system: false
})
}
})
}
const webview = plus.webview.create(SCAN_PATH, SCAN_ID, {
titleNView: {
autoBackButton: true,
type: 'float',
backgroundColor: 'rgba(0,0,0,0)',
titleColor: '#ffffff',
titleText: '扫码',
titleSize: '17px',
buttons
},
popGesture: 'close',
backButtonAutoControl: 'close'
}, {
__uniapp_type: 'scan',
__uniapp_dark: isDark,
__uniapp_scan_type: filters,
'uni-app': 'none'
})
const waiting = plus.nativeUI.showWaiting()
webview.addEventListener('titleUpdate', () => {
webview.show(ANI_SHOW, ANI_DURATION, () => {
waiting.close()
})
})
webview.addEventListener('close', () => {
if (result) {
invoke(callbackId, {
result: result.code,
scanType: SCAN_MAPS[result.type] || '',
charSet: 'utf8',
path: '',
errMsg: 'scanCode:ok'
})
} else {
invoke(callbackId, {
errMsg: 'scanCode:fail cancel'
})
}
consumePlusMessage(MESSAGE_TYPE)
})
if (isDark) { // 状态栏前景色
plus.navigator.setStatusBarStyle('light')
webview.addEventListener('popGesture', ({
type,
result
}) => {
if (type === 'start') {
plus.navigator.setStatusBarStyle('dark')
} else if (type === 'end' && !result) {
plus.navigator.setStatusBarStyle('light')
}
})
}
registerPlusMessage(MESSAGE_TYPE, function (res) {
if (res && 'code' in res) {
result = res
}
}, false)
}
import {
invoke
} from '../../bridge'
import {
showPage
} from '../page.js'
function getStatusBarStyle () {
let style = plus.navigator.getStatusBarStyle()
if (style === 'UIStatusBarStyleBlackTranslucent' || style === 'UIStatusBarStyleBlackOpaque' || style === 'null') {
style = 'light'
} else if (style === 'UIStatusBarStyleDefault') {
style = 'dark'
}
return style
}
export function scanCode (options, callbackId) {
const statusBarStyle = getStatusBarStyle()
const isDark = statusBarStyle !== 'light'
let result
const page = showPage({
url: '__uniappscan',
data: {
scanType: options.scanType
},
style: {
animationType: options.animationType || 'pop-in',
titleNView: {
autoBackButton: true,
type: 'float',
titleText: options.titleText || '扫码',
titleColor: '#ffffff',
backgroundColor: 'rgba(0,0,0,0)',
buttons: !options.onlyFromCamera ? [{
text: options.albumText || '相册',
fontSize: '17px',
width: '60px',
onclick: () => {
page.sendMessage({
type: 'gallery'
})
}
}] : []
},
popGesture: 'close',
backButtonAutoControl: 'close'
},
onMessage ({
event,
detail
}) {
result = detail
if (event === 'marked') {
result.errMsg = 'scanCode:ok'
} else {
result.errMsg = 'scanCode:fail ' + detail.message
}
},
onClose () {
if (isDark) {
plus.navigator.setStatusBarStyle('dark')
}
invoke(callbackId, result || {
errMsg: 'scanCode:fail cancel'
})
}
})
if (isDark) {
plus.navigator.setStatusBarStyle('light')
page.webview.addEventListener('popGesture', ({
type,
result
}) => {
if (type === 'start') {
plus.navigator.setStatusBarStyle('dark')
} else if (type === 'end' && !result) {
plus.navigator.setStatusBarStyle('light')
}
})
}
}
import {
invoke
} from '../../bridge'
import * as webview from './scan-code-webview'
import * as weex from './scan-code-weex'
import {
showPage
} from '../page.js'
function getStatusBarStyle() {
let style = plus.navigator.getStatusBarStyle()
if (style === 'UIStatusBarStyleBlackTranslucent' || style === 'UIStatusBarStyleBlackOpaque' || style === 'null') {
style = 'light'
} else if (style === 'UIStatusBarStyleDefault') {
style = 'dark'
}
return style
}
export function scanCode(options, callbackId) {
const statusBarStyle = getStatusBarStyle()
const isDark = statusBarStyle !== 'light'
let result
const page = showPage({
url: '__uniappscan',
data: {
scanType: options.scanType
},
style: {
animationType: options.animationType || 'pop-in',
titleNView: {
autoBackButton: true,
type: 'float',
titleText: options.titleText || "扫码",
titleColor: '#ffffff',
backgroundColor: 'rgba(0,0,0,0)',
buttons: !options.onlyFromCamera ? [{
text: options.albumText || "相册",
fontSize: "17px",
onclick: () => {
page.sendMessage({
type: "gallery"
})
}
}] : []
},
popGesture: 'close',
backButtonAutoControl: 'close'
},
onMessage({
event,
detail
}) {
result = detail
if (event === 'marked') {
result.errMsg = 'scanCode:ok'
} else {
result.errMsg = 'scanCode:fail ' + detail.message
}
},
onClose() {
if (isDark) {
plus.navigator.setStatusBarStyle('dark')
}
invoke(callbackId, result || {
errMsg: 'scanCode:fail cancel'
})
}
})
if (isDark) {
plus.navigator.setStatusBarStyle('light')
page.webview.addEventListener('popGesture', ({
type,
result
}) => {
if (type === 'start') {
plus.navigator.setStatusBarStyle('dark')
} else if (type === 'end' && !result) {
plus.navigator.setStatusBarStyle('light')
}
})
}
export function scanCode (...array) {
const api = __uniConfig.nvueCompiler === 'uni-app' ? weex : webview
return api.scanCode(...array)
}
import {
MAP_ID
} from '../constants'
import {
invoke
} from '../../bridge'
import {
ANI_DURATION
} from '../../constants'
import {
registerPlusMessage,
consumePlusMessage
} from '../../framework/plus-message'
const CHOOSE_LOCATION_PATH = '_www/__uniappchooselocation.html'
const MESSAGE_TYPE = 'chooseLocation'
export function chooseLocation (params, callbackId) {
const statusBarStyle = plus.navigator.getStatusBarStyle()
const webview = plus.webview.create(
CHOOSE_LOCATION_PATH,
MAP_ID, {
titleNView: {
autoBackButton: true,
backgroundColor: '#000000',
titleColor: '#ffffff',
titleText: '选择位置',
titleSize: '17px',
buttons: [{
float: 'right',
text: '完成',
fontSize: '17px',
width: '60px',
onclick: function () {
webview.evalJS('__chooseLocationConfirm__()')
}
}]
},
popGesture: 'close',
scrollIndicator: 'none'
}, {
__uniapp_type: 'map',
__uniapp_statusbar_style: statusBarStyle,
'uni-app': 'none'
}
)
if (statusBarStyle === 'dark') {
plus.navigator.setStatusBarStyle('light')
webview.addEventListener('popGesture', ({
type,
result
}) => {
if (type === 'start') {
plus.navigator.setStatusBarStyle('dark')
} else if (type === 'end' && !result) {
plus.navigator.setStatusBarStyle('light')
}
})
}
let index = 0
let onShow = function () {
index++
if (index === 2) {
webview.evalJS(`__chooseLocation__(${JSON.stringify(params)})`)
}
}
webview.addEventListener('loaded', onShow)
webview.show('slide-in-bottom', ANI_DURATION, onShow)
let result
webview.addEventListener('close', () => {
if (result) {
invoke(callbackId, {
name: result.poiname,
address: result.poiaddress,
latitude: result.latlng.lat,
longitude: result.latlng.lng,
errMsg: 'chooseLocation:ok'
})
} else {
consumePlusMessage(MESSAGE_TYPE)
invoke(callbackId, {
errMsg: 'chooseLocation:fail cancel'
})
}
})
registerPlusMessage(MESSAGE_TYPE, function (res) {
if (res && 'latlng' in res) {
result = res
}
}, false)
}
import {
invoke
} from '../../bridge'
import {
showPage
} from '../page.js'
function getStatusBarStyle () {
let style = plus.navigator.getStatusBarStyle()
if (style === 'UIStatusBarStyleBlackTranslucent' || style === 'UIStatusBarStyleBlackOpaque' || style === 'null') {
style = 'light'
} else if (style === 'UIStatusBarStyleDefault') {
style = 'dark'
}
return style
}
export function chooseLocation (options, callbackId) {
const statusBarStyle = getStatusBarStyle()
const isDark = statusBarStyle !== 'light'
let result
const page = showPage({
url: '__uniappchooselocation',
data: {
keyword: options.keyword
},
style: {
animationType: options.animationType || 'slide-in-bottom',
titleNView: {
autoBackButton: false,
titleText: options.titleText || '选择位置',
titleColor: '#ffffff',
backgroundColor: 'rgba(0,0,0,1)',
buttons: [{
// text: options.cancelText || "取消",
// fontSize: "17px",
type: 'close',
float: 'left',
onclick: () => {
page.close()
}
}, {
text: options.doneText || '完成',
fontSize: '17px',
width: '60px',
onclick: () => {
page.sendMessage({
type: 'done'
})
}
}]
},
popGesture: 'close',
scrollIndicator: 'none'
},
onMessage ({
event,
detail
}) {
if (event === 'selected') {
result = detail
result.errMsg = 'chooseLocation:ok'
}
},
onClose () {
if (isDark) {
plus.navigator.setStatusBarStyle('dark')
}
invoke(callbackId, result || {
errMsg: 'chooseLocation:fail cancel'
})
}
})
if (isDark) {
plus.navigator.setStatusBarStyle('light')
page.webview.addEventListener('popGesture', ({
type,
result
}) => {
if (type === 'start') {
plus.navigator.setStatusBarStyle('dark')
} else if (type === 'end' && !result) {
plus.navigator.setStatusBarStyle('light')
}
})
}
}
import {
invoke
} from '../../bridge'
import * as webview from './choose-location-webview'
import * as weex from './choose-location-weex'
import {
showPage
} from '../page.js'
function getStatusBarStyle() {
let style = plus.navigator.getStatusBarStyle()
if (style === 'UIStatusBarStyleBlackTranslucent' || style === 'UIStatusBarStyleBlackOpaque' || style === 'null') {
style = 'light'
} else if (style === 'UIStatusBarStyleDefault') {
style = 'dark'
}
return style
}
export function chooseLocation(options, callbackId) {
const statusBarStyle = getStatusBarStyle()
const isDark = statusBarStyle !== 'light'
let result
const page = showPage({
url: '__uniappchooselocation',
data: {
keyword: options.keyword
},
style: {
animationType: options.animationType || 'slide-in-bottom',
titleNView: {
autoBackButton: false,
titleText: options.titleText || "选择位置",
titleColor: '#ffffff',
backgroundColor: 'rgba(0,0,0,1)',
buttons: [{
// text: options.cancelText || "取消",
// fontSize: "17px",
type: "close",
float: "left",
onclick: () => {
page.close()
}
}, {
text: options.doneText || "完成",
fontSize: "17px",
onclick: () => {
page.sendMessage({
type: "done"
})
}
}]
},
popGesture: 'close',
scrollIndicator: 'none'
},
onMessage({
event,
detail
}) {
if (event === 'selected') {
result = detail
result.errMsg = 'chooseLocation:ok'
}
},
onClose() {
if (isDark) {
plus.navigator.setStatusBarStyle('dark')
}
invoke(callbackId, result || {
errMsg: 'chooseLocation:fail cancel'
})
}
})
if (isDark) {
plus.navigator.setStatusBarStyle('light')
page.webview.addEventListener('popGesture', ({
type,
result
}) => {
if (type === 'start') {
plus.navigator.setStatusBarStyle('dark')
} else if (type === 'end' && !result) {
plus.navigator.setStatusBarStyle('light')
}
})
}
export function chooseLocation (...array) {
const api = __uniConfig.nvueCompiler === 'uni-app' ? weex : webview
return api.chooseLocation(...array)
}
import {
MAP_ID
} from '../constants'
import {
ANI_SHOW,
ANI_DURATION
} from '../../constants'
const OPEN_LOCATION_PATH = '_www/__uniappopenlocation.html'
export function openLocation (params) {
const statusBarStyle = plus.navigator.getStatusBarStyle()
const webview = plus.webview.create(
OPEN_LOCATION_PATH,
MAP_ID, {
titleNView: {
autoBackButton: true,
titleColor: '#ffffff',
titleText: '',
titleSize: '17px',
type: 'transparent'
},
popGesture: 'close',
scrollIndicator: 'none'
}, {
__uniapp_type: 'map',
__uniapp_statusbar_style: statusBarStyle,
'uni-app': 'none'
}
)
if (statusBarStyle === 'light') {
plus.navigator.setStatusBarStyle('dark')
webview.addEventListener('popGesture', ({
type,
result
}) => {
if (type === 'start') {
plus.navigator.setStatusBarStyle('light')
} else if (type === 'end' && !result) {
plus.navigator.setStatusBarStyle('dark')
}
})
}
webview.show(ANI_SHOW, ANI_DURATION, () => {
webview.evalJS(`__openLocation__(${JSON.stringify(params)})`)
})
return {
errMsg: 'openLocation:ok'
}
}
import {
showPage
} from '../page.js'
export function openLocation (data) {
showPage({
url: '__uniappopenlocation',
data,
style: {
titleNView: {
type: 'transparent'
}
}
})
return {
errMsg: 'openLocation:ok'
}
}
import {
showPage
} from '../page.js'
import * as webview from './open-location-webview'
import * as weex from './open-location-weex'
export function openLocation(data) {
showPage({
url: '__uniappopenlocation',
data,
style: {
titleNView: {
type: "transparent"
}
}
})
return {
errMsg: 'openLocation:ok'
}
}
export function openLocation (...array) {
const api = __uniConfig.nvueCompiler === 'uni-app' ? weex : webview
return api.openLocation(...array)
}
......@@ -4,27 +4,27 @@ let uni_
let runtime
function getRuntime() {
function getRuntime () {
return runtime || (runtime = typeof window === 'object' && typeof navigator === 'object' && typeof document ===
'object' ?
'webview' : 'v8')
'object'
? 'webview' : 'v8')
}
function setRuntime(value) {
function setRuntime (value) {
runtime = value
}
function getPageId() {
function getPageId () {
return plus_.webview.currentWebview().id
}
let initedEventListener = false
const callbacks = {}
function addEventListener(pageId, callback) {
function addEventListener (pageId, callback) {
const runtime = getRuntime()
function onPlusMessage(res) {
function onPlusMessage (res) {
const message = res.data && res.data.__message
if (!message || !message.__page) {
return
......@@ -51,10 +51,10 @@ function addEventListener(pageId, callback) {
}
class Page {
constructor(webview) {
constructor (webview) {
this.webview = webview
}
sendMessage(data) {
sendMessage (data) {
const runtime = getRuntime()
const message = {
__message: {
......@@ -69,12 +69,12 @@ class Page {
plus_.webview.postMessageToUniNView(message, this.webview.id)
}
}
close() {
close () {
this.webview.close()
}
}
export function showPage({
export function showPage ({
context,
runtime,
url,
......
......@@ -14,9 +14,8 @@ export function requestPayment (params, callbackId) {
})
} else {
plus.payment.request(service, params.orderInfo, res => {
invoke(callbackId, {
errMsg: 'requestPayment:ok'
})
res.errMsg = 'requestPayment:ok'
invoke(callbackId, res)
}, err => {
invoke(callbackId, {
errMsg: 'requestPayment:fail:' + err.message
......
......@@ -68,6 +68,9 @@ class SocketTask {
const data = options.data
const ws = this._webSocket
try {
if (ws.readyState !== ws.OPEN) {
throw new Error('SocketTask.readyState is not OPEN')
}
ws.send(data)
this._callback(options, 'sendSocketMessage:ok')
} catch (error) {
......@@ -118,11 +121,11 @@ class SocketTask {
}
}
}
eventNames.forEach(item => {
const name = item[0].toUpperCase() + item.substr(1)
SocketTask.prototype[`on${name}`] = function (callback) {
this._callbacks[item].push(callback)
}
eventNames.forEach(item => {
const name = item[0].toUpperCase() + item.substr(1)
SocketTask.prototype[`on${name}`] = function (callback) {
this._callbacks[item].push(callback)
}
})
/**
* 创建一个 WebSocket 连接
......
......@@ -281,6 +281,7 @@ export default {
this.$watch('mode', this._setValue)
},
beforeDestroy () {
this.$refs.picker.remove()
this.$dispatch('Form', 'uni-form-group-update', {
type: 'remove',
vm: this
......
......@@ -15,23 +15,29 @@ export default function parseComponent (vueOptions) {
const componentOptions = parseBaseComponent(vueOptions, {
isPage,
initRelation
})
})
// 关于百度小程序新生命周期(2.0)的说明(组件作为页面时):
// lifetimes:attached --> methods:onShow --> methods:onLoad --> methods:onReady
// 这里在新生命周期强制将onShow挪到onLoad之后触发,另外一处修改在page-parser.js
const oldAttached = componentOptions.lifetimes.attached
componentOptions.lifetimes.attached = function attached () {
oldAttached.call(this)
if (isPage.call(this)) { // 百度 onLoad 在 attached 之前触发
// 百度 当组件作为页面时 pageinstancce 不是原来组件的 instance
this.pageinstance.$vm = this.$vm
if (hasOwn(this.pageinstance, '_$args')) {
this.$vm.$mp.query = this.pageinstance._$args
this.$vm.__call_hook('onLoad', this.pageinstance._$args)
this.$vm.__call_hook('onLoad', this.pageinstance._$args)
this.$vm.__call_hook('onShow')
delete this.pageinstance._$args
}
// TODO 3.105.17以下基础库内百度 Component 作为页面时,methods 中的 onShow 不触发
!newLifecycle && this.$vm.__call_hook('onShow')
} else {
// 百度小程序组件不触发methods内的onReady
if (this.$vm) {
this.$vm._isMounted = true
this.$vm.__call_hook('mounted')
}
}
}
......
import {
isPage,
isPage,
initRelation
} from './util'
......@@ -25,13 +25,21 @@ export default function parsePage (vuePageOptions) {
initRelation
})
const newLifecycle = swan.canIUse('lifecycle-2-0')
// 纠正百度小程序新生命周期(2.0)methods:onShow在methods:onLoad之前触发的问题
if (newLifecycle) {
delete pageOptions.methods.onShow
}
pageOptions.methods.onLoad = function onLoad (args) {
// 百度 onLoad 在 attached 之前触发,先存储 args, 在 attached 里边触发 onLoad
if (this.$vm) {
this.$vm.$mp.query = args
this.$vm.__call_hook('onLoad', args)
} else {
this.pageinstance._$args = args
if (this.$vm) {
this.$vm.$mp.query = args
this.$vm.__call_hook('onLoad', args)
this.$vm.__call_hook('onShow')
} else {
this.pageinstance._$args = args
}
}
......@@ -41,4 +49,4 @@ export default function parsePage (vuePageOptions) {
}
return pageOptions
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册