diff --git a/packages/uni-mp-baidu/dist/uni.mp.esm.js b/packages/uni-mp-baidu/dist/uni.mp.esm.js index 409512e14865ce52faf0d43baefbacf75ffd3f7d..a0d171b6796d1a48c72990a75ee105aca44c3782 100644 --- a/packages/uni-mp-baidu/dist/uni.mp.esm.js +++ b/packages/uni-mp-baidu/dist/uni.mp.esm.js @@ -1,4 +1,4 @@ -import { camelize, isPlainObject, isArray, hasOwn, isFunction, extend } from '@vue/shared'; +import { isPlainObject, camelize, isArray, hasOwn, isFunction, extend } from '@vue/shared'; import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue'; // lifecycle @@ -8,6 +8,26 @@ const ON_SHOW$1 = 'onShow'; const ON_LOAD$1 = 'onLoad'; const ON_READY$1 = 'onReady'; +const encode$1 = encodeURIComponent; +function stringifyQuery$1(obj, encodeStr = encode$1) { + const res = obj + ? Object.keys(obj) + .map((key) => { + let val = obj[key]; + if (typeof val === undefined || val === null) { + val = ''; + } + else if (isPlainObject(val)) { + val = JSON.stringify(val); + } + return encodeStr(key) + '=' + encodeStr(val); + }) + .filter((x) => x.length > 0) + .join('&') + : null; + return res ? `?${res}` : ''; +} + class EventChannel$1 { constructor(id, events) { this.id = id; @@ -1152,15 +1172,21 @@ function parse(pageOptions) { this.$vm.$callHook(ON_SHOW$1); } }; - methods.onLoad = function onLoad(args) { + methods.onLoad = function onLoad(query) { // 百度 onLoad 在 attached 之前触发,先存储 args, 在 attached 里边触发 onLoad if (this.$vm) { this._$loaded = true; - this.$vm.$callHook(ON_LOAD$1, args); + const copyQuery = extend({}, query); + delete copyQuery.__id__; + this.options = copyQuery; + this.pageinstance.$page = this.$page = { + fullPath: '/' + this.pageinstance.route + stringifyQuery$1(copyQuery), + }; + this.$vm.$callHook(ON_LOAD$1, query); this.$vm.$callHook(ON_SHOW$1); } else { - this.pageinstance._$args = args; + this.pageinstance._$args = query; } }; } diff --git a/packages/uni-mp-baidu/src/runtime/parsePageOptions.ts b/packages/uni-mp-baidu/src/runtime/parsePageOptions.ts index bf63204a81394b106cd24012a5ee1f94d1732247..b2116ec78eaef7d7ce3e18a677894c6004dfe5f3 100644 --- a/packages/uni-mp-baidu/src/runtime/parsePageOptions.ts +++ b/packages/uni-mp-baidu/src/runtime/parsePageOptions.ts @@ -1,5 +1,6 @@ +import { extend } from '@vue/shared' import { MPComponentOptions, MPComponentInstance } from '@dcloudio/uni-mp-core' -import { ON_LOAD, ON_SHOW } from '@dcloudio/uni-shared' +import { ON_LOAD, ON_SHOW, stringifyQuery } from '@dcloudio/uni-shared' import { parse as parseComponentOptions } from './parseComponentOptions' @@ -18,14 +19,24 @@ export function parse(pageOptions: MPComponentOptions) { } } - methods.onLoad = function onLoad(this: MPComponentInstance, args) { + methods.onLoad = function onLoad( + this: MPComponentInstance, + query: Record + ) { // 百度 onLoad 在 attached 之前触发,先存储 args, 在 attached 里边触发 onLoad if (this.$vm) { ;(this as any)._$loaded = true - this.$vm.$callHook(ON_LOAD, args) + const copyQuery = extend({}, query) + delete copyQuery.__id__ + ;(this as any).options = copyQuery + ;(this as any).pageinstance.$page = (this as any).$page = { + fullPath: + '/' + (this as any).pageinstance.route + stringifyQuery(copyQuery), + } + this.$vm.$callHook(ON_LOAD, query) this.$vm.$callHook(ON_SHOW) } else { - ;(this as any).pageinstance._$args = args + ;(this as any).pageinstance._$args = query } } }