diff --git a/packages/uni-app-plus/dist/index.v3.js b/packages/uni-app-plus/dist/index.v3.js index 02095d88c56d2c7c9e38f696b3cf1535aa381a7d..7567892d6a63a1be154741746891a17cc7d03e88 100644 --- a/packages/uni-app-plus/dist/index.v3.js +++ b/packages/uni-app-plus/dist/index.v3.js @@ -4754,7 +4754,7 @@ var serviceContext = (function () { }); }, indexOf (page) { - const itemLength = config.list.length; + const itemLength = config && config.list && config.list.length; if (itemLength) { for (let i = 0; i < itemLength; i++) { if ( @@ -6048,7 +6048,7 @@ var serviceContext = (function () { hasContentType = true; headers['Content-Type'] = header[name]; // TODO 需要重构 - if(method === 'POST' && header[name].indexOf('application/x-www-form-urlencoded') === 0) { + if (method === 'POST' && header[name].indexOf('application/x-www-form-urlencoded') === 0) { let bodyArray = []; for (let key in data) { if (data.hasOwnProperty(key)) { @@ -12288,7 +12288,18 @@ var serviceContext = (function () { lifecycleMixin(Vue); Vue.mixin({ - beforeCreate () { + beforeCreate () { + // TODO 临时解决方案,service 层也注入 wxs (适用于工具类) + const options = this.$options; + + const wxs = options.wxs; + if (wxs) { + Object.keys(wxs).forEach(module => { + this[module] = wxs[module]; + }); + } + + if (this.mpType === 'page') { this.$scope = this.$options.pageInstance; this.$scope.$vm = this; diff --git a/packages/uni-migration/lib/mp-weixin/transform/script-transformer.js b/packages/uni-migration/lib/mp-weixin/transform/script-transformer.js index 014dcbbbffb71aae3a0442f00795f0ac53e7db99..147f53e605409566342f0779d8342a086be3e416 100644 --- a/packages/uni-migration/lib/mp-weixin/transform/script-transformer.js +++ b/packages/uni-migration/lib/mp-weixin/transform/script-transformer.js @@ -7,7 +7,7 @@ const { function transformScript(content, route, usingComponentsCode) { return `global['__wxRoute'].push('${route}') -global['__wxUsingComponents'] = ${usingComponentsCode} +global['__wxUsingComponents'].push(${usingComponentsCode}) ${content} export default global['__wxComponents']['${route}']` } diff --git a/packages/vue-cli-plugin-uni/lib/app-plus/index.js b/packages/vue-cli-plugin-uni/lib/app-plus/index.js index a2932fa7de65a280cd776963bed7601144110574..ff4c2c6262b7b65d51c6530bc02807c41f948685 100644 --- a/packages/vue-cli-plugin-uni/lib/app-plus/index.js +++ b/packages/vue-cli-plugin-uni/lib/app-plus/index.js @@ -71,13 +71,14 @@ const v3 = { '../../packages/webpack-uni-app-loader/view/script') }] }) - rules.push({ - resourceQuery: [/lang=wxs/, /blockType=wxs/], - use: [{ - loader: path.resolve(__dirname, '../../packages/webpack-uni-filter-loader') - }] - }) - } + } + // TODO 临时方案,将 wxs 也编译至 service + rules.push({ + resourceQuery: [/lang=wxs/, /blockType=wxs/], + use: [{ + loader: path.resolve(__dirname, '../../packages/webpack-uni-filter-loader') + }] + }) const entry = {} if (isAppService) { diff --git a/src/core/runtime/mp/index.js b/src/core/runtime/mp/index.js index 5ac475b5ab809abc1b19e5a4543dcc43774f58ee..a1ec32eb84e6ec6da274cc9dc2791e14c963926c 100644 --- a/src/core/runtime/mp/index.js +++ b/src/core/runtime/mp/index.js @@ -7,13 +7,12 @@ import polyfill from './polyfill' export * from './wxs' global['__wxRoute'] = [] +global['__wxComponents'] = Object.create(null) +global['__wxUsingComponents'] = [] export function Component (options) { const componentOptions = parseComponent(options) componentOptions.mixins.unshift(polyfill) - if (!global['__wxComponents']) { - global['__wxComponents'] = Object.create(null) - } global['__wxComponents'][global['__wxRoute'].pop()] = componentOptions } diff --git a/src/core/runtime/mp/parser/component-parser.js b/src/core/runtime/mp/parser/component-parser.js index ab1b2cb104aba0125e19f8323371631cf8931472..fbe6e3c743d36cf9949b49840c6bb77f7e29bc54 100644 --- a/src/core/runtime/mp/parser/component-parser.js +++ b/src/core/runtime/mp/parser/component-parser.js @@ -6,6 +6,10 @@ import { parseProperties } from './properties-parser' +import { + parseComponents +} from './components-parser' + import { parseOptions } from './options-parser' @@ -68,6 +72,8 @@ export function parseComponent (mpComponentOptions) { } } + parseComponents(vueComponentOptions) + parseData(data, vueComponentOptions) parseOptions(options, vueComponentOptions) parseMethods(methods, vueComponentOptions) diff --git a/src/core/runtime/mp/parser/components-parser.js b/src/core/runtime/mp/parser/components-parser.js new file mode 100644 index 0000000000000000000000000000000000000000..0136201dded3c77c26f2c49590ada3e86ba7aa87 --- /dev/null +++ b/src/core/runtime/mp/parser/components-parser.js @@ -0,0 +1,3 @@ +export function parseComponents (vueComponentOptions) { + vueComponentOptions.components = global['__wxUsingComponents'].pop() +} diff --git a/src/platforms/app-plus/service/framework/plugins/lifecycle.js b/src/platforms/app-plus/service/framework/plugins/lifecycle.js index bf904cca02f87d1cbed195248362be84b0ed50a0..c25b72310fe321433f096b5763f31509f26d94b7 100644 --- a/src/platforms/app-plus/service/framework/plugins/lifecycle.js +++ b/src/platforms/app-plus/service/framework/plugins/lifecycle.js @@ -49,7 +49,17 @@ export function initLifecycle (Vue) { lifecycleMixin(Vue) Vue.mixin({ - beforeCreate () { + beforeCreate () { + // TODO 临时解决方案,service 层也注入 wxs (适用于工具类) + const options = this.$options + + const wxs = options.wxs + if (wxs) { + Object.keys(wxs).forEach(module => { + this[module] = wxs[module] + }) + } + if (this.mpType === 'page') { this.$scope = this.$options.pageInstance this.$scope.$vm = this