Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
41bdae3f
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
718
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
41bdae3f
编写于
3月 18, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(runtime): mp-weixin $parent ,$children
上级
6d6bdf84
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
274 addition
and
133 deletion
+274
-133
packages/uni-mp-baidu/dist/index.js
packages/uni-mp-baidu/dist/index.js
+57
-37
packages/uni-mp-baidu/package.json
packages/uni-mp-baidu/package.json
+1
-1
packages/uni-mp-toutiao/dist/index.js
packages/uni-mp-toutiao/dist/index.js
+59
-25
packages/uni-mp-toutiao/package.json
packages/uni-mp-toutiao/package.json
+1
-1
packages/uni-mp-weixin/dist/index.js
packages/uni-mp-weixin/dist/index.js
+44
-25
packages/uni-mp-weixin/package.json
packages/uni-mp-weixin/package.json
+1
-1
src/core/runtime/wrapper/create-app.js
src/core/runtime/wrapper/create-app.js
+1
-3
src/core/runtime/wrapper/create-component.js
src/core/runtime/wrapper/create-component.js
+17
-19
src/core/runtime/wrapper/create-page.js
src/core/runtime/wrapper/create-page.js
+5
-2
src/core/runtime/wrapper/util.js
src/core/runtime/wrapper/util.js
+15
-19
src/platforms/mp-baidu/runtime/wrapper/index.js
src/platforms/mp-baidu/runtime/wrapper/index.js
+28
-0
src/platforms/mp-toutiao/runtime/wrapper/index.js
src/platforms/mp-toutiao/runtime/wrapper/index.js
+30
-0
src/platforms/mp-weixin/runtime/wrapper/index.js
src/platforms/mp-weixin/runtime/wrapper/index.js
+15
-0
未找到文件。
packages/uni-mp-baidu/dist/index.js
浏览文件 @
41bdae3f
...
...
@@ -432,7 +432,21 @@ function createObserver (name) {
}
function
getProperties
(
props
)
{
const
properties
=
{};
const
properties
=
{
vueSlots
:
{
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
type
:
null
,
value
:
[],
observer
:
function
(
newVal
,
oldVal
)
{
const
$slots
=
Object
.
create
(
null
);
newVal
.
forEach
(
slotName
=>
{
$slots
[
slotName
]
=
true
;
});
this
.
setData
({
$slots
});
}
}
};
if
(
Array
.
isArray
(
props
))
{
// ['title']
props
.
forEach
(
key
=>
{
properties
[
key
]
=
{
...
...
@@ -540,10 +554,6 @@ function handleEvent (event) {
});
}
function
handleLink
(
event
)
{
event
.
detail
.
$parent
=
this
.
$vm
;
}
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
...
...
@@ -567,20 +577,6 @@ function initRefs (vm) {
});
}
function
initChildren
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
Object
.
defineProperty
(
vm
,
'
$children
'
,
{
get
()
{
const
$children
=
[];
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-com
'
);
components
.
forEach
(
component
=>
{
$children
.
push
(
component
.
$vm
);
});
return
$children
}
});
}
function
baiduComponentDestroy
(
$vm
)
{
$vm
.
$children
.
forEach
(
childVm
=>
{
childVm
.
$mp
.
component
.
detached
();
...
...
@@ -621,7 +617,6 @@ function createApp (vueOptions) {
if
(
this
.
mpType
!==
'
app
'
)
{
initRefs
(
this
);
initMocks
(
this
);
initChildren
(
this
);
}
}
});
...
...
@@ -645,6 +640,35 @@ function createApp (vueOptions) {
return
vueOptions
}
function
triggerLink
(
mpInstance
)
{
const
baiduComponentInstances
=
mpInstance
.
pageinstance
.
$baiduComponentInstances
;
baiduComponentInstances
[
mpInstance
.
id
]
=
mpInstance
;
if
(
mpInstance
.
ownerId
)
{
// 组件嵌组件
const
parentBaiduComponentInstance
=
baiduComponentInstances
[
mpInstance
.
ownerId
];
if
(
parentBaiduComponentInstance
)
{
handleLink
.
call
(
parentBaiduComponentInstance
,
{
detail
:
mpInstance
});
}
else
{
console
.
error
(
`查找父组件失败
${
mpInstance
.
ownerId
}
`
);
}
}
else
{
// 页面直属组件
handleLink
.
call
(
mpInstance
.
pageinstance
,
{
detail
:
mpInstance
});
}
}
function
handleLink
(
event
)
{
if
(
!
event
.
detail
.
$parent
)
{
event
.
detail
.
$parent
=
this
.
$vm
;
event
.
detail
.
$parent
.
$children
.
push
(
event
.
detail
);
event
.
detail
.
$root
=
this
.
$vm
.
$root
;
}
}
const
hooks$1
=
[
'
onShow
'
,
'
onHide
'
,
...
...
@@ -679,7 +703,7 @@ function createPage (vueOptions) {
this
.
$vm
.
__call_hook
(
'
onLoad
'
,
args
);
},
onReady
()
{
this
.
$vm
.
_isMounted
=
true
;
this
.
$vm
.
_isMounted
=
true
;
this
.
$vm
.
__call_hook
(
'
mounted
'
);
this
.
$vm
.
__call_hook
(
'
onReady
'
);
},
...
...
@@ -698,7 +722,7 @@ function createPage (vueOptions) {
return
Page
(
pageOptions
)
}
function
initVueComponent
(
mpInstace
,
VueComponent
)
{
function
initVueComponent
(
mpInstace
,
VueComponent
)
{
if
(
mpInstace
.
$vm
)
{
return
}
...
...
@@ -711,6 +735,16 @@ function initVueComponent (mpInstace, VueComponent) {
// 初始化 vue 实例
mpInstace
.
$vm
=
new
VueComponent
(
options
);
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
const
vueSlots
=
mpInstace
.
properties
.
vueSlots
;
if
(
Array
.
isArray
(
vueSlots
)
&&
vueSlots
.
length
)
{
const
$slots
=
Object
.
create
(
null
);
vueSlots
.
forEach
(
slotName
=>
{
$slots
[
slotName
]
=
true
;
});
mpInstace
.
$vm
.
$scopedSlots
=
mpInstace
.
$vm
.
$slots
=
$slots
;
}
// 初始化渲染数据
mpInstace
.
$vm
.
$mount
();
}
...
...
@@ -736,21 +770,7 @@ function createComponent (vueOptions) {
ready
()
{
initVueComponent
(
this
,
VueComponent
);
// 目前发现部分情况小程序 attached 不触发
{
const
baiduComponentInstances
=
this
.
pageinstance
.
$baiduComponentInstances
;
baiduComponentInstances
[
this
.
id
]
=
this
;
if
(
this
.
ownerId
)
{
// 组件嵌组件
const
parentBaiduComponentInstance
=
baiduComponentInstances
[
this
.
ownerId
];
if
(
parentBaiduComponentInstance
)
{
this
.
$vm
.
$parent
=
parentBaiduComponentInstance
.
$vm
;
}
else
{
console
.
error
(
`查找父组件失败
${
this
.
ownerId
}
`
);
}
}
else
{
// 页面直属组件
this
.
$vm
.
$parent
=
this
.
pageinstance
.
$vm
;
}
}
triggerLink
(
this
);
const
eventId
=
this
.
dataset
.
eventId
;
if
(
eventId
)
{
...
...
packages/uni-mp-baidu/package.json
浏览文件 @
41bdae3f
{
"name"
:
"@dcloudio/uni-mp-baidu"
,
"version"
:
"0.0.80
6
"
,
"version"
:
"0.0.80
9
"
,
"description"
:
"uni-app mp-baidu"
,
"main"
:
"dist/index.js"
,
"scripts"
:
{
...
...
packages/uni-mp-toutiao/dist/index.js
浏览文件 @
41bdae3f
...
...
@@ -477,7 +477,21 @@ function createObserver (name) {
}
function
getProperties
(
props
)
{
const
properties
=
{};
const
properties
=
{
vueSlots
:
{
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
type
:
null
,
value
:
[],
observer
:
function
(
newVal
,
oldVal
)
{
const
$slots
=
Object
.
create
(
null
);
newVal
.
forEach
(
slotName
=>
{
$slots
[
slotName
]
=
true
;
});
this
.
setData
({
$slots
});
}
}
};
if
(
Array
.
isArray
(
props
))
{
// ['title']
props
.
forEach
(
key
=>
{
properties
[
key
]
=
{
...
...
@@ -579,10 +593,6 @@ function handleEvent (event) {
});
}
function
handleLink
(
event
)
{
event
.
detail
.
$parent
=
this
.
$vm
;
}
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
...
...
@@ -604,20 +614,6 @@ function initRefs (vm) {
return
$refs
}
});
}
function
initChildren
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
Object
.
defineProperty
(
vm
,
'
$children
'
,
{
get
()
{
const
$children
=
[];
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-com
'
);
components
.
forEach
(
component
=>
{
$children
.
push
(
component
.
$vm
);
});
return
$children
}
});
}
const
hooks
=
[
...
...
@@ -646,7 +642,6 @@ function createApp (vueOptions) {
if
(
this
.
mpType
!==
'
app
'
)
{
initRefs
(
this
);
initMocks
(
this
);
initChildren
(
this
);
}
}
});
...
...
@@ -670,6 +665,37 @@ function createApp (vueOptions) {
return
vueOptions
}
const
instances
=
Object
.
create
(
null
);
function
triggerLink
(
mpInstance
)
{
const
nodeId
=
mpInstance
.
__nodeid__
+
''
;
const
webviewId
=
mpInstance
.
__webviewId__
+
''
;
instances
[
webviewId
+
'
_
'
+
nodeId
]
=
mpInstance
.
$vm
;
mpInstance
.
triggerEvent
(
'
__l
'
,
{
nodeId
,
webviewId
},
{
bubbles
:
true
,
composed
:
true
});
}
// TODO 目前有 bug,composed 不生效
function
handleLink
(
event
)
{
const
nodeId
=
event
.
detail
.
nodeId
;
const
webviewId
=
event
.
detail
.
webviewId
;
const
childVm
=
instances
[
webviewId
+
'
_
'
+
nodeId
];
if
(
childVm
)
{
childVm
.
$parent
=
this
.
$vm
;
childVm
.
$parent
.
$children
.
push
(
event
.
detail
);
childVm
.
$root
=
this
.
$vm
.
$root
;
delete
instances
[
webviewId
+
'
_
'
+
nodeId
];
}
}
const
hooks$1
=
[
'
onShow
'
,
'
onHide
'
,
...
...
@@ -701,7 +727,7 @@ function createPage (vueOptions) {
this
.
$vm
.
__call_hook
(
'
onLoad
'
,
args
);
},
onReady
()
{
this
.
$vm
.
_isMounted
=
true
;
this
.
$vm
.
_isMounted
=
true
;
this
.
$vm
.
__call_hook
(
'
mounted
'
);
this
.
$vm
.
__call_hook
(
'
onReady
'
);
},
...
...
@@ -720,7 +746,7 @@ function createPage (vueOptions) {
return
Page
(
pageOptions
)
}
function
initVueComponent
(
mpInstace
,
VueComponent
)
{
function
initVueComponent
(
mpInstace
,
VueComponent
)
{
if
(
mpInstace
.
$vm
)
{
return
}
...
...
@@ -733,6 +759,16 @@ function initVueComponent (mpInstace, VueComponent) {
// 初始化 vue 实例
mpInstace
.
$vm
=
new
VueComponent
(
options
);
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
const
vueSlots
=
mpInstace
.
properties
.
vueSlots
;
if
(
Array
.
isArray
(
vueSlots
)
&&
vueSlots
.
length
)
{
const
$slots
=
Object
.
create
(
null
);
vueSlots
.
forEach
(
slotName
=>
{
$slots
[
slotName
]
=
true
;
});
mpInstace
.
$vm
.
$scopedSlots
=
mpInstace
.
$vm
.
$slots
=
$slots
;
}
// 初始化渲染数据
mpInstace
.
$vm
.
$mount
();
}
...
...
@@ -758,9 +794,7 @@ function createComponent (vueOptions) {
ready
()
{
initVueComponent
(
this
,
VueComponent
);
// 目前发现部分情况小程序 attached 不触发
{
this
.
triggerEvent
(
'
__l
'
,
this
.
$vm
);
// TODO 百度仅能传递 json 对象
}
triggerLink
(
this
);
const
eventId
=
this
.
dataset
.
eventId
;
if
(
eventId
)
{
...
...
packages/uni-mp-toutiao/package.json
浏览文件 @
41bdae3f
{
"name"
:
"@dcloudio/uni-mp-toutiao"
,
"version"
:
"0.0.30
3
"
,
"version"
:
"0.0.30
5
"
,
"description"
:
"uni-app mp-toutiao"
,
"main"
:
"dist/index.js"
,
"scripts"
:
{
...
...
packages/uni-mp-weixin/dist/index.js
浏览文件 @
41bdae3f
...
...
@@ -319,7 +319,21 @@ function createObserver (name) {
}
function
getProperties
(
props
)
{
const
properties
=
{};
const
properties
=
{
vueSlots
:
{
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
type
:
null
,
value
:
[],
observer
:
function
(
newVal
,
oldVal
)
{
const
$slots
=
Object
.
create
(
null
);
newVal
.
forEach
(
slotName
=>
{
$slots
[
slotName
]
=
true
;
});
this
.
setData
({
$slots
});
}
}
};
if
(
Array
.
isArray
(
props
))
{
// ['title']
props
.
forEach
(
key
=>
{
properties
[
key
]
=
{
...
...
@@ -421,10 +435,6 @@ function handleEvent (event) {
});
}
function
handleLink
(
event
)
{
event
.
detail
.
$parent
=
this
.
$vm
;
}
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
...
...
@@ -446,20 +456,6 @@ function initRefs (vm) {
return
$refs
}
});
}
function
initChildren
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
Object
.
defineProperty
(
vm
,
'
$children
'
,
{
get
()
{
const
$children
=
[];
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-com
'
);
components
.
forEach
(
component
=>
{
$children
.
push
(
component
.
$vm
);
});
return
$children
}
});
}
const
hooks
=
[
...
...
@@ -488,7 +484,6 @@ function createApp (vueOptions) {
if
(
this
.
mpType
!==
'
app
'
)
{
initRefs
(
this
);
initMocks
(
this
);
initChildren
(
this
);
}
}
});
...
...
@@ -512,6 +507,22 @@ function createApp (vueOptions) {
return
vueOptions
}
function
triggerLink
(
mpInstance
)
{
mpInstance
.
triggerEvent
(
'
__l
'
,
mpInstance
.
$vm
,
{
bubbles
:
true
,
composed
:
true
});
}
function
handleLink
(
event
)
{
if
(
!
event
.
detail
.
$parent
)
{
event
.
detail
.
$parent
=
this
.
$vm
;
event
.
detail
.
$parent
.
$children
.
push
(
event
.
detail
);
event
.
detail
.
$root
=
this
.
$vm
.
$root
;
}
}
const
hooks$1
=
[
'
onShow
'
,
'
onHide
'
,
...
...
@@ -543,7 +554,7 @@ function createPage (vueOptions) {
this
.
$vm
.
__call_hook
(
'
onLoad
'
,
args
);
},
onReady
()
{
this
.
$vm
.
_isMounted
=
true
;
this
.
$vm
.
_isMounted
=
true
;
this
.
$vm
.
__call_hook
(
'
mounted
'
);
this
.
$vm
.
__call_hook
(
'
onReady
'
);
},
...
...
@@ -562,7 +573,7 @@ function createPage (vueOptions) {
return
Page
(
pageOptions
)
}
function
initVueComponent
(
mpInstace
,
VueComponent
)
{
function
initVueComponent
(
mpInstace
,
VueComponent
)
{
if
(
mpInstace
.
$vm
)
{
return
}
...
...
@@ -575,6 +586,16 @@ function initVueComponent (mpInstace, VueComponent) {
// 初始化 vue 实例
mpInstace
.
$vm
=
new
VueComponent
(
options
);
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
const
vueSlots
=
mpInstace
.
properties
.
vueSlots
;
if
(
Array
.
isArray
(
vueSlots
)
&&
vueSlots
.
length
)
{
const
$slots
=
Object
.
create
(
null
);
vueSlots
.
forEach
(
slotName
=>
{
$slots
[
slotName
]
=
true
;
});
mpInstace
.
$vm
.
$scopedSlots
=
mpInstace
.
$vm
.
$slots
=
$slots
;
}
// 初始化渲染数据
mpInstace
.
$vm
.
$mount
();
}
...
...
@@ -600,9 +621,7 @@ function createComponent (vueOptions) {
ready
()
{
initVueComponent
(
this
,
VueComponent
);
// 目前发现部分情况小程序 attached 不触发
{
this
.
triggerEvent
(
'
__l
'
,
this
.
$vm
);
// TODO 百度仅能传递 json 对象
}
triggerLink
(
this
);
const
eventId
=
this
.
dataset
.
eventId
;
if
(
eventId
)
{
...
...
packages/uni-mp-weixin/package.json
浏览文件 @
41bdae3f
{
"name"
:
"@dcloudio/uni-mp-weixin"
,
"version"
:
"0.0.90
7
"
,
"version"
:
"0.0.90
9
"
,
"description"
:
"uni-app mp-weixin"
,
"main"
:
"dist/index.js"
,
"scripts"
:
{
...
...
src/core/runtime/wrapper/create-app.js
浏览文件 @
41bdae3f
...
...
@@ -3,8 +3,7 @@ import Vue from 'vue'
import
{
initRefs
,
initHooks
,
initMocks
,
initChildren
initMocks
}
from
'
./util
'
const
hooks
=
[
...
...
@@ -33,7 +32,6 @@ export function createApp (vueOptions) {
if
(
this
.
mpType
!==
'
app
'
)
{
initRefs
(
this
)
initMocks
(
this
)
initChildren
(
this
)
}
}
})
...
...
src/core/runtime/wrapper/create-component.js
浏览文件 @
41bdae3f
import
Vue
from
'
vue
'
import
{
getData
,
handleLink
,
triggerLink
}
from
'
uni-platform/runtime/wrapper/index
'
import
{
getData
,
handleEvent
,
getProperties
}
from
'
./util
'
function
initVueComponent
(
mpInstace
,
VueComponent
)
{
function
initVueComponent
(
mpInstace
,
VueComponent
)
{
if
(
mpInstace
.
$vm
)
{
return
}
...
...
@@ -20,6 +24,16 @@ function initVueComponent (mpInstace, VueComponent) {
// 初始化 vue 实例
mpInstace
.
$vm
=
new
VueComponent
(
options
)
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
const
vueSlots
=
mpInstace
.
properties
.
vueSlots
if
(
Array
.
isArray
(
vueSlots
)
&&
vueSlots
.
length
)
{
const
$slots
=
Object
.
create
(
null
)
vueSlots
.
forEach
(
slotName
=>
{
$slots
[
slotName
]
=
true
})
mpInstace
.
$vm
.
$scopedSlots
=
mpInstace
.
$vm
.
$slots
=
$slots
}
// 初始化渲染数据
mpInstace
.
$vm
.
$mount
()
}
...
...
@@ -45,23 +59,7 @@ export function createComponent (vueOptions) {
ready
()
{
initVueComponent
(
this
,
VueComponent
)
// 目前发现部分情况小程序 attached 不触发
if
(
__PLATFORM__
===
'
mp-baidu
'
)
{
const
baiduComponentInstances
=
this
.
pageinstance
.
$baiduComponentInstances
baiduComponentInstances
[
this
.
id
]
=
this
if
(
this
.
ownerId
)
{
// 组件嵌组件
const
parentBaiduComponentInstance
=
baiduComponentInstances
[
this
.
ownerId
]
if
(
parentBaiduComponentInstance
)
{
this
.
$vm
.
$parent
=
parentBaiduComponentInstance
.
$vm
}
else
{
console
.
error
(
`查找父组件失败
${
this
.
ownerId
}
`
)
}
}
else
{
// 页面直属组件
this
.
$vm
.
$parent
=
this
.
pageinstance
.
$vm
}
}
else
{
this
.
triggerEvent
(
'
__l
'
,
this
.
$vm
)
// TODO 百度仅能传递 json 对象
}
triggerLink
(
this
)
const
eventId
=
this
.
dataset
.
eventId
if
(
eventId
)
{
...
...
src/core/runtime/wrapper/create-page.js
浏览文件 @
41bdae3f
import
Vue
from
'
vue
'
import
{
handleLink
}
from
'
uni-platform/runtime/wrapper/index
'
import
{
getData
,
initHooks
,
handleLink
,
handleEvent
,
baiduPageDestroy
}
from
'
./util
'
...
...
@@ -42,7 +45,7 @@ export function createPage (vueOptions) {
this
.
$vm
.
__call_hook
(
'
onLoad
'
,
args
)
},
onReady
()
{
this
.
$vm
.
_isMounted
=
true
this
.
$vm
.
_isMounted
=
true
this
.
$vm
.
__call_hook
(
'
mounted
'
)
this
.
$vm
.
__call_hook
(
'
onReady
'
)
},
...
...
src/core/runtime/wrapper/util.js
浏览文件 @
41bdae3f
...
...
@@ -56,7 +56,21 @@ function createObserver (name) {
}
export
function
getProperties
(
props
)
{
const
properties
=
{}
const
properties
=
{
vueSlots
:
{
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
type
:
null
,
value
:
[],
observer
:
function
(
newVal
,
oldVal
)
{
const
$slots
=
Object
.
create
(
null
)
newVal
.
forEach
(
slotName
=>
{
$slots
[
slotName
]
=
true
})
this
.
setData
({
$slots
})
}
}
}
if
(
Array
.
isArray
(
props
))
{
// ['title']
props
.
forEach
(
key
=>
{
properties
[
key
]
=
{
...
...
@@ -164,10 +178,6 @@ export function handleEvent (event) {
})
}
export
function
handleLink
(
event
)
{
event
.
detail
.
$parent
=
this
.
$vm
}
export
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
]
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
...
...
@@ -191,20 +201,6 @@ export function initRefs (vm) {
})
}
export
function
initChildren
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
]
Object
.
defineProperty
(
vm
,
'
$children
'
,
{
get
()
{
const
$children
=
[]
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-com
'
)
components
.
forEach
(
component
=>
{
$children
.
push
(
component
.
$vm
)
})
return
$children
}
})
}
function
baiduComponentDestroy
(
$vm
)
{
$vm
.
$children
.
forEach
(
childVm
=>
{
childVm
.
$mp
.
component
.
detached
()
...
...
src/platforms/mp-baidu/runtime/wrapper/index.js
0 → 100644
浏览文件 @
41bdae3f
export
function
triggerLink
(
mpInstance
)
{
const
baiduComponentInstances
=
mpInstance
.
pageinstance
.
$baiduComponentInstances
baiduComponentInstances
[
mpInstance
.
id
]
=
mpInstance
if
(
mpInstance
.
ownerId
)
{
// 组件嵌组件
const
parentBaiduComponentInstance
=
baiduComponentInstances
[
mpInstance
.
ownerId
]
if
(
parentBaiduComponentInstance
)
{
handleLink
.
call
(
parentBaiduComponentInstance
,
{
detail
:
mpInstance
})
}
else
{
console
.
error
(
`查找父组件失败
${
mpInstance
.
ownerId
}
`
)
}
}
else
{
// 页面直属组件
handleLink
.
call
(
mpInstance
.
pageinstance
,
{
detail
:
mpInstance
})
}
}
export
function
handleLink
(
event
)
{
if
(
!
event
.
detail
.
$parent
)
{
event
.
detail
.
$parent
=
this
.
$vm
event
.
detail
.
$parent
.
$children
.
push
(
event
.
detail
)
event
.
detail
.
$root
=
this
.
$vm
.
$root
}
}
src/platforms/mp-toutiao/runtime/wrapper/index.js
0 → 100644
浏览文件 @
41bdae3f
const
instances
=
Object
.
create
(
null
)
export
function
triggerLink
(
mpInstance
)
{
const
nodeId
=
mpInstance
.
__nodeid__
+
''
const
webviewId
=
mpInstance
.
__webviewId__
+
''
instances
[
webviewId
+
'
_
'
+
nodeId
]
=
mpInstance
.
$vm
mpInstance
.
triggerEvent
(
'
__l
'
,
{
nodeId
,
webviewId
},
{
bubbles
:
true
,
composed
:
true
})
}
// TODO 目前有 bug,composed 不生效
export
function
handleLink
(
event
)
{
const
nodeId
=
event
.
detail
.
nodeId
const
webviewId
=
event
.
detail
.
webviewId
const
childVm
=
instances
[
webviewId
+
'
_
'
+
nodeId
]
if
(
childVm
)
{
childVm
.
$parent
=
this
.
$vm
childVm
.
$parent
.
$children
.
push
(
event
.
detail
)
childVm
.
$root
=
this
.
$vm
.
$root
delete
instances
[
webviewId
+
'
_
'
+
nodeId
]
}
}
src/platforms/mp-weixin/runtime/wrapper/index.js
0 → 100644
浏览文件 @
41bdae3f
export
function
triggerLink
(
mpInstance
)
{
mpInstance
.
triggerEvent
(
'
__l
'
,
mpInstance
.
$vm
,
{
bubbles
:
true
,
composed
:
true
})
}
export
function
handleLink
(
event
)
{
if
(
!
event
.
detail
.
$parent
)
{
event
.
detail
.
$parent
=
this
.
$vm
event
.
detail
.
$parent
.
$children
.
push
(
event
.
detail
)
event
.
detail
.
$root
=
this
.
$vm
.
$root
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录