Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
761437f6
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
761437f6
编写于
8月 17, 2023
作者:
朱
朱立行
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(uni-mp-xhs): 修复小红书小程序Page和自定义组件问题
上级
27ead72a
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
56 addition
and
304 deletion
+56
-304
packages/uni-mp-xhs/__tests__/component.spec.ts
packages/uni-mp-xhs/__tests__/component.spec.ts
+10
-10
packages/uni-mp-xhs/__tests__/vModel.spec.ts
packages/uni-mp-xhs/__tests__/vModel.spec.ts
+0
-50
packages/uni-mp-xhs/__tests__/vOn.spec.ts
packages/uni-mp-xhs/__tests__/vOn.spec.ts
+0
-33
packages/uni-mp-xhs/__tests__/vSlot.spec.ts
packages/uni-mp-xhs/__tests__/vSlot.spec.ts
+9
-9
packages/uni-mp-xhs/dist/uni.compiler.js
packages/uni-mp-xhs/dist/uni.compiler.js
+4
-33
packages/uni-mp-xhs/dist/uni.mp.esm.js
packages/uni-mp-xhs/dist/uni.mp.esm.js
+13
-79
packages/uni-mp-xhs/src/compiler/options.ts
packages/uni-mp-xhs/src/compiler/options.ts
+9
-28
packages/uni-mp-xhs/src/compiler/transforms/vModel.ts
packages/uni-mp-xhs/src/compiler/transforms/vModel.ts
+0
-6
packages/uni-mp-xhs/src/compiler/transforms/vOn.ts
packages/uni-mp-xhs/src/compiler/transforms/vOn.ts
+0
-10
packages/uni-mp-xhs/src/runtime/createPage.ts
packages/uni-mp-xhs/src/runtime/createPage.ts
+8
-26
packages/uni-mp-xhs/src/runtime/parseComponentOptions.ts
packages/uni-mp-xhs/src/runtime/parseComponentOptions.ts
+3
-20
未找到文件。
packages/uni-mp-xhs/__tests__/component.spec.ts
浏览文件 @
761437f6
...
...
@@ -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 })
}`
)
})
...
...
packages/uni-mp-xhs/__tests__/vModel.spec.ts
已删除
100644 → 0
浏览文件 @
27ead72a
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 }
}`
)
})
})
packages/uni-mp-xhs/__tests__/vOn.spec.ts
已删除
100644 → 0
浏览文件 @
27ead72a
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(); }) }) }
}`
)
})
})
})
packages/uni-mp-xhs/__tests__/vSlot.spec.ts
浏览文件 @
761437f6
...
...
@@ -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 }) }; }) }; }) }
}`
...
...
packages/uni-mp-xhs/dist/uni.compiler.js
浏览文件 @
761437f6
...
...
@@ -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
:
{
...
...
packages/uni-mp-xhs/dist/uni.mp.esm.js
浏览文件 @
761437f6
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
({
...
...
packages/uni-mp-xhs/src/compiler/options.ts
浏览文件 @
761437f6
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
,
},
...
...
packages/uni-mp-xhs/src/compiler/transforms/vModel.ts
已删除
100644 → 0
浏览文件 @
27ead72a
import
{
createTransformModel
}
from
'
@dcloudio/uni-cli-shared
'
import
{
transformModel
as
baseTransformModel
}
from
'
@dcloudio/uni-mp-compiler
'
/**
* 小红书小程序的自定义组件,不支持动态事件绑定,故 v-model 也需要调整
*/
export
const
transformModel
=
createTransformModel
(
baseTransformModel
)
packages/uni-mp-xhs/src/compiler/transforms/vOn.ts
已删除
100644 → 0
浏览文件 @
27ead72a
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
},
})
packages/uni-mp-xhs/src/runtime/createPage.ts
浏览文件 @
761437f6
...
...
@@ -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
)
...
...
packages/uni-mp-xhs/src/runtime/parseComponentOptions.ts
浏览文件 @
761437f6
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录