Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzb_79
uni-app
提交
a53b4733
U
uni-app
项目概览
lzb_79
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
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,发现更多精彩内容 >>
提交
a53b4733
编写于
7月 29, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(App): picker
上级
e645e1f3
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
363 addition
and
21 deletion
+363
-21
packages/uni-app-plus/src/helpers/page.ts
packages/uni-app-plus/src/helpers/page.ts
+8
-6
packages/uni-app-plus/src/service/api/device/scanCode.ts
packages/uni-app-plus/src/service/api/device/scanCode.ts
+1
-1
packages/uni-app-plus/src/service/api/location/chooseLocation.ts
...s/uni-app-plus/src/service/api/location/chooseLocation.ts
+1
-1
packages/uni-app-plus/src/service/api/location/openLocation.ts
...ges/uni-app-plus/src/service/api/location/openLocation.ts
+1
-1
packages/uni-app-plus/src/view/components/picker/index.tsx
packages/uni-app-plus/src/view/components/picker/index.tsx
+337
-1
packages/uni-components/src/components/button/index.tsx
packages/uni-components/src/components/button/index.tsx
+1
-1
packages/uni-components/src/components/radio-group/index.tsx
packages/uni-components/src/components/radio-group/index.tsx
+14
-10
未找到文件。
packages/uni-app-plus/src/
service/api
/page.ts
→
packages/uni-app-plus/src/
helpers
/page.ts
浏览文件 @
a53b4733
...
...
@@ -64,7 +64,7 @@ function addEventListener(pageId: string, callback: CallBack) {
callbacks
[
pageId
]
=
callback
}
class
Page
{
export
class
Page
{
webview
:
PlusWebviewWebviewObject
constructor
(
webview
:
PlusWebviewWebviewObject
)
{
...
...
@@ -72,11 +72,13 @@ class Page {
}
sendMessage
(
data
:
any
)
{
const
message
=
{
const
message
=
JSON
.
parse
(
JSON
.
stringify
({
__message
:
{
data
,
},
}
})
)
const
id
=
this
.
webview
.
id
if
(
BroadcastChannel_
)
{
const
channel
=
new
BroadcastChannel_
(
id
)
...
...
packages/uni-app-plus/src/service/api/device/scanCode.ts
浏览文件 @
a53b4733
import
{
showPage
}
from
'
../page.js
'
import
{
showPage
}
from
'
../
../../helpers/
page.js
'
import
{
defineAsyncApi
,
API_SCAN_CODE
,
...
...
packages/uni-app-plus/src/service/api/location/chooseLocation.ts
浏览文件 @
a53b4733
...
...
@@ -4,7 +4,7 @@ import {
defineAsyncApi
,
ChooseLocationProtocol
,
}
from
'
@dcloudio/uni-api
'
import
{
showPage
}
from
'
../page
'
import
{
showPage
}
from
'
../
../../helpers/
page
'
import
{
getStatusBarStyle
}
from
'
../../../helpers/statusBar
'
export
const
chooseLocation
=
<
API_TYPE_CHOOSE_LOCATION
>
defineAsyncApi
(
...
...
packages/uni-app-plus/src/service/api/location/openLocation.ts
浏览文件 @
a53b4733
...
...
@@ -5,7 +5,7 @@ import {
OpenLocationProtocol
,
OpenLocationOptions
,
}
from
'
@dcloudio/uni-api
'
import
{
showPage
}
from
'
../page.js
'
import
{
showPage
}
from
'
../
../../helpers/
page.js
'
export
const
openLocation
=
<
API_TYPE_OPEN_LOCATION
>
defineAsyncApi
(
API_OPEN_LOCATION
,
...
...
packages/uni-app-plus/src/view/components/picker/index.tsx
浏览文件 @
a53b4733
import
{
defineBuiltInComponent
}
from
'
@dcloudio/uni-components
'
import
{
Ref
,
ref
,
watch
,
onBeforeUnmount
,
ExtractPropTypes
,
inject
}
from
'
vue
'
import
{
defineBuiltInComponent
,
useCustomEvent
,
EmitEvent
,
}
from
'
@dcloudio/uni-components
'
import
{
useI18n
,
initI18nPickerMsgsOnce
}
from
'
@dcloudio/uni-core
'
import
{
UniFormCtx
,
uniFormKey
}
from
'
@dcloudio/uni-components
'
import
{
showPage
,
Page
}
from
'
../../../helpers/page
'
import
{
getNavigationBarHeight
}
from
'
../../../helpers/navigationBar
'
type
Mode
=
'
selector
'
|
'
multiSelector
'
|
'
time
'
|
'
date
'
type
Field
=
'
year
'
|
'
month
'
|
'
day
'
const
mode
:
Record
<
string
,
Mode
>
=
{
SELECTOR
:
'
selector
'
,
MULTISELECTOR
:
'
multiSelector
'
,
TIME
:
'
time
'
,
DATE
:
'
date
'
,
// 暂不支持城市选择
// REGION: 'region'
}
const
fields
:
Record
<
string
,
Field
>
=
{
YEAR
:
'
year
'
,
MONTH
:
'
month
'
,
DAY
:
'
day
'
,
}
function
padLeft
(
num
:
number
)
{
return
num
>
9
?
num
:
`0
${
num
}
`
}
function
getDate
(
str
:
Props
[
'
value
'
],
_mode
:
Mode
)
{
str
=
String
(
str
||
''
)
const
date
=
new
Date
()
if
(
_mode
===
mode
.
TIME
)
{
const
strs
=
str
.
split
(
'
:
'
)
if
(
strs
.
length
===
2
)
{
date
.
setHours
(
parseInt
(
strs
[
0
]),
parseInt
(
strs
[
1
]))
}
}
else
{
const
strs
=
str
.
split
(
'
-
'
)
if
(
strs
.
length
===
3
)
{
date
.
setFullYear
(
parseInt
(
strs
[
0
]),
parseInt
(
String
(
parseFloat
(
strs
[
1
])
-
1
)),
parseInt
(
strs
[
2
])
)
}
}
return
date
}
function
getDefaultStartValue
(
props
:
any
)
{
if
((
props
as
Props
).
mode
===
mode
.
TIME
)
{
return
'
00:00
'
}
if
((
props
as
Props
).
mode
===
mode
.
DATE
)
{
const
year
=
new
Date
().
getFullYear
()
-
100
switch
((
props
as
Props
).
fields
)
{
case
fields
.
YEAR
:
return
year
case
fields
.
MONTH
:
return
year
+
'
-01
'
default
:
return
year
+
'
-01-01
'
}
}
return
''
}
function
getDefaultEndValue
(
props
:
any
)
{
if
((
props
as
Props
).
mode
===
mode
.
TIME
)
{
return
'
23:59
'
}
if
((
props
as
Props
).
mode
===
mode
.
DATE
)
{
const
year
=
new
Date
().
getFullYear
()
+
100
switch
((
props
as
Props
).
fields
)
{
case
fields
.
YEAR
:
return
year
case
fields
.
MONTH
:
return
year
+
'
-12
'
default
:
return
year
+
'
-12-31
'
}
}
return
''
}
const
props
=
{
name
:
{
type
:
String
,
default
:
''
,
},
range
:
{
type
:
Array
,
default
()
{
return
[]
},
},
rangeKey
:
{
type
:
String
,
default
:
''
,
},
value
:
{
type
:
[
Number
,
String
,
Array
],
default
:
0
,
},
mode
:
{
type
:
String
,
default
:
mode
.
SELECTOR
,
validator
(
val
:
string
)
{
return
Object
.
values
(
mode
).
indexOf
(
val
as
Mode
)
>=
0
},
},
fields
:
{
type
:
String
,
default
:
''
,
},
start
:
{
type
:
String
,
default
:
getDefaultStartValue
,
},
end
:
{
type
:
String
,
default
:
getDefaultEndValue
,
},
disabled
:
{
type
:
[
Boolean
,
String
],
default
:
false
,
},
}
type
Props
=
ExtractPropTypes
<
typeof
props
>
export
default
/*#__PURE__*/
defineBuiltInComponent
({
name
:
'
Picker
'
,
props
,
emits
:
[
'
change
'
,
'
cancel
'
,
'
columnchange
'
],
setup
(
props
,
{
emit
})
{
initI18nPickerMsgsOnce
()
const
{
t
,
getLocale
}
=
useI18n
()
const
rootRef
:
Ref
<
HTMLElement
|
null
>
=
ref
(
null
)
const
trigger
=
useCustomEvent
<
EmitEvent
<
typeof
emit
>>
(
rootRef
,
emit
)
const
valueSync
:
Ref
<
Array
<
number
>
|
number
|
string
|
null
>
=
ref
(
null
)
const
page
:
Ref
<
Page
|
null
>
=
ref
(
null
)
type
ShowPickerData
=
Props
&
{
value
:
typeof
valueSync
.
value
locale
:
ReturnType
<
typeof
getLocale
>
messages
:
{
done
:
string
cancel
:
string
}
}
const
_setValueSync
=
()
=>
{
let
val
=
props
.
value
switch
(
props
.
mode
)
{
case
mode
.
MULTISELECTOR
:
{
if
(
!
Array
.
isArray
(
val
))
{
val
=
[]
}
if
(
!
Array
.
isArray
(
valueSync
.
value
))
{
valueSync
.
value
=
[]
}
const
length
=
(
valueSync
.
value
.
length
=
Math
.
max
(
val
.
length
,
props
.
range
.
length
))
for
(
let
index
=
0
;
index
<
length
;
index
++
)
{
const
val0
=
Number
(
val
[
index
])
const
val1
=
Number
(
valueSync
.
value
[
index
])
const
val2
=
isNaN
(
val0
)
?
(
isNaN
(
val1
)
?
0
:
val1
)
:
val0
valueSync
.
value
.
splice
(
index
,
1
,
val2
<
0
?
0
:
val2
)
}
}
break
case
mode
.
TIME
:
case
mode
.
DATE
:
valueSync
.
value
=
String
(
val
)
break
default
:
{
const
_valueSync
=
Number
(
val
)
valueSync
.
value
=
_valueSync
<
0
?
0
:
_valueSync
break
}
}
}
const
_updatePicker
=
(
data
:
ShowPickerData
)
=>
{
page
.
value
&&
page
.
value
.
sendMessage
(
data
)
}
const
_showWeexPicker
=
(
data
:
ShowPickerData
)
=>
{
let
res
:
{
event
?:
Parameters
<
typeof
emit
>
[
0
]
}
=
{
event
:
'
cancel
'
}
page
.
value
=
showPage
({
url
:
'
__uniapppicker
'
,
data
,
style
:
{
titleNView
:
undefined
,
animationType
:
'
none
'
,
animationDuration
:
0
,
background
:
'
rgba(0,0,0,0)
'
,
popGesture
:
'
none
'
,
},
onMessage
:
(
message
)
=>
{
const
event
=
message
.
event
if
(
event
===
'
created
'
)
{
_updatePicker
(
data
)
return
}
if
(
event
===
'
columnchange
'
)
{
delete
message
.
event
trigger
(
event
,
{}
as
Event
,
message
)
return
}
res
=
message
},
onClose
:
()
=>
{
page
.
value
=
null
const
event
=
res
.
event
delete
res
.
event
event
&&
trigger
(
event
,
{}
as
Event
,
res
)
},
})
}
const
_showNativePicker
=
(
data
:
ShowPickerData
,
popover
:
any
)
=>
{
plus
.
nativeUI
[
props
.
mode
===
mode
.
TIME
?
'
pickTime
'
:
'
pickDate
'
](
(
res
)
=>
{
const
date
=
res
.
date
trigger
(
'
change
'
,
{}
as
Event
,
{
value
:
props
.
mode
===
mode
.
TIME
?
`
${
padLeft
(
date
.
getHours
())}
:
${
padLeft
(
date
.
getMinutes
())}
`
:
`
${
date
.
getFullYear
()}
-
${
padLeft
(
date
.
getMonth
()
+
1
)}
-
${
padLeft
(
date
.
getDate
())}
`
,
})
},
()
=>
{
trigger
(
'
cancel
'
,
{}
as
Event
,
{})
},
props
.
mode
===
mode
.
TIME
?
{
time
:
getDate
(
props
.
value
,
mode
.
TIME
),
popover
,
}
:
{
date
:
getDate
(
props
.
value
,
mode
.
DATE
),
minDate
:
getDate
(
props
.
start
,
mode
.
DATE
),
maxDate
:
getDate
(
props
.
end
,
mode
.
DATE
),
popover
,
}
)
}
const
_showPicker
=
(
data
:
ShowPickerData
,
popover
:
any
)
=>
{
if
(
(
data
.
mode
===
mode
.
TIME
||
data
.
mode
===
mode
.
DATE
)
&&
!
data
.
fields
)
{
_showNativePicker
(
data
,
popover
)
}
else
{
data
.
fields
=
Object
.
values
(
fields
).
includes
(
data
.
fields
as
Field
)
?
data
.
fields
:
fields
.
DAY
_showWeexPicker
(
data
)
}
}
const
_show
=
(
event
:
MouseEvent
)
=>
{
if
(
props
.
disabled
)
{
return
}
const
eventTarget
=
event
.
currentTarget
as
HTMLElement
const
rect
=
eventTarget
.
getBoundingClientRect
()
_showPicker
(
Object
.
assign
({},
props
,
{
value
:
valueSync
.
value
,
locale
:
getLocale
(),
messages
:
{
done
:
t
(
'
uni.picker.done
'
),
cancel
:
t
(
'
uni.picker.cancel
'
),
},
}),
{
top
:
rect
.
top
+
getNavigationBarHeight
(),
left
:
rect
.
left
,
width
:
rect
.
width
,
height
:
rect
.
height
,
}
)
}
const
uniForm
=
inject
<
UniFormCtx
>
(
uniFormKey
,
false
as
unknown
as
UniFormCtx
)
const
formField
=
{
submit
:
():
[
string
,
any
]
=>
[
props
.
name
,
valueSync
.
value
],
reset
:
()
=>
{
switch
(
props
.
mode
)
{
case
mode
.
SELECTOR
:
valueSync
.
value
=
0
break
case
mode
.
MULTISELECTOR
:
Array
.
isArray
(
props
.
value
)
&&
(
valueSync
.
value
=
props
.
value
.
map
((
val
)
=>
0
))
break
case
mode
.
DATE
:
case
mode
.
TIME
:
valueSync
.
value
=
''
break
default
:
break
}
},
}
if
(
uniForm
)
{
uniForm
.
addField
(
formField
)
onBeforeUnmount
(()
=>
uniForm
.
removeField
(
formField
))
}
Object
.
keys
(
props
).
forEach
((
key
)
=>
{
if
(
key
!==
'
name
'
)
{
watch
(
()
=>
(
props
as
any
)[
key
],
(
val
)
=>
{
const
data
=
{}
;(
data
as
any
)[
key
]
=
val
_updatePicker
(
data
as
any
)
},
{
deep
:
true
}
)
}
})
watch
(()
=>
props
.
value
,
_setValueSync
,
{
deep
:
true
})
_setValueSync
()
return
()
=>
(
<
uni
-
picker
ref
=
{
rootRef
}
onClick
=
{
_show
}
>
<
slot
/>
</
uni
-
picker
>
)
},
})
packages/uni-components/src/components/button/index.tsx
浏览文件 @
a53b4733
import
{
inject
,
onBeforeUnmount
,
ref
}
from
'
vue
'
import
{
inject
,
onBeforeUnmount
,
ref
,
getCurrentInstance
}
from
'
vue
'
import
{
useI18n
,
initI18nButtonMsgsOnce
}
from
'
@dcloudio/uni-core
'
import
{
defineBuiltInComponent
}
from
'
../../helpers/component
'
import
{
useHover
}
from
'
../../helpers/useHover
'
...
...
packages/uni-components/src/components/radio-group/index.tsx
浏览文件 @
a53b4733
import
{
inject
,
provide
,
ref
,
onMounted
}
from
'
vue
'
import
{
inject
,
provide
,
ref
,
onMounted
,
onBeforeUnmount
}
from
'
vue
'
import
type
{
Ref
,
ExtractPropTypes
,
WritableComputedRef
}
from
'
vue
'
import
{
PolySymbol
}
from
'
@dcloudio/uni-core
'
import
{
UniFormCtx
,
uniFormKey
}
from
'
../form
'
...
...
@@ -77,8 +77,7 @@ function useProvideRadioGroup(
})
const
uniForm
=
inject
<
UniFormCtx
>
(
uniFormKey
,
false
as
unknown
as
UniFormCtx
)
if
(
uniForm
)
{
uniForm
.
addField
({
const
formField
=
{
submit
:
()
=>
{
let
data
:
[
string
,
any
]
=
[
''
,
null
]
if
(
props
.
name
!==
''
)
{
...
...
@@ -87,6 +86,11 @@ function useProvideRadioGroup(
}
return
data
},
}
if
(
uniForm
)
{
uniForm
.
addField
(
formField
)
onBeforeUnmount
(()
=>
{
uniForm
.
removeField
(
formField
)
})
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录