提交 761437f6 编写于 作者: 朱立行

fix(uni-mp-xhs): 修复小红书小程序Page和自定义组件问题

上级 27ead72a
......@@ -11,9 +11,9 @@ describe('mp-xhs: transform component', () => {
)
assert(
`<textarea @input="input"></textarea>`,
`<block xhs:if="{{r0}}"><textarea bindinput="__e" data-e-o="{{a}}"></textarea></block>`,
`<block xhs:if="{{r0}}"><textarea bindinput="{{a}}"></textarea></block>`,
`(_ctx, _cache) => {
return { a: { 'input': _o(_ctx.input) } }
return { a: _o(_ctx.input) }
}`
)
assert(
......@@ -25,9 +25,9 @@ describe('mp-xhs: transform component', () => {
)
assert(
`<textarea v-if="ok1" @input="input"/><textarea v-else-if="ok2"/><textarea v-else @input="input"/>`,
`<textarea xhs:if="{{a}}" bindinput="__e" data-e-o="{{b}}"/><textarea xhs:elif="{{c}}"/><block xhs:else><textarea xhs:if="{{r0}}" bindinput="__e" data-e-o="{{d}}"/></block>`,
`<textarea xhs:if="{{a}}" bindinput="{{b}}"/><textarea xhs:elif="{{c}}"/><block xhs:else><textarea xhs:if="{{r0}}" bindinput="{{d}}"/></block>`,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok1 }, _ctx.ok1 ? { b: { 'input': _o(_ctx.input) } } : _ctx.ok2 ? {} : { d: { 'input': _o(_ctx.input) } }, { c: _ctx.ok2 })
return _e({ a: _ctx.ok1 }, _ctx.ok1 ? { b: _o(_ctx.input) } : _ctx.ok2 ? {} : { d: _o(_ctx.input) }, { c: _ctx.ok2 })
}`
)
})
......@@ -41,23 +41,23 @@ describe('mp-xhs: transform component', () => {
)
assert(
`<editor @ready="ready"/>`,
`<block xhs:if="{{r0}}"><editor bindready="__e" data-e-o="{{a}}"/></block>`,
`<block xhs:if="{{r0}}"><editor bindready="{{a}}"/></block>`,
`(_ctx, _cache) => {
return { a: { 'ready': _o(_ctx.ready) } }
return { a: _o(_ctx.ready) }
}`
)
assert(
`<editor v-if="ok1" @ready="ready"/><editor v-else-if="ok2"/><editor v-else/>`,
`<editor xhs:if="{{a}}" bindready="__e" data-e-o="{{b}}"/><editor xhs:elif="{{c}}"/><editor xhs:else/>`,
`<editor xhs:if="{{a}}" bindready="{{b}}"/><editor xhs:elif="{{c}}"/><editor xhs:else/>`,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok1 }, _ctx.ok1 ? { b: { 'ready': _o(_ctx.ready) } } : _ctx.ok2 ? {} : {}, { c: _ctx.ok2 })
return _e({ a: _ctx.ok1 }, _ctx.ok1 ? { b: _o(_ctx.ready) } : _ctx.ok2 ? {} : {}, { c: _ctx.ok2 })
}`
)
assert(
`<editor v-if="ok1" @ready="ready"/><editor v-else-if="ok2"/><editor v-else @ready="ready"/>`,
`<editor xhs:if="{{a}}" bindready="__e" data-e-o="{{b}}"/><editor xhs:elif="{{c}}"/><block xhs:else><editor xhs:if="{{r0}}" bindready="__e" data-e-o="{{d}}"/></block>`,
`<editor xhs:if="{{a}}" bindready="{{b}}"/><editor xhs:elif="{{c}}"/><block xhs:else><editor xhs:if="{{r0}}" bindready="{{d}}"/></block>`,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok1 }, _ctx.ok1 ? { b: { 'ready': _o(_ctx.ready) } } : _ctx.ok2 ? {} : { d: { 'ready': _o(_ctx.ready) } }, { c: _ctx.ok2 })
return _e({ a: _ctx.ok1 }, _ctx.ok1 ? { b: _o(_ctx.ready) } : _ctx.ok2 ? {} : { d: _o(_ctx.ready) }, { c: _ctx.ok2 })
}`
)
})
......
import { assert } from './testUtils'
describe('mp-xhs: transform v-model', () => {
test(`component v-model`, () => {
assert(
`<Comp v-model="model" />`,
`<comp xhs:if="{{b}}" u-i="2a9ec0b0-0" eO="{{a}}" bindupdateModelValue="__e" u-p="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: _j({ 'updateModelValue': _o($event => _ctx.model = $event) }), b: _p({ modelValue: _ctx.model }) }
}`
)
})
test(`component v-model with cache`, () => {
assert(
`<Comp v-model="model" />`,
`<comp xhs:if="{{b}}" u-i="2a9ec0b0-0" eO="{{a}}" bindupdateModelValue="__e" u-p="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: _j({ 'updateModelValue': _o($event => _ctx.model = $event) }), b: _p({ modelValue: _ctx.model }) }
}`,
{
cacheHandlers: true,
}
)
})
test(`input,textarea v-model`, () => {
assert(
`<input v-model="model" />`,
`<input value="{{a}}" bindinput="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _o($event => _ctx.model = $event.detail.value) }
}`
)
assert(
`<textarea v-model="model" />`,
`<block xhs:if="{{r0}}"><textarea value="{{a}}" bindinput="{{b}}"/></block>`,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _o($event => _ctx.model = $event.detail.value) }
}`
)
})
test(`input v-model + v-on`, () => {
assert(
`<input @input="input" v-model="model" />`,
`<input bindinput="__e" data-e-o="{{a}}" value="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: { 'input': _o([$event => _ctx.model = $event.detail.value, _ctx.input]) }, b: _ctx.model }
}`
)
})
})
import { assert } from './testUtils'
describe('mp-xhs: transform v-on', () => {
describe('component', () => {
test(`built-in event`, () => {
assert(
`<custom @tap="tap"/>`,
`<custom bindtap="__e" u-i="2a9ec0b0-0" eO="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _j({ 'tap': _o(_ctx.tap) }) }
}`
)
})
test(`custom event`, () => {
assert(
`<custom @click="click"/>`,
`<custom bindclick="__e" u-i="2a9ec0b0-0" eO="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _j({ 'click': _o(_ctx.click) }) }
}`
)
}),
test(`multi custom event`, () => {
assert(
`<custom @unmount="unmount" @update:modelValue="changeHandle" @custom-mount="mount();created();"/>`,
`<custom bindunmount="__e" bindupdateModelValue="__e" bindcustomMount="__e" u-i="2a9ec0b0-0" eO="{{a}}"/>`,
`(_ctx, _cache) => {
return { a: _j({ 'unmount': _o(_ctx.unmount), 'updateModelValue': _o(_ctx.changeHandle), 'customMount': _o($event => { _ctx.mount(); _ctx.created(); }) }) }
}`
)
})
})
})
......@@ -4,14 +4,14 @@ describe('compiler: transform v-slot', () => {
test('default slot', () => {
assert(
`<custom><template v-slot/></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view/></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0" bind:__l="__l"><view/></custom>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<custom>test</custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0">test</custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0" bind:__l="__l">test</custom>`,
`(_ctx, _cache) => {
return {}
}`
......@@ -20,14 +20,14 @@ describe('compiler: transform v-slot', () => {
test('named slots', () => {
assert(
`<custom><template v-slot:header/><template v-slot:default/><template v-slot:footer/></custom>`,
`<custom u-s="{{['header','d','footer']}}" u-i="2a9ec0b0-0"><view slot="header"/><view/><view slot="footer"/></custom>`,
`<custom u-s="{{['header','d','footer']}}" u-i="2a9ec0b0-0" bind:__l="__l"><view slot="header"/><view/><view slot="footer"/></custom>`,
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<unicloud-db v-slot:default="{data, loading, error, options}"><view v-if="error">{{error.message}}</view><view v-else></view></unicloud-db>`,
`<unicloud-db u-s="{{['d']}}" u-i="2a9ec0b0-0"><view><block xhs:for="{{a}}" xhs:for-item="v0" xhs:key="c"><view xhs:if="{{v0.a}}">{{v0.b}}</view><view xhs:else></view></block></view></unicloud-db>`,
`<unicloud-db u-s="{{['d']}}" u-i="2a9ec0b0-0" bind:__l="__l"><view><block xhs:for="{{a}}" xhs:for-item="v0" xhs:key="c"><view xhs:if="{{v0.a}}">{{v0.b}}</view><view xhs:else></view></block></view></unicloud-db>`,
`(_ctx, _cache) => {
return { a: _w(({ data, loading, error, options }, s0, i0) => { return _e({ a: error }, error ? { b: _t(error.message) } : {}, { c: i0 }); }, { name: 'd', path: 'a', vueId: '2a9ec0b0-0' }) }
}`
......@@ -37,7 +37,7 @@ describe('compiler: transform v-slot', () => {
test('scoped slots', () => {
assert(
`<custom><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view><block xhs:for="{{a}}" xhs:for-item="slotProps" xhs:key="b"><view>{{slotProps.a}}</view></block></view></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0" bind:__l="__l"><view><block xhs:for="{{a}}" xhs:for-item="slotProps" xhs:key="b"><view>{{slotProps.a}}</view></block></view></custom>`,
`(_ctx, _cache) => {
return { a: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: i0 }; }, { name: 'd', path: 'a', vueId: '2a9ec0b0-0' }) }
}`
......@@ -47,7 +47,7 @@ describe('compiler: transform v-slot', () => {
test('scoped slots + scoped slots', () => {
assert(
`<custom><template v-slot:default="slotProps"><custom1><template v-slot:default="slotProps1">{{ slotProps.item }}{{ slotProps1.item }}</template></custom1></template></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view><block xhs:for="{{a}}" xhs:for-item="slotProps" xhs:key="d"><custom1 u-s="{{['d']}}" u-i="{{slotProps.c}}"><view><block xhs:for="{{slotProps.a}}" xhs:for-item="slotProps1" xhs:key="b">{{slotProps.b}}{{slotProps1.a}}</block></view></custom1></block></view></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0" bind:__l="__l"><view><block xhs:for="{{a}}" xhs:for-item="slotProps" xhs:key="d"><custom1 u-s="{{['d']}}" u-i="{{slotProps.c}}" bind:__l="__l"><view><block xhs:for="{{slotProps.a}}" xhs:for-item="slotProps1" xhs:key="b">{{slotProps.b}}{{slotProps1.a}}</block></view></custom1></block></view></custom>`,
`(_ctx, _cache) => {
return { a: _w((slotProps, s0, i0) => { return { a: _w((slotProps1, s1, i1) => { return { a: _t(slotProps1.item), b: i1 }; }, { name: 'd', path: 'a[' + i0 + '].' + 'a', vueId: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0' }), b: _t(slotProps.item), c: '2a9ec0b0-1' + '-' + i0 + ',' + '2a9ec0b0-0', d: i0 }; }, { name: 'd', path: 'a', vueId: '2a9ec0b0-0' }) }
}`
......@@ -57,7 +57,7 @@ describe('compiler: transform v-slot', () => {
test('v-if + scoped slots', () => {
assert(
`<custom><template v-if="ok" v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0"><view xhs:if="{{a}}"><block xhs:for="{{b}}" xhs:for-item="slotProps" xhs:key="b"><view>{{slotProps.a}}</view></block></view></custom>`,
`<custom u-s="{{['d']}}" u-i="2a9ec0b0-0" bind:__l="__l"><view xhs:if="{{a}}"><block xhs:for="{{b}}" xhs:for-item="slotProps" xhs:key="b"><view>{{slotProps.a}}</view></block></view></custom>`,
`(_ctx, _cache) => {
return _e({ a: _ctx.ok }, _ctx.ok ? { b: _w((slotProps, s0, i0) => { return { a: _t(slotProps.item), b: i0 }; }, { name: 'd', path: 'b', vueId: '2a9ec0b0-0' }) } : {})
}`
......@@ -67,7 +67,7 @@ describe('compiler: transform v-slot', () => {
test('v-for + scoped slots', () => {
assert(
`<custom v-for="item in items"><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom>`,
`<custom xhs:for="{{a}}" xhs:for-item="item" u-s="{{['d']}}" u-i="{{item.b}}"><view><block xhs:for="{{item.a}}" xhs:for-item="slotProps" xhs:key="b"><view>{{slotProps.a}}</view></block></view></custom>`,
`<custom xhs:for="{{a}}" xhs:for-item="item" u-s="{{['d']}}" u-i="{{item.b}}" bind:__l="__l"><view><block xhs:for="{{item.a}}" xhs:for-item="slotProps" xhs:key="b"><view>{{slotProps.a}}</view></block></view></custom>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _w((slotProps, s1, i1) => { return { a: _t(slotProps.item), b: i1 }; }, { name: 'd', path: 'a[' + i0 + '].' + 'a', vueId: '2a9ec0b0-0' + '-' + i0 }), b: '2a9ec0b0-0' + '-' + i0 }; }) }
}`
......@@ -77,7 +77,7 @@ describe('compiler: transform v-slot', () => {
test('v-for + v-for + scoped slots', () => {
assert(
`<view v-for="item in items"><custom v-for="item1 in item.list" :item="item1"><template v-slot:default="slotProps"><view>{{ slotProps.item }}</view></template></custom></view>`,
`<view xhs:for="{{a}}" xhs:for-item="item"><custom xhs:for="{{item.a}}" xhs:for-item="item1" u-s="{{['d']}}" u-i="{{item1.b}}" u-p="{{item1.c}}"><view><block xhs:for="{{item1.a}}" xhs:for-item="slotProps" xhs:key="b"><view>{{slotProps.a}}</view></block></view></custom></view>`,
`<view xhs:for="{{a}}" xhs:for-item="item"><custom xhs:for="{{item.a}}" xhs:for-item="item1" u-s="{{['d']}}" u-i="{{item1.b}}" bind:__l="__l" u-p="{{item1.c}}"><view><block xhs:for="{{item1.a}}" xhs:for-item="slotProps" xhs:key="b"><view>{{slotProps.a}}</view></block></view></custom></view>`,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: _f(item.list, (item1, k1, i1) => { return { a: _w((slotProps, s2, i2) => { return { a: _t(slotProps.item), b: i2 }; }, { name: 'd', path: 'a[' + i0 + '].' + ('a[' + i1 + '].') + 'a', vueId: '2a9ec0b0-0' + '-' + i0 + '-' + i1 }), b: '2a9ec0b0-0' + '-' + i0 + '-' + i1, c: _p({ item: item1 }) }; }) }; }) }
}`
......
......@@ -3,7 +3,6 @@
var uniCliShared = require('@dcloudio/uni-cli-shared');
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var path = require('path');
var uniMpCompiler = require('@dcloudio/uni-mp-compiler');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
......@@ -60,30 +59,9 @@ var source = {
condition: condition
};
/**
* 小红书小程序的Page和自定义组件,不支持动态事件绑定,需要通过__e转发
*/
const transformOn = uniCliShared.createTransformOn(uniMpCompiler.transformOn, {
match: (name, node, context) => {
return true;
},
});
/**
* 小红书小程序的自定义组件,不支持动态事件绑定,故 v-model 也需要调整
*/
const transformModel = uniCliShared.createTransformModel(uniMpCompiler.transformModel);
const directiveTransforms = {
on: transformOn,
model: transformModel,
};
const directiveTransforms = {};
const compilerOptions = {
nodeTransforms: [
uniCliShared.transformRef,
// transformComponentLink,
uniCliShared.transformMatchMedia,
],
nodeTransforms: [uniCliShared.transformRef, uniCliShared.transformComponentLink, uniCliShared.transformMatchMedia],
directiveTransforms,
};
const COMPONENTS_DIR = 'xhscomponents';
......@@ -166,18 +144,11 @@ const options = {
config: ['project.config.json'],
source,
},
template: Object.assign(Object.assign({}, miniProgram), { filter:
// undefined,
{
template: Object.assign(Object.assign({}, miniProgram), { filter: {
extname: '.sjs',
lang: 'sjs',
generate(filter, filename) {
if (filename) {
return `<import-sjs src="${filename}.sjs" module="${filter.name}"/>`;
}
return `<import-sjs module="${filter.name}">
${filter.code}
</import-sjs>`;
return `<sjs src="${filename}.sjs" module="${filter.name}"/>`;
},
}, extname: '.xhsml', compilerOptions }),
style: {
......
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, isString } from '@vue/shared';
import { ref, nextTick, findComponentPropsData, toRaw, updateProps, hasQueueJob, invalidateJob, devtoolsComponentAdded, getExposeProxy, pruneComponentPropsCache, EMPTY_OBJ, isRef, setTemplateRef } from 'vue';
import { isArray, isFunction, hasOwn, 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';
const MP_METHODS = [
......@@ -830,53 +830,6 @@ function initSpecialMethods(mpInstance) {
});
}
}
function handleRef(ref) {
if (!ref) {
return;
}
const refName = ref.props.uR; // data-ref
const refInForName = ref.props.uRIF; // data-ref-in-for
if (!refName && !refInForName) {
return;
}
const instance = this.$vm.$;
const refs = instance.refs === EMPTY_OBJ ? (instance.refs = {}) : instance.refs;
const { setupState } = instance;
const refValue = ref.$vm;
if (refName) {
if (isString(refName)) {
refs[refName] = refValue;
if (hasOwn(setupState, refName)) {
setupState[refName] = refValue;
}
}
else {
setRef(refName, refValue, refs, setupState);
}
}
else if (refInForName) {
if (isString(refInForName)) {
(refs[refInForName] || (refs[refInForName] = [])).push(refValue);
}
else {
setRef(refInForName, refValue, refs, setupState);
}
}
}
function isTemplateRef(opts) {
return !!(opts && opts.r);
}
function setRef(ref, refValue, refs, setupState) {
if (isRef(ref)) {
ref.value = refValue;
}
else if (isFunction(ref)) {
const templateRef = ref(refValue, refs);
if (isTemplateRef(templateRef)) {
setTemplateRef(templateRef, refValue, setupState);
}
}
}
function createVueComponent(mpType, mpInstance, vueOptions, parent) {
return $createComponent({
type: vueOptions,
......@@ -907,21 +860,21 @@ function initCreatePage() {
this.props = query;
},
onShow() {
if (this.$vm) {
this.$vm.$callHook(ON_SHOW);
}
if (__VUE_PROD_DEVTOOLS__) {
devtoolsComponentAdded(this.$vm.$);
}
},
onReady() {
this.$vm = createVueComponent("page", this, vueOptions);
this.$vm.$callHook("mounted");
this.$vm = createVueComponent('page', this, vueOptions);
this.$vm.$callHook('mounted');
this.$vm.$callHook(ON_LOAD, this.options);
initSpecialMethods(this);
if (this.$vm) {
this.$vm.$callHook(ON_SHOW);
}
},
onReady() {
setTimeout(() => {
this.$vm.$callHook(ON_READY);
});
}, 50);
},
onUnload() {
if (this.$vm) {
......@@ -929,16 +882,8 @@ function initCreatePage() {
$destroyComponent(this.$vm);
}
},
__r: handleRef,
__l: handleLink,
__e: function (event) {
var _a, _b;
const { currentTarget: { dataset }, } = event;
dataset['eO'] = Object.assign(Object.assign({}, dataset['eO']), { tap: ((_a = dataset['eO']) === null || _a === void 0 ? void 0 : _a.tap) || ((_b = dataset['eO']) === null || _b === void 0 ? void 0 : _b.click) });
// console.log('触发了page事件', event)
// @ts-ignore
return handleEvent.call(this, event);
},
__e: handleEvent,
};
if (isPlainObject(vueOptions.events)) {
extend(pageOptions.events, vueOptions.events);
......@@ -959,23 +904,12 @@ function isPage(mpInstance) {
return !!mpInstance.route;
}
function initRelation(mpInstance, detail) {
// 小红书自定义组件从customEventMap取事件名
mpInstance.customEventMap = {
// @ts-ignore
__l: '__l',
};
mpInstance.triggerEvent('__l', detail);
}
function parse(componentOptions) {
const methods = componentOptions.methods;
methods.__e = function (event) {
var _a, _b;
const { currentTarget: { dataset }, } = event;
dataset['eO'] = Object.assign(Object.assign({}, dataset['eO']), { tap: ((_a = dataset['eO']) === null || _a === void 0 ? void 0 : _a.tap) || ((_b = dataset['eO']) === null || _b === void 0 ? void 0 : _b.click) });
// console.log('触发了component事件', event)
// @ts-ignore
return handleEvent.call(this, event);
};
methods.__e = handleEvent;
methods.__l = handleLink;
}
var parseComponentOptions = /*#__PURE__*/Object.freeze({
......
import path from 'path'
import type { CompilerOptions } from '@vue/compiler-core'
import {
// COMPONENT_CUSTOM_HIDDEN,
// copyMiniProgramPluginJson,
// copyMiniProgramThemeJson,
MiniProgramCompilerOptions,
// transformComponentLink,
transformComponentLink,
transformMatchMedia,
transformRef,
} from '@dcloudio/uni-cli-shared'
import { UniMiniProgramPluginOptions } from '@dcloudio/uni-mp-vite'
import source from './project.config.json'
import { transformOn } from './transforms/vOn'
import { transformModel } from './transforms/vModel'
const directiveTransforms = {
on: transformOn,
model: transformModel,
}
const directiveTransforms = {}
export const compilerOptions: CompilerOptions = {
nodeTransforms: [
transformRef,
// transformComponentLink,
transformMatchMedia,
],
nodeTransforms: [transformRef, transformComponentLink, transformMatchMedia],
directiveTransforms,
}
......@@ -114,20 +102,13 @@ export const options: UniMiniProgramPluginOptions = {
template: {
/* eslint-disable no-restricted-syntax */
...miniProgram,
filter:
// undefined,
{
extname: '.sjs',
lang: 'sjs',
generate(filter, filename) {
if (filename) {
return `<import-sjs src="${filename}.sjs" module="${filter.name}"/>`
}
return `<import-sjs module="${filter.name}">
${filter.code}
</import-sjs>`
},
filter: {
extname: '.sjs',
lang: 'sjs',
generate(filter, filename) {
return `<sjs src="${filename}.sjs" module="${filter.name}"/>`
},
},
extname: '.xhsml',
compilerOptions,
},
......
import { createTransformModel } from '@dcloudio/uni-cli-shared'
import { transformModel as baseTransformModel } from '@dcloudio/uni-mp-compiler'
/**
* 小红书小程序的自定义组件,不支持动态事件绑定,故 v-model 也需要调整
*/
export const transformModel = createTransformModel(baseTransformModel)
import { createTransformOn } from '@dcloudio/uni-cli-shared'
import { transformOn as baseTransformOn } from '@dcloudio/uni-mp-compiler'
/**
* 小红书小程序的Page和自定义组件,不支持动态事件绑定,需要通过__e转发
*/
export const transformOn = createTransformOn(baseTransformOn, {
match: (name, node, context) => {
return true
},
})
......@@ -24,12 +24,7 @@ import {
stringifyQuery,
} from '@dcloudio/uni-shared'
import {
handleRef,
handleLink,
initSpecialMethods,
createVueComponent,
} from './util'
import { handleLink, initSpecialMethods, createVueComponent } from './util'
import { extend, isPlainObject } from '@vue/shared'
......@@ -48,21 +43,21 @@ export function initCreatePage() {
this.props = query
},
onShow() {
if (this.$vm) {
this.$vm.$callHook(ON_SHOW)
}
if (__VUE_PROD_DEVTOOLS__) {
devtoolsComponentAdded(this.$vm.$)
}
},
onReady() {
this.$vm = createVueComponent('page', this, vueOptions)
this.$vm.$callHook('mounted')
this.$vm.$callHook(ON_LOAD, this.options)
initSpecialMethods(this)
if (this.$vm) {
this.$vm.$callHook(ON_SHOW)
}
},
onReady() {
setTimeout(() => {
this.$vm.$callHook(ON_READY)
})
}, 50)
},
onUnload() {
if (this.$vm) {
......@@ -70,21 +65,8 @@ export function initCreatePage() {
$destroyComponent(this.$vm)
}
},
__r: handleRef,
__l: handleLink,
__e: function (event: any) {
const {
currentTarget: { dataset },
} = event
dataset['eO'] = {
// eslint-disable-next-line no-restricted-syntax
...dataset['eO'],
tap: dataset['eO']?.tap || dataset['eO']?.click,
}
// console.log('触发了page事件', event)
// @ts-ignore
return handleEvent.call(this, event)
},
__e: handleEvent,
}
if (isPlainObject(vueOptions.events)) {
extend(pageOptions.events!, vueOptions.events)
......
......@@ -3,8 +3,7 @@ import {
MPComponentOptions,
handleEvent,
} from '@dcloudio/uni-mp-core'
// import { handleLink } from '@dcloudio/uni-mp-weixin'
import { handleLink } from '@dcloudio/uni-mp-weixin'
export { handleLink, initLifetimes } from '@dcloudio/uni-mp-weixin'
......@@ -18,11 +17,6 @@ export function initRelation(
mpInstance: MPComponentInstance,
detail: Record<string, unknown>
) {
// 小红书自定义组件从customEventMap取事件名
mpInstance.customEventMap = {
// @ts-ignore
__l: '__l',
}
mpInstance.triggerEvent('__l', detail)
}
export function parse(componentOptions: MPComponentOptions) {
......@@ -30,17 +24,6 @@ export function parse(componentOptions: MPComponentOptions) {
string,
(...args: any[]) => any
>
methods.__e = function (event: any) {
const {
currentTarget: { dataset },
} = event
dataset['eO'] = {
// eslint-disable-next-line no-restricted-syntax
...dataset['eO'],
tap: dataset['eO']?.tap || dataset['eO']?.click,
}
// console.log('触发了component事件', event)
// @ts-ignore
return handleEvent.call(this, event)
}
methods.__e = handleEvent
methods.__l = handleLink
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册