Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wychl
uni-app
提交
f94428c7
U
uni-app
项目概览
wychl
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f94428c7
编写于
7月 27, 2021
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' into alpha
上级
9237a5ab
b76374b7
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
756 addition
and
607 deletion
+756
-607
packages/uni-mp-alipay/dist/uni.mp.esm.js
packages/uni-mp-alipay/dist/uni.mp.esm.js
+130
-108
packages/uni-mp-baidu/dist/uni.mp.esm.js
packages/uni-mp-baidu/dist/uni.mp.esm.js
+123
-102
packages/uni-mp-qq/dist/uni.mp.esm.js
packages/uni-mp-qq/dist/uni.mp.esm.js
+116
-91
packages/uni-mp-toutiao/dist/uni.mp.esm.js
packages/uni-mp-toutiao/dist/uni.mp.esm.js
+136
-108
packages/uni-mp-weixin/dist/uni.mp.esm.js
packages/uni-mp-weixin/dist/uni.mp.esm.js
+112
-91
packages/uni-quickapp-webview/dist/uni.mp.esm.js
packages/uni-quickapp-webview/dist/uni.mp.esm.js
+135
-107
packages/vue-cli-plugin-uni/lib/env.js
packages/vue-cli-plugin-uni/lib/env.js
+4
-0
未找到文件。
packages/uni-mp-alipay/dist/uni.mp.esm.js
浏览文件 @
f94428c7
import
{
capitalize
,
hasOwn
,
isArray
,
toNumber
,
isPlainObject
,
isObject
,
isFunction
,
extend
,
NOOP
,
EMPTY_OBJ
,
camelize
}
from
'
@vue/shared
'
;
import
{
hasOwn
,
isArray
,
toNumber
,
isPlainObject
,
isObject
,
capitalize
,
isFunction
,
extend
,
NOOP
,
EMPTY_OBJ
,
camelize
}
from
'
@vue/shared
'
;
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
...
...
@@ -50,7 +50,7 @@ const MP_METHODS = [
'
createSelectorQuery
'
,
'
createIntersectionObserver
'
,
'
selectAllComponents
'
,
'
selectComponent
'
'
selectComponent
'
,
];
function
createEmitFn
(
oldEmit
,
ctx
)
{
return
function
emit
(
event
,
...
args
)
{
...
...
@@ -85,7 +85,7 @@ function initBaseInstance(instance, options) {
Object
.
defineProperty
(
instance
,
'
slots
'
,
{
get
()
{
return
this
.
$scope
&&
this
.
$scope
.
props
.
$slots
;
}
}
,
});
}
// $emit
...
...
@@ -94,7 +94,7 @@ function initBaseInstance(instance, options) {
function
initComponentInstance
(
instance
,
options
)
{
initBaseInstance
(
instance
,
options
);
const
ctx
=
instance
.
ctx
;
MP_METHODS
.
forEach
(
method
=>
{
MP_METHODS
.
forEach
(
(
method
)
=>
{
ctx
[
method
]
=
function
(...
args
)
{
const
mpInstance
=
ctx
.
$scope
;
if
(
mpInstance
&&
mpInstance
[
method
])
{
...
...
@@ -115,31 +115,71 @@ function initComponentInstance(instance, options) {
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
const
ctx
=
instance
.
ctx
;
mocks
.
forEach
(
mock
=>
{
mocks
.
forEach
(
(
mock
)
=>
{
if
(
hasOwn
(
mpInstance
,
mock
))
{
ctx
[
mock
]
=
mpInstance
[
mock
];
}
});
}
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
const
res
=
obj
?
Object
.
keys
(
obj
)
.
map
((
key
)
=>
{
let
val
=
obj
[
key
];
if
(
typeof
val
===
undefined
||
val
===
null
)
{
val
=
''
;
}
else
if
(
isPlainObject
(
val
))
{
val
=
JSON
.
stringify
(
val
);
}
return
encodeStr
(
key
)
+
'
=
'
+
encodeStr
(
val
);
})
.
filter
((
x
)
=>
x
.
length
>
0
)
.
join
(
'
&
'
)
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
// lifecycle
// App and Page
const
ON_SHOW
=
'
onShow
'
;
const
ON_HIDE
=
'
onHide
'
;
//App
const
ON_LAUNCH
=
'
onLaunch
'
;
const
ON_ERROR
=
'
onError
'
;
const
ON_THEME_CHANGE
=
'
onThemeChange
'
;
const
ON_PAGE_NOT_FOUND
=
'
onPageNotFound
'
;
const
ON_UNHANDLE_REJECTION
=
'
onUnhandledRejection
'
;
//Page
const
ON_LOAD
=
'
onLoad
'
;
const
ON_READY
=
'
onReady
'
;
const
ON_UNLOAD
=
'
onUnload
'
;
const
ON_RESIZE
=
'
onResize
'
;
const
ON_BACK_PRESS
=
'
onBackPress
'
;
const
ON_TAB_ITEM_TAP
=
'
onTabItemTap
'
;
const
ON_REACH_BOTTOM
=
'
onReachBottom
'
;
const
ON_PULL_DOWN_REFRESH
=
'
onPullDownRefresh
'
;
const
ON_ADD_TO_FAVORITES
=
'
onAddToFavorites
'
;
const
PAGE_HOOKS
=
[
'
onLoad
'
,
'
onShow
'
,
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
,
// 'onReady', // lifetimes.ready
'
onHide
'
,
'
onUnload
'
,
'
onResize
'
,
// 'onPageScroll', // 影响性能,开发者手动注册
'
onTabItemTap
'
,
'
onReachBottom
'
,
'
onPullDownRefresh
'
,
// 'onShareTimeline', // 右上角菜单,开发者手动注册
'
onAddToFavorites
'
// 'onShareAppMessage' // 右上角菜单,开发者手动注册
];
function
findHooks
(
vueOptions
,
hooks
=
new
Set
())
{
if
(
vueOptions
)
{
Object
.
keys
(
vueOptions
).
forEach
(
name
=>
{
Object
.
keys
(
vueOptions
).
forEach
(
(
name
)
=>
{
if
(
name
.
indexOf
(
'
on
'
)
===
0
&&
isFunction
(
vueOptions
[
name
]))
{
hooks
.
add
(
name
);
}
...
...
@@ -147,7 +187,7 @@ function findHooks(vueOptions, hooks = new Set()) {
if
(
__VUE_OPTIONS_API__
)
{
const
{
extends
:
extendsOptions
,
mixins
}
=
vueOptions
;
if
(
mixins
)
{
mixins
.
forEach
(
mixin
=>
findHooks
(
mixin
,
hooks
));
mixins
.
forEach
(
(
mixin
)
=>
findHooks
(
mixin
,
hooks
));
}
if
(
extendsOptions
)
{
findHooks
(
extendsOptions
,
hooks
);
...
...
@@ -163,21 +203,21 @@ function initHook(mpOptions, hook, excludes) {
};
}
}
const
EXCLUDE_HOOKS
=
[
'
onReady
'
];
const
EXCLUDE_HOOKS
=
[
ON_READY
];
function
initHooks
(
mpOptions
,
hooks
,
excludes
=
EXCLUDE_HOOKS
)
{
hooks
.
forEach
(
hook
=>
initHook
(
mpOptions
,
hook
,
excludes
));
hooks
.
forEach
(
(
hook
)
=>
initHook
(
mpOptions
,
hook
,
excludes
));
}
function
initUnknownHooks
(
mpOptions
,
vueOptions
,
excludes
=
EXCLUDE_HOOKS
)
{
findHooks
(
vueOptions
).
forEach
(
hook
=>
initHook
(
mpOptions
,
hook
,
excludes
));
findHooks
(
vueOptions
).
forEach
(
(
hook
)
=>
initHook
(
mpOptions
,
hook
,
excludes
));
}
const
HOOKS
=
[
'
onShow
'
,
'
onHide
'
,
'
onError
'
,
'
onThemeChange
'
,
'
onPageNotFound
'
,
'
onUnhandledRejection
'
ON_SHOW
,
ON_HIDE
,
ON_ERROR
,
ON_THEME_CHANGE
,
ON_PAGE_NOT_FOUND
,
ON_UNHANDLE_REJECTION
,
];
function
parseApp
(
instance
,
parseAppOptions
)
{
const
internalInstance
=
instance
.
$
;
...
...
@@ -193,11 +233,11 @@ function parseApp(instance, parseAppOptions) {
initBaseInstance
(
internalInstance
,
{
mpType
:
'
app
'
,
mpInstance
:
this
,
slots
:
[]
slots
:
[]
,
});
ctx
.
globalData
=
this
.
globalData
;
instance
.
$callHook
(
'
onLaunch
'
,
options
);
}
instance
.
$callHook
(
ON_LAUNCH
,
options
);
}
,
};
const
vueOptions
=
instance
.
$
.
type
;
initHooks
(
appOptions
,
HOOKS
);
...
...
@@ -217,26 +257,6 @@ function initCreateApp(parseAppOptions) {
};
}
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
const
res
=
obj
?
Object
.
keys
(
obj
)
.
map
(
key
=>
{
let
val
=
obj
[
key
];
if
(
typeof
val
===
undefined
||
val
===
null
)
{
val
=
''
;
}
else
if
(
isPlainObject
(
val
))
{
val
=
JSON
.
stringify
(
val
);
}
return
encodeStr
(
key
)
+
'
=
'
+
encodeStr
(
val
);
})
.
filter
(
x
=>
x
.
length
>
0
)
.
join
(
'
&
'
)
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
...
...
@@ -294,7 +314,7 @@ function initDefaultProps(isBehavior = false) {
if
(
!
isBehavior
)
{
properties
.
vueId
=
{
type
:
String
,
value
:
''
value
:
''
,
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
properties
.
vueSlots
=
{
...
...
@@ -306,9 +326,9 @@ function initDefaultProps(isBehavior = false) {
$slots
[
slotName
]
=
true
;
});
this
.
setData
({
$slots
$slots
,
});
}
}
,
};
}
return
properties
;
...
...
@@ -321,14 +341,14 @@ function createProperty(key, prop) {
function
initProps
(
mpComponentOptions
,
rawProps
,
isBehavior
=
false
)
{
const
properties
=
initDefaultProps
(
isBehavior
);
if
(
isArray
(
rawProps
))
{
rawProps
.
forEach
(
key
=>
{
rawProps
.
forEach
(
(
key
)
=>
{
properties
[
key
]
=
createProperty
(
key
,
{
type
:
null
type
:
null
,
});
});
}
else
if
(
isPlainObject
(
rawProps
))
{
Object
.
keys
(
rawProps
).
forEach
(
key
=>
{
Object
.
keys
(
rawProps
).
forEach
(
(
key
)
=>
{
const
opts
=
rawProps
[
key
];
if
(
isPlainObject
(
opts
))
{
// title:{type:String,default:''}
...
...
@@ -340,14 +360,14 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) {
opts
.
type
=
parsePropType
(
key
,
type
);
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
value
value
,
});
}
else
{
// content:String
const
type
=
parsePropType
(
key
,
opts
);
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
});
}
});
...
...
@@ -359,8 +379,7 @@ function initData(vueOptions) {
let
data
=
vueOptions
.
data
||
{};
if
(
typeof
data
===
'
function
'
)
{
try
{
const
appConfig
=
getApp
().
$vm
.
$
.
appContext
.
config
;
const
appConfig
=
getApp
().
$vm
.
$
.
appContext
.
config
;
data
=
data
.
call
(
appConfig
.
globalProperties
);
}
catch
(
e
)
{
...
...
@@ -391,7 +410,7 @@ function initBehaviors(vueOptions, initBehavior) {
}
const
behaviors
=
[];
if
(
isArray
(
vueBehaviors
))
{
vueBehaviors
.
forEach
(
behavior
=>
{
vueBehaviors
.
forEach
(
(
behavior
)
=>
{
behaviors
.
push
(
behavior
.
replace
(
'
uni://
'
,
`
${
__PLATFORM_PREFIX__
}
://`
));
if
(
behavior
===
'
uni://form-field
'
)
{
if
(
isArray
(
vueProps
))
{
...
...
@@ -401,24 +420,24 @@ function initBehaviors(vueOptions, initBehavior) {
else
{
vueProps
.
name
=
{
type
:
String
,
default
:
''
default
:
''
,
};
vueProps
.
value
=
{
type
:
[
String
,
Number
,
Boolean
,
Array
,
Object
,
Date
],
default
:
''
default
:
''
,
};
}
}
});
}
if
(
isPlainObject
(
vueExtends
)
&&
vueExtends
.
props
)
{
if
(
vueExtends
.
props
)
{
const
behavior
=
{};
initProps
(
behavior
,
vueExtends
.
props
,
true
);
behaviors
.
push
(
initBehavior
(
behavior
));
}
if
(
isArray
(
vueMixins
))
{
vueMixins
.
forEach
(
vueMixin
=>
{
if
(
isPlainObject
(
vueMixin
)
&&
vueMixin
.
props
)
{
vueMixins
.
forEach
(
(
vueMixin
)
=>
{
if
(
vueMixin
.
props
)
{
const
behavior
=
{};
initProps
(
behavior
,
vueMixin
.
props
,
true
);
behaviors
.
push
(
initBehavior
(
behavior
));
...
...
@@ -442,7 +461,7 @@ function getValue(obj, path) {
}
function
getExtraValue
(
instance
,
dataPathsArray
)
{
let
context
=
instance
;
dataPathsArray
.
forEach
(
dataPathArray
=>
{
dataPathsArray
.
forEach
(
(
dataPathArray
)
=>
{
const
dataPath
=
dataPathArray
[
0
];
const
value
=
dataPathArray
[
2
];
if
(
dataPath
||
typeof
value
!==
'
undefined
'
)
{
...
...
@@ -472,12 +491,12 @@ function getExtraValue(instance, dataPathsArray) {
}
else
{
if
(
isArray
(
vFor
))
{
context
=
vFor
.
find
(
vForItem
=>
{
context
=
vFor
.
find
(
(
vForItem
)
=>
{
return
getValue
(
vForItem
,
propPath
)
===
value
;
});
}
else
if
(
isPlainObject
(
vFor
))
{
context
=
Object
.
keys
(
vFor
).
find
(
vForKey
=>
{
context
=
Object
.
keys
(
vFor
).
find
(
(
vForKey
)
=>
{
return
getValue
(
vFor
[
vForKey
],
propPath
)
===
value
;
});
}
...
...
@@ -567,7 +586,7 @@ function processEventArgs(instance, event, args = [], extra = [], isCustom, meth
}
const
extraObj
=
processEventExtra
(
instance
,
extra
,
event
);
const
ret
=
[];
args
.
forEach
(
arg
=>
{
args
.
forEach
(
(
arg
)
=>
{
if
(
arg
===
'
$event
'
)
{
if
(
methodName
===
'
__set_model
'
&&
!
isCustom
)
{
// input v-model value
...
...
@@ -609,7 +628,7 @@ function wrapper(event) {
event
.
detail
.
markerId
=
event
.
markerId
;
}
if
(
isPlainObject
(
event
.
detail
))
{
event
.
target
=
Object
.
assign
({},
event
.
target
,
event
.
detail
);
event
.
target
=
extend
({},
event
.
target
,
event
.
detail
);
}
return
event
;
}
...
...
@@ -719,7 +738,7 @@ function onAliGetAuthorize(method, $event) {
$event
.
type
=
'
getphonenumber
'
;
$event
.
detail
.
errMsg
=
'
getPhoneNumber:fail
'
;
this
[
method
](
$event
);
}
}
,
});
}
function
parse
(
appOptions
)
{
...
...
@@ -742,7 +761,7 @@ var parseAppOptions = /*#__PURE__*/Object.freeze({
parse
:
parse
});
function
handleLink
(
event
)
{
function
handleLink
$1
(
event
)
{
// detail 是微信,value 是百度(dipatch)
const
detail
=
(
event
.
detail
||
event
.
value
);
...
...
@@ -815,11 +834,11 @@ function customize(str) {
}
function
initBehavior
({
properties
})
{
const
props
=
{};
Object
.
keys
(
properties
).
forEach
(
key
=>
{
Object
.
keys
(
properties
).
forEach
(
(
key
)
=>
{
props
[
key
]
=
properties
[
key
].
value
;
});
return
{
props
props
,
};
}
function
initRelation
(
mpInstance
,
detail
)
{
...
...
@@ -859,10 +878,10 @@ function initChildVues(mpInstance) {
}
const
childVues
=
mpInstance
.
_$childVues
;
if
(
childVues
)
{
childVues
.
forEach
(
relationOptions
=>
{
childVues
.
forEach
(
(
relationOptions
)
=>
{
// 父子关系
handleLink
.
call
(
mpInstance
,
{
detail
:
relationOptions
handleLink
$1
.
call
(
mpInstance
,
{
detail
:
relationOptions
,
});
const
{
mpInstance
:
childMPInstance
,
createComponent
}
=
relationOptions
;
childMPInstance
.
$vm
=
createComponent
(
relationOptions
.
parent
);
...
...
@@ -872,7 +891,7 @@ function initChildVues(mpInstance) {
}
initChildVues
(
childMPInstance
);
childMPInstance
.
$vm
.
$callHook
(
'
mounted
'
);
childMPInstance
.
$vm
.
$callHook
(
'
onReady
'
);
childMPInstance
.
$vm
.
$callHook
(
ON_READY
);
});
}
delete
mpInstance
.
_$childVues
;
...
...
@@ -904,14 +923,14 @@ function triggerEvent(type, detail) {
const
eventOpts
=
this
.
props
[
'
data-event-opts
'
];
const
target
=
{
dataset
:
{
eventOpts
}
eventOpts
,
}
,
};
handler
({
type
:
customize
(
type
),
target
,
currentTarget
:
target
,
detail
detail
,
});
}
const
IGNORES
=
[
'
$slots
'
,
'
$scopedSlots
'
];
...
...
@@ -922,7 +941,7 @@ function createObserver(isDidUpdate = false) {
if
(
equal
(
prevProps
,
nextProps
))
{
return
;
}
Object
.
keys
(
prevProps
).
forEach
(
name
=>
{
Object
.
keys
(
prevProps
).
forEach
(
(
name
)
=>
{
if
(
IGNORES
.
indexOf
(
name
)
===
-
1
)
{
const
prevValue
=
prevProps
[
name
];
const
nextValue
=
nextProps
[
name
];
...
...
@@ -935,19 +954,19 @@ function createObserver(isDidUpdate = false) {
});
};
}
const
handleLink
$1
=
(
function
()
{
const
handleLink
=
(
function
()
{
if
(
isComponent2
)
{
return
function
handleLink
$1
(
detail
)
{
return
handleLink
.
call
(
this
,
{
detail
return
function
handleLink
(
detail
)
{
return
handleLink
$1
.
call
(
this
,
{
detail
,
});
};
}
return
function
handleLink
$1
(
detail
)
{
return
function
handleLink
(
detail
)
{
if
(
this
.
$vm
&&
this
.
$vm
.
$
.
isMounted
)
{
// 父已初始化
return
handleLink
.
call
(
this
,
{
detail
return
handleLink
$1
.
call
(
this
,
{
detail
,
});
}
(
this
.
_$childVues
||
(
this
.
_$childVues
=
[])).
unshift
(
detail
);
...
...
@@ -956,7 +975,7 @@ const handleLink$1 = (function () {
function
createVueComponent
(
mpType
,
mpInstance
,
vueOptions
,
parent
)
{
return
$createComponent
({
type
:
vueOptions
,
props
:
mpInstance
.
props
props
:
mpInstance
.
props
,
},
{
mpType
,
mpInstance
,
...
...
@@ -964,43 +983,43 @@ function createVueComponent(mpType, mpInstance, vueOptions, parent) {
onBeforeSetup
(
instance
,
options
)
{
initMocks
(
instance
,
mpInstance
,
mocks
);
initComponentInstance
(
instance
,
options
);
}
}
,
});
}
function
createPage
(
vueOptions
)
{
function
createPage
$1
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
;
const
pageOptions
=
{
onLoad
(
query
)
{
this
.
options
=
query
;
this
.
$page
=
{
fullPath
:
'
/
'
+
this
.
route
+
stringifyQuery
(
query
)
fullPath
:
'
/
'
+
this
.
route
+
stringifyQuery
(
query
)
,
};
// 初始化 vue 实例
this
.
$vm
=
createVueComponent
(
'
page
'
,
this
,
vueOptions
);
initSpecialMethods
(
this
);
this
.
$vm
.
$callHook
(
'
onLoad
'
,
query
);
this
.
$vm
.
$callHook
(
ON_LOAD
,
query
);
},
onReady
()
{
initChildVues
(
this
);
this
.
$vm
.
$callHook
(
'
mounted
'
);
this
.
$vm
.
$callHook
(
'
onReady
'
);
this
.
$vm
.
$callHook
(
ON_READY
);
},
onUnload
()
{
if
(
this
.
$vm
)
{
this
.
$vm
.
$callHook
(
'
onUnload
'
);
this
.
$vm
.
$callHook
(
ON_UNLOAD
);
$destroyComponent
(
this
.
$vm
);
}
},
events
:
{
// 支付宝小程序有些页面事件只能放在events下
onBack
()
{
this
.
$vm
.
$callHook
(
'
onBackPress
'
);
}
this
.
$vm
.
$callHook
(
ON_BACK_PRESS
);
}
,
},
__r
:
handleRef
,
__e
:
handleEvent
,
__l
:
handleLink
$1
__l
:
handleLink
,
};
if
(
__VUE_OPTIONS_API__
)
{
pageOptions
.
data
=
initData
(
vueOptions
);
...
...
@@ -1013,14 +1032,14 @@ function createPage(vueOptions) {
function
initComponentProps
(
rawProps
)
{
const
propertiesOptions
=
{
properties
:
{}
properties
:
{}
,
};
initProps
(
propertiesOptions
,
rawProps
,
false
);
const
properties
=
propertiesOptions
.
properties
;
const
props
=
{
onVueInit
:
function
()
{
}
onVueInit
:
function
()
{
}
,
};
Object
.
keys
(
properties
).
forEach
(
key
=>
{
Object
.
keys
(
properties
).
forEach
(
(
key
)
=>
{
if
(
key
!==
'
vueSlots
'
)
{
props
[
key
]
=
properties
[
key
].
value
;
}
...
...
@@ -1036,7 +1055,7 @@ function initVm(mpInstance, createComponent) {
const
relationOptions
=
{
vuePid
:
mpInstance
.
_$vuePid
,
mpInstance
,
createComponent
createComponent
,
};
if
(
isComponent2
)
{
// 处理父子关系
...
...
@@ -1057,7 +1076,7 @@ function initVm(mpInstance, createComponent) {
}
}
}
function
createComponent
(
vueOptions
)
{
function
createComponent
$1
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
;
const
mpComponentOptions
=
{
props
:
initComponentProps
(
vueOptions
.
props
),
...
...
@@ -1085,9 +1104,9 @@ function createComponent(vueOptions) {
methods
:
{
__r
:
handleRef
,
__e
:
handleEvent
,
__l
:
handleLink
$1
,
triggerEvent
}
__l
:
handleLink
,
triggerEvent
,
}
,
};
if
(
__VUE_OPTIONS_API__
)
{
mpComponentOptions
.
data
=
initData
(
vueOptions
);
...
...
@@ -1108,6 +1127,9 @@ function createComponent(vueOptions) {
return
Component
(
mpComponentOptions
);
}
const
createApp
=
initCreateApp
(
parseAppOptions
);
const
createApp
=
initCreateApp
(
parseAppOptions
);
my
.
createApp
=
createApp
;
my
.
createPage
=
createPage
;
my
.
createComponent
=
createComponent
;
export
{
createApp
,
createComponent
,
createPage
};
export
{
createApp
,
createComponent
$1
as
createComponent
,
createPage$1
as
createPage
};
packages/uni-mp-baidu/dist/uni.mp.esm.js
浏览文件 @
f94428c7
此差异已折叠。
点击以展开。
packages/uni-mp-qq/dist/uni.mp.esm.js
浏览文件 @
f94428c7
...
...
@@ -50,7 +50,7 @@ const MP_METHODS = [
'
createSelectorQuery
'
,
'
createIntersectionObserver
'
,
'
selectAllComponents
'
,
'
selectComponent
'
'
selectComponent
'
,
];
function
createEmitFn
(
oldEmit
,
ctx
)
{
return
function
emit
(
event
,
...
args
)
{
...
...
@@ -77,7 +77,7 @@ function initBaseInstance(instance, options) {
{
instance
.
slots
=
{};
if
(
isArray
(
options
.
slots
)
&&
options
.
slots
.
length
)
{
options
.
slots
.
forEach
(
name
=>
{
options
.
slots
.
forEach
(
(
name
)
=>
{
instance
.
slots
[
name
]
=
true
;
});
}
...
...
@@ -88,7 +88,7 @@ function initBaseInstance(instance, options) {
function
initComponentInstance
(
instance
,
options
)
{
initBaseInstance
(
instance
,
options
);
const
ctx
=
instance
.
ctx
;
MP_METHODS
.
forEach
(
method
=>
{
MP_METHODS
.
forEach
(
(
method
)
=>
{
ctx
[
method
]
=
function
(...
args
)
{
const
mpInstance
=
ctx
.
$scope
;
if
(
mpInstance
&&
mpInstance
[
method
])
{
...
...
@@ -106,31 +106,70 @@ function initComponentInstance(instance, options) {
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
const
ctx
=
instance
.
ctx
;
mocks
.
forEach
(
mock
=>
{
mocks
.
forEach
(
(
mock
)
=>
{
if
(
hasOwn
(
mpInstance
,
mock
))
{
ctx
[
mock
]
=
mpInstance
[
mock
];
}
});
}
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
const
res
=
obj
?
Object
.
keys
(
obj
)
.
map
((
key
)
=>
{
let
val
=
obj
[
key
];
if
(
typeof
val
===
undefined
||
val
===
null
)
{
val
=
''
;
}
else
if
(
isPlainObject
(
val
))
{
val
=
JSON
.
stringify
(
val
);
}
return
encodeStr
(
key
)
+
'
=
'
+
encodeStr
(
val
);
})
.
filter
((
x
)
=>
x
.
length
>
0
)
.
join
(
'
&
'
)
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
// lifecycle
// App and Page
const
ON_SHOW
=
'
onShow
'
;
const
ON_HIDE
=
'
onHide
'
;
//App
const
ON_LAUNCH
=
'
onLaunch
'
;
const
ON_ERROR
=
'
onError
'
;
const
ON_THEME_CHANGE
=
'
onThemeChange
'
;
const
ON_PAGE_NOT_FOUND
=
'
onPageNotFound
'
;
const
ON_UNHANDLE_REJECTION
=
'
onUnhandledRejection
'
;
//Page
const
ON_LOAD
=
'
onLoad
'
;
const
ON_READY
=
'
onReady
'
;
const
ON_UNLOAD
=
'
onUnload
'
;
const
ON_RESIZE
=
'
onResize
'
;
const
ON_TAB_ITEM_TAP
=
'
onTabItemTap
'
;
const
ON_REACH_BOTTOM
=
'
onReachBottom
'
;
const
ON_PULL_DOWN_REFRESH
=
'
onPullDownRefresh
'
;
const
ON_ADD_TO_FAVORITES
=
'
onAddToFavorites
'
;
const
PAGE_HOOKS
=
[
'
onLoad
'
,
'
onShow
'
,
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
,
// 'onReady', // lifetimes.ready
'
onHide
'
,
'
onUnload
'
,
'
onResize
'
,
// 'onPageScroll', // 影响性能,开发者手动注册
'
onTabItemTap
'
,
'
onReachBottom
'
,
'
onPullDownRefresh
'
,
// 'onShareTimeline', // 右上角菜单,开发者手动注册
'
onAddToFavorites
'
// 'onShareAppMessage' // 右上角菜单,开发者手动注册
];
function
findHooks
(
vueOptions
,
hooks
=
new
Set
())
{
if
(
vueOptions
)
{
Object
.
keys
(
vueOptions
).
forEach
(
name
=>
{
Object
.
keys
(
vueOptions
).
forEach
(
(
name
)
=>
{
if
(
name
.
indexOf
(
'
on
'
)
===
0
&&
isFunction
(
vueOptions
[
name
]))
{
hooks
.
add
(
name
);
}
...
...
@@ -138,7 +177,7 @@ function findHooks(vueOptions, hooks = new Set()) {
if
(
__VUE_OPTIONS_API__
)
{
const
{
extends
:
extendsOptions
,
mixins
}
=
vueOptions
;
if
(
mixins
)
{
mixins
.
forEach
(
mixin
=>
findHooks
(
mixin
,
hooks
));
mixins
.
forEach
(
(
mixin
)
=>
findHooks
(
mixin
,
hooks
));
}
if
(
extendsOptions
)
{
findHooks
(
extendsOptions
,
hooks
);
...
...
@@ -147,28 +186,28 @@ function findHooks(vueOptions, hooks = new Set()) {
}
return
hooks
;
}
function
initHook
(
mpOptions
,
hook
,
excludes
)
{
function
initHook
$1
(
mpOptions
,
hook
,
excludes
)
{
if
(
excludes
.
indexOf
(
hook
)
===
-
1
&&
!
hasOwn
(
mpOptions
,
hook
))
{
mpOptions
[
hook
]
=
function
(
args
)
{
return
this
.
$vm
&&
this
.
$vm
.
$callHook
(
hook
,
args
);
};
}
}
const
EXCLUDE_HOOKS
=
[
'
onReady
'
];
const
EXCLUDE_HOOKS
=
[
ON_READY
];
function
initHooks
(
mpOptions
,
hooks
,
excludes
=
EXCLUDE_HOOKS
)
{
hooks
.
forEach
(
hook
=>
initHook
(
mpOptions
,
hook
,
excludes
));
hooks
.
forEach
(
(
hook
)
=>
initHook$1
(
mpOptions
,
hook
,
excludes
));
}
function
initUnknownHooks
(
mpOptions
,
vueOptions
,
excludes
=
EXCLUDE_HOOKS
)
{
findHooks
(
vueOptions
).
forEach
(
hook
=>
initHook
(
mpOptions
,
hook
,
excludes
));
findHooks
(
vueOptions
).
forEach
(
(
hook
)
=>
initHook$1
(
mpOptions
,
hook
,
excludes
));
}
const
HOOKS
=
[
'
onShow
'
,
'
onHide
'
,
'
onError
'
,
'
onThemeChange
'
,
'
onPageNotFound
'
,
'
onUnhandledRejection
'
ON_SHOW
,
ON_HIDE
,
ON_ERROR
,
ON_THEME_CHANGE
,
ON_PAGE_NOT_FOUND
,
ON_UNHANDLE_REJECTION
,
];
function
parseApp
(
instance
,
parseAppOptions
)
{
const
internalInstance
=
instance
.
$
;
...
...
@@ -184,11 +223,11 @@ function parseApp(instance, parseAppOptions) {
initBaseInstance
(
internalInstance
,
{
mpType
:
'
app
'
,
mpInstance
:
this
,
slots
:
[]
slots
:
[]
,
});
ctx
.
globalData
=
this
.
globalData
;
instance
.
$callHook
(
'
onLaunch
'
,
options
);
}
instance
.
$callHook
(
ON_LAUNCH
,
options
);
}
,
};
const
vueOptions
=
instance
.
$
.
type
;
initHooks
(
appOptions
,
HOOKS
);
...
...
@@ -208,26 +247,6 @@ function initCreateApp(parseAppOptions) {
};
}
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
const
res
=
obj
?
Object
.
keys
(
obj
)
.
map
(
key
=>
{
let
val
=
obj
[
key
];
if
(
typeof
val
===
undefined
||
val
===
null
)
{
val
=
''
;
}
else
if
(
isPlainObject
(
val
))
{
val
=
JSON
.
stringify
(
val
);
}
return
encodeStr
(
key
)
+
'
=
'
+
encodeStr
(
val
);
})
.
filter
(
x
=>
x
.
length
>
0
)
.
join
(
'
&
'
)
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
);
}
...
...
@@ -247,7 +266,7 @@ function initVueIds(vueIds, mpInstance) {
}
const
EXTRAS
=
[
'
externalClasses
'
];
function
initExtraOptions
(
miniProgramComponentOptions
,
vueOptions
)
{
EXTRAS
.
forEach
(
name
=>
{
EXTRAS
.
forEach
(
(
name
)
=>
{
if
(
hasOwn
(
vueOptions
,
name
))
{
miniProgramComponentOptions
[
name
]
=
vueOptions
[
name
];
}
...
...
@@ -268,12 +287,12 @@ function initRefs(instance, mpInstance) {
get
()
{
const
$refs
=
{};
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
);
components
.
forEach
(
component
=>
{
components
.
forEach
(
(
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
);
forComponents
.
forEach
(
component
=>
{
forComponents
.
forEach
(
(
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
if
(
!
$refs
[
ref
])
{
$refs
[
ref
]
=
[];
...
...
@@ -281,7 +300,7 @@ function initRefs(instance, mpInstance) {
$refs
[
ref
].
push
(
component
.
$vm
||
component
);
});
return
$refs
;
}
}
,
});
}
function
findVmByVueId
(
instance
,
vuePid
)
{
...
...
@@ -324,7 +343,7 @@ function initDefaultProps(isBehavior = false) {
if
(
!
isBehavior
)
{
properties
.
vueId
=
{
type
:
String
,
value
:
''
value
:
''
,
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
properties
.
vueSlots
=
{
...
...
@@ -336,9 +355,9 @@ function initDefaultProps(isBehavior = false) {
$slots
[
slotName
]
=
true
;
});
this
.
setData
({
$slots
$slots
,
});
}
}
,
};
}
return
properties
;
...
...
@@ -350,14 +369,14 @@ function createProperty(key, prop) {
function
initProps
(
mpComponentOptions
,
rawProps
,
isBehavior
=
false
)
{
const
properties
=
initDefaultProps
(
isBehavior
);
if
(
isArray
(
rawProps
))
{
rawProps
.
forEach
(
key
=>
{
rawProps
.
forEach
(
(
key
)
=>
{
properties
[
key
]
=
createProperty
(
key
,
{
type
:
null
type
:
null
,
});
});
}
else
if
(
isPlainObject
(
rawProps
))
{
Object
.
keys
(
rawProps
).
forEach
(
key
=>
{
Object
.
keys
(
rawProps
).
forEach
(
(
key
)
=>
{
const
opts
=
rawProps
[
key
];
if
(
isPlainObject
(
opts
))
{
// title:{type:String,default:''}
...
...
@@ -369,14 +388,14 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) {
opts
.
type
=
parsePropType
(
key
,
type
);
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
value
value
,
});
}
else
{
// content:String
const
type
=
parsePropType
(
key
,
opts
);
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
});
}
});
...
...
@@ -388,8 +407,7 @@ function initData(vueOptions) {
let
data
=
vueOptions
.
data
||
{};
if
(
typeof
data
===
'
function
'
)
{
try
{
const
appConfig
=
getApp
().
$vm
.
$
.
appContext
.
config
;
const
appConfig
=
getApp
().
$vm
.
$
.
appContext
.
config
;
data
=
data
.
call
(
appConfig
.
globalProperties
);
}
catch
(
e
)
{
...
...
@@ -420,7 +438,7 @@ function initBehaviors(vueOptions, initBehavior) {
}
const
behaviors
=
[];
if
(
isArray
(
vueBehaviors
))
{
vueBehaviors
.
forEach
(
behavior
=>
{
vueBehaviors
.
forEach
(
(
behavior
)
=>
{
behaviors
.
push
(
behavior
.
replace
(
'
uni://
'
,
`
${
__PLATFORM_PREFIX__
}
://`
));
if
(
behavior
===
'
uni://form-field
'
)
{
if
(
isArray
(
vueProps
))
{
...
...
@@ -430,24 +448,24 @@ function initBehaviors(vueOptions, initBehavior) {
else
{
vueProps
.
name
=
{
type
:
String
,
default
:
''
default
:
''
,
};
vueProps
.
value
=
{
type
:
[
String
,
Number
,
Boolean
,
Array
,
Object
,
Date
],
default
:
''
default
:
''
,
};
}
}
});
}
if
(
isPlainObject
(
vueExtends
)
&&
vueExtends
.
props
)
{
if
(
vueExtends
.
props
)
{
const
behavior
=
{};
initProps
(
behavior
,
vueExtends
.
props
,
true
);
behaviors
.
push
(
initBehavior
(
behavior
));
}
if
(
isArray
(
vueMixins
))
{
vueMixins
.
forEach
(
vueMixin
=>
{
if
(
isPlainObject
(
vueMixin
)
&&
vueMixin
.
props
)
{
vueMixins
.
forEach
(
(
vueMixin
)
=>
{
if
(
vueMixin
.
props
)
{
const
behavior
=
{};
initProps
(
behavior
,
vueMixin
.
props
,
true
);
behaviors
.
push
(
initBehavior
(
behavior
));
...
...
@@ -475,7 +493,7 @@ function getValue(obj, path) {
}
function
getExtraValue
(
instance
,
dataPathsArray
)
{
let
context
=
instance
;
dataPathsArray
.
forEach
(
dataPathArray
=>
{
dataPathsArray
.
forEach
(
(
dataPathArray
)
=>
{
const
dataPath
=
dataPathArray
[
0
];
const
value
=
dataPathArray
[
2
];
if
(
dataPath
||
typeof
value
!==
'
undefined
'
)
{
...
...
@@ -505,12 +523,12 @@ function getExtraValue(instance, dataPathsArray) {
}
else
{
if
(
isArray
(
vFor
))
{
context
=
vFor
.
find
(
vForItem
=>
{
context
=
vFor
.
find
(
(
vForItem
)
=>
{
return
getValue
(
vForItem
,
propPath
)
===
value
;
});
}
else
if
(
isPlainObject
(
vFor
))
{
context
=
Object
.
keys
(
vFor
).
find
(
vForKey
=>
{
context
=
Object
.
keys
(
vFor
).
find
(
(
vForKey
)
=>
{
return
getValue
(
vFor
[
vForKey
],
propPath
)
===
value
;
});
}
...
...
@@ -600,7 +618,7 @@ function processEventArgs(instance, event, args = [], extra = [], isCustom, meth
}
const
extraObj
=
processEventExtra
(
instance
,
extra
,
event
);
const
ret
=
[];
args
.
forEach
(
arg
=>
{
args
.
forEach
(
(
arg
)
=>
{
if
(
arg
===
'
$event
'
)
{
if
(
methodName
===
'
__set_model
'
&&
!
isCustom
)
{
// input v-model value
...
...
@@ -642,7 +660,7 @@ function wrapper(event) {
event
.
detail
.
markerId
=
event
.
markerId
;
}
if
(
isPlainObject
(
event
.
detail
))
{
event
.
target
=
Object
.
assign
({},
event
.
target
,
event
.
detail
);
event
.
target
=
extend
({},
event
.
target
,
event
.
detail
);
}
return
event
;
}
...
...
@@ -712,11 +730,11 @@ function handleEvent(event) {
}
}
function
parseComponent
(
vueOptions
,
{
parse
,
mocks
,
isPage
,
initRelation
,
handleLink
,
initLifetimes
})
{
function
parseComponent
(
vueOptions
,
{
parse
,
mocks
,
isPage
,
initRelation
,
handleLink
,
initLifetimes
,
})
{
vueOptions
=
vueOptions
.
default
||
vueOptions
;
const
options
=
{
multipleSlots
:
true
,
addGlobalClass
:
true
addGlobalClass
:
true
,
};
if
(
vueOptions
.
options
)
{
extend
(
options
,
vueOptions
.
options
);
...
...
@@ -733,12 +751,12 @@ function parseComponent(vueOptions, { parse, mocks, isPage, initRelation, handle
},
resize
(
size
)
{
this
.
$vm
&&
this
.
$vm
.
$callHook
(
'
onPageResize
'
,
size
);
}
}
,
},
methods
:
{
__l
:
handleLink
,
__e
:
handleEvent
}
__e
:
handleEvent
,
}
,
};
if
(
__VUE_OPTIONS_API__
)
{
applyOptions
(
mpComponentOptions
,
vueOptions
,
initBehavior
);
...
...
@@ -778,15 +796,15 @@ function parsePage(vueOptions, parseOptions) {
isPage
,
initRelation
,
handleLink
,
initLifetimes
initLifetimes
,
});
const
methods
=
miniProgramPageOptions
.
methods
;
methods
.
onLoad
=
function
(
query
)
{
this
.
options
=
query
;
this
.
$page
=
{
fullPath
:
'
/
'
+
this
.
route
+
stringifyQuery
(
query
)
fullPath
:
'
/
'
+
this
.
route
+
stringifyQuery
(
query
)
,
};
return
this
.
$vm
&&
this
.
$vm
.
$callHook
(
'
onLoad
'
,
query
);
return
this
.
$vm
&&
this
.
$vm
.
$callHook
(
ON_LOAD
,
query
);
};
initHooks
(
methods
,
PAGE_HOOKS
);
initUnknownHooks
(
methods
,
vueOptions
);
...
...
@@ -811,7 +829,7 @@ function initTriggerEvent(mpInstance) {
return
oldTriggerEvent
.
apply
(
mpInstance
,
[
customize
(
event
),
...
args
]);
};
}
function
initHook
$1
(
name
,
options
)
{
function
initHook
(
name
,
options
)
{
const
oldHook
=
options
[
name
];
if
(
!
oldHook
)
{
options
[
name
]
=
function
()
{
...
...
@@ -826,21 +844,21 @@ function initHook$1(name, options) {
}
}
Page
=
function
(
options
)
{
initHook
$1
(
'
onLoad
'
,
options
);
initHook
(
ON_LOAD
,
options
);
return
MPPage
(
options
);
};
Component
=
function
(
options
)
{
initHook
$1
(
'
created
'
,
options
);
initHook
(
'
created
'
,
options
);
return
MPComponent
(
options
);
};
function
initLifetimes
({
mocks
,
isPage
,
initRelation
,
vueOptions
})
{
function
initLifetimes
({
mocks
,
isPage
,
initRelation
,
vueOptions
,
})
{
return
{
attached
()
{
const
properties
=
this
.
properties
;
initVueIds
(
properties
.
vueId
,
this
);
const
relationOptions
=
{
vuePid
:
this
.
_$vuePid
vuePid
:
this
.
_$vuePid
,
};
// 处理父子关系
initRelation
(
this
,
relationOptions
);
...
...
@@ -848,7 +866,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions }) {
const
mpInstance
=
this
;
this
.
$vm
=
$createComponent
({
type
:
vueOptions
,
props
:
properties
props
:
properties
,
},
{
mpType
:
isPage
(
mpInstance
)
?
'
page
'
:
'
component
'
,
mpInstance
,
...
...
@@ -858,7 +876,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions }) {
initRefs
(
instance
,
mpInstance
);
initMocks
(
instance
,
mpInstance
,
mocks
);
initComponentInstance
(
instance
,
options
);
}
}
,
});
},
ready
()
{
...
...
@@ -866,12 +884,12 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions }) {
// https://developers.weixin.qq.com/community/develop/doc/00066ae2844cc0f8eb883e2a557800
if
(
this
.
$vm
)
{
this
.
$vm
.
$callHook
(
'
mounted
'
);
this
.
$vm
.
$callHook
(
'
onReady
'
);
this
.
$vm
.
$callHook
(
ON_READY
);
}
},
detached
()
{
this
.
$vm
&&
$destroyComponent
(
this
.
$vm
);
}
}
,
};
}
...
...
@@ -908,6 +926,13 @@ var parseOptions = /*#__PURE__*/Object.freeze({
const
createApp
=
initCreateApp
();
const
createPage
=
initCreatePage
(
parseOptions
);
const
createComponent
=
initCreateComponent
(
parseOptions
);
const
createComponent
=
initCreateComponent
(
parseOptions
);
wx
.
createApp
=
createApp
;
wx
.
createPage
=
createPage
;
wx
.
createComponent
=
createComponent
;
qq
.
createApp
=
createApp
;
qq
.
createPage
=
createPage
;
qq
.
createComponent
=
createComponent
;
export
{
createApp
,
createComponent
,
createPage
};
packages/uni-mp-toutiao/dist/uni.mp.esm.js
浏览文件 @
f94428c7
此差异已折叠。
点击以展开。
packages/uni-mp-weixin/dist/uni.mp.esm.js
浏览文件 @
f94428c7
...
...
@@ -50,7 +50,7 @@ const MP_METHODS = [
'
createSelectorQuery
'
,
'
createIntersectionObserver
'
,
'
selectAllComponents
'
,
'
selectComponent
'
'
selectComponent
'
,
];
function
createEmitFn
(
oldEmit
,
ctx
)
{
return
function
emit
(
event
,
...
args
)
{
...
...
@@ -77,7 +77,7 @@ function initBaseInstance(instance, options) {
{
instance
.
slots
=
{};
if
(
isArray
(
options
.
slots
)
&&
options
.
slots
.
length
)
{
options
.
slots
.
forEach
(
name
=>
{
options
.
slots
.
forEach
(
(
name
)
=>
{
instance
.
slots
[
name
]
=
true
;
});
}
...
...
@@ -88,7 +88,7 @@ function initBaseInstance(instance, options) {
function
initComponentInstance
(
instance
,
options
)
{
initBaseInstance
(
instance
,
options
);
const
ctx
=
instance
.
ctx
;
MP_METHODS
.
forEach
(
method
=>
{
MP_METHODS
.
forEach
(
(
method
)
=>
{
ctx
[
method
]
=
function
(...
args
)
{
const
mpInstance
=
ctx
.
$scope
;
if
(
mpInstance
&&
mpInstance
[
method
])
{
...
...
@@ -106,31 +106,70 @@ function initComponentInstance(instance, options) {
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
const
ctx
=
instance
.
ctx
;
mocks
.
forEach
(
mock
=>
{
mocks
.
forEach
(
(
mock
)
=>
{
if
(
hasOwn
(
mpInstance
,
mock
))
{
ctx
[
mock
]
=
mpInstance
[
mock
];
}
});
}
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
const
res
=
obj
?
Object
.
keys
(
obj
)
.
map
((
key
)
=>
{
let
val
=
obj
[
key
];
if
(
typeof
val
===
undefined
||
val
===
null
)
{
val
=
''
;
}
else
if
(
isPlainObject
(
val
))
{
val
=
JSON
.
stringify
(
val
);
}
return
encodeStr
(
key
)
+
'
=
'
+
encodeStr
(
val
);
})
.
filter
((
x
)
=>
x
.
length
>
0
)
.
join
(
'
&
'
)
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
// lifecycle
// App and Page
const
ON_SHOW
=
'
onShow
'
;
const
ON_HIDE
=
'
onHide
'
;
//App
const
ON_LAUNCH
=
'
onLaunch
'
;
const
ON_ERROR
=
'
onError
'
;
const
ON_THEME_CHANGE
=
'
onThemeChange
'
;
const
ON_PAGE_NOT_FOUND
=
'
onPageNotFound
'
;
const
ON_UNHANDLE_REJECTION
=
'
onUnhandledRejection
'
;
//Page
const
ON_LOAD
=
'
onLoad
'
;
const
ON_READY
=
'
onReady
'
;
const
ON_UNLOAD
=
'
onUnload
'
;
const
ON_RESIZE
=
'
onResize
'
;
const
ON_TAB_ITEM_TAP
=
'
onTabItemTap
'
;
const
ON_REACH_BOTTOM
=
'
onReachBottom
'
;
const
ON_PULL_DOWN_REFRESH
=
'
onPullDownRefresh
'
;
const
ON_ADD_TO_FAVORITES
=
'
onAddToFavorites
'
;
const
PAGE_HOOKS
=
[
'
onLoad
'
,
'
onShow
'
,
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
,
// 'onReady', // lifetimes.ready
'
onHide
'
,
'
onUnload
'
,
'
onResize
'
,
// 'onPageScroll', // 影响性能,开发者手动注册
'
onTabItemTap
'
,
'
onReachBottom
'
,
'
onPullDownRefresh
'
,
// 'onShareTimeline', // 右上角菜单,开发者手动注册
'
onAddToFavorites
'
// 'onShareAppMessage' // 右上角菜单,开发者手动注册
];
function
findHooks
(
vueOptions
,
hooks
=
new
Set
())
{
if
(
vueOptions
)
{
Object
.
keys
(
vueOptions
).
forEach
(
name
=>
{
Object
.
keys
(
vueOptions
).
forEach
(
(
name
)
=>
{
if
(
name
.
indexOf
(
'
on
'
)
===
0
&&
isFunction
(
vueOptions
[
name
]))
{
hooks
.
add
(
name
);
}
...
...
@@ -138,7 +177,7 @@ function findHooks(vueOptions, hooks = new Set()) {
if
(
__VUE_OPTIONS_API__
)
{
const
{
extends
:
extendsOptions
,
mixins
}
=
vueOptions
;
if
(
mixins
)
{
mixins
.
forEach
(
mixin
=>
findHooks
(
mixin
,
hooks
));
mixins
.
forEach
(
(
mixin
)
=>
findHooks
(
mixin
,
hooks
));
}
if
(
extendsOptions
)
{
findHooks
(
extendsOptions
,
hooks
);
...
...
@@ -147,28 +186,28 @@ function findHooks(vueOptions, hooks = new Set()) {
}
return
hooks
;
}
function
initHook
(
mpOptions
,
hook
,
excludes
)
{
function
initHook
$1
(
mpOptions
,
hook
,
excludes
)
{
if
(
excludes
.
indexOf
(
hook
)
===
-
1
&&
!
hasOwn
(
mpOptions
,
hook
))
{
mpOptions
[
hook
]
=
function
(
args
)
{
return
this
.
$vm
&&
this
.
$vm
.
$callHook
(
hook
,
args
);
};
}
}
const
EXCLUDE_HOOKS
=
[
'
onReady
'
];
const
EXCLUDE_HOOKS
=
[
ON_READY
];
function
initHooks
(
mpOptions
,
hooks
,
excludes
=
EXCLUDE_HOOKS
)
{
hooks
.
forEach
(
hook
=>
initHook
(
mpOptions
,
hook
,
excludes
));
hooks
.
forEach
(
(
hook
)
=>
initHook$1
(
mpOptions
,
hook
,
excludes
));
}
function
initUnknownHooks
(
mpOptions
,
vueOptions
,
excludes
=
EXCLUDE_HOOKS
)
{
findHooks
(
vueOptions
).
forEach
(
hook
=>
initHook
(
mpOptions
,
hook
,
excludes
));
findHooks
(
vueOptions
).
forEach
(
(
hook
)
=>
initHook$1
(
mpOptions
,
hook
,
excludes
));
}
const
HOOKS
=
[
'
onShow
'
,
'
onHide
'
,
'
onError
'
,
'
onThemeChange
'
,
'
onPageNotFound
'
,
'
onUnhandledRejection
'
ON_SHOW
,
ON_HIDE
,
ON_ERROR
,
ON_THEME_CHANGE
,
ON_PAGE_NOT_FOUND
,
ON_UNHANDLE_REJECTION
,
];
function
parseApp
(
instance
,
parseAppOptions
)
{
const
internalInstance
=
instance
.
$
;
...
...
@@ -184,11 +223,11 @@ function parseApp(instance, parseAppOptions) {
initBaseInstance
(
internalInstance
,
{
mpType
:
'
app
'
,
mpInstance
:
this
,
slots
:
[]
slots
:
[]
,
});
ctx
.
globalData
=
this
.
globalData
;
instance
.
$callHook
(
'
onLaunch
'
,
options
);
}
instance
.
$callHook
(
ON_LAUNCH
,
options
);
}
,
};
const
vueOptions
=
instance
.
$
.
type
;
initHooks
(
appOptions
,
HOOKS
);
...
...
@@ -208,26 +247,6 @@ function initCreateApp(parseAppOptions) {
};
}
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
const
res
=
obj
?
Object
.
keys
(
obj
)
.
map
(
key
=>
{
let
val
=
obj
[
key
];
if
(
typeof
val
===
undefined
||
val
===
null
)
{
val
=
''
;
}
else
if
(
isPlainObject
(
val
))
{
val
=
JSON
.
stringify
(
val
);
}
return
encodeStr
(
key
)
+
'
=
'
+
encodeStr
(
val
);
})
.
filter
(
x
=>
x
.
length
>
0
)
.
join
(
'
&
'
)
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
);
}
...
...
@@ -247,7 +266,7 @@ function initVueIds(vueIds, mpInstance) {
}
const
EXTRAS
=
[
'
externalClasses
'
];
function
initExtraOptions
(
miniProgramComponentOptions
,
vueOptions
)
{
EXTRAS
.
forEach
(
name
=>
{
EXTRAS
.
forEach
(
(
name
)
=>
{
if
(
hasOwn
(
vueOptions
,
name
))
{
miniProgramComponentOptions
[
name
]
=
vueOptions
[
name
];
}
...
...
@@ -268,12 +287,12 @@ function initRefs(instance, mpInstance) {
get
()
{
const
$refs
=
{};
const
components
=
mpInstance
.
selectAllComponents
(
'
.vue-ref
'
);
components
.
forEach
(
component
=>
{
components
.
forEach
(
(
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.vue-ref-in-for
'
);
forComponents
.
forEach
(
component
=>
{
forComponents
.
forEach
(
(
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
if
(
!
$refs
[
ref
])
{
$refs
[
ref
]
=
[];
...
...
@@ -281,7 +300,7 @@ function initRefs(instance, mpInstance) {
$refs
[
ref
].
push
(
component
.
$vm
||
component
);
});
return
$refs
;
}
}
,
});
}
function
findVmByVueId
(
instance
,
vuePid
)
{
...
...
@@ -324,7 +343,7 @@ function initDefaultProps(isBehavior = false) {
if
(
!
isBehavior
)
{
properties
.
vueId
=
{
type
:
String
,
value
:
''
value
:
''
,
};
// 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
properties
.
vueSlots
=
{
...
...
@@ -336,9 +355,9 @@ function initDefaultProps(isBehavior = false) {
$slots
[
slotName
]
=
true
;
});
this
.
setData
({
$slots
$slots
,
});
}
}
,
};
}
return
properties
;
...
...
@@ -350,14 +369,14 @@ function createProperty(key, prop) {
function
initProps
(
mpComponentOptions
,
rawProps
,
isBehavior
=
false
)
{
const
properties
=
initDefaultProps
(
isBehavior
);
if
(
isArray
(
rawProps
))
{
rawProps
.
forEach
(
key
=>
{
rawProps
.
forEach
(
(
key
)
=>
{
properties
[
key
]
=
createProperty
(
key
,
{
type
:
null
type
:
null
,
});
});
}
else
if
(
isPlainObject
(
rawProps
))
{
Object
.
keys
(
rawProps
).
forEach
(
key
=>
{
Object
.
keys
(
rawProps
).
forEach
(
(
key
)
=>
{
const
opts
=
rawProps
[
key
];
if
(
isPlainObject
(
opts
))
{
// title:{type:String,default:''}
...
...
@@ -369,14 +388,14 @@ function initProps(mpComponentOptions, rawProps, isBehavior = false) {
opts
.
type
=
parsePropType
(
key
,
type
);
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
value
value
,
});
}
else
{
// content:String
const
type
=
parsePropType
(
key
,
opts
);
properties
[
key
]
=
createProperty
(
key
,
{
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
type
:
PROP_TYPES
.
indexOf
(
type
)
!==
-
1
?
type
:
null
,
});
}
});
...
...
@@ -388,8 +407,7 @@ function initData(vueOptions) {
let
data
=
vueOptions
.
data
||
{};
if
(
typeof
data
===
'
function
'
)
{
try
{
const
appConfig
=
getApp
().
$vm
.
$
.
appContext
.
config
;
const
appConfig
=
getApp
().
$vm
.
$
.
appContext
.
config
;
data
=
data
.
call
(
appConfig
.
globalProperties
);
}
catch
(
e
)
{
...
...
@@ -420,7 +438,7 @@ function initBehaviors(vueOptions, initBehavior) {
}
const
behaviors
=
[];
if
(
isArray
(
vueBehaviors
))
{
vueBehaviors
.
forEach
(
behavior
=>
{
vueBehaviors
.
forEach
(
(
behavior
)
=>
{
behaviors
.
push
(
behavior
.
replace
(
'
uni://
'
,
`
${
__PLATFORM_PREFIX__
}
://`
));
if
(
behavior
===
'
uni://form-field
'
)
{
if
(
isArray
(
vueProps
))
{
...
...
@@ -430,24 +448,24 @@ function initBehaviors(vueOptions, initBehavior) {
else
{
vueProps
.
name
=
{
type
:
String
,
default
:
''
default
:
''
,
};
vueProps
.
value
=
{
type
:
[
String
,
Number
,
Boolean
,
Array
,
Object
,
Date
],
default
:
''
default
:
''
,
};
}
}
});
}
if
(
isPlainObject
(
vueExtends
)
&&
vueExtends
.
props
)
{
if
(
vueExtends
.
props
)
{
const
behavior
=
{};
initProps
(
behavior
,
vueExtends
.
props
,
true
);
behaviors
.
push
(
initBehavior
(
behavior
));
}
if
(
isArray
(
vueMixins
))
{
vueMixins
.
forEach
(
vueMixin
=>
{
if
(
isPlainObject
(
vueMixin
)
&&
vueMixin
.
props
)
{
vueMixins
.
forEach
(
(
vueMixin
)
=>
{
if
(
vueMixin
.
props
)
{
const
behavior
=
{};
initProps
(
behavior
,
vueMixin
.
props
,
true
);
behaviors
.
push
(
initBehavior
(
behavior
));
...
...
@@ -475,7 +493,7 @@ function getValue(obj, path) {
}
function
getExtraValue
(
instance
,
dataPathsArray
)
{
let
context
=
instance
;
dataPathsArray
.
forEach
(
dataPathArray
=>
{
dataPathsArray
.
forEach
(
(
dataPathArray
)
=>
{
const
dataPath
=
dataPathArray
[
0
];
const
value
=
dataPathArray
[
2
];
if
(
dataPath
||
typeof
value
!==
'
undefined
'
)
{
...
...
@@ -505,12 +523,12 @@ function getExtraValue(instance, dataPathsArray) {
}
else
{
if
(
isArray
(
vFor
))
{
context
=
vFor
.
find
(
vForItem
=>
{
context
=
vFor
.
find
(
(
vForItem
)
=>
{
return
getValue
(
vForItem
,
propPath
)
===
value
;
});
}
else
if
(
isPlainObject
(
vFor
))
{
context
=
Object
.
keys
(
vFor
).
find
(
vForKey
=>
{
context
=
Object
.
keys
(
vFor
).
find
(
(
vForKey
)
=>
{
return
getValue
(
vFor
[
vForKey
],
propPath
)
===
value
;
});
}
...
...
@@ -600,7 +618,7 @@ function processEventArgs(instance, event, args = [], extra = [], isCustom, meth
}
const
extraObj
=
processEventExtra
(
instance
,
extra
,
event
);
const
ret
=
[];
args
.
forEach
(
arg
=>
{
args
.
forEach
(
(
arg
)
=>
{
if
(
arg
===
'
$event
'
)
{
if
(
methodName
===
'
__set_model
'
&&
!
isCustom
)
{
// input v-model value
...
...
@@ -642,7 +660,7 @@ function wrapper(event) {
event
.
detail
.
markerId
=
event
.
markerId
;
}
if
(
isPlainObject
(
event
.
detail
))
{
event
.
target
=
Object
.
assign
({},
event
.
target
,
event
.
detail
);
event
.
target
=
extend
({},
event
.
target
,
event
.
detail
);
}
return
event
;
}
...
...
@@ -712,11 +730,11 @@ function handleEvent(event) {
}
}
function
parseComponent
(
vueOptions
,
{
parse
,
mocks
,
isPage
,
initRelation
,
handleLink
,
initLifetimes
})
{
function
parseComponent
(
vueOptions
,
{
parse
,
mocks
,
isPage
,
initRelation
,
handleLink
,
initLifetimes
,
})
{
vueOptions
=
vueOptions
.
default
||
vueOptions
;
const
options
=
{
multipleSlots
:
true
,
addGlobalClass
:
true
addGlobalClass
:
true
,
};
if
(
vueOptions
.
options
)
{
extend
(
options
,
vueOptions
.
options
);
...
...
@@ -733,12 +751,12 @@ function parseComponent(vueOptions, { parse, mocks, isPage, initRelation, handle
},
resize
(
size
)
{
this
.
$vm
&&
this
.
$vm
.
$callHook
(
'
onPageResize
'
,
size
);
}
}
,
},
methods
:
{
__l
:
handleLink
,
__e
:
handleEvent
}
__e
:
handleEvent
,
}
,
};
if
(
__VUE_OPTIONS_API__
)
{
applyOptions
(
mpComponentOptions
,
vueOptions
,
initBehavior
);
...
...
@@ -778,15 +796,15 @@ function parsePage(vueOptions, parseOptions) {
isPage
,
initRelation
,
handleLink
,
initLifetimes
initLifetimes
,
});
const
methods
=
miniProgramPageOptions
.
methods
;
methods
.
onLoad
=
function
(
query
)
{
this
.
options
=
query
;
this
.
$page
=
{
fullPath
:
'
/
'
+
this
.
route
+
stringifyQuery
(
query
)
fullPath
:
'
/
'
+
this
.
route
+
stringifyQuery
(
query
)
,
};
return
this
.
$vm
&&
this
.
$vm
.
$callHook
(
'
onLoad
'
,
query
);
return
this
.
$vm
&&
this
.
$vm
.
$callHook
(
ON_LOAD
,
query
);
};
initHooks
(
methods
,
PAGE_HOOKS
);
initUnknownHooks
(
methods
,
vueOptions
);
...
...
@@ -811,7 +829,7 @@ function initTriggerEvent(mpInstance) {
return
oldTriggerEvent
.
apply
(
mpInstance
,
[
customize
(
event
),
...
args
]);
};
}
function
initHook
$1
(
name
,
options
)
{
function
initHook
(
name
,
options
)
{
const
oldHook
=
options
[
name
];
if
(
!
oldHook
)
{
options
[
name
]
=
function
()
{
...
...
@@ -826,21 +844,21 @@ function initHook$1(name, options) {
}
}
Page
=
function
(
options
)
{
initHook
$1
(
'
onLoad
'
,
options
);
initHook
(
ON_LOAD
,
options
);
return
MPPage
(
options
);
};
Component
=
function
(
options
)
{
initHook
$1
(
'
created
'
,
options
);
initHook
(
'
created
'
,
options
);
return
MPComponent
(
options
);
};
function
initLifetimes
({
mocks
,
isPage
,
initRelation
,
vueOptions
})
{
function
initLifetimes
({
mocks
,
isPage
,
initRelation
,
vueOptions
,
})
{
return
{
attached
()
{
const
properties
=
this
.
properties
;
initVueIds
(
properties
.
vueId
,
this
);
const
relationOptions
=
{
vuePid
:
this
.
_$vuePid
vuePid
:
this
.
_$vuePid
,
};
// 处理父子关系
initRelation
(
this
,
relationOptions
);
...
...
@@ -848,7 +866,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions }) {
const
mpInstance
=
this
;
this
.
$vm
=
$createComponent
({
type
:
vueOptions
,
props
:
properties
props
:
properties
,
},
{
mpType
:
isPage
(
mpInstance
)
?
'
page
'
:
'
component
'
,
mpInstance
,
...
...
@@ -858,7 +876,7 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions }) {
initRefs
(
instance
,
mpInstance
);
initMocks
(
instance
,
mpInstance
,
mocks
);
initComponentInstance
(
instance
,
options
);
}
}
,
});
},
ready
()
{
...
...
@@ -866,12 +884,12 @@ function initLifetimes({ mocks, isPage, initRelation, vueOptions }) {
// https://developers.weixin.qq.com/community/develop/doc/00066ae2844cc0f8eb883e2a557800
if
(
this
.
$vm
)
{
this
.
$vm
.
$callHook
(
'
mounted
'
);
this
.
$vm
.
$callHook
(
'
onReady
'
);
this
.
$vm
.
$callHook
(
ON_READY
);
}
},
detached
()
{
this
.
$vm
&&
$destroyComponent
(
this
.
$vm
);
}
}
,
};
}
...
...
@@ -908,6 +926,9 @@ var parseOptions = /*#__PURE__*/Object.freeze({
const
createApp
=
initCreateApp
();
const
createPage
=
initCreatePage
(
parseOptions
);
const
createComponent
=
initCreateComponent
(
parseOptions
);
const
createComponent
=
initCreateComponent
(
parseOptions
);
wx
.
createApp
=
createApp
;
wx
.
createPage
=
createPage
;
wx
.
createComponent
=
createComponent
;
export
{
createApp
,
createComponent
,
createPage
};
packages/uni-quickapp-webview/dist/uni.mp.esm.js
浏览文件 @
f94428c7
此差异已折叠。
点击以展开。
packages/vue-cli-plugin-uni/lib/env.js
浏览文件 @
f94428c7
...
...
@@ -279,6 +279,10 @@ process.env.SCOPED_SLOTS_COMPILER = modes.includes(scopedSlotsCompiler) ? scoped
if
(
process
.
env
.
UNI_PLATFORM
===
'
mp-kuaishou
'
&&
process
.
env
.
SCOPED_SLOTS_COMPILER
!==
modes
[
0
])
{
process
.
env
.
SCOPED_SLOTS_COMPILER
=
modes
[
2
]
}
// Vue3 暂时固定为 legacy 模式
if
(
process
.
env
.
UNI_USING_VUE3
)
{
process
.
env
.
SCOPED_SLOTS_COMPILER
=
modes
[
0
]
}
if
(
process
.
env
.
UNI_USING_COMPONENTS
||
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录