Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小浣熊撸代码
uni-app
提交
f5bf601f
U
uni-app
项目概览
小浣熊撸代码
/
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,发现更多精彩内容 >>
提交
f5bf601f
编写于
7月 30, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mp): add internal method
上级
dba4dee4
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
2171 addition
and
597 deletion
+2171
-597
packages/uni-mp-alipay/dist/uni.api.esm.js
packages/uni-mp-alipay/dist/uni.api.esm.js
+117
-1
packages/uni-mp-alipay/dist/uni.mp.esm.js
packages/uni-mp-alipay/dist/uni.mp.esm.js
+187
-65
packages/uni-mp-baidu/dist/uni.api.esm.js
packages/uni-mp-baidu/dist/uni.api.esm.js
+117
-1
packages/uni-mp-baidu/dist/uni.mp.esm.js
packages/uni-mp-baidu/dist/uni.mp.esm.js
+222
-100
packages/uni-mp-core/src/api/index.ts
packages/uni-mp-core/src/api/index.ts
+15
-2
packages/uni-mp-core/src/runtime/componentEvents.ts
packages/uni-mp-core/src/runtime/componentEvents.ts
+25
-31
packages/uni-mp-core/src/runtime/componentInstance/index.ts
packages/uni-mp-core/src/runtime/componentInstance/index.ts
+6
-3
packages/uni-mp-core/src/runtime/componentInstance/utils.ts
packages/uni-mp-core/src/runtime/componentInstance/utils.ts
+120
-0
packages/uni-mp-core/src/runtime/util.ts
packages/uni-mp-core/src/runtime/util.ts
+16
-0
packages/uni-mp-qq/dist/uni.api.esm.js
packages/uni-mp-qq/dist/uni.api.esm.js
+117
-1
packages/uni-mp-qq/dist/uni.mp.esm.js
packages/uni-mp-qq/dist/uni.mp.esm.js
+222
-100
packages/uni-mp-toutiao/dist/uni.api.esm.js
packages/uni-mp-toutiao/dist/uni.api.esm.js
+117
-1
packages/uni-mp-toutiao/dist/uni.mp.esm.js
packages/uni-mp-toutiao/dist/uni.mp.esm.js
+222
-100
packages/uni-mp-weixin/dist/uni.api.esm.js
packages/uni-mp-weixin/dist/uni.api.esm.js
+117
-1
packages/uni-mp-weixin/dist/uni.mp.esm.js
packages/uni-mp-weixin/dist/uni.mp.esm.js
+231
-109
packages/uni-quickapp-webview/dist/uni.api.esm.js
packages/uni-quickapp-webview/dist/uni.api.esm.js
+117
-1
packages/uni-quickapp-webview/dist/uni.mp.esm.js
packages/uni-quickapp-webview/dist/uni.mp.esm.js
+203
-81
未找到文件。
packages/uni-mp-alipay/dist/uni.api.esm.js
浏览文件 @
f5bf601f
...
@@ -462,6 +462,114 @@ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interce
...
@@ -462,6 +462,114 @@ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interce
}
}
},
RemoveInterceptorProtocol
);
},
RemoveInterceptorProtocol
);
const
API_ON
=
'
$on
'
;
const
OnProtocol
=
[
{
name
:
'
event
'
,
type
:
String
,
required
:
true
,
},
{
name
:
'
callback
'
,
type
:
Function
,
required
:
true
,
},
];
const
API_ONCE
=
'
$once
'
;
const
OnceProtocol
=
OnProtocol
;
const
API_OFF
=
'
$off
'
;
const
OffProtocol
=
[
{
name
:
'
event
'
,
type
:
[
String
,
Array
],
},
{
name
:
'
callback
'
,
type
:
Function
,
},
];
const
API_EMIT
=
'
$emit
'
;
const
EmitProtocol
=
[
{
name
:
'
event
'
,
type
:
String
,
required
:
true
,
},
];
const
E
=
function
()
{
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
};
E
.
prototype
=
{
on
:
function
(
name
,
callback
,
ctx
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
(
e
[
name
]
||
(
e
[
name
]
=
[])).
push
({
fn
:
callback
,
ctx
:
ctx
,
});
return
this
;
},
once
:
function
(
name
,
callback
,
ctx
)
{
var
self
=
this
;
function
listener
()
{
self
.
off
(
name
,
listener
);
callback
.
apply
(
ctx
,
arguments
);
}
listener
.
_
=
callback
;
return
this
.
on
(
name
,
listener
,
ctx
);
},
emit
:
function
(
name
)
{
var
data
=
[].
slice
.
call
(
arguments
,
1
);
var
evtArr
=
((
this
.
e
||
(
this
.
e
=
{}))[
name
]
||
[]).
slice
();
var
i
=
0
;
var
len
=
evtArr
.
length
;
for
(
i
;
i
<
len
;
i
++
)
{
evtArr
[
i
].
fn
.
apply
(
evtArr
[
i
].
ctx
,
data
);
}
return
this
;
},
off
:
function
(
name
,
callback
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
var
evts
=
e
[
name
];
var
liveEvents
=
[];
if
(
evts
&&
callback
)
{
for
(
var
i
=
0
,
len
=
evts
.
length
;
i
<
len
;
i
++
)
{
if
(
evts
[
i
].
fn
!==
callback
&&
evts
[
i
].
fn
.
_
!==
callback
)
liveEvents
.
push
(
evts
[
i
]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
liveEvents
.
length
?
(
e
[
name
]
=
liveEvents
)
:
delete
e
[
name
];
return
this
;
},
};
var
Emitter
=
E
;
const
emitter
=
new
Emitter
();
const
$on
=
defineSyncApi
(
API_ON
,
(
name
,
callback
)
=>
{
emitter
.
on
(
name
,
callback
);
return
()
=>
emitter
.
off
(
name
,
callback
);
},
OnProtocol
);
const
$once
=
defineSyncApi
(
API_ONCE
,
(
name
,
callback
)
=>
{
emitter
.
once
(
name
,
callback
);
return
()
=>
emitter
.
off
(
name
,
callback
);
},
OnceProtocol
);
const
$off
=
defineSyncApi
(
API_OFF
,
(
name
,
callback
)
=>
{
if
(
!
name
)
{
emitter
.
e
=
{};
return
;
}
if
(
!
Array
.
isArray
(
name
))
name
=
[
name
];
name
.
forEach
((
n
)
=>
emitter
.
off
(
n
,
callback
));
},
OffProtocol
);
const
$emit
=
defineSyncApi
(
API_EMIT
,
(
name
,
...
args
)
=>
{
emitter
.
emit
(
name
,
...
args
);
},
EmitProtocol
);
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
// Context例外情况
// Context例外情况
...
@@ -606,7 +714,15 @@ function initWrapper(protocols) {
...
@@ -606,7 +714,15 @@ function initWrapper(protocols) {
};
};
}
}
const
baseApis
=
{
upx2px
,
addInterceptor
,
removeInterceptor
};
const
baseApis
=
{
$on
,
$off
,
$once
,
$emit
,
upx2px
,
addInterceptor
,
removeInterceptor
,
};
function
initUni
(
api
,
protocols
)
{
function
initUni
(
api
,
protocols
)
{
const
wrapper
=
initWrapper
(
protocols
);
const
wrapper
=
initWrapper
(
protocols
);
const
UniProxyHandlers
=
{
const
UniProxyHandlers
=
{
...
...
packages/uni-mp-alipay/dist/uni.mp.esm.js
浏览文件 @
f5bf601f
import
{
isPlainObject
,
hasOwn
,
isArray
,
toNumber
,
isObject
,
capitalize
,
isFunction
,
extend
,
NOOP
,
EMPTY_OBJ
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
isArray
,
extend
,
hyphenate
,
isObject
,
hasOwn
,
toNumber
,
capitalize
,
isFunction
,
NOOP
,
EMPTY_OBJ
,
camelize
}
from
'
@vue/shared
'
;
const
encode
=
encodeURIComponent
;
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
...
@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
...
@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
return
res
?
`?
${
res
}
`
:
''
;
}
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
@@ -121,6 +129,167 @@ function getEventChannel(id) {
...
@@ -121,6 +129,167 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
return
eventChannelStack
.
shift
();
}
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
}
const
ids
=
vueIds
.
split
(
'
,
'
);
const
len
=
ids
.
length
;
if
(
len
===
1
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
}
else
if
(
len
===
2
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
mpInstance
.
_$vuePid
=
ids
[
1
];
}
}
function
initWxsCallMethods
(
methods
,
wxsCallMethods
)
{
if
(
!
isArray
(
wxsCallMethods
))
{
return
;
}
wxsCallMethods
.
forEach
((
callMethod
)
=>
{
methods
[
callMethod
]
=
function
(
args
)
{
return
this
.
$vm
[
callMethod
](
args
);
};
});
}
function
findVmByVueId
(
instance
,
vuePid
)
{
// 标准 vue3 中 没有 $children,定制了内核
const
$children
=
instance
.
$children
;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childVm
=
$children
[
i
];
if
(
childVm
.
$scope
.
_$vueId
===
vuePid
)
{
return
childVm
;
}
}
// 反向递归查找
let
parentVm
;
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
parentVm
=
findVmByVueId
(
$children
[
i
],
vuePid
);
if
(
parentVm
)
{
return
parentVm
;
}
}
}
function
getTarget
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
));
}
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getTarget
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
getValue
(
dataPath
,
target
)
{
return
getTarget
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
...
@@ -239,7 +408,9 @@ function initComponentInstance(instance, options) {
...
@@ -239,7 +408,9 @@ function initComponentInstance(instance, options) {
ctx
.
__set_sync
=
setSync
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
ctx
.
__get_orig
=
getOrig
;
// TODO
// TODO
// ctx.__get_style = getStyle
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
ctx
.
__map
=
map
;
}
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
...
@@ -366,50 +537,6 @@ function initCreateApp(parseAppOptions) {
...
@@ -366,50 +537,6 @@ function initCreateApp(parseAppOptions) {
};
};
}
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
}
const
ids
=
vueIds
.
split
(
'
,
'
);
const
len
=
ids
.
length
;
if
(
len
===
1
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
}
else
if
(
len
===
2
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
mpInstance
.
_$vuePid
=
ids
[
1
];
}
}
function
initWxsCallMethods
(
methods
,
wxsCallMethods
)
{
if
(
!
isArray
(
wxsCallMethods
))
{
return
;
}
wxsCallMethods
.
forEach
((
callMethod
)
=>
{
methods
[
callMethod
]
=
function
(
args
)
{
return
this
.
$vm
[
callMethod
](
args
);
};
});
}
function
findVmByVueId
(
instance
,
vuePid
)
{
// 标准 vue3 中 没有 $children,定制了内核
const
$children
=
instance
.
$children
;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childVm
=
$children
[
i
];
if
(
childVm
.
$scope
.
_$vueId
===
vuePid
)
{
return
childVm
;
}
}
// 反向递归查找
let
parentVm
;
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
parentVm
=
findVmByVueId
(
$children
[
i
],
vuePid
);
if
(
parentVm
)
{
return
parentVm
;
}
}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
function
parsePropType
(
key
,
type
,
defaultValue
)
{
function
parsePropType
(
key
,
type
,
defaultValue
)
{
// [String]=>String
// [String]=>String
...
@@ -556,18 +683,6 @@ function initBehaviors(vueOptions, initBehavior) {
...
@@ -556,18 +683,6 @@ function initBehaviors(vueOptions, initBehavior) {
return
behaviors
;
return
behaviors
;
}
}
function
getValue
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
));
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getValue
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
getExtraValue
(
instance
,
dataPathsArray
)
{
function
getExtraValue
(
instance
,
dataPathsArray
)
{
let
context
=
instance
;
let
context
=
instance
;
dataPathsArray
.
forEach
((
dataPathArray
)
=>
{
dataPathsArray
.
forEach
((
dataPathArray
)
=>
{
...
@@ -589,7 +704,7 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -589,7 +704,7 @@ function getExtraValue(instance, dataPathsArray) {
vFor
=
dataPath
.
substr
(
3
);
vFor
=
dataPath
.
substr
(
3
);
}
}
else
{
else
{
vFor
=
get
Value
(
context
,
dataPath
);
vFor
=
get
Target
(
context
,
dataPath
);
}
}
}
}
if
(
Number
.
isInteger
(
vFor
))
{
if
(
Number
.
isInteger
(
vFor
))
{
...
@@ -601,12 +716,12 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -601,12 +716,12 @@ function getExtraValue(instance, dataPathsArray) {
else
{
else
{
if
(
isArray
(
vFor
))
{
if
(
isArray
(
vFor
))
{
context
=
vFor
.
find
((
vForItem
)
=>
{
context
=
vFor
.
find
((
vForItem
)
=>
{
return
get
Value
(
vForItem
,
propPath
)
===
value
;
return
get
Target
(
vForItem
,
propPath
)
===
value
;
});
});
}
}
else
if
(
isPlainObject
(
vFor
))
{
else
if
(
isPlainObject
(
vFor
))
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
return
get
Value
(
vFor
[
vForKey
],
propPath
)
===
value
;
return
get
Target
(
vFor
[
vForKey
],
propPath
)
===
value
;
});
});
}
}
else
{
else
{
...
@@ -614,7 +729,7 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -614,7 +729,7 @@ function getExtraValue(instance, dataPathsArray) {
}
}
}
}
if
(
valuePath
)
{
if
(
valuePath
)
{
context
=
get
Value
(
context
,
valuePath
);
context
=
get
Target
(
context
,
valuePath
);
}
}
}
}
});
});
...
@@ -655,10 +770,10 @@ function processEventExtra(instance, extra, event) {
...
@@ -655,10 +770,10 @@ function processEventExtra(instance, extra, event) {
}
}
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
// $event.target.value
// $event.target.value
extraObj
[
'
$
'
+
index
]
=
get
Value
(
event
,
dataPath
.
replace
(
'
$event.
'
,
''
));
extraObj
[
'
$
'
+
index
]
=
get
Target
(
event
,
dataPath
.
replace
(
'
$event.
'
,
''
));
}
}
else
{
else
{
extraObj
[
'
$
'
+
index
]
=
get
Value
(
instance
,
dataPath
);
extraObj
[
'
$
'
+
index
]
=
get
Target
(
instance
,
dataPath
);
}
}
}
}
}
}
...
@@ -795,7 +910,14 @@ function handleEvent(event) {
...
@@ -795,7 +910,14 @@ function handleEvent(event) {
}
}
handler
.
once
=
true
;
handler
.
once
=
true
;
}
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
processEventArgs
(
this
.
$vm
,
event
,
eventArray
[
1
],
eventArray
[
2
],
isCustom
,
methodName
)));
let
params
=
processEventArgs
(
this
.
$vm
,
event
,
eventArray
[
1
],
eventArray
[
2
],
isCustom
,
methodName
);
params
=
Array
.
isArray
(
params
)
?
params
:
[];
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if
(
/=
\s
*
\S
+
\.
eventParams
\s
*
\|\|\s
*
\S
+
\[[
'"
]
event-params
[
'"
]\]
/
.
test
(
handler
.
toString
()))
{
// eslint-disable-next-line no-sparse-arrays
params
=
params
.
concat
([,
,
,
,
,
,
,
,
,
,
event
]);
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
params
));
}
}
});
});
}
}
...
...
packages/uni-mp-baidu/dist/uni.api.esm.js
浏览文件 @
f5bf601f
...
@@ -462,6 +462,114 @@ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interce
...
@@ -462,6 +462,114 @@ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interce
}
}
},
RemoveInterceptorProtocol
);
},
RemoveInterceptorProtocol
);
const
API_ON
=
'
$on
'
;
const
OnProtocol
=
[
{
name
:
'
event
'
,
type
:
String
,
required
:
true
,
},
{
name
:
'
callback
'
,
type
:
Function
,
required
:
true
,
},
];
const
API_ONCE
=
'
$once
'
;
const
OnceProtocol
=
OnProtocol
;
const
API_OFF
=
'
$off
'
;
const
OffProtocol
=
[
{
name
:
'
event
'
,
type
:
[
String
,
Array
],
},
{
name
:
'
callback
'
,
type
:
Function
,
},
];
const
API_EMIT
=
'
$emit
'
;
const
EmitProtocol
=
[
{
name
:
'
event
'
,
type
:
String
,
required
:
true
,
},
];
const
E
=
function
()
{
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
};
E
.
prototype
=
{
on
:
function
(
name
,
callback
,
ctx
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
(
e
[
name
]
||
(
e
[
name
]
=
[])).
push
({
fn
:
callback
,
ctx
:
ctx
,
});
return
this
;
},
once
:
function
(
name
,
callback
,
ctx
)
{
var
self
=
this
;
function
listener
()
{
self
.
off
(
name
,
listener
);
callback
.
apply
(
ctx
,
arguments
);
}
listener
.
_
=
callback
;
return
this
.
on
(
name
,
listener
,
ctx
);
},
emit
:
function
(
name
)
{
var
data
=
[].
slice
.
call
(
arguments
,
1
);
var
evtArr
=
((
this
.
e
||
(
this
.
e
=
{}))[
name
]
||
[]).
slice
();
var
i
=
0
;
var
len
=
evtArr
.
length
;
for
(
i
;
i
<
len
;
i
++
)
{
evtArr
[
i
].
fn
.
apply
(
evtArr
[
i
].
ctx
,
data
);
}
return
this
;
},
off
:
function
(
name
,
callback
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
var
evts
=
e
[
name
];
var
liveEvents
=
[];
if
(
evts
&&
callback
)
{
for
(
var
i
=
0
,
len
=
evts
.
length
;
i
<
len
;
i
++
)
{
if
(
evts
[
i
].
fn
!==
callback
&&
evts
[
i
].
fn
.
_
!==
callback
)
liveEvents
.
push
(
evts
[
i
]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
liveEvents
.
length
?
(
e
[
name
]
=
liveEvents
)
:
delete
e
[
name
];
return
this
;
},
};
var
Emitter
=
E
;
const
emitter
=
new
Emitter
();
const
$on
=
defineSyncApi
(
API_ON
,
(
name
,
callback
)
=>
{
emitter
.
on
(
name
,
callback
);
return
()
=>
emitter
.
off
(
name
,
callback
);
},
OnProtocol
);
const
$once
=
defineSyncApi
(
API_ONCE
,
(
name
,
callback
)
=>
{
emitter
.
once
(
name
,
callback
);
return
()
=>
emitter
.
off
(
name
,
callback
);
},
OnceProtocol
);
const
$off
=
defineSyncApi
(
API_OFF
,
(
name
,
callback
)
=>
{
if
(
!
name
)
{
emitter
.
e
=
{};
return
;
}
if
(
!
Array
.
isArray
(
name
))
name
=
[
name
];
name
.
forEach
((
n
)
=>
emitter
.
off
(
n
,
callback
));
},
OffProtocol
);
const
$emit
=
defineSyncApi
(
API_EMIT
,
(
name
,
...
args
)
=>
{
emitter
.
emit
(
name
,
...
args
);
},
EmitProtocol
);
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
// Context例外情况
// Context例外情况
...
@@ -606,7 +714,15 @@ function initWrapper(protocols) {
...
@@ -606,7 +714,15 @@ function initWrapper(protocols) {
};
};
}
}
const
baseApis
=
{
upx2px
,
addInterceptor
,
removeInterceptor
};
const
baseApis
=
{
$on
,
$off
,
$once
,
$emit
,
upx2px
,
addInterceptor
,
removeInterceptor
,
};
function
initUni
(
api
,
protocols
)
{
function
initUni
(
api
,
protocols
)
{
const
wrapper
=
initWrapper
(
protocols
);
const
wrapper
=
initWrapper
(
protocols
);
const
UniProxyHandlers
=
{
const
UniProxyHandlers
=
{
...
...
packages/uni-mp-baidu/dist/uni.mp.esm.js
浏览文件 @
f5bf601f
import
{
isPlainObject
,
isArray
,
hasOwn
,
toNumber
,
isObject
,
isFunction
,
extend
,
NOOP
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
hasOwn
,
isArray
,
extend
,
hyphenate
,
isObject
,
toNumber
,
isFunction
,
NOOP
,
camelize
}
from
'
@vue/shared
'
;
const
encode
=
encodeURIComponent
;
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
...
@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
...
@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
return
res
?
`?
${
res
}
`
:
''
;
}
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
@@ -120,6 +128,202 @@ function getEventChannel(id) {
...
@@ -120,6 +128,202 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
return
eventChannelStack
.
shift
();
}
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
);
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
}
const
ids
=
vueIds
.
split
(
'
,
'
);
const
len
=
ids
.
length
;
if
(
len
===
1
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
}
else
if
(
len
===
2
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
mpInstance
.
_$vuePid
=
ids
[
1
];
}
}
const
EXTRAS
=
[
'
externalClasses
'
];
function
initExtraOptions
(
miniProgramComponentOptions
,
vueOptions
)
{
EXTRAS
.
forEach
((
name
)
=>
{
if
(
hasOwn
(
vueOptions
,
name
))
{
miniProgramComponentOptions
[
name
]
=
vueOptions
[
name
];
}
});
}
function
initWxsCallMethods
(
methods
,
wxsCallMethods
)
{
if
(
!
isArray
(
wxsCallMethods
))
{
return
;
}
wxsCallMethods
.
forEach
((
callMethod
)
=>
{
methods
[
callMethod
]
=
function
(
args
)
{
return
this
.
$vm
[
callMethod
](
args
);
};
});
}
function
selectAllComponents
(
mpInstance
,
selector
,
$refs
)
{
const
components
=
mpInstance
.
selectAllComponents
(
selector
);
components
.
forEach
((
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
}
function
initRefs
(
instance
,
mpInstance
)
{
Object
.
defineProperty
(
instance
,
'
refs
'
,
{
get
()
{
const
$refs
=
{};
selectAllComponents
(
mpInstance
,
'
.vue-ref
'
,
$refs
);
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
findVmByVueId
(
instance
,
vuePid
)
{
// 标准 vue3 中 没有 $children,定制了内核
const
$children
=
instance
.
$children
;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childVm
=
$children
[
i
];
if
(
childVm
.
$scope
.
_$vueId
===
vuePid
)
{
return
childVm
;
}
}
// 反向递归查找
let
parentVm
;
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
parentVm
=
findVmByVueId
(
$children
[
i
],
vuePid
);
if
(
parentVm
)
{
return
parentVm
;
}
}
}
function
getTarget
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
));
}
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getTarget
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
getValue
(
dataPath
,
target
)
{
return
getTarget
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
...
@@ -229,7 +433,9 @@ function initComponentInstance(instance, options) {
...
@@ -229,7 +433,9 @@ function initComponentInstance(instance, options) {
ctx
.
__set_sync
=
setSync
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
ctx
.
__get_orig
=
getOrig
;
// TODO
// TODO
// ctx.__get_style = getStyle
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
ctx
.
__map
=
map
;
}
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
...
@@ -356,85 +562,6 @@ function initCreateApp(parseAppOptions) {
...
@@ -356,85 +562,6 @@ function initCreateApp(parseAppOptions) {
};
};
}
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
);
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
}
const
ids
=
vueIds
.
split
(
'
,
'
);
const
len
=
ids
.
length
;
if
(
len
===
1
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
}
else
if
(
len
===
2
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
mpInstance
.
_$vuePid
=
ids
[
1
];
}
}
const
EXTRAS
=
[
'
externalClasses
'
];
function
initExtraOptions
(
miniProgramComponentOptions
,
vueOptions
)
{
EXTRAS
.
forEach
((
name
)
=>
{
if
(
hasOwn
(
vueOptions
,
name
))
{
miniProgramComponentOptions
[
name
]
=
vueOptions
[
name
];
}
});
}
function
initWxsCallMethods
(
methods
,
wxsCallMethods
)
{
if
(
!
isArray
(
wxsCallMethods
))
{
return
;
}
wxsCallMethods
.
forEach
((
callMethod
)
=>
{
methods
[
callMethod
]
=
function
(
args
)
{
return
this
.
$vm
[
callMethod
](
args
);
};
});
}
function
selectAllComponents
(
mpInstance
,
selector
,
$refs
)
{
const
components
=
mpInstance
.
selectAllComponents
(
selector
);
components
.
forEach
((
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
}
function
initRefs
(
instance
,
mpInstance
)
{
Object
.
defineProperty
(
instance
,
'
refs
'
,
{
get
()
{
const
$refs
=
{};
selectAllComponents
(
mpInstance
,
'
.vue-ref
'
,
$refs
);
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
findVmByVueId
(
instance
,
vuePid
)
{
// 标准 vue3 中 没有 $children,定制了内核
const
$children
=
instance
.
$children
;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childVm
=
$children
[
i
];
if
(
childVm
.
$scope
.
_$vueId
===
vuePid
)
{
return
childVm
;
}
}
// 反向递归查找
let
parentVm
;
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
parentVm
=
findVmByVueId
(
$children
[
i
],
vuePid
);
if
(
parentVm
)
{
return
parentVm
;
}
}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
function
createObserver
(
name
)
{
function
createObserver
(
name
)
{
return
function
observer
(
newVal
)
{
return
function
observer
(
newVal
)
{
...
@@ -602,18 +729,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
...
@@ -602,18 +729,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
componentOptions
.
behaviors
=
initBehaviors
(
vueOptions
,
initBehavior
);
componentOptions
.
behaviors
=
initBehaviors
(
vueOptions
,
initBehavior
);
}
}
function
getValue
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
));
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getValue
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
getExtraValue
(
instance
,
dataPathsArray
)
{
function
getExtraValue
(
instance
,
dataPathsArray
)
{
let
context
=
instance
;
let
context
=
instance
;
dataPathsArray
.
forEach
((
dataPathArray
)
=>
{
dataPathsArray
.
forEach
((
dataPathArray
)
=>
{
...
@@ -635,7 +750,7 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -635,7 +750,7 @@ function getExtraValue(instance, dataPathsArray) {
vFor
=
dataPath
.
substr
(
3
);
vFor
=
dataPath
.
substr
(
3
);
}
}
else
{
else
{
vFor
=
get
Value
(
context
,
dataPath
);
vFor
=
get
Target
(
context
,
dataPath
);
}
}
}
}
if
(
Number
.
isInteger
(
vFor
))
{
if
(
Number
.
isInteger
(
vFor
))
{
...
@@ -647,12 +762,12 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -647,12 +762,12 @@ function getExtraValue(instance, dataPathsArray) {
else
{
else
{
if
(
isArray
(
vFor
))
{
if
(
isArray
(
vFor
))
{
context
=
vFor
.
find
((
vForItem
)
=>
{
context
=
vFor
.
find
((
vForItem
)
=>
{
return
get
Value
(
vForItem
,
propPath
)
===
value
;
return
get
Target
(
vForItem
,
propPath
)
===
value
;
});
});
}
}
else
if
(
isPlainObject
(
vFor
))
{
else
if
(
isPlainObject
(
vFor
))
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
return
get
Value
(
vFor
[
vForKey
],
propPath
)
===
value
;
return
get
Target
(
vFor
[
vForKey
],
propPath
)
===
value
;
});
});
}
}
else
{
else
{
...
@@ -660,7 +775,7 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -660,7 +775,7 @@ function getExtraValue(instance, dataPathsArray) {
}
}
}
}
if
(
valuePath
)
{
if
(
valuePath
)
{
context
=
get
Value
(
context
,
valuePath
);
context
=
get
Target
(
context
,
valuePath
);
}
}
}
}
});
});
...
@@ -701,10 +816,10 @@ function processEventExtra(instance, extra, event) {
...
@@ -701,10 +816,10 @@ function processEventExtra(instance, extra, event) {
}
}
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
// $event.target.value
// $event.target.value
extraObj
[
'
$
'
+
index
]
=
get
Value
(
event
,
dataPath
.
replace
(
'
$event.
'
,
''
));
extraObj
[
'
$
'
+
index
]
=
get
Target
(
event
,
dataPath
.
replace
(
'
$event.
'
,
''
));
}
}
else
{
else
{
extraObj
[
'
$
'
+
index
]
=
get
Value
(
instance
,
dataPath
);
extraObj
[
'
$
'
+
index
]
=
get
Target
(
instance
,
dataPath
);
}
}
}
}
}
}
...
@@ -849,7 +964,14 @@ function handleEvent(event) {
...
@@ -849,7 +964,14 @@ function handleEvent(event) {
}
}
handler
.
once
=
true
;
handler
.
once
=
true
;
}
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
processEventArgs
(
this
.
$vm
,
event
,
eventArray
[
1
],
eventArray
[
2
],
isCustom
,
methodName
)));
let
params
=
processEventArgs
(
this
.
$vm
,
event
,
eventArray
[
1
],
eventArray
[
2
],
isCustom
,
methodName
);
params
=
Array
.
isArray
(
params
)
?
params
:
[];
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if
(
/=
\s
*
\S
+
\.
eventParams
\s
*
\|\|\s
*
\S
+
\[[
'"
]
event-params
[
'"
]\]
/
.
test
(
handler
.
toString
()))
{
// eslint-disable-next-line no-sparse-arrays
params
=
params
.
concat
([,
,
,
,
,
,
,
,
,
,
event
]);
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
params
));
}
}
});
});
}
}
...
...
packages/uni-mp-core/src/api/index.ts
浏览文件 @
f5bf601f
...
@@ -5,13 +5,26 @@ import {
...
@@ -5,13 +5,26 @@ import {
addInterceptor
,
addInterceptor
,
removeInterceptor
,
removeInterceptor
,
}
from
'
@dcloudio/uni-api/src/service/base/interceptor
'
}
from
'
@dcloudio/uni-api/src/service/base/interceptor
'
import
{
$on
,
$off
,
$once
,
$emit
,
}
from
'
@dcloudio/uni-api/src/service/base/eventBus
'
import
{
promisify
}
from
'
./promise
'
import
{
promisify
}
from
'
./promise
'
import
{
initWrapper
}
from
'
./wrapper
'
import
{
initWrapper
}
from
'
./wrapper
'
import
{
MPProtocols
}
from
'
./protocols
'
import
{
MPProtocols
}
from
'
./protocols
'
const
baseApis
=
{
upx2px
,
addInterceptor
,
removeInterceptor
}
const
baseApis
=
{
$on
,
$off
,
$once
,
$emit
,
upx2px
,
addInterceptor
,
removeInterceptor
,
}
export
function
initUni
(
api
:
Record
<
string
,
any
>
,
protocols
:
MPProtocols
)
{
export
function
initUni
(
api
:
Record
<
string
,
any
>
,
protocols
:
MPProtocols
)
{
const
wrapper
=
initWrapper
(
protocols
)
const
wrapper
=
initWrapper
(
protocols
)
...
...
packages/uni-mp-core/src/runtime/componentEvents.ts
浏览文件 @
f5bf601f
...
@@ -8,6 +8,7 @@ import {
...
@@ -8,6 +8,7 @@ import {
}
from
'
@vue/shared
'
}
from
'
@vue/shared
'
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
MPComponentInstance
}
from
'
./component
'
import
{
MPComponentInstance
}
from
'
./component
'
import
{
getTarget
}
from
'
./util
'
interface
Event
extends
WechatMiniprogram
.
BaseEvent
{
interface
Event
extends
WechatMiniprogram
.
BaseEvent
{
detail
:
Record
<
string
,
any
>
detail
:
Record
<
string
,
any
>
...
@@ -15,19 +16,6 @@ interface Event extends WechatMiniprogram.BaseEvent {
...
@@ -15,19 +16,6 @@ interface Event extends WechatMiniprogram.BaseEvent {
preventDefault
:
()
=>
void
preventDefault
:
()
=>
void
}
}
function
getValue
(
obj
:
any
,
path
:
string
):
unknown
{
const
parts
=
path
.
split
(
'
.
'
)
let
key
:
string
|
number
=
parts
[
0
]
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
))
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
]
}
return
getValue
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
))
}
function
getExtraValue
(
function
getExtraValue
(
instance
:
ComponentPublicInstance
,
instance
:
ComponentPublicInstance
,
dataPathsArray
:
string
[]
dataPathsArray
:
string
[]
...
@@ -50,7 +38,7 @@ function getExtraValue(
...
@@ -50,7 +38,7 @@ function getExtraValue(
if
(
dataPath
.
indexOf
(
'
#s#
'
)
===
0
)
{
if
(
dataPath
.
indexOf
(
'
#s#
'
)
===
0
)
{
vFor
=
dataPath
.
substr
(
3
)
vFor
=
dataPath
.
substr
(
3
)
}
else
{
}
else
{
vFor
=
get
Value
(
context
,
dataPath
)
vFor
=
get
Target
(
context
,
dataPath
)
}
}
}
}
...
@@ -61,11 +49,11 @@ function getExtraValue(
...
@@ -61,11 +49,11 @@ function getExtraValue(
}
else
{
}
else
{
if
(
isArray
(
vFor
))
{
if
(
isArray
(
vFor
))
{
context
=
vFor
.
find
((
vForItem
)
=>
{
context
=
vFor
.
find
((
vForItem
)
=>
{
return
get
Value
(
vForItem
,
propPath
)
===
value
return
get
Target
(
vForItem
,
propPath
)
===
value
})
})
}
else
if
(
isPlainObject
(
vFor
))
{
}
else
if
(
isPlainObject
(
vFor
))
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
return
get
Value
(
vFor
[
vForKey
],
propPath
)
===
value
return
get
Target
(
vFor
[
vForKey
],
propPath
)
===
value
})
})
}
else
{
}
else
{
console
.
error
(
'
v-for 暂不支持循环数据:
'
,
vFor
)
console
.
error
(
'
v-for 暂不支持循环数据:
'
,
vFor
)
...
@@ -73,7 +61,7 @@ function getExtraValue(
...
@@ -73,7 +61,7 @@ function getExtraValue(
}
}
if
(
valuePath
)
{
if
(
valuePath
)
{
context
=
get
Value
(
context
,
valuePath
)
context
=
get
Target
(
context
,
valuePath
)
}
}
}
}
})
})
...
@@ -116,12 +104,12 @@ function processEventExtra(
...
@@ -116,12 +104,12 @@ function processEventExtra(
}
}
}
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
}
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
// $event.target.value
// $event.target.value
extraObj
[
'
$
'
+
index
]
=
get
Value
(
extraObj
[
'
$
'
+
index
]
=
get
Target
(
event
,
event
,
dataPath
.
replace
(
'
$event.
'
,
''
)
dataPath
.
replace
(
'
$event.
'
,
''
)
)
)
}
else
{
}
else
{
extraObj
[
'
$
'
+
index
]
=
get
Value
(
instance
,
dataPath
)
extraObj
[
'
$
'
+
index
]
=
get
Target
(
instance
,
dataPath
)
}
}
}
}
}
else
{
}
else
{
...
@@ -305,19 +293,25 @@ export function handleEvent(this: MPComponentInstance, event: Event) {
...
@@ -305,19 +293,25 @@ export function handleEvent(this: MPComponentInstance, event: Event) {
}
}
handler
.
once
=
true
handler
.
once
=
true
}
}
ret
.
push
(
let
params
=
processEventArgs
(
handler
.
apply
(
this
.
$vm
!
,
handlerCtx
,
event
,
processEventArgs
(
eventArray
[
1
],
this
.
$vm
!
,
eventArray
[
2
],
event
,
isCustom
,
eventArray
[
1
],
methodName
eventArray
[
2
],
isCustom
,
methodName
)
)
)
)
params
=
Array
.
isArray
(
params
)
?
params
:
[]
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if
(
/=
\s
*
\S
+
\.
eventParams
\s
*
\|\|\s
*
\S
+
\[[
'"
]
event-params
[
'"
]\]
/
.
test
(
handler
.
toString
()
)
)
{
// eslint-disable-next-line no-sparse-arrays
params
=
params
.
concat
([,
,
,
,
,
,
,
,
,
,
event
])
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
params
))
}
}
})
})
}
}
...
...
packages/uni-mp-core/src/runtime/componentInstance.ts
→
packages/uni-mp-core/src/runtime/componentInstance
/index
.ts
浏览文件 @
f5bf601f
...
@@ -9,8 +9,9 @@ import {
...
@@ -9,8 +9,9 @@ import {
}
from
'
@vue/shared
'
}
from
'
@vue/shared
'
import
{
ComponentPublicInstance
,
ComponentInternalInstance
}
from
'
vue
'
import
{
ComponentPublicInstance
,
ComponentInternalInstance
}
from
'
vue
'
import
{
getEventChannel
}
from
'
../api/protocols/navigateTo
'
import
{
getEventChannel
}
from
'
../../api/protocols/navigateTo
'
import
{
MPComponentInstance
}
from
'
../index
'
import
{
MPComponentInstance
}
from
'
../component
'
import
{
getClass
,
getStyle
,
getValue
}
from
'
./utils
'
function
setModel
(
function
setModel
(
this
:
ComponentPublicInstance
,
this
:
ComponentPublicInstance
,
...
@@ -185,7 +186,9 @@ export function initComponentInstance(
...
@@ -185,7 +186,9 @@ export function initComponentInstance(
ctx
.
__set_sync
=
setSync
ctx
.
__set_sync
=
setSync
ctx
.
__get_orig
=
getOrig
ctx
.
__get_orig
=
getOrig
// TODO
// TODO
// ctx.__get_style = getStyle
ctx
.
__get_value
=
getValue
ctx
.
__get_class
=
getClass
ctx
.
__get_style
=
getStyle
ctx
.
__map
=
map
ctx
.
__map
=
map
}
}
...
...
packages/uni-mp-core/src/runtime/componentInstance/utils.ts
0 → 100644
浏览文件 @
f5bf601f
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
extend
,
isObject
,
hyphenate
}
from
'
@vue/shared
'
import
{
cache
}
from
'
@dcloudio/uni-shared
'
import
{
getTarget
}
from
'
../util
'
export
function
getValue
(
this
:
ComponentPublicInstance
,
dataPath
:
string
,
target
:
Record
<
string
,
any
>
)
{
return
getTarget
(
target
||
this
,
dataPath
)
}
export
function
getClass
(
dynamicClass
:
unknown
,
staticClass
:
string
)
{
return
renderClass
(
staticClass
,
dynamicClass
)
}
export
function
getStyle
(
dynamicStyle
:
unknown
,
staticStyle
:
string
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
)
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
return
Object
.
keys
(
styleObj
as
any
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
(
styleObj
as
any
)[
name
]
})
.
join
(
'
;
'
)
}
function
toObject
(
arr
:
unknown
[])
{
var
res
=
{}
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
])
}
}
return
res
}
function
normalizeStyleBinding
(
bindingStyle
:
unknown
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
)
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
)
}
return
bindingStyle
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{}
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
var
propertyDelimiter
=
/:
(
.+
)
/
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
)
tmp
.
length
>
1
&&
((
res
as
any
)[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
())
}
})
return
res
})
function
isDef
(
v
:
unknown
)
{
return
v
!==
undefined
&&
v
!==
null
}
function
renderClass
(
staticClass
:
string
,
dynamicClass
:
unknown
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
))
}
/* istanbul ignore next */
return
''
}
function
concat
(
a
?:
string
,
b
?:
string
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
}
function
stringifyClass
(
value
:
unknown
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
)
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
)
}
if
(
typeof
value
===
'
string
'
)
{
return
value
}
/* istanbul ignore next */
return
''
}
function
stringifyArray
(
value
:
unknown
[])
{
var
res
=
''
var
stringified
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
}
res
+=
stringified
}
}
return
res
}
function
stringifyObject
(
value
:
Record
<
string
,
any
>
)
{
var
res
=
''
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
}
res
+=
key
}
}
return
res
}
packages/uni-mp-core/src/runtime/util.ts
浏览文件 @
f5bf601f
...
@@ -124,3 +124,19 @@ export function findVmByVueId(
...
@@ -124,3 +124,19 @@ export function findVmByVueId(
}
}
}
}
}
}
export
function
getTarget
(
obj
:
any
,
path
:
string
):
unknown
{
const
parts
=
path
.
split
(
'
.
'
)
let
key
:
number
|
string
=
parts
[
0
]
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
))
}
if
(
!
obj
)
{
obj
=
{}
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
]
}
return
getTarget
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
))
}
packages/uni-mp-qq/dist/uni.api.esm.js
浏览文件 @
f5bf601f
...
@@ -462,6 +462,114 @@ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interce
...
@@ -462,6 +462,114 @@ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interce
}
}
},
RemoveInterceptorProtocol
);
},
RemoveInterceptorProtocol
);
const
API_ON
=
'
$on
'
;
const
OnProtocol
=
[
{
name
:
'
event
'
,
type
:
String
,
required
:
true
,
},
{
name
:
'
callback
'
,
type
:
Function
,
required
:
true
,
},
];
const
API_ONCE
=
'
$once
'
;
const
OnceProtocol
=
OnProtocol
;
const
API_OFF
=
'
$off
'
;
const
OffProtocol
=
[
{
name
:
'
event
'
,
type
:
[
String
,
Array
],
},
{
name
:
'
callback
'
,
type
:
Function
,
},
];
const
API_EMIT
=
'
$emit
'
;
const
EmitProtocol
=
[
{
name
:
'
event
'
,
type
:
String
,
required
:
true
,
},
];
const
E
=
function
()
{
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
};
E
.
prototype
=
{
on
:
function
(
name
,
callback
,
ctx
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
(
e
[
name
]
||
(
e
[
name
]
=
[])).
push
({
fn
:
callback
,
ctx
:
ctx
,
});
return
this
;
},
once
:
function
(
name
,
callback
,
ctx
)
{
var
self
=
this
;
function
listener
()
{
self
.
off
(
name
,
listener
);
callback
.
apply
(
ctx
,
arguments
);
}
listener
.
_
=
callback
;
return
this
.
on
(
name
,
listener
,
ctx
);
},
emit
:
function
(
name
)
{
var
data
=
[].
slice
.
call
(
arguments
,
1
);
var
evtArr
=
((
this
.
e
||
(
this
.
e
=
{}))[
name
]
||
[]).
slice
();
var
i
=
0
;
var
len
=
evtArr
.
length
;
for
(
i
;
i
<
len
;
i
++
)
{
evtArr
[
i
].
fn
.
apply
(
evtArr
[
i
].
ctx
,
data
);
}
return
this
;
},
off
:
function
(
name
,
callback
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
var
evts
=
e
[
name
];
var
liveEvents
=
[];
if
(
evts
&&
callback
)
{
for
(
var
i
=
0
,
len
=
evts
.
length
;
i
<
len
;
i
++
)
{
if
(
evts
[
i
].
fn
!==
callback
&&
evts
[
i
].
fn
.
_
!==
callback
)
liveEvents
.
push
(
evts
[
i
]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
liveEvents
.
length
?
(
e
[
name
]
=
liveEvents
)
:
delete
e
[
name
];
return
this
;
},
};
var
Emitter
=
E
;
const
emitter
=
new
Emitter
();
const
$on
=
defineSyncApi
(
API_ON
,
(
name
,
callback
)
=>
{
emitter
.
on
(
name
,
callback
);
return
()
=>
emitter
.
off
(
name
,
callback
);
},
OnProtocol
);
const
$once
=
defineSyncApi
(
API_ONCE
,
(
name
,
callback
)
=>
{
emitter
.
once
(
name
,
callback
);
return
()
=>
emitter
.
off
(
name
,
callback
);
},
OnceProtocol
);
const
$off
=
defineSyncApi
(
API_OFF
,
(
name
,
callback
)
=>
{
if
(
!
name
)
{
emitter
.
e
=
{};
return
;
}
if
(
!
Array
.
isArray
(
name
))
name
=
[
name
];
name
.
forEach
((
n
)
=>
emitter
.
off
(
n
,
callback
));
},
OffProtocol
);
const
$emit
=
defineSyncApi
(
API_EMIT
,
(
name
,
...
args
)
=>
{
emitter
.
emit
(
name
,
...
args
);
},
EmitProtocol
);
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
// Context例外情况
// Context例外情况
...
@@ -606,7 +714,15 @@ function initWrapper(protocols) {
...
@@ -606,7 +714,15 @@ function initWrapper(protocols) {
};
};
}
}
const
baseApis
=
{
upx2px
,
addInterceptor
,
removeInterceptor
};
const
baseApis
=
{
$on
,
$off
,
$once
,
$emit
,
upx2px
,
addInterceptor
,
removeInterceptor
,
};
function
initUni
(
api
,
protocols
)
{
function
initUni
(
api
,
protocols
)
{
const
wrapper
=
initWrapper
(
protocols
);
const
wrapper
=
initWrapper
(
protocols
);
const
UniProxyHandlers
=
{
const
UniProxyHandlers
=
{
...
...
packages/uni-mp-qq/dist/uni.mp.esm.js
浏览文件 @
f5bf601f
import
{
isPlainObject
,
isArray
,
hasOwn
,
toNumber
,
isObject
,
isFunction
,
extend
,
NOOP
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
hasOwn
,
isArray
,
extend
,
hyphenate
,
isObject
,
toNumber
,
isFunction
,
NOOP
,
camelize
}
from
'
@vue/shared
'
;
const
encode
=
encodeURIComponent
;
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
...
@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
...
@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
return
res
?
`?
${
res
}
`
:
''
;
}
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
@@ -120,6 +128,202 @@ function getEventChannel(id) {
...
@@ -120,6 +128,202 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
return
eventChannelStack
.
shift
();
}
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
);
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
}
const
ids
=
vueIds
.
split
(
'
,
'
);
const
len
=
ids
.
length
;
if
(
len
===
1
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
}
else
if
(
len
===
2
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
mpInstance
.
_$vuePid
=
ids
[
1
];
}
}
const
EXTRAS
=
[
'
externalClasses
'
];
function
initExtraOptions
(
miniProgramComponentOptions
,
vueOptions
)
{
EXTRAS
.
forEach
((
name
)
=>
{
if
(
hasOwn
(
vueOptions
,
name
))
{
miniProgramComponentOptions
[
name
]
=
vueOptions
[
name
];
}
});
}
function
initWxsCallMethods
(
methods
,
wxsCallMethods
)
{
if
(
!
isArray
(
wxsCallMethods
))
{
return
;
}
wxsCallMethods
.
forEach
((
callMethod
)
=>
{
methods
[
callMethod
]
=
function
(
args
)
{
return
this
.
$vm
[
callMethod
](
args
);
};
});
}
function
selectAllComponents
(
mpInstance
,
selector
,
$refs
)
{
const
components
=
mpInstance
.
selectAllComponents
(
selector
);
components
.
forEach
((
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
}
function
initRefs
(
instance
,
mpInstance
)
{
Object
.
defineProperty
(
instance
,
'
refs
'
,
{
get
()
{
const
$refs
=
{};
selectAllComponents
(
mpInstance
,
'
.vue-ref
'
,
$refs
);
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
findVmByVueId
(
instance
,
vuePid
)
{
// 标准 vue3 中 没有 $children,定制了内核
const
$children
=
instance
.
$children
;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childVm
=
$children
[
i
];
if
(
childVm
.
$scope
.
_$vueId
===
vuePid
)
{
return
childVm
;
}
}
// 反向递归查找
let
parentVm
;
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
parentVm
=
findVmByVueId
(
$children
[
i
],
vuePid
);
if
(
parentVm
)
{
return
parentVm
;
}
}
}
function
getTarget
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
));
}
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getTarget
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
getValue
(
dataPath
,
target
)
{
return
getTarget
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
...
@@ -229,7 +433,9 @@ function initComponentInstance(instance, options) {
...
@@ -229,7 +433,9 @@ function initComponentInstance(instance, options) {
ctx
.
__set_sync
=
setSync
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
ctx
.
__get_orig
=
getOrig
;
// TODO
// TODO
// ctx.__get_style = getStyle
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
ctx
.
__map
=
map
;
}
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
...
@@ -356,85 +562,6 @@ function initCreateApp(parseAppOptions) {
...
@@ -356,85 +562,6 @@ function initCreateApp(parseAppOptions) {
};
};
}
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
);
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
}
const
ids
=
vueIds
.
split
(
'
,
'
);
const
len
=
ids
.
length
;
if
(
len
===
1
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
}
else
if
(
len
===
2
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
mpInstance
.
_$vuePid
=
ids
[
1
];
}
}
const
EXTRAS
=
[
'
externalClasses
'
];
function
initExtraOptions
(
miniProgramComponentOptions
,
vueOptions
)
{
EXTRAS
.
forEach
((
name
)
=>
{
if
(
hasOwn
(
vueOptions
,
name
))
{
miniProgramComponentOptions
[
name
]
=
vueOptions
[
name
];
}
});
}
function
initWxsCallMethods
(
methods
,
wxsCallMethods
)
{
if
(
!
isArray
(
wxsCallMethods
))
{
return
;
}
wxsCallMethods
.
forEach
((
callMethod
)
=>
{
methods
[
callMethod
]
=
function
(
args
)
{
return
this
.
$vm
[
callMethod
](
args
);
};
});
}
function
selectAllComponents
(
mpInstance
,
selector
,
$refs
)
{
const
components
=
mpInstance
.
selectAllComponents
(
selector
);
components
.
forEach
((
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
}
function
initRefs
(
instance
,
mpInstance
)
{
Object
.
defineProperty
(
instance
,
'
refs
'
,
{
get
()
{
const
$refs
=
{};
selectAllComponents
(
mpInstance
,
'
.vue-ref
'
,
$refs
);
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
findVmByVueId
(
instance
,
vuePid
)
{
// 标准 vue3 中 没有 $children,定制了内核
const
$children
=
instance
.
$children
;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childVm
=
$children
[
i
];
if
(
childVm
.
$scope
.
_$vueId
===
vuePid
)
{
return
childVm
;
}
}
// 反向递归查找
let
parentVm
;
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
parentVm
=
findVmByVueId
(
$children
[
i
],
vuePid
);
if
(
parentVm
)
{
return
parentVm
;
}
}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
function
createObserver
(
name
)
{
function
createObserver
(
name
)
{
return
function
observer
(
newVal
)
{
return
function
observer
(
newVal
)
{
...
@@ -591,18 +718,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
...
@@ -591,18 +718,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
componentOptions
.
behaviors
=
initBehaviors
(
vueOptions
,
initBehavior
);
componentOptions
.
behaviors
=
initBehaviors
(
vueOptions
,
initBehavior
);
}
}
function
getValue
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
));
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getValue
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
getExtraValue
(
instance
,
dataPathsArray
)
{
function
getExtraValue
(
instance
,
dataPathsArray
)
{
let
context
=
instance
;
let
context
=
instance
;
dataPathsArray
.
forEach
((
dataPathArray
)
=>
{
dataPathsArray
.
forEach
((
dataPathArray
)
=>
{
...
@@ -624,7 +739,7 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -624,7 +739,7 @@ function getExtraValue(instance, dataPathsArray) {
vFor
=
dataPath
.
substr
(
3
);
vFor
=
dataPath
.
substr
(
3
);
}
}
else
{
else
{
vFor
=
get
Value
(
context
,
dataPath
);
vFor
=
get
Target
(
context
,
dataPath
);
}
}
}
}
if
(
Number
.
isInteger
(
vFor
))
{
if
(
Number
.
isInteger
(
vFor
))
{
...
@@ -636,12 +751,12 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -636,12 +751,12 @@ function getExtraValue(instance, dataPathsArray) {
else
{
else
{
if
(
isArray
(
vFor
))
{
if
(
isArray
(
vFor
))
{
context
=
vFor
.
find
((
vForItem
)
=>
{
context
=
vFor
.
find
((
vForItem
)
=>
{
return
get
Value
(
vForItem
,
propPath
)
===
value
;
return
get
Target
(
vForItem
,
propPath
)
===
value
;
});
});
}
}
else
if
(
isPlainObject
(
vFor
))
{
else
if
(
isPlainObject
(
vFor
))
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
return
get
Value
(
vFor
[
vForKey
],
propPath
)
===
value
;
return
get
Target
(
vFor
[
vForKey
],
propPath
)
===
value
;
});
});
}
}
else
{
else
{
...
@@ -649,7 +764,7 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -649,7 +764,7 @@ function getExtraValue(instance, dataPathsArray) {
}
}
}
}
if
(
valuePath
)
{
if
(
valuePath
)
{
context
=
get
Value
(
context
,
valuePath
);
context
=
get
Target
(
context
,
valuePath
);
}
}
}
}
});
});
...
@@ -690,10 +805,10 @@ function processEventExtra(instance, extra, event) {
...
@@ -690,10 +805,10 @@ function processEventExtra(instance, extra, event) {
}
}
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
// $event.target.value
// $event.target.value
extraObj
[
'
$
'
+
index
]
=
get
Value
(
event
,
dataPath
.
replace
(
'
$event.
'
,
''
));
extraObj
[
'
$
'
+
index
]
=
get
Target
(
event
,
dataPath
.
replace
(
'
$event.
'
,
''
));
}
}
else
{
else
{
extraObj
[
'
$
'
+
index
]
=
get
Value
(
instance
,
dataPath
);
extraObj
[
'
$
'
+
index
]
=
get
Target
(
instance
,
dataPath
);
}
}
}
}
}
}
...
@@ -830,7 +945,14 @@ function handleEvent(event) {
...
@@ -830,7 +945,14 @@ function handleEvent(event) {
}
}
handler
.
once
=
true
;
handler
.
once
=
true
;
}
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
processEventArgs
(
this
.
$vm
,
event
,
eventArray
[
1
],
eventArray
[
2
],
isCustom
,
methodName
)));
let
params
=
processEventArgs
(
this
.
$vm
,
event
,
eventArray
[
1
],
eventArray
[
2
],
isCustom
,
methodName
);
params
=
Array
.
isArray
(
params
)
?
params
:
[];
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if
(
/=
\s
*
\S
+
\.
eventParams
\s
*
\|\|\s
*
\S
+
\[[
'"
]
event-params
[
'"
]\]
/
.
test
(
handler
.
toString
()))
{
// eslint-disable-next-line no-sparse-arrays
params
=
params
.
concat
([,
,
,
,
,
,
,
,
,
,
event
]);
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
params
));
}
}
});
});
}
}
...
...
packages/uni-mp-toutiao/dist/uni.api.esm.js
浏览文件 @
f5bf601f
...
@@ -462,6 +462,114 @@ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interce
...
@@ -462,6 +462,114 @@ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interce
}
}
},
RemoveInterceptorProtocol
);
},
RemoveInterceptorProtocol
);
const
API_ON
=
'
$on
'
;
const
OnProtocol
=
[
{
name
:
'
event
'
,
type
:
String
,
required
:
true
,
},
{
name
:
'
callback
'
,
type
:
Function
,
required
:
true
,
},
];
const
API_ONCE
=
'
$once
'
;
const
OnceProtocol
=
OnProtocol
;
const
API_OFF
=
'
$off
'
;
const
OffProtocol
=
[
{
name
:
'
event
'
,
type
:
[
String
,
Array
],
},
{
name
:
'
callback
'
,
type
:
Function
,
},
];
const
API_EMIT
=
'
$emit
'
;
const
EmitProtocol
=
[
{
name
:
'
event
'
,
type
:
String
,
required
:
true
,
},
];
const
E
=
function
()
{
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
};
E
.
prototype
=
{
on
:
function
(
name
,
callback
,
ctx
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
(
e
[
name
]
||
(
e
[
name
]
=
[])).
push
({
fn
:
callback
,
ctx
:
ctx
,
});
return
this
;
},
once
:
function
(
name
,
callback
,
ctx
)
{
var
self
=
this
;
function
listener
()
{
self
.
off
(
name
,
listener
);
callback
.
apply
(
ctx
,
arguments
);
}
listener
.
_
=
callback
;
return
this
.
on
(
name
,
listener
,
ctx
);
},
emit
:
function
(
name
)
{
var
data
=
[].
slice
.
call
(
arguments
,
1
);
var
evtArr
=
((
this
.
e
||
(
this
.
e
=
{}))[
name
]
||
[]).
slice
();
var
i
=
0
;
var
len
=
evtArr
.
length
;
for
(
i
;
i
<
len
;
i
++
)
{
evtArr
[
i
].
fn
.
apply
(
evtArr
[
i
].
ctx
,
data
);
}
return
this
;
},
off
:
function
(
name
,
callback
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
var
evts
=
e
[
name
];
var
liveEvents
=
[];
if
(
evts
&&
callback
)
{
for
(
var
i
=
0
,
len
=
evts
.
length
;
i
<
len
;
i
++
)
{
if
(
evts
[
i
].
fn
!==
callback
&&
evts
[
i
].
fn
.
_
!==
callback
)
liveEvents
.
push
(
evts
[
i
]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
liveEvents
.
length
?
(
e
[
name
]
=
liveEvents
)
:
delete
e
[
name
];
return
this
;
},
};
var
Emitter
=
E
;
const
emitter
=
new
Emitter
();
const
$on
=
defineSyncApi
(
API_ON
,
(
name
,
callback
)
=>
{
emitter
.
on
(
name
,
callback
);
return
()
=>
emitter
.
off
(
name
,
callback
);
},
OnProtocol
);
const
$once
=
defineSyncApi
(
API_ONCE
,
(
name
,
callback
)
=>
{
emitter
.
once
(
name
,
callback
);
return
()
=>
emitter
.
off
(
name
,
callback
);
},
OnceProtocol
);
const
$off
=
defineSyncApi
(
API_OFF
,
(
name
,
callback
)
=>
{
if
(
!
name
)
{
emitter
.
e
=
{};
return
;
}
if
(
!
Array
.
isArray
(
name
))
name
=
[
name
];
name
.
forEach
((
n
)
=>
emitter
.
off
(
n
,
callback
));
},
OffProtocol
);
const
$emit
=
defineSyncApi
(
API_EMIT
,
(
name
,
...
args
)
=>
{
emitter
.
emit
(
name
,
...
args
);
},
EmitProtocol
);
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
// Context例外情况
// Context例外情况
...
@@ -606,7 +714,15 @@ function initWrapper(protocols) {
...
@@ -606,7 +714,15 @@ function initWrapper(protocols) {
};
};
}
}
const
baseApis
=
{
upx2px
,
addInterceptor
,
removeInterceptor
};
const
baseApis
=
{
$on
,
$off
,
$once
,
$emit
,
upx2px
,
addInterceptor
,
removeInterceptor
,
};
function
initUni
(
api
,
protocols
)
{
function
initUni
(
api
,
protocols
)
{
const
wrapper
=
initWrapper
(
protocols
);
const
wrapper
=
initWrapper
(
protocols
);
const
UniProxyHandlers
=
{
const
UniProxyHandlers
=
{
...
...
packages/uni-mp-toutiao/dist/uni.mp.esm.js
浏览文件 @
f5bf601f
import
{
isPlainObject
,
isArray
,
hasOwn
,
toNumber
,
isObject
,
isFunction
,
extend
,
NOOP
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
hasOwn
,
isArray
,
extend
,
hyphenate
,
isObject
,
toNumber
,
isFunction
,
NOOP
,
camelize
}
from
'
@vue/shared
'
;
const
encode
=
encodeURIComponent
;
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
...
@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
...
@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
return
res
?
`?
${
res
}
`
:
''
;
}
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
@@ -120,6 +128,202 @@ function getEventChannel(id) {
...
@@ -120,6 +128,202 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
return
eventChannelStack
.
shift
();
}
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
);
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
}
const
ids
=
vueIds
.
split
(
'
,
'
);
const
len
=
ids
.
length
;
if
(
len
===
1
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
}
else
if
(
len
===
2
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
mpInstance
.
_$vuePid
=
ids
[
1
];
}
}
const
EXTRAS
=
[
'
externalClasses
'
];
function
initExtraOptions
(
miniProgramComponentOptions
,
vueOptions
)
{
EXTRAS
.
forEach
((
name
)
=>
{
if
(
hasOwn
(
vueOptions
,
name
))
{
miniProgramComponentOptions
[
name
]
=
vueOptions
[
name
];
}
});
}
function
initWxsCallMethods
(
methods
,
wxsCallMethods
)
{
if
(
!
isArray
(
wxsCallMethods
))
{
return
;
}
wxsCallMethods
.
forEach
((
callMethod
)
=>
{
methods
[
callMethod
]
=
function
(
args
)
{
return
this
.
$vm
[
callMethod
](
args
);
};
});
}
function
selectAllComponents
(
mpInstance
,
selector
,
$refs
)
{
const
components
=
mpInstance
.
selectAllComponents
(
selector
);
components
.
forEach
((
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
}
function
initRefs
(
instance
,
mpInstance
)
{
Object
.
defineProperty
(
instance
,
'
refs
'
,
{
get
()
{
const
$refs
=
{};
selectAllComponents
(
mpInstance
,
'
.vue-ref
'
,
$refs
);
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
findVmByVueId
(
instance
,
vuePid
)
{
// 标准 vue3 中 没有 $children,定制了内核
const
$children
=
instance
.
$children
;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childVm
=
$children
[
i
];
if
(
childVm
.
$scope
.
_$vueId
===
vuePid
)
{
return
childVm
;
}
}
// 反向递归查找
let
parentVm
;
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
parentVm
=
findVmByVueId
(
$children
[
i
],
vuePid
);
if
(
parentVm
)
{
return
parentVm
;
}
}
}
function
getTarget
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
));
}
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getTarget
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
getValue
(
dataPath
,
target
)
{
return
getTarget
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
...
@@ -229,7 +433,9 @@ function initComponentInstance(instance, options) {
...
@@ -229,7 +433,9 @@ function initComponentInstance(instance, options) {
ctx
.
__set_sync
=
setSync
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
ctx
.
__get_orig
=
getOrig
;
// TODO
// TODO
// ctx.__get_style = getStyle
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
ctx
.
__map
=
map
;
}
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
...
@@ -359,85 +565,6 @@ function initCreateApp(parseAppOptions) {
...
@@ -359,85 +565,6 @@ function initCreateApp(parseAppOptions) {
};
};
}
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
);
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
}
const
ids
=
vueIds
.
split
(
'
,
'
);
const
len
=
ids
.
length
;
if
(
len
===
1
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
}
else
if
(
len
===
2
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
mpInstance
.
_$vuePid
=
ids
[
1
];
}
}
const
EXTRAS
=
[
'
externalClasses
'
];
function
initExtraOptions
(
miniProgramComponentOptions
,
vueOptions
)
{
EXTRAS
.
forEach
((
name
)
=>
{
if
(
hasOwn
(
vueOptions
,
name
))
{
miniProgramComponentOptions
[
name
]
=
vueOptions
[
name
];
}
});
}
function
initWxsCallMethods
(
methods
,
wxsCallMethods
)
{
if
(
!
isArray
(
wxsCallMethods
))
{
return
;
}
wxsCallMethods
.
forEach
((
callMethod
)
=>
{
methods
[
callMethod
]
=
function
(
args
)
{
return
this
.
$vm
[
callMethod
](
args
);
};
});
}
function
selectAllComponents
(
mpInstance
,
selector
,
$refs
)
{
const
components
=
mpInstance
.
selectAllComponents
(
selector
);
components
.
forEach
((
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
}
function
initRefs
(
instance
,
mpInstance
)
{
Object
.
defineProperty
(
instance
,
'
refs
'
,
{
get
()
{
const
$refs
=
{};
selectAllComponents
(
mpInstance
,
'
.vue-ref
'
,
$refs
);
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
findVmByVueId
(
instance
,
vuePid
)
{
// 标准 vue3 中 没有 $children,定制了内核
const
$children
=
instance
.
$children
;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childVm
=
$children
[
i
];
if
(
childVm
.
$scope
.
_$vueId
===
vuePid
)
{
return
childVm
;
}
}
// 反向递归查找
let
parentVm
;
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
parentVm
=
findVmByVueId
(
$children
[
i
],
vuePid
);
if
(
parentVm
)
{
return
parentVm
;
}
}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
function
createObserver
(
name
)
{
function
createObserver
(
name
)
{
return
function
observer
(
newVal
)
{
return
function
observer
(
newVal
)
{
...
@@ -600,18 +727,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
...
@@ -600,18 +727,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
componentOptions
.
behaviors
=
initBehaviors
(
vueOptions
,
initBehavior
);
componentOptions
.
behaviors
=
initBehaviors
(
vueOptions
,
initBehavior
);
}
}
function
getValue
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
));
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getValue
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
getExtraValue
(
instance
,
dataPathsArray
)
{
function
getExtraValue
(
instance
,
dataPathsArray
)
{
let
context
=
instance
;
let
context
=
instance
;
dataPathsArray
.
forEach
((
dataPathArray
)
=>
{
dataPathsArray
.
forEach
((
dataPathArray
)
=>
{
...
@@ -633,7 +748,7 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -633,7 +748,7 @@ function getExtraValue(instance, dataPathsArray) {
vFor
=
dataPath
.
substr
(
3
);
vFor
=
dataPath
.
substr
(
3
);
}
}
else
{
else
{
vFor
=
get
Value
(
context
,
dataPath
);
vFor
=
get
Target
(
context
,
dataPath
);
}
}
}
}
if
(
Number
.
isInteger
(
vFor
))
{
if
(
Number
.
isInteger
(
vFor
))
{
...
@@ -645,12 +760,12 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -645,12 +760,12 @@ function getExtraValue(instance, dataPathsArray) {
else
{
else
{
if
(
isArray
(
vFor
))
{
if
(
isArray
(
vFor
))
{
context
=
vFor
.
find
((
vForItem
)
=>
{
context
=
vFor
.
find
((
vForItem
)
=>
{
return
get
Value
(
vForItem
,
propPath
)
===
value
;
return
get
Target
(
vForItem
,
propPath
)
===
value
;
});
});
}
}
else
if
(
isPlainObject
(
vFor
))
{
else
if
(
isPlainObject
(
vFor
))
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
return
get
Value
(
vFor
[
vForKey
],
propPath
)
===
value
;
return
get
Target
(
vFor
[
vForKey
],
propPath
)
===
value
;
});
});
}
}
else
{
else
{
...
@@ -658,7 +773,7 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -658,7 +773,7 @@ function getExtraValue(instance, dataPathsArray) {
}
}
}
}
if
(
valuePath
)
{
if
(
valuePath
)
{
context
=
get
Value
(
context
,
valuePath
);
context
=
get
Target
(
context
,
valuePath
);
}
}
}
}
});
});
...
@@ -699,10 +814,10 @@ function processEventExtra(instance, extra, event) {
...
@@ -699,10 +814,10 @@ function processEventExtra(instance, extra, event) {
}
}
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
// $event.target.value
// $event.target.value
extraObj
[
'
$
'
+
index
]
=
get
Value
(
event
,
dataPath
.
replace
(
'
$event.
'
,
''
));
extraObj
[
'
$
'
+
index
]
=
get
Target
(
event
,
dataPath
.
replace
(
'
$event.
'
,
''
));
}
}
else
{
else
{
extraObj
[
'
$
'
+
index
]
=
get
Value
(
instance
,
dataPath
);
extraObj
[
'
$
'
+
index
]
=
get
Target
(
instance
,
dataPath
);
}
}
}
}
}
}
...
@@ -839,7 +954,14 @@ function handleEvent(event) {
...
@@ -839,7 +954,14 @@ function handleEvent(event) {
}
}
handler
.
once
=
true
;
handler
.
once
=
true
;
}
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
processEventArgs
(
this
.
$vm
,
event
,
eventArray
[
1
],
eventArray
[
2
],
isCustom
,
methodName
)));
let
params
=
processEventArgs
(
this
.
$vm
,
event
,
eventArray
[
1
],
eventArray
[
2
],
isCustom
,
methodName
);
params
=
Array
.
isArray
(
params
)
?
params
:
[];
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if
(
/=
\s
*
\S
+
\.
eventParams
\s
*
\|\|\s
*
\S
+
\[[
'"
]
event-params
[
'"
]\]
/
.
test
(
handler
.
toString
()))
{
// eslint-disable-next-line no-sparse-arrays
params
=
params
.
concat
([,
,
,
,
,
,
,
,
,
,
event
]);
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
params
));
}
}
});
});
}
}
...
...
packages/uni-mp-weixin/dist/uni.api.esm.js
浏览文件 @
f5bf601f
...
@@ -426,6 +426,114 @@ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interce
...
@@ -426,6 +426,114 @@ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interce
}
}
},
RemoveInterceptorProtocol
);
},
RemoveInterceptorProtocol
);
const
API_ON
=
'
$on
'
;
const
OnProtocol
=
[
{
name
:
'
event
'
,
type
:
String
,
required
:
true
,
},
{
name
:
'
callback
'
,
type
:
Function
,
required
:
true
,
},
];
const
API_ONCE
=
'
$once
'
;
const
OnceProtocol
=
OnProtocol
;
const
API_OFF
=
'
$off
'
;
const
OffProtocol
=
[
{
name
:
'
event
'
,
type
:
[
String
,
Array
],
},
{
name
:
'
callback
'
,
type
:
Function
,
},
];
const
API_EMIT
=
'
$emit
'
;
const
EmitProtocol
=
[
{
name
:
'
event
'
,
type
:
String
,
required
:
true
,
},
];
const
E
=
function
()
{
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
};
E
.
prototype
=
{
on
:
function
(
name
,
callback
,
ctx
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
(
e
[
name
]
||
(
e
[
name
]
=
[])).
push
({
fn
:
callback
,
ctx
:
ctx
,
});
return
this
;
},
once
:
function
(
name
,
callback
,
ctx
)
{
var
self
=
this
;
function
listener
()
{
self
.
off
(
name
,
listener
);
callback
.
apply
(
ctx
,
arguments
);
}
listener
.
_
=
callback
;
return
this
.
on
(
name
,
listener
,
ctx
);
},
emit
:
function
(
name
)
{
var
data
=
[].
slice
.
call
(
arguments
,
1
);
var
evtArr
=
((
this
.
e
||
(
this
.
e
=
{}))[
name
]
||
[]).
slice
();
var
i
=
0
;
var
len
=
evtArr
.
length
;
for
(
i
;
i
<
len
;
i
++
)
{
evtArr
[
i
].
fn
.
apply
(
evtArr
[
i
].
ctx
,
data
);
}
return
this
;
},
off
:
function
(
name
,
callback
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
var
evts
=
e
[
name
];
var
liveEvents
=
[];
if
(
evts
&&
callback
)
{
for
(
var
i
=
0
,
len
=
evts
.
length
;
i
<
len
;
i
++
)
{
if
(
evts
[
i
].
fn
!==
callback
&&
evts
[
i
].
fn
.
_
!==
callback
)
liveEvents
.
push
(
evts
[
i
]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
liveEvents
.
length
?
(
e
[
name
]
=
liveEvents
)
:
delete
e
[
name
];
return
this
;
},
};
var
Emitter
=
E
;
const
emitter
=
new
Emitter
();
const
$on
=
defineSyncApi
(
API_ON
,
(
name
,
callback
)
=>
{
emitter
.
on
(
name
,
callback
);
return
()
=>
emitter
.
off
(
name
,
callback
);
},
OnProtocol
);
const
$once
=
defineSyncApi
(
API_ONCE
,
(
name
,
callback
)
=>
{
emitter
.
once
(
name
,
callback
);
return
()
=>
emitter
.
off
(
name
,
callback
);
},
OnceProtocol
);
const
$off
=
defineSyncApi
(
API_OFF
,
(
name
,
callback
)
=>
{
if
(
!
name
)
{
emitter
.
e
=
{};
return
;
}
if
(
!
Array
.
isArray
(
name
))
name
=
[
name
];
name
.
forEach
((
n
)
=>
emitter
.
off
(
n
,
callback
));
},
OffProtocol
);
const
$emit
=
defineSyncApi
(
API_EMIT
,
(
name
,
...
args
)
=>
{
emitter
.
emit
(
name
,
...
args
);
},
EmitProtocol
);
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
// Context例外情况
// Context例外情况
...
@@ -570,7 +678,15 @@ function initWrapper(protocols) {
...
@@ -570,7 +678,15 @@ function initWrapper(protocols) {
};
};
}
}
const
baseApis
=
{
upx2px
,
addInterceptor
,
removeInterceptor
};
const
baseApis
=
{
$on
,
$off
,
$once
,
$emit
,
upx2px
,
addInterceptor
,
removeInterceptor
,
};
function
initUni
(
api
,
protocols
)
{
function
initUni
(
api
,
protocols
)
{
const
wrapper
=
initWrapper
(
protocols
);
const
wrapper
=
initWrapper
(
protocols
);
const
UniProxyHandlers
=
{
const
UniProxyHandlers
=
{
...
...
packages/uni-mp-weixin/dist/uni.mp.esm.js
浏览文件 @
f5bf601f
import
{
isPlainObject
,
isArray
,
hasOwn
,
toNumber
,
isObject
,
isFunction
,
extend
,
NOOP
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
hasOwn
,
isArray
,
extend
,
hyphenate
,
isObject
,
toNumber
,
isFunction
,
NOOP
,
camelize
}
from
'
@vue/shared
'
;
const
encode
=
encodeURIComponent
;
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
...
@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
...
@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
return
res
?
`?
${
res
}
`
:
''
;
}
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
@@ -57,6 +65,211 @@ function getEventChannel(id) {
...
@@ -57,6 +65,211 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
return
eventChannelStack
.
shift
();
}
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
);
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
}
const
ids
=
vueIds
.
split
(
'
,
'
);
const
len
=
ids
.
length
;
if
(
len
===
1
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
}
else
if
(
len
===
2
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
mpInstance
.
_$vuePid
=
ids
[
1
];
}
}
const
EXTRAS
=
[
'
externalClasses
'
];
function
initExtraOptions
(
miniProgramComponentOptions
,
vueOptions
)
{
EXTRAS
.
forEach
((
name
)
=>
{
if
(
hasOwn
(
vueOptions
,
name
))
{
miniProgramComponentOptions
[
name
]
=
vueOptions
[
name
];
}
});
}
function
initWxsCallMethods
(
methods
,
wxsCallMethods
)
{
if
(
!
isArray
(
wxsCallMethods
))
{
return
;
}
wxsCallMethods
.
forEach
((
callMethod
)
=>
{
methods
[
callMethod
]
=
function
(
args
)
{
return
this
.
$vm
[
callMethod
](
args
);
};
});
}
function
selectAllComponents
(
mpInstance
,
selector
,
$refs
)
{
const
components
=
mpInstance
.
selectAllComponents
(
selector
);
components
.
forEach
((
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
{
if
(
component
.
dataset
.
vueGeneric
===
'
scoped
'
)
{
component
.
selectAllComponents
(
'
.scoped-ref
'
)
.
forEach
((
scopedComponent
)
=>
{
selectAllComponents
(
scopedComponent
,
selector
,
$refs
);
});
}
}
});
}
function
initRefs
(
instance
,
mpInstance
)
{
Object
.
defineProperty
(
instance
,
'
refs
'
,
{
get
()
{
const
$refs
=
{};
selectAllComponents
(
mpInstance
,
'
.vue-ref
'
,
$refs
);
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
findVmByVueId
(
instance
,
vuePid
)
{
// 标准 vue3 中 没有 $children,定制了内核
const
$children
=
instance
.
$children
;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childVm
=
$children
[
i
];
if
(
childVm
.
$scope
.
_$vueId
===
vuePid
)
{
return
childVm
;
}
}
// 反向递归查找
let
parentVm
;
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
parentVm
=
findVmByVueId
(
$children
[
i
],
vuePid
);
if
(
parentVm
)
{
return
parentVm
;
}
}
}
function
getTarget
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
));
}
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getTarget
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
getValue
(
dataPath
,
target
)
{
return
getTarget
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
...
@@ -166,7 +379,9 @@ function initComponentInstance(instance, options) {
...
@@ -166,7 +379,9 @@ function initComponentInstance(instance, options) {
ctx
.
__set_sync
=
setSync
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
ctx
.
__get_orig
=
getOrig
;
// TODO
// TODO
// ctx.__get_style = getStyle
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
ctx
.
__map
=
map
;
}
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
...
@@ -293,94 +508,6 @@ function initCreateApp(parseAppOptions) {
...
@@ -293,94 +508,6 @@ function initCreateApp(parseAppOptions) {
};
};
}
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
);
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
}
const
ids
=
vueIds
.
split
(
'
,
'
);
const
len
=
ids
.
length
;
if
(
len
===
1
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
}
else
if
(
len
===
2
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
mpInstance
.
_$vuePid
=
ids
[
1
];
}
}
const
EXTRAS
=
[
'
externalClasses
'
];
function
initExtraOptions
(
miniProgramComponentOptions
,
vueOptions
)
{
EXTRAS
.
forEach
((
name
)
=>
{
if
(
hasOwn
(
vueOptions
,
name
))
{
miniProgramComponentOptions
[
name
]
=
vueOptions
[
name
];
}
});
}
function
initWxsCallMethods
(
methods
,
wxsCallMethods
)
{
if
(
!
isArray
(
wxsCallMethods
))
{
return
;
}
wxsCallMethods
.
forEach
((
callMethod
)
=>
{
methods
[
callMethod
]
=
function
(
args
)
{
return
this
.
$vm
[
callMethod
](
args
);
};
});
}
function
selectAllComponents
(
mpInstance
,
selector
,
$refs
)
{
const
components
=
mpInstance
.
selectAllComponents
(
selector
);
components
.
forEach
((
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
{
if
(
component
.
dataset
.
vueGeneric
===
'
scoped
'
)
{
component
.
selectAllComponents
(
'
.scoped-ref
'
)
.
forEach
((
scopedComponent
)
=>
{
selectAllComponents
(
scopedComponent
,
selector
,
$refs
);
});
}
}
});
}
function
initRefs
(
instance
,
mpInstance
)
{
Object
.
defineProperty
(
instance
,
'
refs
'
,
{
get
()
{
const
$refs
=
{};
selectAllComponents
(
mpInstance
,
'
.vue-ref
'
,
$refs
);
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
findVmByVueId
(
instance
,
vuePid
)
{
// 标准 vue3 中 没有 $children,定制了内核
const
$children
=
instance
.
$children
;
// 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
childVm
=
$children
[
i
];
if
(
childVm
.
$scope
.
_$vueId
===
vuePid
)
{
return
childVm
;
}
}
// 反向递归查找
let
parentVm
;
for
(
let
i
=
$children
.
length
-
1
;
i
>=
0
;
i
--
)
{
parentVm
=
findVmByVueId
(
$children
[
i
],
vuePid
);
if
(
parentVm
)
{
return
parentVm
;
}
}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
function
createObserver
(
name
)
{
function
createObserver
(
name
)
{
return
function
observer
(
newVal
)
{
return
function
observer
(
newVal
)
{
...
@@ -537,18 +664,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
...
@@ -537,18 +664,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
componentOptions
.
behaviors
=
initBehaviors
(
vueOptions
,
initBehavior
);
componentOptions
.
behaviors
=
initBehaviors
(
vueOptions
,
initBehavior
);
}
}
function
getValue
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
));
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getValue
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
getExtraValue
(
instance
,
dataPathsArray
)
{
function
getExtraValue
(
instance
,
dataPathsArray
)
{
let
context
=
instance
;
let
context
=
instance
;
dataPathsArray
.
forEach
((
dataPathArray
)
=>
{
dataPathsArray
.
forEach
((
dataPathArray
)
=>
{
...
@@ -570,7 +685,7 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -570,7 +685,7 @@ function getExtraValue(instance, dataPathsArray) {
vFor
=
dataPath
.
substr
(
3
);
vFor
=
dataPath
.
substr
(
3
);
}
}
else
{
else
{
vFor
=
get
Value
(
context
,
dataPath
);
vFor
=
get
Target
(
context
,
dataPath
);
}
}
}
}
if
(
Number
.
isInteger
(
vFor
))
{
if
(
Number
.
isInteger
(
vFor
))
{
...
@@ -582,12 +697,12 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -582,12 +697,12 @@ function getExtraValue(instance, dataPathsArray) {
else
{
else
{
if
(
isArray
(
vFor
))
{
if
(
isArray
(
vFor
))
{
context
=
vFor
.
find
((
vForItem
)
=>
{
context
=
vFor
.
find
((
vForItem
)
=>
{
return
get
Value
(
vForItem
,
propPath
)
===
value
;
return
get
Target
(
vForItem
,
propPath
)
===
value
;
});
});
}
}
else
if
(
isPlainObject
(
vFor
))
{
else
if
(
isPlainObject
(
vFor
))
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
return
get
Value
(
vFor
[
vForKey
],
propPath
)
===
value
;
return
get
Target
(
vFor
[
vForKey
],
propPath
)
===
value
;
});
});
}
}
else
{
else
{
...
@@ -595,7 +710,7 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -595,7 +710,7 @@ function getExtraValue(instance, dataPathsArray) {
}
}
}
}
if
(
valuePath
)
{
if
(
valuePath
)
{
context
=
get
Value
(
context
,
valuePath
);
context
=
get
Target
(
context
,
valuePath
);
}
}
}
}
});
});
...
@@ -636,10 +751,10 @@ function processEventExtra(instance, extra, event) {
...
@@ -636,10 +751,10 @@ function processEventExtra(instance, extra, event) {
}
}
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
// $event.target.value
// $event.target.value
extraObj
[
'
$
'
+
index
]
=
get
Value
(
event
,
dataPath
.
replace
(
'
$event.
'
,
''
));
extraObj
[
'
$
'
+
index
]
=
get
Target
(
event
,
dataPath
.
replace
(
'
$event.
'
,
''
));
}
}
else
{
else
{
extraObj
[
'
$
'
+
index
]
=
get
Value
(
instance
,
dataPath
);
extraObj
[
'
$
'
+
index
]
=
get
Target
(
instance
,
dataPath
);
}
}
}
}
}
}
...
@@ -776,7 +891,14 @@ function handleEvent(event) {
...
@@ -776,7 +891,14 @@ function handleEvent(event) {
}
}
handler
.
once
=
true
;
handler
.
once
=
true
;
}
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
processEventArgs
(
this
.
$vm
,
event
,
eventArray
[
1
],
eventArray
[
2
],
isCustom
,
methodName
)));
let
params
=
processEventArgs
(
this
.
$vm
,
event
,
eventArray
[
1
],
eventArray
[
2
],
isCustom
,
methodName
);
params
=
Array
.
isArray
(
params
)
?
params
:
[];
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if
(
/=
\s
*
\S
+
\.
eventParams
\s
*
\|\|\s
*
\S
+
\[[
'"
]
event-params
[
'"
]\]
/
.
test
(
handler
.
toString
()))
{
// eslint-disable-next-line no-sparse-arrays
params
=
params
.
concat
([,
,
,
,
,
,
,
,
,
,
event
]);
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
params
));
}
}
});
});
}
}
...
...
packages/uni-quickapp-webview/dist/uni.api.esm.js
浏览文件 @
f5bf601f
...
@@ -462,6 +462,114 @@ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interce
...
@@ -462,6 +462,114 @@ const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interce
}
}
},
RemoveInterceptorProtocol
);
},
RemoveInterceptorProtocol
);
const
API_ON
=
'
$on
'
;
const
OnProtocol
=
[
{
name
:
'
event
'
,
type
:
String
,
required
:
true
,
},
{
name
:
'
callback
'
,
type
:
Function
,
required
:
true
,
},
];
const
API_ONCE
=
'
$once
'
;
const
OnceProtocol
=
OnProtocol
;
const
API_OFF
=
'
$off
'
;
const
OffProtocol
=
[
{
name
:
'
event
'
,
type
:
[
String
,
Array
],
},
{
name
:
'
callback
'
,
type
:
Function
,
},
];
const
API_EMIT
=
'
$emit
'
;
const
EmitProtocol
=
[
{
name
:
'
event
'
,
type
:
String
,
required
:
true
,
},
];
const
E
=
function
()
{
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
};
E
.
prototype
=
{
on
:
function
(
name
,
callback
,
ctx
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
(
e
[
name
]
||
(
e
[
name
]
=
[])).
push
({
fn
:
callback
,
ctx
:
ctx
,
});
return
this
;
},
once
:
function
(
name
,
callback
,
ctx
)
{
var
self
=
this
;
function
listener
()
{
self
.
off
(
name
,
listener
);
callback
.
apply
(
ctx
,
arguments
);
}
listener
.
_
=
callback
;
return
this
.
on
(
name
,
listener
,
ctx
);
},
emit
:
function
(
name
)
{
var
data
=
[].
slice
.
call
(
arguments
,
1
);
var
evtArr
=
((
this
.
e
||
(
this
.
e
=
{}))[
name
]
||
[]).
slice
();
var
i
=
0
;
var
len
=
evtArr
.
length
;
for
(
i
;
i
<
len
;
i
++
)
{
evtArr
[
i
].
fn
.
apply
(
evtArr
[
i
].
ctx
,
data
);
}
return
this
;
},
off
:
function
(
name
,
callback
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{});
var
evts
=
e
[
name
];
var
liveEvents
=
[];
if
(
evts
&&
callback
)
{
for
(
var
i
=
0
,
len
=
evts
.
length
;
i
<
len
;
i
++
)
{
if
(
evts
[
i
].
fn
!==
callback
&&
evts
[
i
].
fn
.
_
!==
callback
)
liveEvents
.
push
(
evts
[
i
]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
liveEvents
.
length
?
(
e
[
name
]
=
liveEvents
)
:
delete
e
[
name
];
return
this
;
},
};
var
Emitter
=
E
;
const
emitter
=
new
Emitter
();
const
$on
=
defineSyncApi
(
API_ON
,
(
name
,
callback
)
=>
{
emitter
.
on
(
name
,
callback
);
return
()
=>
emitter
.
off
(
name
,
callback
);
},
OnProtocol
);
const
$once
=
defineSyncApi
(
API_ONCE
,
(
name
,
callback
)
=>
{
emitter
.
once
(
name
,
callback
);
return
()
=>
emitter
.
off
(
name
,
callback
);
},
OnceProtocol
);
const
$off
=
defineSyncApi
(
API_OFF
,
(
name
,
callback
)
=>
{
if
(
!
name
)
{
emitter
.
e
=
{};
return
;
}
if
(
!
Array
.
isArray
(
name
))
name
=
[
name
];
name
.
forEach
((
n
)
=>
emitter
.
off
(
n
,
callback
));
},
OffProtocol
);
const
$emit
=
defineSyncApi
(
API_EMIT
,
(
name
,
...
args
)
=>
{
emitter
.
emit
(
name
,
...
args
);
},
EmitProtocol
);
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
SYNC_API_RE
=
/^
\$
|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
// Context例外情况
// Context例外情况
...
@@ -606,7 +714,15 @@ function initWrapper(protocols) {
...
@@ -606,7 +714,15 @@ function initWrapper(protocols) {
};
};
}
}
const
baseApis
=
{
upx2px
,
addInterceptor
,
removeInterceptor
};
const
baseApis
=
{
$on
,
$off
,
$once
,
$emit
,
upx2px
,
addInterceptor
,
removeInterceptor
,
};
function
initUni
(
api
,
protocols
)
{
function
initUni
(
api
,
protocols
)
{
const
wrapper
=
initWrapper
(
protocols
);
const
wrapper
=
initWrapper
(
protocols
);
const
UniProxyHandlers
=
{
const
UniProxyHandlers
=
{
...
...
packages/uni-quickapp-webview/dist/uni.mp.esm.js
浏览文件 @
f5bf601f
import
{
isPlainObject
,
isArray
,
hasOwn
,
toNumber
,
isObject
,
isFunction
,
extend
,
NOOP
,
camelize
}
from
'
@vue/shared
'
;
import
{
isPlainObject
,
hasOwn
,
isArray
,
extend
,
hyphenate
,
isObject
,
toNumber
,
isFunction
,
NOOP
,
camelize
}
from
'
@vue/shared
'
;
const
encode
=
encodeURIComponent
;
const
encode
=
encodeURIComponent
;
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
function
stringifyQuery
(
obj
,
encodeStr
=
encode
)
{
...
@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
...
@@ -19,6 +19,14 @@ function stringifyQuery(obj, encodeStr = encode) {
:
null
;
:
null
;
return
res
?
`?
${
res
}
`
:
''
;
return
res
?
`?
${
res
}
`
:
''
;
}
}
function
cache
(
fn
)
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
}
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
const
invokeArrayFns
=
(
fns
,
arg
)
=>
{
let
ret
;
let
ret
;
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
fns
.
length
;
i
++
)
{
...
@@ -120,6 +128,183 @@ function getEventChannel(id) {
...
@@ -120,6 +128,183 @@ function getEventChannel(id) {
return
eventChannelStack
.
shift
();
return
eventChannelStack
.
shift
();
}
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
);
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
}
const
ids
=
vueIds
.
split
(
'
,
'
);
const
len
=
ids
.
length
;
if
(
len
===
1
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
}
else
if
(
len
===
2
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
mpInstance
.
_$vuePid
=
ids
[
1
];
}
}
const
EXTRAS
=
[
'
externalClasses
'
];
function
initExtraOptions
(
miniProgramComponentOptions
,
vueOptions
)
{
EXTRAS
.
forEach
((
name
)
=>
{
if
(
hasOwn
(
vueOptions
,
name
))
{
miniProgramComponentOptions
[
name
]
=
vueOptions
[
name
];
}
});
}
function
initWxsCallMethods
(
methods
,
wxsCallMethods
)
{
if
(
!
isArray
(
wxsCallMethods
))
{
return
;
}
wxsCallMethods
.
forEach
((
callMethod
)
=>
{
methods
[
callMethod
]
=
function
(
args
)
{
return
this
.
$vm
[
callMethod
](
args
);
};
});
}
function
selectAllComponents
(
mpInstance
,
selector
,
$refs
)
{
const
components
=
mpInstance
.
selectAllComponents
(
selector
);
components
.
forEach
((
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
}
function
initRefs
(
instance
,
mpInstance
)
{
Object
.
defineProperty
(
instance
,
'
refs
'
,
{
get
()
{
const
$refs
=
{};
selectAllComponents
(
mpInstance
,
'
.vue-ref
'
,
$refs
);
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
getTarget
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
));
}
if
(
!
obj
)
{
obj
=
{};
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getTarget
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
getValue
(
dataPath
,
target
)
{
return
getTarget
(
target
||
this
,
dataPath
);
}
function
getClass
(
dynamicClass
,
staticClass
)
{
return
renderClass
(
staticClass
,
dynamicClass
);
}
function
getStyle
(
dynamicStyle
,
staticStyle
)
{
if
(
!
dynamicStyle
&&
!
staticStyle
)
{
return
''
;
}
var
dynamicStyleObj
=
normalizeStyleBinding
(
dynamicStyle
);
var
styleObj
=
staticStyle
?
extend
(
staticStyle
,
dynamicStyleObj
)
:
dynamicStyleObj
;
return
Object
.
keys
(
styleObj
)
.
map
(
function
(
name
)
{
return
hyphenate
(
name
)
+
'
:
'
+
styleObj
[
name
];
})
.
join
(
'
;
'
);
}
function
toObject
(
arr
)
{
var
res
=
{};
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
])
{
extend
(
res
,
arr
[
i
]);
}
}
return
res
;
}
function
normalizeStyleBinding
(
bindingStyle
)
{
if
(
Array
.
isArray
(
bindingStyle
))
{
return
toObject
(
bindingStyle
);
}
if
(
typeof
bindingStyle
===
'
string
'
)
{
return
parseStyleText
(
bindingStyle
);
}
return
bindingStyle
;
}
var
parseStyleText
=
cache
(
function
parseStyleText
(
cssText
)
{
var
res
=
{};
var
listDelimiter
=
/;
(?![^
(
]
*
\))
/g
;
var
propertyDelimiter
=
/:
(
.+
)
/
;
cssText
.
split
(
listDelimiter
).
forEach
(
function
(
item
)
{
if
(
item
)
{
var
tmp
=
item
.
split
(
propertyDelimiter
);
tmp
.
length
>
1
&&
(
res
[
tmp
[
0
].
trim
()]
=
tmp
[
1
].
trim
());
}
});
return
res
;
});
function
isDef
(
v
)
{
return
v
!==
undefined
&&
v
!==
null
;
}
function
renderClass
(
staticClass
,
dynamicClass
)
{
if
(
isDef
(
staticClass
)
||
isDef
(
dynamicClass
))
{
return
concat
(
staticClass
,
stringifyClass
(
dynamicClass
));
}
/* istanbul ignore next */
return
''
;
}
function
concat
(
a
,
b
)
{
return
a
?
(
b
?
a
+
'
'
+
b
:
a
)
:
b
||
''
;
}
function
stringifyClass
(
value
)
{
if
(
Array
.
isArray
(
value
))
{
return
stringifyArray
(
value
);
}
if
(
isObject
(
value
))
{
return
stringifyObject
(
value
);
}
if
(
typeof
value
===
'
string
'
)
{
return
value
;
}
/* istanbul ignore next */
return
''
;
}
function
stringifyArray
(
value
)
{
var
res
=
''
;
var
stringified
;
for
(
var
i
=
0
,
l
=
value
.
length
;
i
<
l
;
i
++
)
{
if
(
isDef
((
stringified
=
stringifyClass
(
value
[
i
])))
&&
stringified
!==
''
)
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
stringified
;
}
}
return
res
;
}
function
stringifyObject
(
value
)
{
var
res
=
''
;
for
(
var
key
in
value
)
{
if
(
value
[
key
])
{
if
(
res
)
{
res
+=
'
'
;
}
res
+=
key
;
}
}
return
res
;
}
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
function
setModel
(
target
,
key
,
value
,
modifiers
)
{
if
(
isArray
(
modifiers
))
{
if
(
isArray
(
modifiers
))
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
if
(
modifiers
.
indexOf
(
'
trim
'
)
!==
-
1
)
{
...
@@ -229,7 +414,9 @@ function initComponentInstance(instance, options) {
...
@@ -229,7 +414,9 @@ function initComponentInstance(instance, options) {
ctx
.
__set_sync
=
setSync
;
ctx
.
__set_sync
=
setSync
;
ctx
.
__get_orig
=
getOrig
;
ctx
.
__get_orig
=
getOrig
;
// TODO
// TODO
// ctx.__get_style = getStyle
ctx
.
__get_value
=
getValue
;
ctx
.
__get_class
=
getClass
;
ctx
.
__get_style
=
getStyle
;
ctx
.
__map
=
map
;
ctx
.
__map
=
map
;
}
}
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
function
initMocks
(
instance
,
mpInstance
,
mocks
)
{
...
@@ -356,66 +543,6 @@ function initCreateApp(parseAppOptions) {
...
@@ -356,66 +543,6 @@ function initCreateApp(parseAppOptions) {
};
};
}
}
function
initBehavior
(
options
)
{
return
Behavior
(
options
);
}
function
initVueIds
(
vueIds
,
mpInstance
)
{
if
(
!
vueIds
)
{
return
;
}
const
ids
=
vueIds
.
split
(
'
,
'
);
const
len
=
ids
.
length
;
if
(
len
===
1
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
}
else
if
(
len
===
2
)
{
mpInstance
.
_$vueId
=
ids
[
0
];
mpInstance
.
_$vuePid
=
ids
[
1
];
}
}
const
EXTRAS
=
[
'
externalClasses
'
];
function
initExtraOptions
(
miniProgramComponentOptions
,
vueOptions
)
{
EXTRAS
.
forEach
((
name
)
=>
{
if
(
hasOwn
(
vueOptions
,
name
))
{
miniProgramComponentOptions
[
name
]
=
vueOptions
[
name
];
}
});
}
function
initWxsCallMethods
(
methods
,
wxsCallMethods
)
{
if
(
!
isArray
(
wxsCallMethods
))
{
return
;
}
wxsCallMethods
.
forEach
((
callMethod
)
=>
{
methods
[
callMethod
]
=
function
(
args
)
{
return
this
.
$vm
[
callMethod
](
args
);
};
});
}
function
selectAllComponents
(
mpInstance
,
selector
,
$refs
)
{
const
components
=
mpInstance
.
selectAllComponents
(
selector
);
components
.
forEach
((
component
)
=>
{
const
ref
=
component
.
dataset
.
ref
;
$refs
[
ref
]
=
component
.
$vm
||
component
;
});
}
function
initRefs
(
instance
,
mpInstance
)
{
Object
.
defineProperty
(
instance
,
'
refs
'
,
{
get
()
{
const
$refs
=
{};
selectAllComponents
(
mpInstance
,
'
.vue-ref
'
,
$refs
);
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
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
function
createObserver
(
name
)
{
function
createObserver
(
name
)
{
return
function
observer
(
newVal
)
{
return
function
observer
(
newVal
)
{
...
@@ -572,18 +699,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
...
@@ -572,18 +699,6 @@ function applyOptions(componentOptions, vueOptions, initBehavior) {
componentOptions
.
behaviors
=
initBehaviors
(
vueOptions
,
initBehavior
);
componentOptions
.
behaviors
=
initBehaviors
(
vueOptions
,
initBehavior
);
}
}
function
getValue
(
obj
,
path
)
{
const
parts
=
path
.
split
(
'
.
'
);
let
key
=
parts
[
0
];
if
(
key
.
indexOf
(
'
__$n
'
)
===
0
)
{
//number index
key
=
parseInt
(
key
.
replace
(
'
__$n
'
,
''
));
}
if
(
parts
.
length
===
1
)
{
return
obj
[
key
];
}
return
getValue
(
obj
[
key
],
parts
.
slice
(
1
).
join
(
'
.
'
));
}
function
getExtraValue
(
instance
,
dataPathsArray
)
{
function
getExtraValue
(
instance
,
dataPathsArray
)
{
let
context
=
instance
;
let
context
=
instance
;
dataPathsArray
.
forEach
((
dataPathArray
)
=>
{
dataPathsArray
.
forEach
((
dataPathArray
)
=>
{
...
@@ -605,7 +720,7 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -605,7 +720,7 @@ function getExtraValue(instance, dataPathsArray) {
vFor
=
dataPath
.
substr
(
3
);
vFor
=
dataPath
.
substr
(
3
);
}
}
else
{
else
{
vFor
=
get
Value
(
context
,
dataPath
);
vFor
=
get
Target
(
context
,
dataPath
);
}
}
}
}
if
(
Number
.
isInteger
(
vFor
))
{
if
(
Number
.
isInteger
(
vFor
))
{
...
@@ -617,12 +732,12 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -617,12 +732,12 @@ function getExtraValue(instance, dataPathsArray) {
else
{
else
{
if
(
isArray
(
vFor
))
{
if
(
isArray
(
vFor
))
{
context
=
vFor
.
find
((
vForItem
)
=>
{
context
=
vFor
.
find
((
vForItem
)
=>
{
return
get
Value
(
vForItem
,
propPath
)
===
value
;
return
get
Target
(
vForItem
,
propPath
)
===
value
;
});
});
}
}
else
if
(
isPlainObject
(
vFor
))
{
else
if
(
isPlainObject
(
vFor
))
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
context
=
Object
.
keys
(
vFor
).
find
((
vForKey
)
=>
{
return
get
Value
(
vFor
[
vForKey
],
propPath
)
===
value
;
return
get
Target
(
vFor
[
vForKey
],
propPath
)
===
value
;
});
});
}
}
else
{
else
{
...
@@ -630,7 +745,7 @@ function getExtraValue(instance, dataPathsArray) {
...
@@ -630,7 +745,7 @@ function getExtraValue(instance, dataPathsArray) {
}
}
}
}
if
(
valuePath
)
{
if
(
valuePath
)
{
context
=
get
Value
(
context
,
valuePath
);
context
=
get
Target
(
context
,
valuePath
);
}
}
}
}
});
});
...
@@ -671,10 +786,10 @@ function processEventExtra(instance, extra, event) {
...
@@ -671,10 +786,10 @@ function processEventExtra(instance, extra, event) {
}
}
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
else
if
(
dataPath
.
indexOf
(
'
$event.
'
)
===
0
)
{
// $event.target.value
// $event.target.value
extraObj
[
'
$
'
+
index
]
=
get
Value
(
event
,
dataPath
.
replace
(
'
$event.
'
,
''
));
extraObj
[
'
$
'
+
index
]
=
get
Target
(
event
,
dataPath
.
replace
(
'
$event.
'
,
''
));
}
}
else
{
else
{
extraObj
[
'
$
'
+
index
]
=
get
Value
(
instance
,
dataPath
);
extraObj
[
'
$
'
+
index
]
=
get
Target
(
instance
,
dataPath
);
}
}
}
}
}
}
...
@@ -811,7 +926,14 @@ function handleEvent(event) {
...
@@ -811,7 +926,14 @@ function handleEvent(event) {
}
}
handler
.
once
=
true
;
handler
.
once
=
true
;
}
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
processEventArgs
(
this
.
$vm
,
event
,
eventArray
[
1
],
eventArray
[
2
],
isCustom
,
methodName
)));
let
params
=
processEventArgs
(
this
.
$vm
,
event
,
eventArray
[
1
],
eventArray
[
2
],
isCustom
,
methodName
);
params
=
Array
.
isArray
(
params
)
?
params
:
[];
// 参数尾部增加原始事件对象用于复杂表达式内获取额外数据
if
(
/=
\s
*
\S
+
\.
eventParams
\s
*
\|\|\s
*
\S
+
\[[
'"
]
event-params
[
'"
]\]
/
.
test
(
handler
.
toString
()))
{
// eslint-disable-next-line no-sparse-arrays
params
=
params
.
concat
([,
,
,
,
,
,
,
,
,
,
event
]);
}
ret
.
push
(
handler
.
apply
(
handlerCtx
,
params
));
}
}
});
});
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录