Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

小红书平台 Feature & Bugfix #4926

Open
wants to merge 5 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/uni-app/dist/uni-app.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions packages/uni-app/dist/uni-app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,38 @@ declare type onSaveExitStateHook = () => SaveExitState;

export declare const onShareAppMessage: (hook: (options: Page.ShareAppMessageOption) => Page.CustomShareContent | Promise<Omit<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<any>;
/**
* 好友分享的内容描述
* @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;
Expand Down
6 changes: 4 additions & 2 deletions packages/uni-app/dist/uni-app.es.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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 };
46 changes: 46 additions & 0 deletions packages/uni-app/src/apiLifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<any>
/**
* 好友分享的内容描述
* @default 默认取小程序描述
*/
content?: string
}) => void
}

export const onShareChat =
/*#__PURE__*/ createHook<Required<XhsPageInstance>['onShareChat']>(
ON_SHARE_CHAT
)

export const onNavigationBarButtonTap = /*#__PURE__*/ createHook<
Required<Page.PageInstance>['onNavigationBarButtonTap']
>(ON_NAVIGATION_BAR_BUTTON_TAP)
Expand Down
16 changes: 11 additions & 5 deletions packages/uni-mp-vue/dist/vue.runtime.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-vue/lib/vue.runtime.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions packages/uni-mp-vue/src/helpers/vOn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 64 additions & 1 deletion packages/uni-mp-xhs/dist/uni.compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down
38 changes: 17 additions & 21 deletions packages/uni-mp-xhs/dist/uni.mp.esm.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion packages/uni-mp-xhs/src/compiler/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
Expand Down Expand Up @@ -102,7 +114,7 @@ export const options: UniMiniProgramPluginOptions = {
project: {
filename: projectConfigFilename,
config: ['project.config.json'],
source,
source: uniappInfoSource,
},
template: {
/* eslint-disable no-restricted-syntax */
Expand Down
Loading
Loading