Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
陈庄旺
uni-app
提交
73ddbc99
U
uni-app
项目概览
陈庄旺
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
73ddbc99
编写于
5月 18, 2021
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: callOptions move to shared
上级
18ac357d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
186 addition
and
126 deletion
+186
-126
packages/uni-h5/src/helpers/utils.ts
packages/uni-h5/src/helpers/utils.ts
+0
-34
packages/uni-h5/src/service/api/network/socket.ts
packages/uni-h5/src/service/api/network/socket.ts
+5
-5
packages/uni-h5/src/view/components/map/index.tsx
packages/uni-h5/src/view/components/map/index.tsx
+90
-86
packages/uni-shared/dist/uni-shared.cjs.js
packages/uni-shared/dist/uni-shared.cjs.js
+22
-0
packages/uni-shared/dist/uni-shared.d.ts
packages/uni-shared/dist/uni-shared.d.ts
+13
-0
packages/uni-shared/dist/uni-shared.es.js
packages/uni-shared/dist/uni-shared.es.js
+22
-1
packages/uni-shared/src/utils.ts
packages/uni-shared/src/utils.ts
+34
-0
未找到文件。
packages/uni-h5/src/helpers/utils.ts
浏览文件 @
73ddbc99
...
...
@@ -12,37 +12,3 @@ export function isInWindows(vm: ComponentPublicInstance) {
}
return
false
}
interface
Options
{
success
?:
(
res
:
any
)
=>
void
fail
?:
(
res
:
any
)
=>
void
complete
?:
(
res
:
any
)
=>
void
}
export
function
callback
(
options
:
Options
,
errMsg
:
string
):
void
export
function
callback
(
options
:
Options
,
data
:
{
[
key
:
string
]:
any
;
errMsg
:
string
}
):
void
export
function
callback
(
options
:
Options
,
data
:
{
[
key
:
string
]:
any
;
errMsg
:
string
}
|
string
):
void
{
options
=
options
||
{}
if
(
typeof
data
===
'
string
'
)
{
data
=
{
errMsg
:
data
,
}
}
if
(
/:ok$/
.
test
(
data
.
errMsg
))
{
if
(
typeof
options
.
success
===
'
function
'
)
{
options
.
success
(
data
)
}
}
else
{
if
(
typeof
options
.
fail
===
'
function
'
)
{
options
.
fail
(
data
)
}
}
if
(
typeof
options
.
complete
===
'
function
'
)
{
options
.
complete
(
data
)
}
}
packages/uni-h5/src/service/api/network/socket.ts
浏览文件 @
73ddbc99
...
...
@@ -14,7 +14,7 @@ import {
API_TYPE_CLOSE_SOCKET
,
CloseSocketProtocol
,
}
from
'
@dcloudio/uni-api
'
import
{
call
back
}
from
'
../../../helpers/utils
'
import
{
call
Options
}
from
'
@dcloudio/uni-shared
'
type
eventName
=
keyof
WebSocketEventMap
...
...
@@ -117,9 +117,9 @@ class SocketTask implements UniApp.SocketTask {
throw
new
Error
(
'
SocketTask.readyState is not OPEN
'
)
}
ws
.
send
(
data
)
call
back
(
options
,
'
sendSocketMessage:ok
'
)
call
Options
(
options
,
'
sendSocketMessage:ok
'
)
}
catch
(
error
)
{
call
back
(
options
,
`sendSocketMessage:fail
${
error
}
`
)
call
Options
(
options
,
`sendSocketMessage:fail
${
error
}
`
)
}
}
...
...
@@ -138,9 +138,9 @@ class SocketTask implements UniApp.SocketTask {
}
else
{
ws
.
close
(
code
)
}
call
back
(
options
,
'
closeSocket:ok
'
)
call
Options
(
options
,
'
closeSocket:ok
'
)
}
catch
(
error
)
{
call
back
(
options
,
`closeSocket:fail
${
error
}
`
)
call
Options
(
options
,
`closeSocket:fail
${
error
}
`
)
}
}
onOpen
(
callback
:
(
result
:
any
)
=>
void
)
{
...
...
packages/uni-h5/src/view/components/map/index.tsx
浏览文件 @
73ddbc99
...
...
@@ -14,7 +14,7 @@ import {
useSubscribe
,
useCustomEvent
,
}
from
'
@dcloudio/uni-components
'
import
{
call
back
}
from
'
../../../helpers/utils
'
import
{
call
Options
}
from
'
@dcloudio/uni-shared
'
import
{
QQMapsExt
,
loadMaps
}
from
'
./qqMap
'
import
{
Map
}
from
'
./qqMap/types
'
import
MapMarker
,
{
...
...
@@ -301,99 +301,103 @@ function useMap(
try
{
// TODO 支持在页面外使用
const
id
=
useContextInfo
()
useSubscribe
((
type
,
data
:
any
=
{})
=>
{
switch
(
type
)
{
case
'
getCenterLocation
'
:
onMapReady
(()
=>
{
const
center
=
map
.
getCenter
()
callback
(
data
,
{
latitude
:
center
.
getLat
(),
longitude
:
center
.
getLng
(),
errMsg
:
`
${
type
}
:ok`
,
useSubscribe
(
(
type
,
data
:
any
=
{})
=>
{
switch
(
type
)
{
case
'
getCenterLocation
'
:
onMapReady
(()
=>
{
const
center
=
map
.
getCenter
()
callOptions
(
data
,
{
latitude
:
center
.
getLat
(),
longitude
:
center
.
getLng
(),
errMsg
:
`
${
type
}
:ok`
,
})
})
})
break
case
'
moveToLocation
'
:
{
let
latitude
=
Number
(
data
.
lat
itude
)
let
longitude
=
Number
(
data
.
longitude
)
if
(
!
latitude
||
!
longitude
)
{
const
context
:
MapLocationContext
=
contexts
[
MAP_LOCATION_CONTEXT_ID
]
as
MapLocationContext
if
(
context
)
{
latitude
=
context
.
state
.
lat
itude
longitude
=
context
.
state
.
longitude
break
case
'
moveToLocation
'
:
{
let
latitude
=
Number
(
data
.
latitude
)
let
longitude
=
Number
(
data
.
long
itude
)
if
(
!
latitude
||
!
longitude
)
{
const
context
:
MapLocationContext
=
contexts
[
MAP_LOCATION_CONTEXT_ID
]
as
MapLocationContext
if
(
context
)
{
latitude
=
context
.
state
.
latitude
longitude
=
context
.
state
.
long
itude
}
}
}
if
(
latitude
&&
longitude
)
{
state
.
latitude
=
latitude
state
.
longitude
=
longitude
if
(
map
)
{
map
.
setCenter
(
new
maps
.
LatLng
(
latitude
,
longitude
))
if
(
latitude
&&
longitude
)
{
state
.
latitude
=
latitude
state
.
longitude
=
longitude
if
(
map
)
{
map
.
setCenter
(
new
maps
.
LatLng
(
latitude
,
longitude
))
}
onMapReady
(()
=>
{
callOptions
(
data
,
`
${
type
}
:ok`
)
})
}
else
{
callOptions
(
data
,
`
${
type
}
:fail`
)
}
onMapReady
(()
=>
{
callback
(
data
,
`
${
type
}
:ok`
)
})
}
else
{
callback
(
data
,
`
${
type
}
:fail`
)
}
}
break
case
'
translateMarker
'
:
onMapReady
(()
=>
{
const
context
:
MapMarkerContext
=
contexts
[
data
.
markerId
]
as
MapMarkerContext
if
(
context
)
{
try
{
context
.
translate
(
data
)
}
catch
(
error
)
{
callback
(
data
,
`
${
type
}
:fail
${
error
.
message
}
`
)
break
case
'
translateMarker
'
:
onMapReady
(()
=>
{
const
context
:
MapMarkerContext
=
contexts
[
data
.
markerId
]
as
MapMarkerContext
if
(
context
)
{
try
{
context
.
translate
(
data
)
}
catch
(
error
)
{
callOptions
(
data
,
`
${
type
}
:fail
${
error
.
message
}
`
)
}
callOptions
(
data
,
`
${
type
}
:ok`
)
}
else
{
callOptions
(
data
,
`
${
type
}
:fail not found`
)
}
callback
(
data
,
`
${
type
}
:ok`
)
}
else
{
callback
(
data
,
`
${
type
}
:fail not found`
)
})
break
case
'
includePoints
'
:
state
.
includePoints
=
getPoints
(
data
.
includePoints
as
Point
[])
if
(
isBoundsReady
)
{
updateBounds
()
}
})
break
case
'
includePoints
'
:
state
.
includePoints
=
getPoints
(
data
.
includePoints
as
Point
[])
if
(
isBoundsReady
)
{
updateBounds
()
}
onBoundsReady
(()
=>
{
callback
(
data
,
`
${
type
}
:ok`
)
})
break
case
'
getRegion
'
:
onBoundsReady
(()
=>
{
const
latLngBounds
=
map
.
getBounds
()
const
southwest
=
latLngBounds
.
getSouthWest
()
const
northeast
=
latLngBounds
.
getNorthEast
()
callback
(
data
,
{
southwest
:
{
latitude
:
southwest
.
getLat
(),
longitude
:
southwest
.
getLng
(),
},
northeast
:
{
latitude
:
northeast
.
getLat
(),
longitude
:
northeast
.
getLng
(),
},
errMsg
:
`
${
type
}
:ok`
,
onBoundsReady
(()
=>
{
callOptions
(
data
,
`
${
type
}
:ok`
)
})
})
break
case
'
getScale
'
:
onMapReady
(()
=>
{
callback
(
data
,
{
scale
:
map
.
getZoom
(),
errMsg
:
`
${
type
}
:ok`
,
break
case
'
getRegion
'
:
onBoundsReady
(()
=>
{
const
latLngBounds
=
map
.
getBounds
()
const
southwest
=
latLngBounds
.
getSouthWest
()
const
northeast
=
latLngBounds
.
getNorthEast
()
callOptions
(
data
,
{
southwest
:
{
latitude
:
southwest
.
getLat
(),
longitude
:
southwest
.
getLng
(),
},
northeast
:
{
latitude
:
northeast
.
getLat
(),
longitude
:
northeast
.
getLng
(),
},
errMsg
:
`
${
type
}
:ok`
,
})
})
})
break
}
},
id
,
true
)
break
case
'
getScale
'
:
onMapReady
(()
=>
{
callOptions
(
data
,
{
scale
:
map
.
getZoom
(),
errMsg
:
`
${
type
}
:ok`
,
})
})
break
}
},
id
,
true
)
}
catch
(
error
)
{}
onMounted
(()
=>
{
loadMaps
((
result
)
=>
{
...
...
packages/uni-shared/dist/uni-shared.cjs.js
浏览文件 @
73ddbc99
...
...
@@ -227,6 +227,27 @@ function formatDateTime({ date = new Date(), mode = 'date' }) {
'
-
'
+
_completeValue
(
date
.
getDate
()));
}
}
function
callOptions
(
options
,
data
)
{
options
=
options
||
{};
if
(
typeof
data
===
'
string
'
)
{
data
=
{
errMsg
:
data
,
};
}
if
(
/:ok$/
.
test
(
data
.
errMsg
))
{
if
(
typeof
options
.
success
===
'
function
'
)
{
options
.
success
(
data
);
}
}
else
{
if
(
typeof
options
.
fail
===
'
function
'
)
{
options
.
fail
(
data
);
}
}
if
(
typeof
options
.
complete
===
'
function
'
)
{
options
.
complete
(
data
);
}
}
const
encode
=
encodeURIComponent
;
...
...
@@ -358,6 +379,7 @@ exports.UNI_SSR_DATA = UNI_SSR_DATA;
exports
.
UNI_SSR_GLOBAL_DATA
=
UNI_SSR_GLOBAL_DATA
;
exports
.
UNI_SSR_STORE
=
UNI_SSR_STORE
;
exports
.
addFont
=
addFont
;
exports
.
callOptions
=
callOptions
;
exports
.
createRpx2Unit
=
createRpx2Unit
;
exports
.
debounce
=
debounce
;
exports
.
decode
=
decode
;
...
...
packages/uni-shared/dist/uni-shared.d.ts
浏览文件 @
73ddbc99
...
...
@@ -4,6 +4,13 @@ export declare function addFont(family: string, source: string, desc?: FontFaceD
export
declare
const
BUILT_IN_TAGS
:
string
[];
export
declare
function
callOptions
(
options
:
Options
,
errMsg
:
string
):
void
;
export
declare
function
callOptions
(
options
:
Options
,
data
:
{
[
key
:
string
]:
any
;
errMsg
:
string
;
}):
void
;
export
declare
const
COMPONENT_NAME_PREFIX
=
"
VUni
"
;
export
declare
const
COMPONENT_PREFIX
:
string
;
...
...
@@ -66,6 +73,12 @@ export declare const ON_REACH_BOTTOM_DISTANCE = 50;
export
declare
function
once
<
T
extends
(...
args
:
any
[])
=>
any
>
(
fn
:
T
,
ctx
?:
unknown
):
T
;
declare
interface
Options
{
success
?:
(
res
:
any
)
=>
void
;
fail
?:
(
res
:
any
)
=>
void
;
complete
?:
(
res
:
any
)
=>
void
;
}
/**
* https://github.com/vuejs/vue-router-next/blob/master/src/query.ts
* @internal
...
...
packages/uni-shared/dist/uni-shared.es.js
浏览文件 @
73ddbc99
...
...
@@ -223,6 +223,27 @@ function formatDateTime({ date = new Date(), mode = 'date' }) {
'
-
'
+
_completeValue
(
date
.
getDate
()));
}
}
function
callOptions
(
options
,
data
)
{
options
=
options
||
{};
if
(
typeof
data
===
'
string
'
)
{
data
=
{
errMsg
:
data
,
};
}
if
(
/:ok$/
.
test
(
data
.
errMsg
))
{
if
(
typeof
options
.
success
===
'
function
'
)
{
options
.
success
(
data
);
}
}
else
{
if
(
typeof
options
.
fail
===
'
function
'
)
{
options
.
fail
(
data
);
}
}
if
(
typeof
options
.
complete
===
'
function
'
)
{
options
.
complete
(
data
);
}
}
const
encode
=
encodeURIComponent
;
...
...
@@ -338,4 +359,4 @@ function getEnvLocale() {
return
(
lang
&&
lang
.
replace
(
/
[
.:
]
.*/
,
''
))
||
'
en
'
;
}
export
{
BUILT_IN_TAGS
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
NAVBAR_HEIGHT
,
ON_REACH_BOTTOM_DISTANCE
,
PLUS_RE
,
PRIMARY_COLOR
,
RESPONSIVE_MIN_WIDTH
,
TABBAR_HEIGHT
,
TAGS
,
UNI_SSR
,
UNI_SSR_DATA
,
UNI_SSR_GLOBAL_DATA
,
UNI_SSR_STORE
,
addFont
,
createRpx2Unit
,
debounce
,
decode
,
decodedQuery
,
defaultRpx2Unit
,
formatDateTime
,
getEnvLocale
,
getLen
,
invokeArrayFns
,
isBuiltInComponent
,
isCustomElement
,
isNativeTag
,
normalizeDataset
,
normalizeTarget
,
once
,
parseQuery
,
passive
,
plusReady
,
removeLeadingSlash
,
sanitise
,
scrollTo
,
stringifyQuery
,
updateElementStyle
};
export
{
BUILT_IN_TAGS
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
NAVBAR_HEIGHT
,
ON_REACH_BOTTOM_DISTANCE
,
PLUS_RE
,
PRIMARY_COLOR
,
RESPONSIVE_MIN_WIDTH
,
TABBAR_HEIGHT
,
TAGS
,
UNI_SSR
,
UNI_SSR_DATA
,
UNI_SSR_GLOBAL_DATA
,
UNI_SSR_STORE
,
addFont
,
c
allOptions
,
c
reateRpx2Unit
,
debounce
,
decode
,
decodedQuery
,
defaultRpx2Unit
,
formatDateTime
,
getEnvLocale
,
getLen
,
invokeArrayFns
,
isBuiltInComponent
,
isCustomElement
,
isNativeTag
,
normalizeDataset
,
normalizeTarget
,
once
,
parseQuery
,
passive
,
plusReady
,
removeLeadingSlash
,
sanitise
,
scrollTo
,
stringifyQuery
,
updateElementStyle
};
packages/uni-shared/src/utils.ts
浏览文件 @
73ddbc99
...
...
@@ -57,3 +57,37 @@ export function formatDateTime({ date = new Date(), mode = 'date' }) {
)
}
}
interface
Options
{
success
?:
(
res
:
any
)
=>
void
fail
?:
(
res
:
any
)
=>
void
complete
?:
(
res
:
any
)
=>
void
}
export
function
callOptions
(
options
:
Options
,
errMsg
:
string
):
void
export
function
callOptions
(
options
:
Options
,
data
:
{
[
key
:
string
]:
any
;
errMsg
:
string
}
):
void
export
function
callOptions
(
options
:
Options
,
data
:
{
[
key
:
string
]:
any
;
errMsg
:
string
}
|
string
):
void
{
options
=
options
||
{}
if
(
typeof
data
===
'
string
'
)
{
data
=
{
errMsg
:
data
,
}
}
if
(
/:ok$/
.
test
(
data
.
errMsg
))
{
if
(
typeof
options
.
success
===
'
function
'
)
{
options
.
success
(
data
)
}
}
else
{
if
(
typeof
options
.
fail
===
'
function
'
)
{
options
.
fail
(
data
)
}
}
if
(
typeof
options
.
complete
===
'
function
'
)
{
options
.
complete
(
data
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录