diff --git a/packages/uni-mp-alipay/lib/uni.config.js b/packages/uni-mp-alipay/lib/uni.config.js index 0cb7b631d9b4482352bacb88f8fe160738f69d14..a96c4b53af466a455175256b625f8f4b954a25f3 100644 --- a/packages/uni-mp-alipay/lib/uni.config.js +++ b/packages/uni-mp-alipay/lib/uni.config.js @@ -20,7 +20,7 @@ module.exports = { subPackages: true }, copyWebpackOptions (platformOptions, vueOptions) { - const copyOptions = ['mycomponents', 'customize-tab-bar'] + const copyOptions = ['mycomponents', 'customize-tab-bar', 'ext.json'] global.uniModules.forEach(module => { copyOptions.push('uni_modules/' + module + '/mycomponents') diff --git a/packages/uni-mp-baidu/lib/uni.config.js b/packages/uni-mp-baidu/lib/uni.config.js index 38afcfef3c8d1854681d84414ae1a6eb7ec2e23a..4b054c38e73a82d923da38f9f4e84493a6bc311e 100644 --- a/packages/uni-mp-baidu/lib/uni.config.js +++ b/packages/uni-mp-baidu/lib/uni.config.js @@ -17,10 +17,10 @@ module.exports = { subPackages: true }, copyWebpackOptions (platformOptions, vueOptions) { - const copyOptions = ['swancomponents'] + const copyOptions = ['swancomponents', 'ext.json'] global.uniModules.forEach(module => { copyOptions.push('uni_modules/' + module + '/swancomponents') }) return copyOptions } -} +} diff --git a/packages/uni-mp-kuaishou/lib/uni.config.js b/packages/uni-mp-kuaishou/lib/uni.config.js index 5af7798fab53fef7514406bb5e8ecdbae37befa5..7ad8172c247cf07adb2c164213f8bdaee2f9f146 100644 --- a/packages/uni-mp-kuaishou/lib/uni.config.js +++ b/packages/uni-mp-kuaishou/lib/uni.config.js @@ -14,10 +14,10 @@ module.exports = { project: 'project.ks.json' }, copyWebpackOptions (platformOptions, vueOptions) { - const copyOptions = ['kscomponents'] + const copyOptions = ['kscomponents', 'ext.json'] global.uniModules.forEach(module => { copyOptions.push('uni_modules/' + module + '/kscomponents') }) return copyOptions } -} +} diff --git a/packages/uni-mp-toutiao/lib/uni.config.js b/packages/uni-mp-toutiao/lib/uni.config.js index 3424a34ed222443616dc146a982ac04a4e9f0a5d..00429c80cec55e8b2cb4f5cc4b5df7f7221e44da 100644 --- a/packages/uni-mp-toutiao/lib/uni.config.js +++ b/packages/uni-mp-toutiao/lib/uni.config.js @@ -15,7 +15,7 @@ module.exports = { project: 'project.tt.json' }, copyWebpackOptions (platformOptions, vueOptions) { - const copyOptions = ['ttcomponents'] + const copyOptions = ['ttcomponents', 'ext.json'] global.uniModules.forEach(module => { copyOptions.push('uni_modules/' + module + '/ttcomponents') }) diff --git a/packages/vue-cli-plugin-uni/lib/configure-webpack.js b/packages/vue-cli-plugin-uni/lib/configure-webpack.js index 4011c1193eaaa909b7d355717e7e8098c0bee019..59168a560e6ab2b3bd2b07f654e5e0d600e0e72b 100644 --- a/packages/vue-cli-plugin-uni/lib/configure-webpack.js +++ b/packages/vue-cli-plugin-uni/lib/configure-webpack.js @@ -182,16 +182,25 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt for (let i = rawRules.length - 1; i >= 0; i--) { const uses = rawRules[i].use if (Array.isArray(uses)) { - if (uses.find(use => babelLoaderRe.test(use.loader))) { - const index = uses.findIndex(use => cacheLoaderRe.test(use.loader)) - if (index >= 0) { + const babelLoader = uses.find(use => babelLoaderRe.test(use.loader)) + if (babelLoader) { + const options = api.genCacheConfig('babel-loader/' + process.env.UNI_PLATFORM, getPartialIdentifier()) + if (webpack.version[0] > 4) { if (process.env.UNI_USING_CACHE) { - Object.assign(uses[index].options, api.genCacheConfig( - 'babel-loader/' + process.env.UNI_PLATFORM, - getPartialIdentifier() - )) + Object.assign(babelLoader.options, options) } 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) + } } } } diff --git a/packages/vue-cli-plugin-uni/lib/mp/index.js b/packages/vue-cli-plugin-uni/lib/mp/index.js index ffcb975d0833d8deb261a42cf73b9afb86c6904e..a13bc6cb7b69fd2d99a6cd2703a97b248471a236 100644 --- a/packages/vue-cli-plugin-uni/lib/mp/index.js +++ b/packages/vue-cli-plugin-uni/lib/mp/index.js @@ -169,6 +169,10 @@ module.exports = { webpackConfig.optimization.splitChunks = require('../split-chunks')() + if (webpack.version[0] > 4) { + webpackConfig.optimization.chunkIds = 'named' + } + parseEntry() const statCode = getPlatformStat() @@ -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) { initSubpackageConfig(webpackConfig, vueOptions) } diff --git a/packages/webpack-uni-mp-loader/lib/babel/plugin-create-app.js b/packages/webpack-uni-mp-loader/lib/babel/plugin-create-app.js index af41fdb267a6271c2a9c9ad5bd3d7a382ea54c27..c3fd3be6611900de9cc25b85a260b825294f0b4a 100644 --- a/packages/webpack-uni-mp-loader/lib/babel/plugin-create-app.js +++ b/packages/webpack-uni-mp-loader/lib/babel/plugin-create-app.js @@ -5,8 +5,6 @@ module.exports = function ({ visitor: { MemberExpression (path, state) { if ( - // main.js main.ts - state.filename.startsWith(require('path').join(process.env.UNI_INPUT_DIR, 'main.')) && t.isIdentifier(path.node.property) && path.node.property.name === '$mount' && !path.node.$createApp diff --git a/packages/webpack-uni-mp-loader/lib/main-new.js b/packages/webpack-uni-mp-loader/lib/main-new.js index db7088e2d1b5cf083dc151fc3ce0c8e5372a3e1a..15b7c48ddb3e3853c91095d822b2a2ded118a43c 100644 --- a/packages/webpack-uni-mp-loader/lib/main-new.js +++ b/packages/webpack-uni-mp-loader/lib/main-new.js @@ -96,12 +96,21 @@ createPage(Page) components: [] }) - const babelLoader = findBabelLoader(this.loaders) + let babelLoader = findBabelLoader(this.loaders) if (!babelLoader) { throw new Error(uniI18n.__('mpLoader.findFail', { 0: 'babel-loader' })) } 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) } @@ -147,4 +156,4 @@ createPage(Page) callback(err, content, map) }) } -} +} diff --git a/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js b/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js index 6502daed8d1d200059669f8857466857a7bc63f8..f49deac6252ddc066ea0fd949c582782eeadfdac 100644 --- a/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js +++ b/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js @@ -70,7 +70,11 @@ module.exports = function generateComponent (compilation, jsonpFunction = 'webpa const modules = compilation.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 fixSlots = {} const vueOuterComponentSting = 'vueOuterComponents' diff --git a/src/core/runtime/wrapper/util.js b/src/core/runtime/wrapper/util.js index 5e409ba9f4e408f8010fbee8491728ca2aabe39d..7b53ef48139de1697c2b760edc1d4a793ef34105 100644 --- a/src/core/runtime/wrapper/util.js +++ b/src/core/runtime/wrapper/util.js @@ -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) { vueOptions = vueOptions.default || vueOptions let VueComponent diff --git a/src/core/service/plugins/page/create-page.js b/src/core/service/plugins/page/create-page.js index 4d62b7eb728c7edb2cd13c85885b90d417403f26..426ba0fb28299ba01a69fb3a50b970255af78d89 100644 --- a/src/core/service/plugins/page/create-page.js +++ b/src/core/service/plugins/page/create-page.js @@ -12,11 +12,15 @@ export default function createPage (pageVm, options) { } 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__ = { id, path: $route.path, route: $route.meta.pagePath, - fullPath: $route.meta.isEntry ? $route.meta.pagePath : $route.fullPath, + fullPath, options: options, meta: Object.assign({}, $route.meta) } diff --git a/src/platforms/app-plus/service/api/device/system.js b/src/platforms/app-plus/service/api/device/system.js index 34cc7e327d25cd4ee2ccad9835287fc5d3330709..e9c322ba05f80398451fd3bb25a9eb34a64b3cce 100644 --- a/src/platforms/app-plus/service/api/device/system.js +++ b/src/platforms/app-plus/service/api/device/system.js @@ -46,7 +46,8 @@ export function getAppBaseInfo () { const { hostPackageName, hostName, osLanguage, hostVersion, hostLanguage, hostTheme, - appId, appName, appVersion, appVersionCode + appId, appName, appVersion, appVersionCode, + appWgtVersion } = systemInfo const appLanguage = uni @@ -60,6 +61,7 @@ export function getAppBaseInfo () { appName, appVersion, appVersionCode, + appWgtVersion, appLanguage, enableDebug: false, hostSDKVersion: undefined, diff --git a/src/platforms/h5/view/components/map/index.vue b/src/platforms/h5/view/components/map/index.vue index 479d80d046053e6745a629f555c0c0887c75b45b..bdb0b260484b7b4c3bbfd06af1fc9f9ae0ec9384 100644 --- a/src/platforms/h5/view/components/map/index.vue +++ b/src/platforms/h5/view/components/map/index.vue @@ -229,6 +229,10 @@ export default { methods: { handleAMapClick (e) { 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] this.$trigger('click', { x: pageX, y: pageY }, {}) this.$trigger('tap', { x: pageX, y: pageY }, {}) @@ -611,6 +615,7 @@ export default { style.height = 0 style.top = 0 style.left = 0 + style.zIndex = 999 img.onload = () => { if (option.position.width) { img.width = option.position.width diff --git a/src/platforms/h5/view/components/map/map-marker.js b/src/platforms/h5/view/components/map/map-marker.js index 34b27d946d0db945cb6bbf4a54bb867ae4a2f6c1..460a7ffbb334ebec084e1fa1ded5809052546464 100644 --- a/src/platforms/h5/view/components/map/map-marker.js +++ b/src/platforms/h5/view/components/map/map-marker.js @@ -96,17 +96,18 @@ export default { }) this.$parent._markers[this.idString] = marker this.updateMarker(props) - maps.event.addListener(marker, 'click', (e) => { - const callout = marker.callout - if (callout && !callout.alwaysVisible) { - if (IS_AMAP) { - callout.visible = !callout.visible - if (callout.visible) { - marker.callout.createAMapText() - } else { - marker.callout.removeAMapText() - } - } else { + if (IS_AMAP) { + // 不通过 addListener 方式绑定事件,为了规避高德地图覆盖物点击触发map点击问题 + marker.dom.addEventListener('click', e => { + this.handleAMapMarkerClick(e, marker) + }) + marker.dom.addEventListener('touchend', e => { + this.handleAMapMarkerClick(e, marker) + }) + } else { + maps.event.addListener(marker, 'click', (e) => { + const callout = marker.callout + if (callout && !callout.alwaysVisible) { callout.set('visible', !callout.visible) if (callout.visible) { const div = callout.div @@ -115,19 +116,26 @@ export default { 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 - event.stopPropagation() - }) + const event = e.event || e.domEvent + + 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) { const map = this._map @@ -274,9 +282,9 @@ export default { callout.setOption(calloutStyle) } else { if (IS_AMAP) { - const callback = (self) => { + const callback = ($event, self) => { if (self.idString) { - self.$parent.$trigger('callouttap', {}, { + self.$parent.$trigger('callouttap', $event, { markerId: Number(self.idString) }) } @@ -308,6 +316,25 @@ export default { 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) { const className = 'uni-map-marker-label-' + id let styleEl = document.getElementById(className) diff --git a/src/platforms/h5/view/components/map/maps/callout.js b/src/platforms/h5/view/components/map/maps/callout.js index e9037b608177eba3a1fdde858aebe3b6f8cfdab1..545e2f97d8996c9546b8b254ad6b2ee940cb9461 100644 --- a/src/platforms/h5/view/components/map/maps/callout.js +++ b/src/platforms/h5/view/components/map/maps/callout.js @@ -18,9 +18,8 @@ export function createCallout (maps) { this.Text = new maps.Text({ text: option.content, anchor: 'bottom-center', // 设置文本标记锚点 - offset: new maps.Pixel(0, option.offsetY), + offset: new maps.Pixel(0, option.offsetY - 16), style: { - 'margin-bottom': '1rem', padding: (option.padding || 8) + 'px', 'line-height': (option.fontSize || 14) + 'px', 'border-radius': (option.borderRadius || 0) + 'px', @@ -33,14 +32,22 @@ export function createCallout (maps) { }, position: option.position }) - - maps.event.addListener(this.Text, 'click', () => { - this.callback(this.parent) + // 不通过 addListener 方式绑定事件,为了规避高德地图覆盖物点击触发map点击问题 + this.Text.dom.addEventListener('click', e => { + handleAMapTextClick(this, e) + }) + this.Text.dom.addEventListener('touchend', e => { + handleAMapTextClick(this, e) }) this.Text.setMap(option.map) } + function handleAMapTextClick (self, e) { + self.callback(e, self.parent) + e.stopPropagation() + } + function removeAMapText () { if (this.Text) { this.option.map.remove(this.Text) diff --git a/src/platforms/mp-alipay/runtime/api/protocols.js b/src/platforms/mp-alipay/runtime/api/protocols.js index 7bf23a3d1ed7fdb37b0c9c55792ad57e06433d53..0ea989ffa7a28f4b50036b58190a45bb67ba6ea9 100644 --- a/src/platforms/mp-alipay/runtime/api/protocols.js +++ b/src/platforms/mp-alipay/runtime/api/protocols.js @@ -466,12 +466,6 @@ const protocols = { // 需要做转换的 API 列表 hideHomeButton: { name: 'hideBackHome' }, - saveImageToPhotosAlbum: { - name: 'saveImage', - args: { - filePath: 'url' - } - }, saveVideoToPhotosAlbum: { args: { filePath: 'src' diff --git a/src/platforms/mp-alipay/runtime/wrapper/page-parser.js b/src/platforms/mp-alipay/runtime/wrapper/page-parser.js index 756a6534f70efff0de49b47d20ccf4bf3ddbd910..69f3997b4f97c01a091041600a9b1c3fc08c6dea 100644 --- a/src/platforms/mp-alipay/runtime/wrapper/page-parser.js +++ b/src/platforms/mp-alipay/runtime/wrapper/page-parser.js @@ -7,6 +7,7 @@ import { import { initData, initHooks, + initUnknownHooks, handleEvent, initBehaviors, initVueComponent, @@ -93,6 +94,7 @@ export default function parsePage (vuePageOptions) { } initHooks(pageOptions, hooks, vuePageOptions) + initUnknownHooks(pageOptions, vuePageOptions) if (Array.isArray(vueOptions.wxsCallMethods)) { vueOptions.wxsCallMethods.forEach(callMethod => { diff --git a/src/platforms/mp-weixin/runtime/wrapper/app-base-parser.js b/src/platforms/mp-weixin/runtime/wrapper/app-base-parser.js index d8659b99c9ec7066767febbb5a8d4676c948ac6d..762c3c740ab7aa5a40bf76bad5398abf44459112 100644 --- a/src/platforms/mp-weixin/runtime/wrapper/app-base-parser.js +++ b/src/platforms/mp-weixin/runtime/wrapper/app-base-parser.js @@ -2,6 +2,7 @@ import Vue from 'vue' import { initHooks, + initUnknownHooks, initMocks } from 'uni-wrapper/util' @@ -190,6 +191,7 @@ export default function parseBaseApp (vm, { initAppLocale(Vue, vm, normalizeLocale(__GLOBAL__.getSystemInfoSync().language) || LOCALE_EN) initHooks(appOptions, hooks) + initUnknownHooks(appOptions, vm.$options) return appOptions } diff --git a/src/platforms/mp-weixin/runtime/wrapper/page-base-parser.js b/src/platforms/mp-weixin/runtime/wrapper/page-base-parser.js index 7d908d9f0ebfa11e8c0b15d63183b589235a0ded..71f57dfb30f61512439d2744aeeb35b74d2d1b7f 100644 --- a/src/platforms/mp-weixin/runtime/wrapper/page-base-parser.js +++ b/src/platforms/mp-weixin/runtime/wrapper/page-base-parser.js @@ -4,6 +4,7 @@ import { import { initHooks, + initUnknownHooks, PAGE_EVENT_HOOKS } from 'uni-wrapper/util' @@ -27,6 +28,7 @@ export default function parseBasePage (vuePageOptions, { }) initHooks(pageOptions.methods, hooks, vuePageOptions) + initUnknownHooks(pageOptions.methods, vuePageOptions) pageOptions.methods.onLoad = function (query) { this.options = query @@ -40,4 +42,4 @@ export default function parseBasePage (vuePageOptions, { } return pageOptions -} +} diff --git a/src/platforms/mp-xhs/runtime/wrapper/page-parser.js b/src/platforms/mp-xhs/runtime/wrapper/page-parser.js index f60f8f69ed1d9bf8e4da26d2a59ee44640e8f3cb..de62a01c0dff5f75d6908969f4fd81b6b6218dcd 100644 --- a/src/platforms/mp-xhs/runtime/wrapper/page-parser.js +++ b/src/platforms/mp-xhs/runtime/wrapper/page-parser.js @@ -7,6 +7,7 @@ import { import { initData, initHooks, + initUnknownHooks, handleEvent, initBehaviors, initVueComponent, @@ -80,6 +81,7 @@ export default function parsePage (vuePageOptions) { } initHooks(pageOptions, hooks, vuePageOptions) + initUnknownHooks(pageOptions, vuePageOptions) if (Array.isArray(vueOptions.wxsCallMethods)) { vueOptions.wxsCallMethods.forEach(callMethod => {