提交 d2e80217 编写于 作者: Q qiang

Merge branch 'dev' into alpha

...@@ -20,7 +20,7 @@ module.exports = { ...@@ -20,7 +20,7 @@ module.exports = {
subPackages: true subPackages: true
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
const copyOptions = ['mycomponents', 'customize-tab-bar'] const copyOptions = ['mycomponents', 'customize-tab-bar', 'ext.json']
global.uniModules.forEach(module => { global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/mycomponents') copyOptions.push('uni_modules/' + module + '/mycomponents')
......
...@@ -17,10 +17,10 @@ module.exports = { ...@@ -17,10 +17,10 @@ module.exports = {
subPackages: true subPackages: true
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
const copyOptions = ['swancomponents'] const copyOptions = ['swancomponents', 'ext.json']
global.uniModules.forEach(module => { global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/swancomponents') copyOptions.push('uni_modules/' + module + '/swancomponents')
}) })
return copyOptions return copyOptions
} }
} }
...@@ -14,10 +14,10 @@ module.exports = { ...@@ -14,10 +14,10 @@ module.exports = {
project: 'project.ks.json' project: 'project.ks.json'
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
const copyOptions = ['kscomponents'] const copyOptions = ['kscomponents', 'ext.json']
global.uniModules.forEach(module => { global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/kscomponents') copyOptions.push('uni_modules/' + module + '/kscomponents')
}) })
return copyOptions return copyOptions
} }
} }
...@@ -15,7 +15,7 @@ module.exports = { ...@@ -15,7 +15,7 @@ module.exports = {
project: 'project.tt.json' project: 'project.tt.json'
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
const copyOptions = ['ttcomponents'] const copyOptions = ['ttcomponents', 'ext.json']
global.uniModules.forEach(module => { global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/ttcomponents') copyOptions.push('uni_modules/' + module + '/ttcomponents')
}) })
......
...@@ -182,16 +182,25 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt ...@@ -182,16 +182,25 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
for (let i = rawRules.length - 1; i >= 0; i--) { for (let i = rawRules.length - 1; i >= 0; i--) {
const uses = rawRules[i].use const uses = rawRules[i].use
if (Array.isArray(uses)) { if (Array.isArray(uses)) {
if (uses.find(use => babelLoaderRe.test(use.loader))) { const babelLoader = uses.find(use => babelLoaderRe.test(use.loader))
const index = uses.findIndex(use => cacheLoaderRe.test(use.loader)) if (babelLoader) {
if (index >= 0) { const options = api.genCacheConfig('babel-loader/' + process.env.UNI_PLATFORM, getPartialIdentifier())
if (webpack.version[0] > 4) {
if (process.env.UNI_USING_CACHE) { if (process.env.UNI_USING_CACHE) {
Object.assign(uses[index].options, api.genCacheConfig( Object.assign(babelLoader.options, options)
'babel-loader/' + process.env.UNI_PLATFORM,
getPartialIdentifier()
))
} else { } else {
uses.splice(index, 1) Object.assign(babelLoader.options, {
cacheDirectory: false
})
}
} else {
const index = uses.findIndex(use => cacheLoaderRe.test(use.loader))
if (index >= 0) {
if (process.env.UNI_USING_CACHE) {
Object.assign(uses[index].options, options)
} else {
uses.splice(index, 1)
}
} }
} }
} }
......
...@@ -169,6 +169,10 @@ module.exports = { ...@@ -169,6 +169,10 @@ module.exports = {
webpackConfig.optimization.splitChunks = require('../split-chunks')() webpackConfig.optimization.splitChunks = require('../split-chunks')()
if (webpack.version[0] > 4) {
webpackConfig.optimization.chunkIds = 'named'
}
parseEntry() parseEntry()
const statCode = getPlatformStat() const statCode = getPlatformStat()
...@@ -330,6 +334,11 @@ ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;` ...@@ -330,6 +334,11 @@ ${globalEnv}.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;`
} }
} }
if (process.env.NODE_ENV === 'production' && webpack.version[0] > 4) {
// 暂时禁用,否则导致 provide 被压缩和裁剪
webpackConfig.optimization.usedExports(false)
}
if (process.env.UNI_SUBPACKGE || process.env.UNI_MP_PLUGIN) { if (process.env.UNI_SUBPACKGE || process.env.UNI_MP_PLUGIN) {
initSubpackageConfig(webpackConfig, vueOptions) initSubpackageConfig(webpackConfig, vueOptions)
} }
......
...@@ -5,8 +5,6 @@ module.exports = function ({ ...@@ -5,8 +5,6 @@ module.exports = function ({
visitor: { visitor: {
MemberExpression (path, state) { MemberExpression (path, state) {
if ( if (
// main.js main.ts
state.filename.startsWith(require('path').join(process.env.UNI_INPUT_DIR, 'main.')) &&
t.isIdentifier(path.node.property) && t.isIdentifier(path.node.property) &&
path.node.property.name === '$mount' && path.node.property.name === '$mount' &&
!path.node.$createApp !path.node.$createApp
......
...@@ -96,12 +96,21 @@ createPage(Page) ...@@ -96,12 +96,21 @@ createPage(Page)
components: [] components: []
}) })
const babelLoader = findBabelLoader(this.loaders) let babelLoader = findBabelLoader(this.loaders)
if (!babelLoader) { if (!babelLoader) {
throw new Error(uniI18n.__('mpLoader.findFail', { throw new Error(uniI18n.__('mpLoader.findFail', {
0: 'babel-loader' 0: 'babel-loader'
})) }))
} else { } else {
const webpack = require('webpack')
if (webpack.version[0] > 4) {
// clone babelLoader and options
const index = this.loaders.indexOf(babelLoader)
const newBabelLoader = Object.assign({}, babelLoader)
Object.assign(newBabelLoader, { options: Object.assign({}, babelLoader.options) })
this.loaders.splice(index, 1, newBabelLoader)
babelLoader = newBabelLoader
}
addCreateApp(babelLoader) addCreateApp(babelLoader)
} }
...@@ -147,4 +156,4 @@ createPage(Page) ...@@ -147,4 +156,4 @@ createPage(Page)
callback(err, content, map) callback(err, content, map)
}) })
} }
} }
...@@ -70,7 +70,11 @@ module.exports = function generateComponent (compilation, jsonpFunction = 'webpa ...@@ -70,7 +70,11 @@ module.exports = function generateComponent (compilation, jsonpFunction = 'webpa
const modules = compilation.modules const modules = compilation.modules
const concatenatedModules = modules.filter(module => module.modules) const concatenatedModules = modules.filter(module => module.modules)
const uniModuleId = modules.find(module => module.resource && normalizePath(module.resource) === uniPath).id let uniModule = modules.find(module => module.resource && normalizePath(module.resource) === uniPath)
if (!uniModule && webpack.version[0] > 4) {
uniModule = modules.find(module => module.rootModule && module.rootModule.resource && normalizePath(module.rootModule.resource) === uniPath)
}
const uniModuleId = uniModule.id
const styleImports = {} const styleImports = {}
const fixSlots = {} const fixSlots = {}
const vueOuterComponentSting = 'vueOuterComponents' const vueOuterComponentSting = 'vueOuterComponents'
......
...@@ -69,6 +69,35 @@ export function initHooks (mpOptions, hooks, vueOptions) { ...@@ -69,6 +69,35 @@ export function initHooks (mpOptions, hooks, vueOptions) {
}) })
} }
export function initUnknownHooks (mpOptions, vueOptions, excludes = []) {
findHooks(vueOptions).forEach((hook) => initHook(mpOptions, hook, excludes))
}
function findHooks (vueOptions, hooks = []) {
if (vueOptions) {
Object.keys(vueOptions).forEach((name) => {
if (name.indexOf('on') === 0 && isFn(vueOptions[name])) {
hooks.push(name)
}
})
}
return hooks
}
function initHook (mpOptions, hook, excludes) {
if (excludes.indexOf(hook) === -1 && !hasOwn(mpOptions, hook)) {
mpOptions[hook] = function (args) {
if (
(__PLATFORM__ === 'mp-toutiao' || __PLATFORM__ === 'mp-lark') &&
hook === 'onError'
) {
return getApp().$vm.$callHook(hook, args)
}
return this.$vm && this.$vm.__call_hook(hook, args)
}
}
}
export function initVueComponent (Vue, vueOptions) { export function initVueComponent (Vue, vueOptions) {
vueOptions = vueOptions.default || vueOptions vueOptions = vueOptions.default || vueOptions
let VueComponent let VueComponent
......
...@@ -12,11 +12,15 @@ export default function createPage (pageVm, options) { ...@@ -12,11 +12,15 @@ export default function createPage (pageVm, options) {
} }
const id = hasOwn($route.params, '__id__') ? $route.params.__id__ : $route.meta.id const id = hasOwn($route.params, '__id__') ? $route.params.__id__ : $route.meta.id
let fullPath = $route.fullPath
if ($route.meta.isEntry && fullPath.indexOf($route.meta.pagePath) === -1) {
fullPath = '/' + $route.meta.pagePath + fullPath.replace('/', '')
}
pageVm.__page__ = { pageVm.__page__ = {
id, id,
path: $route.path, path: $route.path,
route: $route.meta.pagePath, route: $route.meta.pagePath,
fullPath: $route.meta.isEntry ? $route.meta.pagePath : $route.fullPath, fullPath,
options: options, options: options,
meta: Object.assign({}, $route.meta) meta: Object.assign({}, $route.meta)
} }
......
...@@ -46,7 +46,8 @@ export function getAppBaseInfo () { ...@@ -46,7 +46,8 @@ export function getAppBaseInfo () {
const { const {
hostPackageName, hostName, osLanguage, hostPackageName, hostName, osLanguage,
hostVersion, hostLanguage, hostTheme, hostVersion, hostLanguage, hostTheme,
appId, appName, appVersion, appVersionCode appId, appName, appVersion, appVersionCode,
appWgtVersion
} = systemInfo } = systemInfo
const appLanguage = uni const appLanguage = uni
...@@ -60,6 +61,7 @@ export function getAppBaseInfo () { ...@@ -60,6 +61,7 @@ export function getAppBaseInfo () {
appName, appName,
appVersion, appVersion,
appVersionCode, appVersionCode,
appWgtVersion,
appLanguage, appLanguage,
enableDebug: false, enableDebug: false,
hostSDKVersion: undefined, hostSDKVersion: undefined,
......
...@@ -229,6 +229,10 @@ export default { ...@@ -229,6 +229,10 @@ export default {
methods: { methods: {
handleAMapClick (e) { handleAMapClick (e) {
if (IS_AMAP) { if (IS_AMAP) {
// The mobile terminal prevent not map click event trigger map click
if (e.target.nodeName !== 'CANVAS') {
return
}
const { pageX, pageY } = e.changedTouches[0] const { pageX, pageY } = e.changedTouches[0]
this.$trigger('click', { x: pageX, y: pageY }, {}) this.$trigger('click', { x: pageX, y: pageY }, {})
this.$trigger('tap', { x: pageX, y: pageY }, {}) this.$trigger('tap', { x: pageX, y: pageY }, {})
...@@ -611,6 +615,7 @@ export default { ...@@ -611,6 +615,7 @@ export default {
style.height = 0 style.height = 0
style.top = 0 style.top = 0
style.left = 0 style.left = 0
style.zIndex = 999
img.onload = () => { img.onload = () => {
if (option.position.width) { if (option.position.width) {
img.width = option.position.width img.width = option.position.width
......
...@@ -96,17 +96,18 @@ export default { ...@@ -96,17 +96,18 @@ export default {
}) })
this.$parent._markers[this.idString] = marker this.$parent._markers[this.idString] = marker
this.updateMarker(props) this.updateMarker(props)
maps.event.addListener(marker, 'click', (e) => { if (IS_AMAP) {
const callout = marker.callout // 不通过 addListener 方式绑定事件,为了规避高德地图覆盖物点击触发map点击问题
if (callout && !callout.alwaysVisible) { marker.dom.addEventListener('click', e => {
if (IS_AMAP) { this.handleAMapMarkerClick(e, marker)
callout.visible = !callout.visible })
if (callout.visible) { marker.dom.addEventListener('touchend', e => {
marker.callout.createAMapText() this.handleAMapMarkerClick(e, marker)
} else { })
marker.callout.removeAMapText() } else {
} maps.event.addListener(marker, 'click', (e) => {
} else { const callout = marker.callout
if (callout && !callout.alwaysVisible) {
callout.set('visible', !callout.visible) callout.set('visible', !callout.visible)
if (callout.visible) { if (callout.visible) {
const div = callout.div const div = callout.div
...@@ -115,19 +116,26 @@ export default { ...@@ -115,19 +116,26 @@ export default {
parent.appendChild(div) parent.appendChild(div)
} }
} }
}
if (this.idString) {
const { latitude, longitude } = this.getMarkerLatitudeLongitude(e)
this.$parent.$trigger('markertap', {}, {
markerId: Number(this.idString),
latitude,
longitude
})
}
const event = e.event || e.domEvent || e.originEvent const event = e.event || e.domEvent
event.stopPropagation()
}) if (this.idString) {
const { latitude, longitude } = this.getMarkerLatitudeLongitude(e)
this.$parent.$trigger('markertap', event, {
markerId: Number(this.idString),
latitude,
longitude
})
}
event.stopPropagation()
})
// 处理 google H5移动端 maker 点击触发 map 点击问题
maps.event.addListener(marker, 'mousedown', (e) => {
if (e.domEvent) {
e.domEvent.stopPropagation()
}
})
}
}, },
updateMarker (option) { updateMarker (option) {
const map = this._map const map = this._map
...@@ -274,9 +282,9 @@ export default { ...@@ -274,9 +282,9 @@ export default {
callout.setOption(calloutStyle) callout.setOption(calloutStyle)
} else { } else {
if (IS_AMAP) { if (IS_AMAP) {
const callback = (self) => { const callback = ($event, self) => {
if (self.idString) { if (self.idString) {
self.$parent.$trigger('callouttap', {}, { self.$parent.$trigger('callouttap', $event, {
markerId: Number(self.idString) markerId: Number(self.idString)
}) })
} }
...@@ -308,6 +316,25 @@ export default { ...@@ -308,6 +316,25 @@ export default {
console.error('Marker.iconPath is required.') console.error('Marker.iconPath is required.')
} }
}, },
handleAMapMarkerClick (e, marker) {
const callout = marker.callout
if (callout && !callout.alwaysVisible) {
callout.visible = !callout.visible
if (callout.visible) {
marker.callout.createAMapText()
} else {
marker.callout.removeAMapText()
}
}
if (this.idString) {
this.$parent.$trigger('markertap', e, {
markerId: Number(this.idString),
latitude: marker._position.lat,
longitude: marker._position.lng
})
}
e.stopPropagation()
},
updateMarkerLabelStyle (id, style) { updateMarkerLabelStyle (id, style) {
const className = 'uni-map-marker-label-' + id const className = 'uni-map-marker-label-' + id
let styleEl = document.getElementById(className) let styleEl = document.getElementById(className)
......
...@@ -18,9 +18,8 @@ export function createCallout (maps) { ...@@ -18,9 +18,8 @@ export function createCallout (maps) {
this.Text = new maps.Text({ this.Text = new maps.Text({
text: option.content, text: option.content,
anchor: 'bottom-center', // 设置文本标记锚点 anchor: 'bottom-center', // 设置文本标记锚点
offset: new maps.Pixel(0, option.offsetY), offset: new maps.Pixel(0, option.offsetY - 16),
style: { style: {
'margin-bottom': '1rem',
padding: (option.padding || 8) + 'px', padding: (option.padding || 8) + 'px',
'line-height': (option.fontSize || 14) + 'px', 'line-height': (option.fontSize || 14) + 'px',
'border-radius': (option.borderRadius || 0) + 'px', 'border-radius': (option.borderRadius || 0) + 'px',
...@@ -33,14 +32,22 @@ export function createCallout (maps) { ...@@ -33,14 +32,22 @@ export function createCallout (maps) {
}, },
position: option.position position: option.position
}) })
// 不通过 addListener 方式绑定事件,为了规避高德地图覆盖物点击触发map点击问题
maps.event.addListener(this.Text, 'click', () => { this.Text.dom.addEventListener('click', e => {
this.callback(this.parent) handleAMapTextClick(this, e)
})
this.Text.dom.addEventListener('touchend', e => {
handleAMapTextClick(this, e)
}) })
this.Text.setMap(option.map) this.Text.setMap(option.map)
} }
function handleAMapTextClick (self, e) {
self.callback(e, self.parent)
e.stopPropagation()
}
function removeAMapText () { function removeAMapText () {
if (this.Text) { if (this.Text) {
this.option.map.remove(this.Text) this.option.map.remove(this.Text)
......
...@@ -466,12 +466,6 @@ const protocols = { // 需要做转换的 API 列表 ...@@ -466,12 +466,6 @@ const protocols = { // 需要做转换的 API 列表
hideHomeButton: { hideHomeButton: {
name: 'hideBackHome' name: 'hideBackHome'
}, },
saveImageToPhotosAlbum: {
name: 'saveImage',
args: {
filePath: 'url'
}
},
saveVideoToPhotosAlbum: { saveVideoToPhotosAlbum: {
args: { args: {
filePath: 'src' filePath: 'src'
......
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
import { import {
initData, initData,
initHooks, initHooks,
initUnknownHooks,
handleEvent, handleEvent,
initBehaviors, initBehaviors,
initVueComponent, initVueComponent,
...@@ -93,6 +94,7 @@ export default function parsePage (vuePageOptions) { ...@@ -93,6 +94,7 @@ export default function parsePage (vuePageOptions) {
} }
initHooks(pageOptions, hooks, vuePageOptions) initHooks(pageOptions, hooks, vuePageOptions)
initUnknownHooks(pageOptions, vuePageOptions)
if (Array.isArray(vueOptions.wxsCallMethods)) { if (Array.isArray(vueOptions.wxsCallMethods)) {
vueOptions.wxsCallMethods.forEach(callMethod => { vueOptions.wxsCallMethods.forEach(callMethod => {
......
...@@ -2,6 +2,7 @@ import Vue from 'vue' ...@@ -2,6 +2,7 @@ import Vue from 'vue'
import { import {
initHooks, initHooks,
initUnknownHooks,
initMocks initMocks
} from 'uni-wrapper/util' } from 'uni-wrapper/util'
...@@ -190,6 +191,7 @@ export default function parseBaseApp (vm, { ...@@ -190,6 +191,7 @@ export default function parseBaseApp (vm, {
initAppLocale(Vue, vm, normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN) initAppLocale(Vue, vm, normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN)
initHooks(appOptions, hooks) initHooks(appOptions, hooks)
initUnknownHooks(appOptions, vm.$options)
return appOptions return appOptions
} }
...@@ -4,6 +4,7 @@ import { ...@@ -4,6 +4,7 @@ import {
import { import {
initHooks, initHooks,
initUnknownHooks,
PAGE_EVENT_HOOKS PAGE_EVENT_HOOKS
} from 'uni-wrapper/util' } from 'uni-wrapper/util'
...@@ -27,6 +28,7 @@ export default function parseBasePage (vuePageOptions, { ...@@ -27,6 +28,7 @@ export default function parseBasePage (vuePageOptions, {
}) })
initHooks(pageOptions.methods, hooks, vuePageOptions) initHooks(pageOptions.methods, hooks, vuePageOptions)
initUnknownHooks(pageOptions.methods, vuePageOptions)
pageOptions.methods.onLoad = function (query) { pageOptions.methods.onLoad = function (query) {
this.options = query this.options = query
...@@ -40,4 +42,4 @@ export default function parseBasePage (vuePageOptions, { ...@@ -40,4 +42,4 @@ export default function parseBasePage (vuePageOptions, {
} }
return pageOptions return pageOptions
} }
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
import { import {
initData, initData,
initHooks, initHooks,
initUnknownHooks,
handleEvent, handleEvent,
initBehaviors, initBehaviors,
initVueComponent, initVueComponent,
...@@ -80,6 +81,7 @@ export default function parsePage (vuePageOptions) { ...@@ -80,6 +81,7 @@ export default function parsePage (vuePageOptions) {
} }
initHooks(pageOptions, hooks, vuePageOptions) initHooks(pageOptions, hooks, vuePageOptions)
initUnknownHooks(pageOptions, vuePageOptions)
if (Array.isArray(vueOptions.wxsCallMethods)) { if (Array.isArray(vueOptions.wxsCallMethods)) {
vueOptions.wxsCallMethods.forEach(callMethod => { vueOptions.wxsCallMethods.forEach(callMethod => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册