diff --git a/packages/uni-app/dist/uni-app.cjs.js b/packages/uni-app/dist/uni-app.cjs.js index 95c73381d5d..73d1b563a2d 100644 --- a/packages/uni-app/dist/uni-app.cjs.js +++ b/packages/uni-app/dist/uni-app.cjs.js @@ -141,6 +141,8 @@ const onAddToFavorites = /*#__PURE__*/ createHook(uniShared.ON_ADD_TO_FAVORITES); const onShareAppMessage = /*#__PURE__*/ createHook(uniShared.ON_SHARE_APP_MESSAGE); +const onShareChat = +/*#__PURE__*/ createHook(uniShared.ON_SHARE_CHAT); const onNavigationBarButtonTap = /*#__PURE__*/ createHook(uniShared.ON_NAVIGATION_BAR_BUTTON_TAP); const onNavigationBarSearchInputChanged = /*#__PURE__*/ createHook(uniShared.ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED); const onNavigationBarSearchInputClicked = /*#__PURE__*/ createHook(uniShared.ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED); @@ -201,6 +203,7 @@ exports.onReady = onReady; exports.onResize = onResize; exports.onSaveExitState = onSaveExitState; exports.onShareAppMessage = onShareAppMessage; +exports.onShareChat = onShareChat; exports.onShareTimeline = onShareTimeline; exports.onShow = onShow; exports.onTabItemTap = onTabItemTap; diff --git a/packages/uni-app/dist/uni-app.d.ts b/packages/uni-app/dist/uni-app.d.ts index add3c597a9b..671fd1cc3f6 100644 --- a/packages/uni-app/dist/uni-app.d.ts +++ b/packages/uni-app/dist/uni-app.d.ts @@ -83,6 +83,38 @@ declare type onSaveExitStateHook = () => SaveExitState; export declare const onShareAppMessage: (hook: (options: Page.ShareAppMessageOption) => Page.CustomShareContent | Promise>, target?: ComponentInternalInstance | null) => void; +export declare const onShareChat: (hook: (options: { + /** + * 转发的路径 + * @default 当前页面路径 + */ + path?: string; + /** + * 自定义标题,即聊天群组内分享内容显示的标题 + * @default 当前小程序名称 + */ + title?: string; + /** + * 自定义页面路径中携带的参数,如 path?a=1&b=2 的 “?” 后面部分 + * @default 当前页面路径携带的参数 + */ + query?: string; + /** + * 自定义图片路径,可以是本地文件或者网络图片(IOS 客户端路径中如果含中文需要encode) 。支持 PNG 及 JPG,显示图片长宽比是 1:1 + * @default 默认使用小程序 Logo + */ + imageUrl?: string; + /** + * 如果该参数存在,则以 resolve 结果为准,如果三秒内不 resolve,分享会使用上面传入的默认 + */ + promise?: Promise; + /** + * 好友分享的内容描述 + * @default 默认取小程序描述 + */ + content?: string; +}) => void, target?: ComponentInternalInstance | null) => void; + export declare const onShareTimeline: (hook: () => Page.ShareTimelineContent, target?: ComponentInternalInstance | null) => void; export declare const onShow: (hook: ((options?: App.LaunchShowOption | undefined) => void) | (() => void), target?: ComponentInternalInstance | null) => void; diff --git a/packages/uni-app/dist/uni-app.es.js b/packages/uni-app/dist/uni-app.es.js index 0af09ebf1ff..10e6c553dbb 100644 --- a/packages/uni-app/dist/uni-app.es.js +++ b/packages/uni-app/dist/uni-app.es.js @@ -1,7 +1,7 @@ import { shallowRef, ref, getCurrentInstance, isInSSRComponentSetup, injectHook } from 'vue'; import { hasOwn } from '@vue/shared'; export { capitalize, extend, hasOwn, isPlainObject } from '@vue/shared'; -import { sanitise, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR, ON_SHOW, ON_HIDE, ON_LAUNCH, ON_ERROR, ON_THEME_CHANGE, ON_PAGE_NOT_FOUND, ON_UNHANDLE_REJECTION, ON_EXIT, ON_INIT, ON_LOAD, ON_READY, ON_UNLOAD, ON_RESIZE, ON_BACK_PRESS, ON_PAGE_SCROLL, ON_TAB_ITEM_TAP, ON_REACH_BOTTOM, ON_PULL_DOWN_REFRESH, ON_SAVE_EXIT_STATE, ON_SHARE_TIMELINE, ON_ADD_TO_FAVORITES, ON_SHARE_APP_MESSAGE, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED } from '@dcloudio/uni-shared'; +import { sanitise, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR, ON_SHOW, ON_HIDE, ON_LAUNCH, ON_ERROR, ON_THEME_CHANGE, ON_PAGE_NOT_FOUND, ON_UNHANDLE_REJECTION, ON_EXIT, ON_INIT, ON_LOAD, ON_READY, ON_UNLOAD, ON_RESIZE, ON_BACK_PRESS, ON_PAGE_SCROLL, ON_TAB_ITEM_TAP, ON_REACH_BOTTOM, ON_PULL_DOWN_REFRESH, ON_SAVE_EXIT_STATE, ON_SHARE_TIMELINE, ON_ADD_TO_FAVORITES, ON_SHARE_APP_MESSAGE, ON_SHARE_CHAT, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED } from '@dcloudio/uni-shared'; function getSSRDataType() { return getCurrentInstance() ? UNI_SSR_DATA : UNI_SSR_GLOBAL_DATA; @@ -112,6 +112,8 @@ const onAddToFavorites = /*#__PURE__*/ createHook(ON_ADD_TO_FAVORITES); const onShareAppMessage = /*#__PURE__*/ createHook(ON_SHARE_APP_MESSAGE); +const onShareChat = +/*#__PURE__*/ createHook(ON_SHARE_CHAT); const onNavigationBarButtonTap = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_BUTTON_TAP); const onNavigationBarSearchInputChanged = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED); const onNavigationBarSearchInputClicked = /*#__PURE__*/ createHook(ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED); @@ -129,4 +131,4 @@ function renderComponentSlot(slots, name, props = null) { return null; } -export { formatAppLog, formatH5Log, getCurrentSubNVue, getSsrGlobalData, onAddToFavorites, onBackPress, onError, onExit, onHide, onInit, onLaunch, onLoad, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageHide, onPageNotFound, onPageScroll, onPageShow, onPullDownRefresh, onReachBottom, onReady, onResize, onSaveExitState, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, renderComponentSlot, requireNativePlugin, resolveEasycom, shallowSsrRef, ssrRef }; +export { formatAppLog, formatH5Log, getCurrentSubNVue, getSsrGlobalData, onAddToFavorites, onBackPress, onError, onExit, onHide, onInit, onLaunch, onLoad, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageHide, onPageNotFound, onPageScroll, onPageShow, onPullDownRefresh, onReachBottom, onReady, onResize, onSaveExitState, onShareAppMessage, onShareChat, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, renderComponentSlot, requireNativePlugin, resolveEasycom, shallowSsrRef, ssrRef }; diff --git a/packages/uni-app/src/apiLifecycle.ts b/packages/uni-app/src/apiLifecycle.ts index ef2d9e25935..941d16c2cb3 100644 --- a/packages/uni-app/src/apiLifecycle.ts +++ b/packages/uni-app/src/apiLifecycle.ts @@ -26,6 +26,7 @@ import { ON_RESIZE, ON_SAVE_EXIT_STATE, ON_SHARE_APP_MESSAGE, + ON_SHARE_CHAT, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, @@ -125,6 +126,51 @@ export const onShareAppMessage = ON_SHARE_APP_MESSAGE ) +interface XhsPageInstance extends Page.PageInstance { + /** + * 小红书特有生命周期:监听右上角菜单“分享到微信群组”按钮的行为,并自定义分享内容。 + * @see https://miniapp.xiaohongshu.com/docs?path=/docs/frame/Page#onShareChat + * @param options + * @returns + */ + onShareChat: (options: { + /** + * 转发的路径 + * @default 当前页面路径 + */ + path?: string + /** + * 自定义标题,即聊天群组内分享内容显示的标题 + * @default 当前小程序名称 + */ + title?: string + /** + * 自定义页面路径中携带的参数,如 path?a=1&b=2 的 “?” 后面部分 + * @default 当前页面路径携带的参数 + */ + query?: string + /** + * 自定义图片路径,可以是本地文件或者网络图片(IOS 客户端路径中如果含中文需要encode) 。支持 PNG 及 JPG,显示图片长宽比是 1:1 + * @default 默认使用小程序 Logo + */ + imageUrl?: string + /** + * 如果该参数存在,则以 resolve 结果为准,如果三秒内不 resolve,分享会使用上面传入的默认 + */ + promise?: Promise + /** + * 好友分享的内容描述 + * @default 默认取小程序描述 + */ + content?: string + }) => void +} + +export const onShareChat = + /*#__PURE__*/ createHook['onShareChat']>( + ON_SHARE_CHAT + ) + export const onNavigationBarButtonTap = /*#__PURE__*/ createHook< Required['onNavigationBarButtonTap'] >(ON_NAVIGATION_BAR_BUTTON_TAP) diff --git a/packages/uni-mp-vue/dist/vue.runtime.esm.js b/packages/uni-mp-vue/dist/vue.runtime.esm.js index c456e2e48af..bcc32e5e922 100644 --- a/packages/uni-mp-vue/dist/vue.runtime.esm.js +++ b/packages/uni-mp-vue/dist/vue.runtime.esm.js @@ -7106,7 +7106,7 @@ function setRef$1(instance, isUnmount = false) { (templateRef) => setTemplateRef(templateRef, null, setupState) ); } - const check = $mpPlatform === "mp-baidu" || $mpPlatform === "mp-toutiao"; + const check = $mpPlatform === "mp-baidu" || $mpPlatform === "mp-toutiao" || $mpPlatform === "mp-xhs"; const doSetByRefs = (refs) => { const mpComponents = ( // 字节小程序 selectAllComponents 可能返回 null @@ -7774,13 +7774,19 @@ function vOn(value, key) { const instance = getCurrentInstance(); const ctx = instance.ctx; // 微信小程序,QQ小程序,当 setData diff 的时候,若事件不主动同步过去,会导致事件绑定不更新,(question/137217) - const extraKey = typeof key !== 'undefined' && - (ctx.$mpPlatform === 'mp-weixin' || - ctx.$mpPlatform === 'mp-qq' || - ctx.$mpPlatform === 'mp-xhs') && + let extraKey = typeof key !== 'undefined' && + (ctx.$mpPlatform === 'mp-weixin' || ctx.$mpPlatform === 'mp-qq') && (isString(key) || typeof key === 'number') ? '_' + key : ''; + // 解决小红书平台可能出现自定义组件事件错乱问题 + // @ts-expect-error: ctx.$mpType + const needExtraKey = ctx.$mpPlatform === 'mp-xhs' && ctx.$mpType === 'component'; + const eiCounter = instance.$ei++; + if (needExtraKey) { + // @ts-expect-error: ctx.componentId + extraKey = '_' + ctx.componentId + '_' + eiCounter; + } const name = 'e' + instance.$ei++ + extraKey; const mpInstance = ctx.$scope; if (!value) { diff --git a/packages/uni-mp-vue/lib/vue.runtime.esm.js b/packages/uni-mp-vue/lib/vue.runtime.esm.js index 997de55452d..40b03977f12 100644 --- a/packages/uni-mp-vue/lib/vue.runtime.esm.js +++ b/packages/uni-mp-vue/lib/vue.runtime.esm.js @@ -4744,7 +4744,7 @@ function setRef(instance, isUnmount = false) { (templateRef) => setTemplateRef(templateRef, null, setupState) ); } - const check = $mpPlatform === "mp-baidu" || $mpPlatform === "mp-toutiao"; + const check = $mpPlatform === "mp-baidu" || $mpPlatform === "mp-toutiao" || $mpPlatform === "mp-xhs"; const doSetByRefs = (refs) => { const mpComponents = ( // 字节小程序 selectAllComponents 可能返回 null diff --git a/packages/uni-mp-vue/src/helpers/vOn.ts b/packages/uni-mp-vue/src/helpers/vOn.ts index 331aecebdf5..422ef3756d4 100644 --- a/packages/uni-mp-vue/src/helpers/vOn.ts +++ b/packages/uni-mp-vue/src/helpers/vOn.ts @@ -27,15 +27,23 @@ export function vOn(value: EventValue | undefined, key?: number | string) { } const ctx = instance.ctx // 微信小程序,QQ小程序,当 setData diff 的时候,若事件不主动同步过去,会导致事件绑定不更新,(question/137217) - const extraKey = + let extraKey = typeof key !== 'undefined' && - (ctx.$mpPlatform === 'mp-weixin' || - ctx.$mpPlatform === 'mp-qq' || - ctx.$mpPlatform === 'mp-xhs') && + (ctx.$mpPlatform === 'mp-weixin' || ctx.$mpPlatform === 'mp-qq') && (isString(key) || typeof key === 'number') ? '_' + key : '' + // 解决小红书平台可能出现自定义组件事件错乱问题 + const needExtraKey = + // @ts-expect-error: ctx.$mpType + ctx.$mpPlatform === 'mp-xhs' && ctx.$mpType === 'component' + const eiCounter = instance.$ei++ + if (needExtraKey) { + // @ts-expect-error: ctx.componentId + extraKey = '_' + ctx.componentId + '_' + eiCounter + } + const name = 'e' + instance.$ei++ + extraKey const mpInstance = ctx.$scope diff --git a/packages/uni-mp-xhs/dist/uni.compiler.js b/packages/uni-mp-xhs/dist/uni.compiler.js index a080d48643e..984346c7d8c 100644 --- a/packages/uni-mp-xhs/dist/uni.compiler.js +++ b/packages/uni-mp-xhs/dist/uni.compiler.js @@ -10,6 +10,59 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } var initMiniProgramPlugin__default = /*#__PURE__*/_interopDefault(initMiniProgramPlugin); var path__default = /*#__PURE__*/_interopDefault(path); +var name = "@dcloudio/uni-mp-xhs"; +var version = "3.0.0-alpha-4010820240517001"; +var description$1 = "uniapp mp-xhs"; +var main = "dist/index.js"; +var files = [ + "dist", + "lib" +]; +var repository = { + type: "git", + url: "git+https://github.com/dcloudio/uni-app.git", + directory: "packages/uni-mp-xhs" +}; +var scripts = { + test: "echo \"Error: no test specified\" && exit 1" +}; +var license = "Apache-2.0"; +var gitHead = "33e807d66e1fe47e2ee08ad9c59247e37b8884da"; +var devDependencies = { + "@dcloudio/uni-mp-weixin": "3.0.0-alpha-4010820240517001", + "@dcloudio/uni-mp-alipay": "3.0.0-alpha-4010820240517001", + "@vue/compiler-core": "3.4.21" +}; +var dependencies = { + "@dcloudio/uni-cli-shared": "3.0.0-alpha-4010820240517001", + "@dcloudio/uni-mp-compiler": "3.0.0-alpha-4010820240517001", + "@dcloudio/uni-mp-vite": "3.0.0-alpha-4010820240517001", + "@dcloudio/uni-mp-vue": "3.0.0-alpha-4010820240517001", + "@dcloudio/uni-shared": "3.0.0-alpha-4010820240517001", + "@vue/shared": "3.4.21" +}; +var packageJson = { + name: name, + version: version, + description: description$1, + main: main, + files: files, + repository: repository, + scripts: scripts, + license: license, + "uni-app": { + name: "mp-xhs", + title: "小红书小程序", + apply: [ + "mp-xhs" + ], + main: "dist/uni.compiler.js" +}, + gitHead: gitHead, + devDependencies: devDependencies, + dependencies: dependencies +}; + var description = "项目配置文件。"; var packOptions = { ignore: [ @@ -73,6 +126,16 @@ const compilerOptions = { directiveTransforms, }; const COMPONENTS_DIR = 'xhscomponents'; +/** + * 收集 Uniapp 框架信息,for 小红书开发者工具埋点上报 + */ +const uniappInfoSource = Object.assign(source, { + framework: { + tool: 'Uniapp', + name: packageJson.name, + version: packageJson.version, + }, +}); const miniProgram = { class: { array: false, @@ -150,7 +213,7 @@ const options = { project: { filename: projectConfigFilename, config: ['project.config.json'], - source, + source: uniappInfoSource, }, template: Object.assign(Object.assign({}, miniProgram), { filter: { extname: '.sjs', diff --git a/packages/uni-mp-xhs/dist/uni.mp.esm.js b/packages/uni-mp-xhs/dist/uni.mp.esm.js index 5d69d994521..777eb6c133e 100644 --- a/packages/uni-mp-xhs/dist/uni.mp.esm.js +++ b/packages/uni-mp-xhs/dist/uni.mp.esm.js @@ -1,5 +1,5 @@ import { SLOT_DEFAULT_NAME, EventChannel, invokeArrayFns, MINI_PROGRAM_PAGE_RUNTIME_HOOKS, ON_LOAD, ON_SHOW, ON_HIDE, ON_UNLOAD, ON_RESIZE, ON_TAB_ITEM_TAP, ON_REACH_BOTTOM, ON_PULL_DOWN_REFRESH, ON_ADD_TO_FAVORITES, isUniLifecycleHook, ON_READY, ON_LAUNCH, ON_ERROR, ON_THEME_CHANGE, ON_PAGE_NOT_FOUND, ON_UNHANDLE_REJECTION, customizeEvent, addLeadingSlash, stringifyQuery } from '@dcloudio/uni-shared'; -import { isArray, isFunction, hasOwn, extend, hyphenate, isPlainObject, isObject } from '@vue/shared'; +import { isArray, hasOwn, isFunction, extend, hyphenate, isPlainObject, isObject } from '@vue/shared'; import { ref, nextTick, findComponentPropsData, toRaw, updateProps, hasQueueJob, invalidateJob, devtoolsComponentAdded, getExposeProxy, pruneComponentPropsCache } from 'vue'; import { normalizeLocale, LOCALE_EN } from '@dcloudio/uni-i18n'; @@ -840,22 +840,6 @@ function initSpecialMethods(mpInstance) { }); } } -function createVueComponent(mpType, mpInstance, vueOptions, parent) { - return $createComponent({ - type: vueOptions, - props: findPropsData(mpInstance.props, mpType === 'page'), - }, { - mpType, - mpInstance, - slots: mpInstance.props.uS || {}, // vueSlots - parentComponent: parent && parent.$, - onBeforeSetup(instance, options) { - initRefs(instance, mpInstance); - initMocks(instance, mpInstance, mocks$1); - initComponentInstance(instance, options); - }, - }); -} function initCreatePage() { return function createPage(vueOptions) { @@ -868,18 +852,30 @@ function initCreatePage() { }; // 初始化 vue 实例 this.props = query; - this.$vm = createVueComponent('page', this, vueOptions); + const mpInstance = this; + this.$vm = $createComponent({ + type: vueOptions, + props: findPropsData(this.props, true), + }, { + mpType: 'page', + mpInstance: this, + slots: this.props.uS || {}, // vueSlots + onBeforeSetup(instance, options) { + initRefs(instance, mpInstance); + initMocks(instance, mpInstance, mocks$1); + initComponentInstance(instance, options); + }, + }); initSpecialMethods(this); - this.$vm.$callHook(ON_LOAD, this.options); + this.$vm.$callHook(ON_LOAD, query); }, onShow() { - this.$vm.$callHook(ON_SHOW); if (__VUE_PROD_DEVTOOLS__) { devtoolsComponentAdded(this.$vm.$); } + this.$vm.$callHook(ON_SHOW); }, onReady() { - // 确保页面自定义组件都被收集到 setTimeout(() => { this.$vm.$callHook('mounted'); this.$vm.$callHook(ON_READY); diff --git a/packages/uni-mp-xhs/src/compiler/options.ts b/packages/uni-mp-xhs/src/compiler/options.ts index ddb42fc891a..22763e4c112 100644 --- a/packages/uni-mp-xhs/src/compiler/options.ts +++ b/packages/uni-mp-xhs/src/compiler/options.ts @@ -7,6 +7,7 @@ import { transformRef, } from '@dcloudio/uni-cli-shared' import type { UniMiniProgramPluginOptions } from '@dcloudio/uni-mp-vite' +import packageJson from '@dcloudio/uni-mp-xhs/package.json' import source from './project.config.json' import { transformOn } from './transforms/vOn' @@ -24,6 +25,17 @@ export const compilerOptions: CompilerOptions = { const COMPONENTS_DIR = 'xhscomponents' +/** + * 收集 Uniapp 框架信息,for 小红书开发者工具埋点上报 + */ +const uniappInfoSource = Object.assign(source, { + framework: { + tool: 'Uniapp', + name: packageJson.name, + version: packageJson.version, + }, +}) + export const miniProgram: MiniProgramCompilerOptions = { class: { array: false, @@ -102,7 +114,7 @@ export const options: UniMiniProgramPluginOptions = { project: { filename: projectConfigFilename, config: ['project.config.json'], - source, + source: uniappInfoSource, }, template: { /* eslint-disable no-restricted-syntax */ diff --git a/packages/uni-mp-xhs/src/runtime/createPage.ts b/packages/uni-mp-xhs/src/runtime/createPage.ts index 458c3c6d86d..011f9eb0e7c 100644 --- a/packages/uni-mp-xhs/src/runtime/createPage.ts +++ b/packages/uni-mp-xhs/src/runtime/createPage.ts @@ -1,15 +1,22 @@ import { + type ComponentInternalInstance, type ComponentOptions, - // @ts-expect-error + // @ts-expect-error: 模块“"vue"”没有导出的成员“devtoolsComponentAdded” devtoolsComponentAdded, } from 'vue' import { + $createComponent, $destroyComponent, + type CreateComponentOptions, PAGE_INIT_HOOKS, + findPropsData, handleEvent, + initComponentInstance, initData, initHooks, + initMocks, + initRefs, initRuntimeHooks, initUnknownHooks, initWxsCallMethods, @@ -24,7 +31,7 @@ import { stringifyQuery, } from '@dcloudio/uni-shared' -import { createVueComponent, handleLink, initSpecialMethods } from './util' +import { handleLink, initSpecialMethods, mocks } from './util' import { extend, isPlainObject } from '@vue/shared' @@ -41,18 +48,36 @@ export function initCreatePage() { } // 初始化 vue 实例 this.props = query - this.$vm = createVueComponent('page', this, vueOptions) + const mpInstance = this + this.$vm = $createComponent( + { + type: vueOptions, + props: findPropsData(this.props, true), + }, + { + mpType: 'page', + mpInstance: this, + slots: this.props.uS || {}, // vueSlots + onBeforeSetup( + instance: ComponentInternalInstance, + options: CreateComponentOptions + ) { + initRefs(instance, mpInstance as any) + initMocks(instance, mpInstance as any, mocks) + initComponentInstance(instance, options) + }, + } + ) initSpecialMethods(this) - this.$vm.$callHook(ON_LOAD, this.options) + this.$vm.$callHook(ON_LOAD, query) }, onShow() { - this.$vm.$callHook(ON_SHOW) if (__VUE_PROD_DEVTOOLS__) { devtoolsComponentAdded(this.$vm.$) } + this.$vm.$callHook(ON_SHOW) }, onReady() { - // 确保页面自定义组件都被收集到 setTimeout(() => { this.$vm.$callHook('mounted') this.$vm.$callHook(ON_READY) diff --git a/packages/uni-shared/dist/uni-shared.cjs.js b/packages/uni-shared/dist/uni-shared.cjs.js index 99932009a46..07705c01db5 100644 --- a/packages/uni-shared/dist/uni-shared.cjs.js +++ b/packages/uni-shared/dist/uni-shared.cjs.js @@ -318,6 +318,8 @@ const ON_UNLOAD = 'onUnload'; const ON_INIT = 'onInit'; // 微信特有 const ON_SAVE_EXIT_STATE = 'onSaveExitState'; +// 小红书特有 +const ON_SHARE_CHAT = 'onShareChat'; const ON_RESIZE = 'onResize'; const ON_BACK_PRESS = 'onBackPress'; const ON_PAGE_SCROLL = 'onPageScroll'; @@ -1405,6 +1407,7 @@ const PAGE_HOOKS = [ ON_PULL_DOWN_REFRESH, ON_SHARE_TIMELINE, ON_SHARE_APP_MESSAGE, + ON_SHARE_CHAT, ON_ADD_TO_FAVORITES, ON_SAVE_EXIT_STATE, ON_NAVIGATION_BAR_BUTTON_TAP, @@ -1447,6 +1450,7 @@ const UniLifecycleHooks = [ ON_SHARE_TIMELINE, ON_ADD_TO_FAVORITES, ON_SHARE_APP_MESSAGE, + ON_SHARE_CHAT, ON_SAVE_EXIT_STATE, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, @@ -1459,6 +1463,7 @@ const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = /*#__PURE__*/ (() => { onPageScroll: 1, onShareAppMessage: 1 << 1, onShareTimeline: 1 << 2, + onShareChat: 1 << 3, }; })(); function isUniLifecycleHook(name, value, checkType = true) { @@ -1678,6 +1683,7 @@ exports.ON_READY = ON_READY; exports.ON_RESIZE = ON_RESIZE; exports.ON_SAVE_EXIT_STATE = ON_SAVE_EXIT_STATE; exports.ON_SHARE_APP_MESSAGE = ON_SHARE_APP_MESSAGE; +exports.ON_SHARE_CHAT = ON_SHARE_CHAT; exports.ON_SHARE_TIMELINE = ON_SHARE_TIMELINE; exports.ON_SHOW = ON_SHOW; exports.ON_TAB_ITEM_TAP = ON_TAB_ITEM_TAP; diff --git a/packages/uni-shared/dist/uni-shared.d.ts b/packages/uni-shared/dist/uni-shared.d.ts index b36705322af..e8579bbff6f 100644 --- a/packages/uni-shared/dist/uni-shared.d.ts +++ b/packages/uni-shared/dist/uni-shared.d.ts @@ -317,6 +317,7 @@ export declare const MINI_PROGRAM_PAGE_RUNTIME_HOOKS: { readonly onPageScroll: 1; readonly onShareAppMessage: number; readonly onShareTimeline: number; + readonly onShareChat: number; }; export declare const NAVBAR_HEIGHT = 44; @@ -512,6 +513,8 @@ export declare const ON_SAVE_EXIT_STATE = "onSaveExitState"; export declare const ON_SHARE_APP_MESSAGE = "onShareAppMessage"; +export declare const ON_SHARE_CHAT = "onShareChat"; + export declare const ON_SHARE_TIMELINE = "onShareTimeline"; export declare const ON_SHOW = "onShow"; @@ -781,7 +784,7 @@ export declare class UniInputElement extends UniElement { set value(val: string | number); } -export declare const UniLifecycleHooks: readonly ["onShow", "onHide", "onLaunch", "onError", "onThemeChange", "onPageNotFound", "onUnhandledRejection", "onExit", "onInit", "onLoad", "onReady", "onUnload", "onResize", "onBackPress", "onPageScroll", "onTabItemTap", "onReachBottom", "onPullDownRefresh", "onShareTimeline", "onAddToFavorites", "onShareAppMessage", "onSaveExitState", "onNavigationBarButtonTap", "onNavigationBarSearchInputClicked", "onNavigationBarSearchInputChanged", "onNavigationBarSearchInputConfirmed", "onNavigationBarSearchInputFocusChanged"]; +export declare const UniLifecycleHooks: readonly ["onShow", "onHide", "onLaunch", "onError", "onThemeChange", "onPageNotFound", "onUnhandledRejection", "onExit", "onInit", "onLoad", "onReady", "onUnload", "onResize", "onBackPress", "onPageScroll", "onTabItemTap", "onReachBottom", "onPullDownRefresh", "onShareTimeline", "onAddToFavorites", "onShareAppMessage", "onShareChat", "onSaveExitState", "onNavigationBarButtonTap", "onNavigationBarSearchInputClicked", "onNavigationBarSearchInputChanged", "onNavigationBarSearchInputConfirmed", "onNavigationBarSearchInputFocusChanged"]; export declare class UniNode extends UniEventTarget { nodeId?: number; diff --git a/packages/uni-shared/dist/uni-shared.es.js b/packages/uni-shared/dist/uni-shared.es.js index 854882b5fbc..8a1a0d1d67b 100644 --- a/packages/uni-shared/dist/uni-shared.es.js +++ b/packages/uni-shared/dist/uni-shared.es.js @@ -316,6 +316,8 @@ const ON_UNLOAD = 'onUnload'; const ON_INIT = 'onInit'; // 微信特有 const ON_SAVE_EXIT_STATE = 'onSaveExitState'; +// 小红书特有 +const ON_SHARE_CHAT = 'onShareChat'; const ON_RESIZE = 'onResize'; const ON_BACK_PRESS = 'onBackPress'; const ON_PAGE_SCROLL = 'onPageScroll'; @@ -1403,6 +1405,7 @@ const PAGE_HOOKS = [ ON_PULL_DOWN_REFRESH, ON_SHARE_TIMELINE, ON_SHARE_APP_MESSAGE, + ON_SHARE_CHAT, ON_ADD_TO_FAVORITES, ON_SAVE_EXIT_STATE, ON_NAVIGATION_BAR_BUTTON_TAP, @@ -1445,6 +1448,7 @@ const UniLifecycleHooks = [ ON_SHARE_TIMELINE, ON_ADD_TO_FAVORITES, ON_SHARE_APP_MESSAGE, + ON_SHARE_CHAT, ON_SAVE_EXIT_STATE, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, @@ -1457,6 +1461,7 @@ const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = /*#__PURE__*/ (() => { onPageScroll: 1, onShareAppMessage: 1 << 1, onShareTimeline: 1 << 2, + onShareChat: 1 << 3, }; })(); function isUniLifecycleHook(name, value, checkType = true) { @@ -1607,4 +1612,4 @@ function getEnvLocale() { return (lang && lang.replace(/[.:].*/, '')) || 'en'; } -export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, BUILT_IN_TAG_NAMES, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, E$1 as Emitter, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, MINI_PROGRAM_PAGE_RUNTIME_HOOKS, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVUE_BUILT_IN_TAGS, NVUE_U_BUILT_IN_TAGS, OFF_THEME_CHANGE, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_EXIT, ON_HIDE, ON_INIT, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_CHANGE, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SAVE_EXIT_STATE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UNI_STORAGE_LOCALE, UNI_UI_CONFLICT_TAGS, UVUE_BUILT_IN_TAGS, UVUE_IOS_BUILT_IN_TAGS, UVUE_WEB_BUILT_IN_TAGS, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, addLeadingSlash, borderStyles, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniEvent, customizeEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultNVueRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatDateTime, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDatasetOnce, invokeArrayFns, invokeCreateErrorHandler, invokeCreateVueAppHook, isAppIOSUVueNativeTag, isAppNVueNativeTag, isAppNativeTag, isAppUVueNativeTag, isBuiltInComponent, isComponentInternalInstance, isComponentTag, isH5CustomElement, isH5NativeTag, isMiniProgramNativeTag, isRootHook, isRootImmediateHook, isRootImmediateHookX, isUniLifecycleHook, isUniXElement, normalizeClass, normalizeDataset, normalizeEventType, normalizeProps, normalizeStyle, normalizeStyles, normalizeTabBarStyles, normalizeTarget, normalizeTitleColor, onCreateVueApp, once, parseEventName, parseNVueDataset, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveComponentInstance, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, sortObject, stringifyQuery, updateElementStyle }; +export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, BUILT_IN_TAG_NAMES, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, E$1 as Emitter, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, MINI_PROGRAM_PAGE_RUNTIME_HOOKS, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVUE_BUILT_IN_TAGS, NVUE_U_BUILT_IN_TAGS, OFF_THEME_CHANGE, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_EXIT, ON_HIDE, ON_INIT, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_CHANGE, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SAVE_EXIT_STATE, ON_SHARE_APP_MESSAGE, ON_SHARE_CHAT, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UNI_STORAGE_LOCALE, UNI_UI_CONFLICT_TAGS, UVUE_BUILT_IN_TAGS, UVUE_IOS_BUILT_IN_TAGS, UVUE_WEB_BUILT_IN_TAGS, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, addLeadingSlash, borderStyles, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniEvent, customizeEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultNVueRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatDateTime, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDatasetOnce, invokeArrayFns, invokeCreateErrorHandler, invokeCreateVueAppHook, isAppIOSUVueNativeTag, isAppNVueNativeTag, isAppNativeTag, isAppUVueNativeTag, isBuiltInComponent, isComponentInternalInstance, isComponentTag, isH5CustomElement, isH5NativeTag, isMiniProgramNativeTag, isRootHook, isRootImmediateHook, isRootImmediateHookX, isUniLifecycleHook, isUniXElement, normalizeClass, normalizeDataset, normalizeEventType, normalizeProps, normalizeStyle, normalizeStyles, normalizeTabBarStyles, normalizeTarget, normalizeTitleColor, onCreateVueApp, once, parseEventName, parseNVueDataset, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveComponentInstance, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, sortObject, stringifyQuery, updateElementStyle }; diff --git a/packages/uni-shared/src/constants.ts b/packages/uni-shared/src/constants.ts index ad9faac0f03..a5243a7f88f 100644 --- a/packages/uni-shared/src/constants.ts +++ b/packages/uni-shared/src/constants.ts @@ -56,6 +56,8 @@ export const ON_UNLOAD = 'onUnload' export const ON_INIT = 'onInit' // 微信特有 export const ON_SAVE_EXIT_STATE = 'onSaveExitState' +// 小红书特有 +export const ON_SHARE_CHAT = 'onShareChat' export const ON_RESIZE = 'onResize' export const ON_BACK_PRESS = 'onBackPress' diff --git a/packages/uni-shared/src/lifecycle.ts b/packages/uni-shared/src/lifecycle.ts index 7f669334a3a..68f765b6ad9 100644 --- a/packages/uni-shared/src/lifecycle.ts +++ b/packages/uni-shared/src/lifecycle.ts @@ -21,6 +21,7 @@ import { ON_RESIZE, ON_SAVE_EXIT_STATE, ON_SHARE_APP_MESSAGE, + ON_SHARE_CHAT, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, @@ -42,6 +43,7 @@ const PAGE_HOOKS = [ ON_PULL_DOWN_REFRESH, ON_SHARE_TIMELINE, ON_SHARE_APP_MESSAGE, + ON_SHARE_CHAT, ON_ADD_TO_FAVORITES, ON_SAVE_EXIT_STATE, ON_NAVIGATION_BAR_BUTTON_TAP, @@ -90,6 +92,7 @@ export const UniLifecycleHooks = [ ON_SHARE_TIMELINE, ON_ADD_TO_FAVORITES, ON_SHARE_APP_MESSAGE, + ON_SHARE_CHAT, ON_SAVE_EXIT_STATE, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, @@ -103,6 +106,7 @@ export const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = /*#__PURE__*/ (() => { onPageScroll: 1, onShareAppMessage: 1 << 1, onShareTimeline: 1 << 2, + onShareChat: 1 << 3, } as const })()