Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoderSmallfan
uni-app
提交
39f98c73
U
uni-app
项目概览
CoderSmallfan
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
39f98c73
编写于
4月 24, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
build uni runtime(mp-alipay usingComponents)
上级
ac4bd265
变更
21
展开全部
显示空白变更内容
内联
并排
Showing
21 changed file
with
1540 addition
and
310 deletion
+1540
-310
packages/uni-app-plus/dist/index.js
packages/uni-app-plus/dist/index.js
+60
-53
packages/uni-app-plus/package.json
packages/uni-app-plus/package.json
+1
-1
packages/uni-mp-alipay/dist/index.js
packages/uni-mp-alipay/dist/index.js
+922
-21
packages/uni-mp-alipay/package.json
packages/uni-mp-alipay/package.json
+1
-1
packages/uni-mp-baidu/dist/index.js
packages/uni-mp-baidu/dist/index.js
+69
-61
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
+54
-47
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
+66
-48
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
+30
-8
src/core/runtime/wrapper/create-component.js
src/core/runtime/wrapper/create-component.js
+20
-8
src/core/runtime/wrapper/create-page.js
src/core/runtime/wrapper/create-page.js
+1
-3
src/core/runtime/wrapper/util.js
src/core/runtime/wrapper/util.js
+7
-26
src/platforms/app-plus/runtime/wrapper/index.js
src/platforms/app-plus/runtime/wrapper/index.js
+5
-2
src/platforms/mp-alipay/runtime/wrapper/deep-equal.js
src/platforms/mp-alipay/runtime/wrapper/deep-equal.js
+52
-0
src/platforms/mp-alipay/runtime/wrapper/index.js
src/platforms/mp-alipay/runtime/wrapper/index.js
+191
-0
src/platforms/mp-baidu/runtime/wrapper/index.js
src/platforms/mp-baidu/runtime/wrapper/index.js
+8
-1
src/platforms/mp-toutiao/runtime/wrapper/index.js
src/platforms/mp-toutiao/runtime/wrapper/index.js
+15
-14
src/platforms/mp-weixin/runtime/index.js
src/platforms/mp-weixin/runtime/index.js
+6
-9
src/platforms/mp-weixin/runtime/wrapper/index.js
src/platforms/mp-weixin/runtime/wrapper/index.js
+29
-4
未找到文件。
packages/uni-app-plus/dist/index.js
浏览文件 @
39f98c73
...
...
@@ -282,8 +282,7 @@ function initTriggerEvent (mpInstance) {
};
}
Page
=
function
(
options
=
{})
{
const
name
=
'
onLoad
'
;
function
initHook
(
name
,
options
)
{
const
oldHook
=
options
[
name
];
if
(
!
oldHook
)
{
options
[
name
]
=
function
()
{
...
...
@@ -295,22 +294,45 @@ Page = function (options = {}) {
return
oldHook
.
apply
(
this
,
args
)
};
}
}
Page
=
function
(
options
=
{})
{
initHook
(
'
onLoad
'
,
options
);
return
MPPage
(
options
)
};
const
behavior
=
Behavior
({
created
()
{
initTriggerEvent
(
this
);
}
});
Component
=
function
(
options
=
{})
{
(
options
.
behaviors
||
(
options
.
behaviors
=
[])).
unshift
(
behavior
);
initHook
(
'
created
'
,
options
);
return
MPComponent
(
options
)
};
const
mocks
=
[
'
__route__
'
,
'
__wxExparserNodeId__
'
,
'
__wxWebviewId__
'
];
function
initBehavior
(
options
)
{
return
Behavior
(
options
)
}
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$scope
;
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
get
()
{
const
$refs
=
{};
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
);
components
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
);
forComponents
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
;
if
(
!
$refs
[
ref
])
{
$refs
[
ref
]
=
[];
}
$refs
[
ref
].
push
(
component
.
$vm
||
component
);
});
return
$refs
}
});
}
function
triggerLink
(
mpInstance
,
vueOptions
)
{
mpInstance
.
triggerEvent
(
'
__l
'
,
mpInstance
.
$vm
||
vueOptions
,
{
bubbles
:
true
,
...
...
@@ -334,18 +356,19 @@ function handleLink (event) {
}
function
initPage$1
(
pageOptions
)
{
initComponent$1
(
pageOptions
);
return
initComponent$1
(
pageOptions
)
}
function
initComponent$1
(
componentOptions
)
{
componentOptions
.
methods
.
$getAppWebview
=
function
()
{
return
plus
.
webview
.
getWebviewById
(
`
${
this
.
__wxWebviewId__
}
`
)
};
return
Component
(
componentOptions
)
}
function
initMocks
(
vm
,
mocks
)
{
function
initMocks
(
vm
,
mocks
$$1
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
mocks
.
forEach
(
mock
=>
{
mocks
$$1
.
forEach
(
mock
=>
{
if
(
hasOwn
(
mpInstance
,
mock
))
{
vm
[
mock
]
=
mpInstance
[
mock
];
}
...
...
@@ -430,7 +453,7 @@ function getBehaviors (vueOptions) {
}
if
(
isPlainObject
(
vueExtends
)
&&
vueExtends
.
props
)
{
behaviors
.
push
(
Behavior
({
init
Behavior
({
properties
:
getProperties
(
vueExtends
.
props
,
true
)
})
);
...
...
@@ -439,7 +462,7 @@ function getBehaviors (vueOptions) {
vueMixins
.
forEach
(
vueMixin
=>
{
if
(
isPlainObject
(
vueMixin
)
&&
vueMixin
.
props
)
{
behaviors
.
push
(
Behavior
({
init
Behavior
({
properties
:
getProperties
(
vueMixin
.
props
,
true
)
})
);
...
...
@@ -707,29 +730,6 @@ function handleEvent (event) {
});
}
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
get
()
{
const
$refs
=
{};
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
);
components
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
);
forComponents
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
;
if
(
!
$refs
[
ref
])
{
$refs
[
ref
]
=
[];
}
$refs
[
ref
].
push
(
component
.
$vm
||
component
);
});
return
$refs
}
});
}
const
hooks
=
[
'
onHide
'
,
'
onError
'
,
...
...
@@ -750,24 +750,27 @@ function initVm (vm) {
}
function
createApp
(
vm
)
{
// 外部初始化时 Vue 还未初始化,放到 createApp 内部初始化 mixin
Vue
.
mixin
({
beforeCreate
()
{
if
(
!
this
.
$options
.
mpType
)
{
return
}
this
.
mpType
=
this
.
$options
.
mpType
;
this
.
$mp
=
{
data
:
{},
[
this
.
mpType
]:
this
.
$options
.
mpInstance
};
this
.
$scope
=
this
.
$options
.
mpInstance
;
delete
this
.
$options
.
mpType
;
delete
this
.
$options
.
mpInstance
;
if
(
this
.
mpType
!==
'
app
'
)
{
{
// 头条的 selectComponent 竟然是异步的
initRefs
(
this
);
}
initMocks
(
this
,
mocks
);
}
},
...
...
@@ -878,9 +881,7 @@ function createPage (vueOptions) {
initHooks
(
pageOptions
.
methods
,
hooks$1
);
initPage$1
(
pageOptions
);
return
Component
(
pageOptions
)
return
initPage$1
(
pageOptions
,
vueOptions
)
}
function
initVm$2
(
VueComponent
)
{
...
...
@@ -888,16 +889,18 @@ function initVm$2 (VueComponent) {
return
}
const
properties
=
this
.
properties
;
const
options
=
{
mpType
:
'
component
'
,
mpInstance
:
this
,
propsData
:
this
.
properties
propsData
:
properties
};
// 初始化 vue 实例
this
.
$vm
=
new
VueComponent
(
options
);
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
const
vueSlots
=
this
.
properties
.
vueSlots
;
const
vueSlots
=
properties
.
vueSlots
;
if
(
Array
.
isArray
(
vueSlots
)
&&
vueSlots
.
length
)
{
const
$slots
=
Object
.
create
(
null
);
vueSlots
.
forEach
(
slotName
=>
{
...
...
@@ -913,12 +916,18 @@ function initVm$2 (VueComponent) {
function
createComponent
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
;
let
VueComponent
;
if
(
isFn
(
vueOptions
))
{
VueComponent
=
vueOptions
;
// TODO form-field props.name,props.value
vueOptions
=
VueComponent
.
extendOptions
;
}
else
{
VueComponent
=
Vue
.
extend
(
vueOptions
);
}
const
behaviors
=
getBehaviors
(
vueOptions
);
const
properties
=
getProperties
(
vueOptions
.
props
,
false
,
vueOptions
.
__file
);
const
VueComponent
=
Vue
.
extend
(
vueOptions
);
const
componentOptions
=
{
options
:
{
multipleSlots
:
true
,
...
...
@@ -963,9 +972,7 @@ function createComponent (vueOptions) {
}
};
initComponent$1
(
componentOptions
);
return
Component
(
componentOptions
)
return
initComponent$1
(
componentOptions
,
vueOptions
)
}
let
uni
=
{};
...
...
packages/uni-app-plus/package.json
浏览文件 @
39f98c73
{
"name"
:
"@dcloudio/uni-app-plus"
,
"version"
:
"0.0.2
29
"
,
"version"
:
"0.0.2
30
"
,
"description"
:
"uni-app app-plus"
,
"main"
:
"dist/index.js"
,
"scripts"
:
{
...
...
packages/uni-mp-alipay/dist/index.js
浏览文件 @
39f98c73
此差异已折叠。
点击以展开。
packages/uni-mp-alipay/package.json
浏览文件 @
39f98c73
{
"name"
:
"@dcloudio/uni-mp-alipay"
,
"version"
:
"0.0.8"
,
"version"
:
"0.0.8
01
"
,
"description"
:
"uni-app mp-alipay"
,
"main"
:
"dist/index.js"
,
"scripts"
:
{
...
...
packages/uni-mp-baidu/dist/index.js
浏览文件 @
39f98c73
...
...
@@ -417,8 +417,7 @@ function initTriggerEvent (mpInstance) {
};
}
Page
=
function
(
options
=
{})
{
const
name
=
'
onLoad
'
;
function
initHook
(
name
,
options
)
{
const
oldHook
=
options
[
name
];
if
(
!
oldHook
)
{
options
[
name
]
=
function
()
{
...
...
@@ -430,37 +429,62 @@ Page = function (options = {}) {
return
oldHook
.
apply
(
this
,
args
)
};
}
}
Page
=
function
(
options
=
{})
{
initHook
(
'
onLoad
'
,
options
);
return
MPPage
(
options
)
};
const
behavior
=
Behavior
({
created
()
{
initTriggerEvent
(
this
);
}
});
Component
=
function
(
options
=
{})
{
(
options
.
behaviors
||
(
options
.
behaviors
=
[])).
unshift
(
behavior
);
initHook
(
'
created
'
,
options
);
return
MPComponent
(
options
)
};
const
mocks
=
[
'
nodeId
'
];
function
initBehavior
(
options
)
{
return
Behavior
(
options
)
}
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$scope
;
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
get
()
{
const
$refs
=
{};
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
);
components
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
);
forComponents
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
;
if
(
!
$refs
[
ref
])
{
$refs
[
ref
]
=
[];
}
$refs
[
ref
].
push
(
component
.
$vm
||
component
);
});
return
$refs
}
});
}
const
mocks$1
=
[
'
nodeId
'
];
function
initPage
(
pageOptions
)
{
initComponent
(
pageOptions
);
function
initPage
$1
(
pageOptions
)
{
return
initComponent$1
(
pageOptions
)
}
function
initComponent
(
componentOptions
)
{
function
initComponent
$1
(
componentOptions
)
{
componentOptions
.
messages
=
{
'
__l
'
:
handleLink
'
__l
'
:
handleLink
$1
};
return
Component
(
componentOptions
)
}
function
triggerLink
(
mpInstance
,
vueOptions
)
{
function
triggerLink
$1
(
mpInstance
,
vueOptions
)
{
mpInstance
.
dispatch
(
'
__l
'
,
mpInstance
.
$vm
||
vueOptions
);
}
function
handleLink
(
event
)
{
function
handleLink
$1
(
event
)
{
const
target
=
event
.
value
;
if
(
target
.
$mp
)
{
if
(
!
target
.
$parent
)
{
...
...
@@ -563,7 +587,7 @@ function getBehaviors (vueOptions) {
}
if
(
isPlainObject
(
vueExtends
)
&&
vueExtends
.
props
)
{
behaviors
.
push
(
Behavior
({
init
Behavior
({
properties
:
getProperties
(
vueExtends
.
props
,
true
)
})
);
...
...
@@ -572,7 +596,7 @@ function getBehaviors (vueOptions) {
vueMixins
.
forEach
(
vueMixin
=>
{
if
(
isPlainObject
(
vueMixin
)
&&
vueMixin
.
props
)
{
behaviors
.
push
(
Behavior
({
init
Behavior
({
properties
:
getProperties
(
vueMixin
.
props
,
true
)
})
);
...
...
@@ -866,29 +890,6 @@ function handleEvent (event) {
});
}
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
get
()
{
const
$refs
=
{};
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
);
components
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
);
forComponents
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
;
if
(
!
$refs
[
ref
])
{
$refs
[
ref
]
=
[];
}
$refs
[
ref
].
push
(
component
.
$vm
||
component
);
});
return
$refs
}
});
}
function
baiduComponentDestroy
(
$vm
)
{
$vm
.
$children
.
forEach
(
childVm
=>
{
childVm
.
$mp
.
component
.
detached
();
...
...
@@ -923,25 +924,28 @@ function initVm (vm) {
}
function
createApp
(
vm
)
{
// 外部初始化时 Vue 还未初始化,放到 createApp 内部初始化 mixin
Vue
.
mixin
({
beforeCreate
()
{
if
(
!
this
.
$options
.
mpType
)
{
return
}
this
.
mpType
=
this
.
$options
.
mpType
;
this
.
$mp
=
{
data
:
{},
[
this
.
mpType
]:
this
.
$options
.
mpInstance
};
this
.
$scope
=
this
.
$options
.
mpInstance
;
delete
this
.
$options
.
mpType
;
delete
this
.
$options
.
mpInstance
;
if
(
this
.
mpType
!==
'
app
'
)
{
{
// 头条的 selectComponent 竟然是异步的
initRefs
(
this
);
}
initMocks
(
this
,
mocks
);
initMocks
(
this
,
mocks$1
);
}
},
created
()
{
// 处理 injections
...
...
@@ -1055,15 +1059,13 @@ function createPage (vueOptions) {
}
},
__e
:
handleEvent
,
__l
:
handleLink
__l
:
handleLink
$1
}
};
initHooks
(
pageOptions
.
methods
,
hooks$1
);
initPage
(
pageOptions
);
return
Component
(
pageOptions
)
return
initPage$1
(
pageOptions
,
vueOptions
)
}
function
initVm$2
(
VueComponent
)
{
...
...
@@ -1071,16 +1073,18 @@ function initVm$2 (VueComponent) {
return
}
const
properties
=
this
.
properties
;
const
options
=
{
mpType
:
'
component
'
,
mpInstance
:
this
,
propsData
:
this
.
properties
propsData
:
properties
};
// 初始化 vue 实例
this
.
$vm
=
new
VueComponent
(
options
);
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
const
vueSlots
=
this
.
properties
.
vueSlots
;
const
vueSlots
=
properties
.
vueSlots
;
if
(
Array
.
isArray
(
vueSlots
)
&&
vueSlots
.
length
)
{
const
$slots
=
Object
.
create
(
null
);
vueSlots
.
forEach
(
slotName
=>
{
...
...
@@ -1096,12 +1100,18 @@ function initVm$2 (VueComponent) {
function
createComponent
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
;
let
VueComponent
;
if
(
isFn
(
vueOptions
))
{
VueComponent
=
vueOptions
;
// TODO form-field props.name,props.value
vueOptions
=
VueComponent
.
extendOptions
;
}
else
{
VueComponent
=
Vue
.
extend
(
vueOptions
);
}
const
behaviors
=
getBehaviors
(
vueOptions
);
const
properties
=
getProperties
(
vueOptions
.
props
,
false
,
vueOptions
.
__file
);
const
VueComponent
=
Vue
.
extend
(
vueOptions
);
const
componentOptions
=
{
options
:
{
multipleSlots
:
true
,
...
...
@@ -1116,7 +1126,7 @@ function createComponent (vueOptions) {
},
ready
()
{
initVm$2
.
call
(
this
,
VueComponent
);
// 目前发现部分情况小程序 attached 不触发
triggerLink
(
this
);
// 处理 parent,children
triggerLink
$1
(
this
);
// 处理 parent,children
// 补充生命周期
this
.
$vm
.
__call_hook
(
'
created
'
);
...
...
@@ -1142,13 +1152,11 @@ function createComponent (vueOptions) {
},
methods
:
{
__e
:
handleEvent
,
__l
:
handleLink
__l
:
handleLink
$1
}
};
initComponent
(
componentOptions
);
return
Component
(
componentOptions
)
return
initComponent$1
(
componentOptions
,
vueOptions
)
}
let
uni
=
{};
...
...
packages/uni-mp-baidu/package.json
浏览文件 @
39f98c73
{
"name"
:
"@dcloudio/uni-mp-baidu"
,
"version"
:
"0.0.82
6
"
,
"version"
:
"0.0.82
7
"
,
"description"
:
"uni-app mp-baidu"
,
"main"
:
"dist/index.js"
,
"scripts"
:
{
...
...
packages/uni-mp-toutiao/dist/index.js
浏览文件 @
39f98c73
...
...
@@ -462,8 +462,7 @@ function initTriggerEvent (mpInstance) {
};
}
Page
=
function
(
options
=
{})
{
const
name
=
'
onLoad
'
;
function
initHook
(
name
,
options
)
{
const
oldHook
=
options
[
name
];
if
(
!
oldHook
)
{
options
[
name
]
=
function
()
{
...
...
@@ -475,62 +474,60 @@ Page = function (options = {}) {
return
oldHook
.
apply
(
this
,
args
)
};
}
}
Page
=
function
(
options
=
{})
{
initHook
(
'
onLoad
'
,
options
);
return
MPPage
(
options
)
};
const
behavior
=
Behavior
({
created
()
{
initTriggerEvent
(
this
);
}
});
Component
=
function
(
options
=
{})
{
(
options
.
behaviors
||
(
options
.
behaviors
=
[])).
unshift
(
behavior
);
initHook
(
'
created
'
,
options
);
return
MPComponent
(
options
)
};
function
initBehavior
(
options
)
{
return
Behavior
(
options
)
}
const
instances
=
Object
.
create
(
null
);
const
mocks
=
[
'
__route__
'
,
'
__webviewId__
'
,
'
__nodeid__
'
];
const
mocks
$1
=
[
'
__route__
'
,
'
__webviewId__
'
,
'
__nodeid__
'
];
function
initPage
(
pageOptions
)
{
initComponent
(
pageOptions
);
function
initPage
$1
(
pageOptions
)
{
return
initComponent$1
(
pageOptions
)
}
function
initComponent
(
componentOptions
)
{
function
initComponent
$1
(
componentOptions
)
{
if
(
componentOptions
.
properties
)
{
// ref
componentOptions
.
properties
.
vueRef
=
{
type
:
String
,
value
:
''
};
}
const
oldAttached
=
componentOptions
.
lifetimes
.
attached
;
componentOptions
.
lifetimes
.
attached
=
function
()
{
oldAttached
.
call
(
this
);
// TODO 需要处理动态变化后的 refs
initRefs
.
call
(
this
);
};
return
Component
(
componentOptions
)
}
function
initRefs
()
{
this
.
selectAllComponents
(
'
.vue-ref
'
,
(
components
)
=>
{
function
initRefs$1
(
vm
)
{
const
mpInstance
=
vm
.
$scope
;
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
,
(
components
)
=>
{
components
.
forEach
(
component
=>
{
const
ref
=
component
.
data
.
vueRef
;
// 头条的组件 dataset 竟然是空的
this
.
$
vm
.
$refs
[
ref
]
=
component
.
$vm
||
component
;
vm
.
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
});
this
.
selectAllComponents
(
'
.vue-ref-in-for
'
,
(
forComponents
)
=>
{
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
,
(
forComponents
)
=>
{
forComponents
.
forEach
(
component
=>
{
const
ref
=
component
.
data
.
vueRef
;
if
(
!
this
.
$
vm
.
$refs
[
ref
])
{
this
.
$
vm
.
$refs
[
ref
]
=
[];
if
(
!
vm
.
$refs
[
ref
])
{
vm
.
$refs
[
ref
]
=
[];
}
this
.
$
vm
.
$refs
[
ref
].
push
(
component
.
$vm
||
component
);
vm
.
$refs
[
ref
].
push
(
component
.
$vm
||
component
);
});
});
}
function
triggerLink
(
mpInstance
)
{
function
triggerLink
$1
(
mpInstance
)
{
const
nodeId
=
mpInstance
.
__nodeid__
+
''
;
const
webviewId
=
mpInstance
.
__webviewId__
+
''
;
...
...
@@ -545,7 +542,7 @@ function triggerLink (mpInstance) {
});
}
// TODO 目前有 bug,composed 不生效
function
handleLink
(
event
)
{
function
handleLink
$1
(
event
)
{
const
nodeId
=
event
.
detail
.
nodeId
;
const
webviewId
=
event
.
detail
.
webviewId
;
...
...
@@ -647,7 +644,7 @@ function getBehaviors (vueOptions) {
}
if
(
isPlainObject
(
vueExtends
)
&&
vueExtends
.
props
)
{
behaviors
.
push
(
Behavior
({
init
Behavior
({
properties
:
getProperties
(
vueExtends
.
props
,
true
)
})
);
...
...
@@ -656,7 +653,7 @@ function getBehaviors (vueOptions) {
vueMixins
.
forEach
(
vueMixin
=>
{
if
(
isPlainObject
(
vueMixin
)
&&
vueMixin
.
props
)
{
behaviors
.
push
(
Behavior
({
init
Behavior
({
properties
:
getProperties
(
vueMixin
.
props
,
true
)
})
);
...
...
@@ -944,22 +941,28 @@ function initVm (vm) {
}
function
createApp
(
vm
)
{
// 外部初始化时 Vue 还未初始化,放到 createApp 内部初始化 mixin
Vue
.
mixin
({
beforeCreate
()
{
if
(
!
this
.
$options
.
mpType
)
{
return
}
this
.
mpType
=
this
.
$options
.
mpType
;
this
.
$mp
=
{
data
:
{},
[
this
.
mpType
]:
this
.
$options
.
mpInstance
};
this
.
$scope
=
this
.
$options
.
mpInstance
;
delete
this
.
$options
.
mpType
;
delete
this
.
$options
.
mpInstance
;
if
(
this
.
mpType
!==
'
app
'
)
{
initMocks
(
this
,
mocks
);
initRefs$1
(
this
);
initMocks
(
this
,
mocks$1
);
}
},
created
()
{
// 处理 injections
...
...
@@ -1063,15 +1066,13 @@ function createPage (vueOptions) {
this
.
$vm
.
__call_hook
(
'
onUnload
'
);
},
__e
:
handleEvent
,
__l
:
handleLink
__l
:
handleLink
$1
}
};
initHooks
(
pageOptions
.
methods
,
hooks$1
);
initPage
(
pageOptions
);
return
Component
(
pageOptions
)
return
initPage$1
(
pageOptions
,
vueOptions
)
}
function
initVm$2
(
VueComponent
)
{
...
...
@@ -1079,16 +1080,18 @@ function initVm$2 (VueComponent) {
return
}
const
properties
=
this
.
properties
;
const
options
=
{
mpType
:
'
component
'
,
mpInstance
:
this
,
propsData
:
this
.
properties
propsData
:
properties
};
// 初始化 vue 实例
this
.
$vm
=
new
VueComponent
(
options
);
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
const
vueSlots
=
this
.
properties
.
vueSlots
;
const
vueSlots
=
properties
.
vueSlots
;
if
(
Array
.
isArray
(
vueSlots
)
&&
vueSlots
.
length
)
{
const
$slots
=
Object
.
create
(
null
);
vueSlots
.
forEach
(
slotName
=>
{
...
...
@@ -1104,12 +1107,18 @@ function initVm$2 (VueComponent) {
function
createComponent
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
;
let
VueComponent
;
if
(
isFn
(
vueOptions
))
{
VueComponent
=
vueOptions
;
// TODO form-field props.name,props.value
vueOptions
=
VueComponent
.
extendOptions
;
}
else
{
VueComponent
=
Vue
.
extend
(
vueOptions
);
}
const
behaviors
=
getBehaviors
(
vueOptions
);
const
properties
=
getProperties
(
vueOptions
.
props
,
false
,
vueOptions
.
__file
);
const
VueComponent
=
Vue
.
extend
(
vueOptions
);
const
componentOptions
=
{
options
:
{
multipleSlots
:
true
,
...
...
@@ -1124,7 +1133,7 @@ function createComponent (vueOptions) {
},
ready
()
{
initVm$2
.
call
(
this
,
VueComponent
);
// 目前发现部分情况小程序 attached 不触发
triggerLink
(
this
);
// 处理 parent,children
triggerLink
$1
(
this
);
// 处理 parent,children
// 补充生命周期
this
.
$vm
.
__call_hook
(
'
created
'
);
...
...
@@ -1150,13 +1159,11 @@ function createComponent (vueOptions) {
},
methods
:
{
__e
:
handleEvent
,
__l
:
handleLink
__l
:
handleLink
$1
}
};
initComponent
(
componentOptions
);
return
Component
(
componentOptions
)
return
initComponent$1
(
componentOptions
,
vueOptions
)
}
let
uni
=
{};
...
...
packages/uni-mp-toutiao/package.json
浏览文件 @
39f98c73
{
"name"
:
"@dcloudio/uni-mp-toutiao"
,
"version"
:
"0.0.32
4
"
,
"version"
:
"0.0.32
5
"
,
"description"
:
"uni-app mp-toutiao"
,
"main"
:
"dist/index.js"
,
"scripts"
:
{
...
...
packages/uni-mp-weixin/dist/index.js
浏览文件 @
39f98c73
...
...
@@ -309,8 +309,7 @@ function initTriggerEvent (mpInstance) {
};
}
Page
=
function
(
options
=
{})
{
const
name
=
'
onLoad
'
;
function
initHook
(
name
,
options
)
{
const
oldHook
=
options
[
name
];
if
(
!
oldHook
)
{
options
[
name
]
=
function
()
{
...
...
@@ -322,22 +321,53 @@ Page = function (options = {}) {
return
oldHook
.
apply
(
this
,
args
)
};
}
}
Page
=
function
(
options
=
{})
{
initHook
(
'
onLoad
'
,
options
);
return
MPPage
(
options
)
};
const
behavior
=
Behavior
({
created
()
{
initTriggerEvent
(
this
);
}
});
Component
=
function
(
options
=
{})
{
(
options
.
behaviors
||
(
options
.
behaviors
=
[])).
unshift
(
behavior
);
initHook
(
'
created
'
,
options
);
return
MPComponent
(
options
)
};
const
mocks
=
[
'
__route__
'
,
'
__wxExparserNodeId__
'
,
'
__wxWebviewId__
'
];
function
initPage
(
pageOptions
)
{
return
initComponent
(
pageOptions
)
}
function
initComponent
(
componentOptions
)
{
return
Component
(
componentOptions
)
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
)
}
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$scope
;
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
get
()
{
const
$refs
=
{};
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
);
components
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
);
forComponents
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
;
if
(
!
$refs
[
ref
])
{
$refs
[
ref
]
=
[];
}
$refs
[
ref
].
push
(
component
.
$vm
||
component
);
});
return
$refs
}
});
}
function
triggerLink
(
mpInstance
,
vueOptions
)
{
mpInstance
.
triggerEvent
(
'
__l
'
,
mpInstance
.
$vm
||
vueOptions
,
{
bubbles
:
true
,
...
...
@@ -360,9 +390,9 @@ function handleLink (event) {
}
}
function
initMocks
(
vm
,
mocks
)
{
function
initMocks
(
vm
,
mocks
$$1
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
mocks
.
forEach
(
mock
=>
{
mocks
$$1
.
forEach
(
mock
=>
{
if
(
hasOwn
(
mpInstance
,
mock
))
{
vm
[
mock
]
=
mpInstance
[
mock
];
}
...
...
@@ -447,7 +477,7 @@ function getBehaviors (vueOptions) {
}
if
(
isPlainObject
(
vueExtends
)
&&
vueExtends
.
props
)
{
behaviors
.
push
(
Behavior
({
init
Behavior
({
properties
:
getProperties
(
vueExtends
.
props
,
true
)
})
);
...
...
@@ -456,7 +486,7 @@ function getBehaviors (vueOptions) {
vueMixins
.
forEach
(
vueMixin
=>
{
if
(
isPlainObject
(
vueMixin
)
&&
vueMixin
.
props
)
{
behaviors
.
push
(
Behavior
({
init
Behavior
({
properties
:
getProperties
(
vueMixin
.
props
,
true
)
})
);
...
...
@@ -724,29 +754,6 @@ function handleEvent (event) {
});
}
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
get
()
{
const
$refs
=
{};
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
);
components
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
);
forComponents
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
;
if
(
!
$refs
[
ref
])
{
$refs
[
ref
]
=
[];
}
$refs
[
ref
].
push
(
component
.
$vm
||
component
);
});
return
$refs
}
});
}
const
hooks
=
[
'
onHide
'
,
'
onError
'
,
...
...
@@ -772,24 +779,27 @@ function initVm (vm) {
}
function
createApp
(
vm
)
{
// 外部初始化时 Vue 还未初始化,放到 createApp 内部初始化 mixin
Vue
.
mixin
({
beforeCreate
()
{
if
(
!
this
.
$options
.
mpType
)
{
return
}
this
.
mpType
=
this
.
$options
.
mpType
;
this
.
$mp
=
{
data
:
{},
[
this
.
mpType
]:
this
.
$options
.
mpInstance
};
this
.
$scope
=
this
.
$options
.
mpInstance
;
delete
this
.
$options
.
mpType
;
delete
this
.
$options
.
mpInstance
;
if
(
this
.
mpType
!==
'
app
'
)
{
{
// 头条的 selectComponent 竟然是异步的
initRefs
(
this
);
}
initMocks
(
this
,
mocks
);
}
},
...
...
@@ -900,7 +910,7 @@ function createPage (vueOptions) {
initHooks
(
pageOptions
.
methods
,
hooks$1
);
return
Component
(
pag
eOptions
)
return
initPage
(
pageOptions
,
vu
eOptions
)
}
function
initVm$2
(
VueComponent
)
{
...
...
@@ -908,16 +918,18 @@ function initVm$2 (VueComponent) {
return
}
const
properties
=
this
.
properties
;
const
options
=
{
mpType
:
'
component
'
,
mpInstance
:
this
,
propsData
:
this
.
properties
propsData
:
properties
};
// 初始化 vue 实例
this
.
$vm
=
new
VueComponent
(
options
);
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
const
vueSlots
=
this
.
properties
.
vueSlots
;
const
vueSlots
=
properties
.
vueSlots
;
if
(
Array
.
isArray
(
vueSlots
)
&&
vueSlots
.
length
)
{
const
$slots
=
Object
.
create
(
null
);
vueSlots
.
forEach
(
slotName
=>
{
...
...
@@ -933,12 +945,18 @@ function initVm$2 (VueComponent) {
function
createComponent
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
;
let
VueComponent
;
if
(
isFn
(
vueOptions
))
{
VueComponent
=
vueOptions
;
// TODO form-field props.name,props.value
vueOptions
=
VueComponent
.
extendOptions
;
}
else
{
VueComponent
=
Vue
.
extend
(
vueOptions
);
}
const
behaviors
=
getBehaviors
(
vueOptions
);
const
properties
=
getProperties
(
vueOptions
.
props
,
false
,
vueOptions
.
__file
);
const
VueComponent
=
Vue
.
extend
(
vueOptions
);
const
componentOptions
=
{
options
:
{
multipleSlots
:
true
,
...
...
@@ -983,7 +1001,7 @@ function createComponent (vueOptions) {
}
};
return
Component
(
component
Options
)
return
initComponent
(
componentOptions
,
vue
Options
)
}
let
uni
=
{};
...
...
packages/uni-mp-weixin/package.json
浏览文件 @
39f98c73
{
"name"
:
"@dcloudio/uni-mp-weixin"
,
"version"
:
"0.0.94
8
"
,
"version"
:
"0.0.94
9
"
,
"description"
:
"uni-app mp-weixin"
,
"main"
:
"dist/index.js"
,
"scripts"
:
{
...
...
src/core/runtime/wrapper/create-app.js
浏览文件 @
39f98c73
...
...
@@ -3,11 +3,11 @@ import 'uni-platform/runtime/index'
import
Vue
from
'
vue
'
import
{
mocks
mocks
,
initRefs
}
from
'
uni-platform/runtime/wrapper/index
'
import
{
initRefs
,
initHooks
,
initMocks
}
from
'
./util
'
...
...
@@ -38,23 +38,45 @@ function initVm (vm) {
export
function
createApp
(
vm
)
{
// 外部初始化时 Vue 还未初始化,放到 createApp 内部初始化 mixin
if
(
__PLATFORM__
===
'
mp-alipay
'
)
{
Object
.
defineProperty
(
Vue
.
prototype
,
'
$slots
'
,
{
get
()
{
return
this
.
$scope
&&
this
.
$scope
.
props
.
$slots
},
set
()
{
}
})
Object
.
defineProperty
(
Vue
.
prototype
,
'
$scopedSlots
'
,
{
get
()
{
return
this
.
$scope
&&
this
.
$scope
.
props
.
$scopedSlots
},
set
()
{
}
})
}
Vue
.
mixin
({
beforeCreate
()
{
if
(
!
this
.
$options
.
mpType
)
{
return
}
this
.
mpType
=
this
.
$options
.
mpType
this
.
$mp
=
{
data
:
{},
[
this
.
mpType
]:
this
.
$options
.
mpInstance
}
this
.
$scope
=
this
.
$options
.
mpInstance
delete
this
.
$options
.
mpType
delete
this
.
$options
.
mpInstance
if
(
this
.
mpType
!==
'
app
'
)
{
if
(
__PLATFORM__
!==
'
mp-toutiao
'
)
{
// 头条的 selectComponent 竟然是异步的
initRefs
(
this
)
}
initMocks
(
this
,
mocks
)
}
},
...
...
src/core/runtime/wrapper/create-component.js
浏览文件 @
39f98c73
import
Vue
from
'
vue
'
import
{
isFn
}
from
'
uni-shared
'
import
{
handleLink
,
triggerLink
,
...
...
@@ -18,16 +22,20 @@ function initVm (VueComponent) {
return
}
const
properties
=
__PLATFORM__
===
'
mp-alipay
'
?
this
.
props
:
this
.
properties
const
options
=
{
mpType
:
'
component
'
,
mpInstance
:
this
,
propsData
:
this
.
properties
propsData
:
properties
}
// 初始化 vue 实例
this
.
$vm
=
new
VueComponent
(
options
)
// 处理$slots,$scopedSlots(暂不支持动态变化$slots)
const
vueSlots
=
this
.
properties
.
vueSlots
const
vueSlots
=
properties
.
vueSlots
if
(
Array
.
isArray
(
vueSlots
)
&&
vueSlots
.
length
)
{
const
$slots
=
Object
.
create
(
null
)
vueSlots
.
forEach
(
slotName
=>
{
...
...
@@ -43,12 +51,18 @@ function initVm (VueComponent) {
export
function
createComponent
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
let
VueComponent
if
(
isFn
(
vueOptions
))
{
VueComponent
=
vueOptions
// TODO form-field props.name,props.value
vueOptions
=
VueComponent
.
extendOptions
}
else
{
VueComponent
=
Vue
.
extend
(
vueOptions
)
}
const
behaviors
=
getBehaviors
(
vueOptions
)
const
properties
=
getProperties
(
vueOptions
.
props
,
false
,
vueOptions
.
__file
)
const
VueComponent
=
Vue
.
extend
(
vueOptions
)
const
componentOptions
=
{
options
:
{
multipleSlots
:
true
,
...
...
@@ -93,7 +107,5 @@ export function createComponent (vueOptions) {
}
}
initComponent
(
componentOptions
)
return
Component
(
componentOptions
)
return
initComponent
(
componentOptions
,
vueOptions
)
}
src/core/runtime/wrapper/create-page.js
浏览文件 @
39f98c73
...
...
@@ -101,7 +101,5 @@ export function createPage (vueOptions) {
initHooks
(
pageOptions
.
methods
,
hooks
)
initPage
(
pageOptions
)
return
Component
(
pageOptions
)
return
initPage
(
pageOptions
,
vueOptions
)
}
src/core/runtime/wrapper/util.js
浏览文件 @
39f98c73
...
...
@@ -5,6 +5,10 @@ import {
isPlainObject
}
from
'
uni-shared
'
import
{
initBehavior
}
from
'
uni-platform/runtime/wrapper/index
'
export
function
initMocks
(
vm
,
mocks
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
]
mocks
.
forEach
(
mock
=>
{
...
...
@@ -92,7 +96,7 @@ export function getBehaviors (vueOptions) {
}
if
(
isPlainObject
(
vueExtends
)
&&
vueExtends
.
props
)
{
behaviors
.
push
(
Behavior
({
init
Behavior
({
properties
:
getProperties
(
vueExtends
.
props
,
true
)
})
)
...
...
@@ -101,7 +105,7 @@ export function getBehaviors (vueOptions) {
vueMixins
.
forEach
(
vueMixin
=>
{
if
(
isPlainObject
(
vueMixin
)
&&
vueMixin
.
props
)
{
behaviors
.
push
(
Behavior
({
init
Behavior
({
properties
:
getProperties
(
vueMixin
.
props
,
true
)
})
)
...
...
@@ -395,29 +399,6 @@ export function handleEvent (event) {
})
}
export
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
]
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
get
()
{
const
$refs
=
{}
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
)
components
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
$refs
[
ref
]
=
component
.
$vm
||
component
})
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
)
forComponents
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
if
(
!
$refs
[
ref
])
{
$refs
[
ref
]
=
[]
}
$refs
[
ref
].
push
(
component
.
$vm
||
component
)
})
return
$refs
}
})
}
function
baiduComponentDestroy
(
$vm
)
{
$vm
.
$children
.
forEach
(
childVm
=>
{
childVm
.
$mp
.
component
.
detached
()
...
...
src/platforms/app-plus/runtime/wrapper/index.js
浏览文件 @
39f98c73
export
{
mocks
,
initRefs
,
handleLink
,
triggerLink
triggerLink
,
initBehavior
}
from
'
../../../mp-weixin/runtime/wrapper/index
'
export
function
initPage
(
pageOptions
)
{
initComponent
(
pageOptions
)
return
initComponent
(
pageOptions
)
}
export
function
initComponent
(
componentOptions
)
{
componentOptions
.
methods
.
$getAppWebview
=
function
()
{
return
plus
.
webview
.
getWebviewById
(
`
${
this
.
__wxWebviewId__
}
`
)
}
return
Component
(
componentOptions
)
}
src/platforms/mp-alipay/runtime/wrapper/deep-equal.js
0 → 100644
浏览文件 @
39f98c73
import
{
hasOwn
}
from
'
uni-shared
'
const
isArray
=
Array
.
isArray
const
keyList
=
Object
.
keys
export
default
function
equal
(
a
,
b
)
{
if
(
a
===
b
)
return
true
if
(
a
&&
b
&&
typeof
a
===
'
object
'
&&
typeof
b
===
'
object
'
)
{
const
arrA
=
isArray
(
a
)
const
arrB
=
isArray
(
b
)
let
i
,
length
,
key
if
(
arrA
&&
arrB
)
{
length
=
a
.
length
if
(
length
!==
b
.
length
)
return
false
for
(
i
=
length
;
i
--
!==
0
;)
{
if
(
!
equal
(
a
[
i
],
b
[
i
]))
return
false
}
return
true
}
if
(
arrA
!==
arrB
)
return
false
const
dateA
=
a
instanceof
Date
const
dateB
=
b
instanceof
Date
if
(
dateA
!==
dateB
)
return
false
if
(
dateA
&&
dateB
)
return
a
.
getTime
()
===
b
.
getTime
()
const
regexpA
=
a
instanceof
RegExp
const
regexpB
=
b
instanceof
RegExp
if
(
regexpA
!==
regexpB
)
return
false
if
(
regexpA
&&
regexpB
)
return
a
.
toString
()
===
b
.
toString
()
const
keys
=
keyList
(
a
)
length
=
keys
.
length
if
(
length
!==
keyList
(
b
).
length
)
{
return
false
}
for
(
i
=
length
;
i
--
!==
0
;)
{
if
(
!
hasOwn
.
call
(
b
,
keys
[
i
]))
return
false
}
for
(
i
=
length
;
i
--
!==
0
;)
{
key
=
keys
[
i
]
if
(
!
equal
(
a
[
key
],
b
[
key
]))
return
false
}
return
true
}
return
false
}
src/platforms/mp-alipay/runtime/wrapper/index.js
0 → 100644
浏览文件 @
39f98c73
import
{
isFn
,
cached
,
camelize
}
from
'
uni-shared
'
import
deepEqual
from
'
./deep-equal
'
const
customizeRE
=
/:/g
const
customize
=
cached
((
str
)
=>
{
return
camelize
(
str
.
replace
(
customizeRE
,
'
-
'
))
})
export
const
mocks
=
[
'
$id
'
]
export
function
initRefs
()
{
}
function
handleRef
(
ref
)
{
if
(
!
ref
)
{
return
}
const
refName
=
ref
.
props
[
'
data-ref
'
]
const
refInForName
=
ref
.
props
[
'
data-ref-in-for
'
]
if
(
refName
)
{
this
.
$vm
.
$refs
[
refName
]
=
ref
.
$vm
||
ref
}
else
if
(
refInForName
)
{
this
.
$vm
.
$refs
[
refInForName
]
=
[
ref
.
$vm
||
ref
]
}
}
export
function
initPage
(
pageOptions
,
vueOptions
)
{
const
{
lifetimes
,
methods
}
=
pageOptions
pageOptions
.
onReady
=
lifetimes
.
ready
pageOptions
.
onUnload
=
function
()
{
lifetimes
.
detached
.
call
(
this
)
methods
.
onUnload
.
call
(
this
)
}
Object
.
keys
(
methods
).
forEach
(
method
=>
{
if
(
method
!==
'
onUnload
'
)
{
pageOptions
[
method
]
=
methods
[
method
]
}
})
pageOptions
[
'
__r
'
]
=
handleRef
if
(
vueOptions
.
methods
&&
vueOptions
.
methods
.
formReset
)
{
pageOptions
[
'
formReset
'
]
=
vueOptions
.
methods
.
formReset
}
delete
pageOptions
.
lifetimes
delete
pageOptions
.
methods
return
Page
(
pageOptions
)
}
function
triggerEvent
(
type
,
detail
,
options
)
{
const
handler
=
this
.
props
[
customize
(
'
on-
'
+
type
)]
if
(
!
handler
)
{
return
}
const
eventOpts
=
this
.
props
[
'
data-event-opts
'
]
const
target
=
{
dataset
:
{
eventOpts
}
}
handler
({
type
:
customize
(
type
),
target
,
currentTarget
:
target
,
detail
})
}
const
IGNORES
=
[
'
$slots
'
,
'
$scopedSlots
'
]
function
createObserver
(
isDidUpdate
)
{
return
function
observe
(
props
)
{
const
prevProps
=
isDidUpdate
?
props
:
this
.
props
const
nextProps
=
isDidUpdate
?
this
.
props
:
props
if
(
deepEqual
(
prevProps
,
nextProps
))
{
return
}
Object
.
keys
(
prevProps
).
forEach
(
name
=>
{
if
(
IGNORES
.
indexOf
(
name
)
===
-
1
)
{
const
prevValue
=
prevProps
[
name
]
const
nextValue
=
nextProps
[
name
]
if
(
!
isFn
(
prevValue
)
&&
!
isFn
(
nextValue
)
&&
!
deepEqual
(
prevValue
,
nextValue
))
{
this
.
$vm
[
name
]
=
nextProps
[
name
]
}
}
})
}
}
export
function
initComponent
(
componentOptions
,
vueOptions
)
{
const
{
lifetimes
,
properties
,
behaviors
}
=
componentOptions
componentOptions
.
mixins
=
behaviors
const
props
=
{
onTriggerLink
:
function
()
{}
}
Object
.
keys
(
properties
).
forEach
(
key
=>
{
if
(
key
!==
'
vueSlots
'
)
{
props
[
key
]
=
properties
[
key
].
value
}
})
componentOptions
.
props
=
props
if
(
my
.
canIUse
(
'
component2
'
))
{
componentOptions
.
onInit
=
lifetimes
.
attached
}
componentOptions
.
didMount
=
lifetimes
.
ready
componentOptions
.
didUnmount
=
lifetimes
.
detached
if
(
my
.
canIUse
(
'
component2
'
))
{
componentOptions
.
deriveDataFromProps
=
createObserver
()
// nextProps
}
else
{
componentOptions
.
didUpdate
=
createObserver
(
true
)
// prevProps
}
if
(
!
componentOptions
.
methods
)
{
componentOptions
.
methods
=
{}
}
if
(
vueOptions
.
methods
&&
vueOptions
.
methods
.
formReset
)
{
componentOptions
.
methods
[
'
formReset
'
]
=
vueOptions
.
methods
.
formReset
}
componentOptions
.
methods
[
'
__r
'
]
=
handleRef
componentOptions
.
methods
.
triggerEvent
=
triggerEvent
delete
componentOptions
.
properties
delete
componentOptions
.
behaviors
delete
componentOptions
.
lifetimes
delete
componentOptions
.
pageLifetimes
return
Component
(
componentOptions
)
}
export
function
initBehavior
({
properties
})
{
const
props
=
{}
Object
.
keys
(
properties
).
forEach
(
key
=>
{
props
[
key
]
=
properties
[
key
].
value
})
return
{
props
}
}
export
function
triggerLink
(
mpInstance
,
vueOptions
)
{
mpInstance
.
props
.
onTriggerLink
(
mpInstance
.
$vm
||
vueOptions
)
}
export
function
handleLink
(
detail
)
{
if
(
detail
.
$mp
)
{
// vm
if
(
!
detail
.
$parent
)
{
detail
.
$parent
=
this
.
$vm
if
(
detail
.
$parent
)
{
detail
.
$parent
.
$children
.
push
(
detail
)
detail
.
$root
=
this
.
$vm
.
$root
}
}
}
else
{
// vueOptions
if
(
!
detail
.
parent
)
{
detail
.
parent
=
this
.
$vm
}
}
}
src/platforms/mp-baidu/runtime/wrapper/index.js
浏览文件 @
39f98c73
export
{
initRefs
,
initBehavior
}
from
'
../../../mp-weixin/runtime/wrapper/index
'
export
const
mocks
=
[
'
nodeId
'
]
export
function
initPage
(
pageOptions
)
{
initComponent
(
pageOptions
)
return
initComponent
(
pageOptions
)
}
export
function
initComponent
(
componentOptions
)
{
componentOptions
.
messages
=
{
'
__l
'
:
handleLink
}
return
Component
(
componentOptions
)
}
export
function
triggerLink
(
mpInstance
,
vueOptions
)
{
...
...
src/platforms/mp-toutiao/runtime/wrapper/index.js
浏览文件 @
39f98c73
export
{
initBehavior
}
from
'
../../../mp-weixin/runtime/wrapper/index
'
const
instances
=
Object
.
create
(
null
)
export
const
mocks
=
[
'
__route__
'
,
'
__webviewId__
'
,
'
__nodeid__
'
]
export
function
initPage
(
pageOptions
)
{
initComponent
(
pageOptions
)
return
initComponent
(
pageOptions
)
}
export
function
initComponent
(
componentOptions
)
{
...
...
@@ -13,28 +18,24 @@ export function initComponent (componentOptions) {
value
:
''
}
}
const
oldAttached
=
componentOptions
.
lifetimes
.
attached
componentOptions
.
lifetimes
.
attached
=
function
()
{
oldAttached
.
call
(
this
)
// TODO 需要处理动态变化后的 refs
initRefs
.
call
(
this
)
}
return
Component
(
componentOptions
)
}
function
initRefs
()
{
this
.
selectAllComponents
(
'
.vue-ref
'
,
(
components
)
=>
{
export
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$scope
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
,
(
components
)
=>
{
components
.
forEach
(
component
=>
{
const
ref
=
component
.
data
.
vueRef
// 头条的组件 dataset 竟然是空的
this
.
$
vm
.
$refs
[
ref
]
=
component
.
$vm
||
component
vm
.
$refs
[
ref
]
=
component
.
$vm
||
component
})
})
this
.
selectAllComponents
(
'
.vue-ref-in-for
'
,
(
forComponents
)
=>
{
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
,
(
forComponents
)
=>
{
forComponents
.
forEach
(
component
=>
{
const
ref
=
component
.
data
.
vueRef
if
(
!
this
.
$
vm
.
$refs
[
ref
])
{
this
.
$
vm
.
$refs
[
ref
]
=
[]
if
(
!
vm
.
$refs
[
ref
])
{
vm
.
$refs
[
ref
]
=
[]
}
this
.
$
vm
.
$refs
[
ref
].
push
(
component
.
$vm
||
component
)
vm
.
$refs
[
ref
].
push
(
component
.
$vm
||
component
)
})
})
}
...
...
src/platforms/mp-weixin/runtime/index.js
浏览文件 @
39f98c73
...
...
@@ -24,8 +24,7 @@ function initTriggerEvent (mpInstance) {
}
}
Page
=
function
(
options
=
{})
{
const
name
=
'
onLoad
'
function
initHook
(
name
,
options
)
{
const
oldHook
=
options
[
name
]
if
(
!
oldHook
)
{
options
[
name
]
=
function
()
{
...
...
@@ -37,16 +36,14 @@ Page = function (options = {}) {
return
oldHook
.
apply
(
this
,
args
)
}
}
return
MPPage
(
options
)
}
const
behavior
=
Behavior
({
created
()
{
initTriggerEvent
(
this
)
}
})
Page
=
function
(
options
=
{})
{
initHook
(
'
onLoad
'
,
options
)
return
MPPage
(
options
)
}
Component
=
function
(
options
=
{})
{
(
options
.
behaviors
||
(
options
.
behaviors
=
[])).
unshift
(
behavior
)
initHook
(
'
created
'
,
options
)
return
MPComponent
(
options
)
}
src/platforms/mp-weixin/runtime/wrapper/index.js
浏览文件 @
39f98c73
export
const
mocks
=
[
'
__route__
'
,
'
__wxExparserNodeId__
'
,
'
__wxWebviewId__
'
]
export
function
initPage
()
{
export
function
initPage
(
pageOptions
)
{
return
initComponent
(
pageOptions
)
}
export
function
initComponent
()
{
export
function
initComponent
(
componentOptions
)
{
return
Component
(
componentOptions
)
}
export
function
initBehavior
(
options
)
{
return
Behavior
(
options
)
}
export
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$scope
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
get
()
{
const
$refs
=
{}
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
)
components
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
$refs
[
ref
]
=
component
.
$vm
||
component
})
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
)
forComponents
.
forEach
(
component
=>
{
const
ref
=
component
.
dataset
.
ref
if
(
!
$refs
[
ref
])
{
$refs
[
ref
]
=
[]
}
$refs
[
ref
].
push
(
component
.
$vm
||
component
)
})
return
$refs
}
})
}
export
function
triggerLink
(
mpInstance
,
vueOptions
)
{
mpInstance
.
triggerEvent
(
'
__l
'
,
mpInstance
.
$vm
||
vueOptions
,
{
bubbles
:
true
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录