Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
642b8fd5
U
uni-app
项目概览
qianlong66
/
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,发现更多精彩内容 >>
提交
642b8fd5
编写于
5月 12, 2021
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: picker-view state
上级
ca7ba3b5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
73 addition
and
97 deletion
+73
-97
packages/uni-components/src/components/picker-view-column/index.tsx
...ni-components/src/components/picker-view-column/index.tsx
+12
-12
packages/uni-components/src/components/picker-view/index.tsx
packages/uni-components/src/components/picker-view/index.tsx
+9
-17
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+26
-34
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+26
-34
未找到文件。
packages/uni-components/src/components/picker-view-column/index.tsx
浏览文件 @
642b8fd5
...
@@ -22,8 +22,8 @@ import { flatVNode } from '../../helpers/flatVNode'
...
@@ -22,8 +22,8 @@ import { flatVNode } from '../../helpers/flatVNode'
import
ResizeSensor
from
'
../resize-sensor/index
'
import
ResizeSensor
from
'
../resize-sensor/index
'
import
{
import
{
GetPickerViewColumn
,
GetPickerViewColumn
,
Get
PickerViewProps
,
Props
as
PickerViewProps
,
Get
PickerViewState
,
State
as
PickerViewState
,
}
from
'
../picker-view
'
}
from
'
../picker-view
'
let
scopedIndex
=
0
let
scopedIndex
=
0
...
@@ -100,15 +100,8 @@ export default /*#__PURE__*/ defineComponent({
...
@@ -100,15 +100,8 @@ export default /*#__PURE__*/ defineComponent({
?
getPickerViewColumn
(
instance
)
?
getPickerViewColumn
(
instance
)
:
ref
(
0
)
:
ref
(
0
)
const
getPickerViewProps
:
GetPickerViewProps
=
inject
(
const
pickerViewProps
=
inject
(
'
pickerViewProps
'
)
as
PickerViewProps
'
getPickerViewProps
'
const
pickerViewState
=
inject
(
'
pickerViewState
'
)
as
PickerViewState
)
as
GetPickerViewProps
const
pickerViewProps
=
getPickerViewProps
()
const
getPickerViewState
:
GetPickerViewState
=
inject
(
'
getPickerViewState
'
)
as
GetPickerViewState
const
pickerViewState
=
getPickerViewState
()
const
indicatorHeight
=
ref
(
34
)
const
indicatorHeight
=
ref
(
34
)
const
maskSize
=
computed
(
const
maskSize
=
computed
(
()
=>
(
pickerViewState
.
height
-
indicatorHeight
.
value
)
/
2
()
=>
(
pickerViewState
.
height
-
indicatorHeight
.
value
)
/
2
...
@@ -149,7 +142,14 @@ export default /*#__PURE__*/ defineComponent({
...
@@ -149,7 +142,14 @@ export default /*#__PURE__*/ defineComponent({
()
=>
state
.
current
,
()
=>
state
.
current
,
(
current
)
=>
(
currentRef
.
value
=
current
)
(
current
)
=>
(
currentRef
.
value
=
current
)
)
)
watch
([()
=>
indicatorHeight
.
value
,
()
=>
state
.
length
],
updatesScroller
)
watch
(
[
()
=>
indicatorHeight
.
value
,
()
=>
state
.
length
,
()
=>
pickerViewState
.
height
,
],
updatesScroller
)
let
oldDeltaY
=
0
let
oldDeltaY
=
0
function
handleWheel
(
event
:
Event
)
{
function
handleWheel
(
event
:
Event
)
{
...
...
packages/uni-components/src/components/picker-view/index.tsx
浏览文件 @
642b8fd5
...
@@ -12,6 +12,7 @@ import {
...
@@ -12,6 +12,7 @@ import {
PropType
,
PropType
,
ComponentInternalInstance
,
ComponentInternalInstance
,
}
from
'
vue
'
}
from
'
vue
'
import
{
flatVNode
}
from
'
../../helpers/flatVNode
'
import
ResizeSensor
from
'
../resize-sensor/index
'
import
ResizeSensor
from
'
../resize-sensor/index
'
import
{
useCustomEvent
}
from
'
../../helpers/useEvent
'
import
{
useCustomEvent
}
from
'
../../helpers/useEvent
'
...
@@ -46,17 +47,17 @@ const props = {
...
@@ -46,17 +47,17 @@ const props = {
},
},
}
}
type
Props
=
Record
<
keyof
typeof
props
,
any
>
export
type
Props
=
Record
<
keyof
typeof
props
,
any
>
interface
State
{
export
interface
State
{
value
:
number
[]
value
:
number
[]
height
:
number
height
:
number
}
}
function
useState
(
props
:
Props
):
State
{
function
useState
(
props
:
Props
):
State
{
const
value
:
number
[]
=
reactive
([...
props
.
value
])
const
value
:
number
[]
=
reactive
([...
props
.
value
])
const
state
=
{
const
state
=
reactive
(
{
value
,
value
,
height
:
34
,
height
:
34
,
}
}
)
watch
(
watch
(
()
=>
props
.
value
,
()
=>
props
.
value
,
(
val
:
number
[],
oldVal
:
number
[])
=>
{
(
val
:
number
[],
oldVal
:
number
[])
=>
{
...
@@ -81,8 +82,6 @@ function useState(props: Props): State {
...
@@ -81,8 +82,6 @@ function useState(props: Props): State {
export
type
GetPickerViewColumn
=
(
export
type
GetPickerViewColumn
=
(
columnInstance
:
ComponentInternalInstance
columnInstance
:
ComponentInternalInstance
)
=>
ComputedRef
<
number
>
)
=>
ComputedRef
<
number
>
export
type
GetPickerViewProps
=
()
=>
Props
export
type
GetPickerViewState
=
()
=>
State
export
default
/*#__PURE__*/
defineComponent
({
export
default
/*#__PURE__*/
defineComponent
({
name
:
'
PickerView
'
,
name
:
'
PickerView
'
,
...
@@ -119,20 +118,13 @@ export default /*#__PURE__*/ defineComponent({
...
@@ -119,20 +118,13 @@ export default /*#__PURE__*/ defineComponent({
return
ref
return
ref
}
}
provide
(
'
getPickerViewColumn
'
,
getPickerViewColumn
)
provide
(
'
getPickerViewColumn
'
,
getPickerViewColumn
)
const
getPickerViewProps
:
GetPickerViewProps
=
()
=>
{
provide
(
'
pickerViewProps
'
,
props
)
return
props
provide
(
'
pickerViewState
'
,
state
)
}
provide
(
'
getPickerViewProps
'
,
getPickerViewProps
)
const
getPickerViewState
:
GetPickerViewState
=
()
=>
{
return
state
}
provide
(
'
getPickerViewState
'
,
getPickerViewState
)
return
()
=>
{
return
()
=>
{
const
defaultSlots
=
slots
.
default
&&
slots
.
default
()
const
defaultSlots
=
slots
.
default
&&
slots
.
default
()
// TODO filter
// TODO filter
columnVNodes
=
columnVNodes
=
defaultSlots
||
[]
columnVNodes
=
flatVNode
(
defaultSlots
)
return
(
return
(
<
uni
-
picker
-
view
ref
=
{
rootRef
}
>
<
uni
-
picker
-
view
ref
=
{
rootRef
}
>
<
ResizeSensor
<
ResizeSensor
...
@@ -141,7 +133,7 @@ export default /*#__PURE__*/ defineComponent({
...
@@ -141,7 +133,7 @@ export default /*#__PURE__*/ defineComponent({
(
state
.
height
=
height
)
(
state
.
height
=
height
)
}
}
></
ResizeSensor
>
></
ResizeSensor
>
<
div
class
=
"uni-picker-view-wrapper"
>
{
columnVNode
s
}
</
div
>
<
div
class
=
"uni-picker-view-wrapper"
>
{
defaultSlot
s
}
</
div
>
</
uni
-
picker
-
view
>
</
uni
-
picker
-
view
>
)
)
}
}
...
...
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
642b8fd5
...
@@ -4329,6 +4329,23 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
...
@@ -4329,6 +4329,23 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
]));
]));
}
}
_sfc_main$5
.
render
=
_sfc_render$5
;
_sfc_main$5
.
render
=
_sfc_render$5
;
function
flatVNode
(
nodes
)
{
const
array
=
[];
if
(
Array
.
isArray
(
nodes
))
{
nodes
.
forEach
((
vnode
)
=>
{
if
(
vue
.
isVNode
(
vnode
))
{
if
(
vnode
.
type
===
vue
.
Fragment
)
{
array
.
push
(...
flatVNode
(
vnode
.
children
));
}
else
{
array
.
push
(
vnode
);
}
}
else
if
(
Array
.
isArray
(
vnode
))
{
array
.
push
(...
flatVNode
(
vnode
));
}
});
}
return
array
;
}
const
props$f
=
{
const
props$f
=
{
value
:
{
value
:
{
type
:
Array
,
type
:
Array
,
...
@@ -4358,10 +4375,10 @@ const props$f = {
...
@@ -4358,10 +4375,10 @@ const props$f = {
};
};
function
useState$1
(
props2
)
{
function
useState$1
(
props2
)
{
const
value
=
vue
.
reactive
([...
props2
.
value
]);
const
value
=
vue
.
reactive
([...
props2
.
value
]);
const
state
=
{
const
state
=
vue
.
reactive
(
{
value
,
value
,
height
:
34
height
:
34
};
}
)
;
vue
.
watch
(()
=>
props2
.
value
,
(
val
,
oldVal
)
=>
{
vue
.
watch
(()
=>
props2
.
value
,
(
val
,
oldVal
)
=>
{
{
{
state
.
value
.
length
=
val
.
length
;
state
.
value
.
length
=
val
.
length
;
...
@@ -4411,17 +4428,11 @@ var index$h = /* @__PURE__ */ vue.defineComponent({
...
@@ -4411,17 +4428,11 @@ var index$h = /* @__PURE__ */ vue.defineComponent({
return
ref
;
return
ref
;
};
};
vue
.
provide
(
"
getPickerViewColumn
"
,
getPickerViewColumn
);
vue
.
provide
(
"
getPickerViewColumn
"
,
getPickerViewColumn
);
const
getPickerViewProps
=
()
=>
{
vue
.
provide
(
"
pickerViewProps
"
,
props2
);
return
props2
;
vue
.
provide
(
"
pickerViewState
"
,
state
);
};
vue
.
provide
(
"
getPickerViewProps
"
,
getPickerViewProps
);
const
getPickerViewState
=
()
=>
{
return
state
;
};
vue
.
provide
(
"
getPickerViewState
"
,
getPickerViewState
);
return
()
=>
{
return
()
=>
{
const
defaultSlots
=
slots
.
default
&&
slots
.
default
();
const
defaultSlots
=
slots
.
default
&&
slots
.
default
();
columnVNodes
=
columnVNodes
=
defaultSlots
||
[]
;
columnVNodes
=
flatVNode
(
defaultSlots
)
;
return
vue
.
createVNode
(
"
uni-picker-view
"
,
{
return
vue
.
createVNode
(
"
uni-picker-view
"
,
{
"
ref
"
:
rootRef
"
ref
"
:
rootRef
},
[
vue
.
createVNode
(
ResizeSensor
,
{
},
[
vue
.
createVNode
(
ResizeSensor
,
{
...
@@ -4431,27 +4442,10 @@ var index$h = /* @__PURE__ */ vue.defineComponent({
...
@@ -4431,27 +4442,10 @@ var index$h = /* @__PURE__ */ vue.defineComponent({
})
=>
state
.
height
=
height
})
=>
state
.
height
=
height
},
null
,
8
,
[
"
initial
"
,
"
onResize
"
]),
vue
.
createVNode
(
"
div
"
,
{
},
null
,
8
,
[
"
initial
"
,
"
onResize
"
]),
vue
.
createVNode
(
"
div
"
,
{
"
class
"
:
"
uni-picker-view-wrapper
"
"
class
"
:
"
uni-picker-view-wrapper
"
},
[
columnVNode
s
])],
512
);
},
[
defaultSlot
s
])],
512
);
};
};
}
}
});
});
function
flatVNode
(
nodes
)
{
const
array
=
[];
if
(
Array
.
isArray
(
nodes
))
{
nodes
.
forEach
((
vnode
)
=>
{
if
(
vue
.
isVNode
(
vnode
))
{
if
(
vnode
.
type
===
vue
.
Fragment
)
{
array
.
push
(...
flatVNode
(
vnode
.
children
));
}
else
{
array
.
push
(
vnode
);
}
}
else
if
(
Array
.
isArray
(
vnode
))
{
array
.
push
(...
flatVNode
(
vnode
));
}
});
}
return
array
;
}
let
scopedIndex
=
0
;
let
scopedIndex
=
0
;
function
useScopedClass
(
indicatorHeightRef
)
{
function
useScopedClass
(
indicatorHeightRef
)
{
const
className
=
`uni-picker-view-content-
${
scopedIndex
++
}
`
;
const
className
=
`uni-picker-view-content-
${
scopedIndex
++
}
`
;
...
@@ -4474,10 +4468,8 @@ var index$g = /* @__PURE__ */ vue.defineComponent({
...
@@ -4474,10 +4468,8 @@ var index$g = /* @__PURE__ */ vue.defineComponent({
const
getPickerViewColumn
=
vue
.
inject
(
"
getPickerViewColumn
"
);
const
getPickerViewColumn
=
vue
.
inject
(
"
getPickerViewColumn
"
);
const
instance
=
vue
.
getCurrentInstance
();
const
instance
=
vue
.
getCurrentInstance
();
const
currentRef
=
getPickerViewColumn
?
getPickerViewColumn
(
instance
)
:
vue
.
ref
(
0
);
const
currentRef
=
getPickerViewColumn
?
getPickerViewColumn
(
instance
)
:
vue
.
ref
(
0
);
const
getPickerViewProps
=
vue
.
inject
(
"
getPickerViewProps
"
);
const
pickerViewProps
=
vue
.
inject
(
"
pickerViewProps
"
);
const
pickerViewProps
=
getPickerViewProps
();
const
pickerViewState
=
vue
.
inject
(
"
pickerViewState
"
);
const
getPickerViewState
=
vue
.
inject
(
"
getPickerViewState
"
);
const
pickerViewState
=
getPickerViewState
();
const
indicatorHeight
=
vue
.
ref
(
34
);
const
indicatorHeight
=
vue
.
ref
(
34
);
const
maskSize
=
vue
.
computed
(()
=>
(
pickerViewState
.
height
-
indicatorHeight
.
value
)
/
2
);
const
maskSize
=
vue
.
computed
(()
=>
(
pickerViewState
.
height
-
indicatorHeight
.
value
)
/
2
);
const
{
const
{
...
@@ -4497,7 +4489,7 @@ var index$g = /* @__PURE__ */ vue.defineComponent({
...
@@ -4497,7 +4489,7 @@ var index$g = /* @__PURE__ */ vue.defineComponent({
}
}
});
});
vue
.
watch
(()
=>
state
.
current
,
(
current
)
=>
currentRef
.
value
=
current
);
vue
.
watch
(()
=>
state
.
current
,
(
current
)
=>
currentRef
.
value
=
current
);
vue
.
watch
([()
=>
indicatorHeight
.
value
,
()
=>
state
.
length
],
updatesScroller
);
vue
.
watch
([()
=>
indicatorHeight
.
value
,
()
=>
state
.
length
,
()
=>
pickerViewState
.
height
],
updatesScroller
);
let
oldDeltaY
=
0
;
let
oldDeltaY
=
0
;
function
handleWheel
(
event
)
{
function
handleWheel
(
event
)
{
const
deltaY
=
oldDeltaY
+
event
.
deltaY
;
const
deltaY
=
oldDeltaY
+
event
.
deltaY
;
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
642b8fd5
...
@@ -9104,6 +9104,23 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
...
@@ -9104,6 +9104,23 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
]));
]));
}
}
_sfc_main$5.render = _sfc_render$5;
_sfc_main$5.render = _sfc_render$5;
function flatVNode(nodes) {
const array = [];
if (Array.isArray(nodes)) {
nodes.forEach((vnode) => {
if (isVNode(vnode)) {
if (vnode.type === Fragment) {
array.push(...flatVNode(vnode.children));
} else {
array.push(vnode);
}
} else if (Array.isArray(vnode)) {
array.push(...flatVNode(vnode));
}
});
}
return array;
}
const props$j = {
const props$j = {
value: {
value: {
type: Array,
type: Array,
...
@@ -9133,10 +9150,10 @@ const props$j = {
...
@@ -9133,10 +9150,10 @@ const props$j = {
};
};
function useState$1(props2) {
function useState$1(props2) {
const value = reactive([...props2.value]);
const value = reactive([...props2.value]);
const state2 = {
const state2 =
reactive(
{
value,
value,
height: 34
height: 34
};
}
)
;
watch(() => props2.value, (val, oldVal) => {
watch(() => props2.value, (val, oldVal) => {
{
{
state2.value.length = val.length;
state2.value.length = val.length;
...
@@ -9186,17 +9203,11 @@ var index$f = /* @__PURE__ */ defineComponent({
...
@@ -9186,17 +9203,11 @@ var index$f = /* @__PURE__ */ defineComponent({
return ref2;
return ref2;
};
};
provide("getPickerViewColumn", getPickerViewColumn);
provide("getPickerViewColumn", getPickerViewColumn);
const getPickerViewProps = () => {
provide("pickerViewProps", props2);
return props2;
provide("pickerViewState", state2);
};
provide("getPickerViewProps", getPickerViewProps);
const getPickerViewState = () => {
return state2;
};
provide("getPickerViewState", getPickerViewState);
return () => {
return () => {
const defaultSlots = slots.default && slots.default();
const defaultSlots = slots.default && slots.default();
columnVNodes =
columnVNodes = defaultSlots || []
;
columnVNodes =
flatVNode(defaultSlots)
;
return createVNode("uni-picker-view", {
return createVNode("uni-picker-view", {
"ref": rootRef
"ref": rootRef
}, [createVNode(ResizeSensor, {
}, [createVNode(ResizeSensor, {
...
@@ -9206,7 +9217,7 @@ var index$f = /* @__PURE__ */ defineComponent({
...
@@ -9206,7 +9217,7 @@ var index$f = /* @__PURE__ */ defineComponent({
}) => state2.height = height
}) => state2.height = height
}, null, 8, ["initial", "onResize"]), createVNode("div", {
}, null, 8, ["initial", "onResize"]), createVNode("div", {
"class": "uni-picker-view-wrapper"
"class": "uni-picker-view-wrapper"
}, [
columnVNode
s])], 512);
}, [
defaultSlot
s])], 512);
};
};
}
}
});
});
...
@@ -9890,23 +9901,6 @@ function useScroller(element, options) {
...
@@ -9890,23 +9901,6 @@ function useScroller(element, options) {
handleTouchEnd
handleTouchEnd
};
};
}
}
function flatVNode(nodes) {
const array = [];
if (Array.isArray(nodes)) {
nodes.forEach((vnode) => {
if (isVNode(vnode)) {
if (vnode.type === Fragment) {
array.push(...flatVNode(vnode.children));
} else {
array.push(vnode);
}
} else if (Array.isArray(vnode)) {
array.push(...flatVNode(vnode));
}
});
}
return array;
}
let scopedIndex = 0;
let scopedIndex = 0;
function useScopedClass(indicatorHeightRef) {
function useScopedClass(indicatorHeightRef) {
const className = `uni-picker-view-content-${scopedIndex++}`;
const className = `uni-picker-view-content-${scopedIndex++}`;
...
@@ -9956,10 +9950,8 @@ var index$e = /* @__PURE__ */ defineComponent({
...
@@ -9956,10 +9950,8 @@ var index$e = /* @__PURE__ */ defineComponent({
const getPickerViewColumn = inject("getPickerViewColumn");
const getPickerViewColumn = inject("getPickerViewColumn");
const instance2 = getCurrentInstance();
const instance2 = getCurrentInstance();
const currentRef = getPickerViewColumn ? getPickerViewColumn(instance2) : ref(0);
const currentRef = getPickerViewColumn ? getPickerViewColumn(instance2) : ref(0);
const getPickerViewProps = inject("getPickerViewProps");
const pickerViewProps = inject("pickerViewProps");
const pickerViewProps = getPickerViewProps();
const pickerViewState = inject("pickerViewState");
const getPickerViewState = inject("getPickerViewState");
const pickerViewState = getPickerViewState();
const indicatorHeight = ref(34);
const indicatorHeight = ref(34);
const maskSize = computed(() => (pickerViewState.height - indicatorHeight.value) / 2);
const maskSize = computed(() => (pickerViewState.height - indicatorHeight.value) / 2);
const {
const {
...
@@ -9987,7 +9979,7 @@ var index$e = /* @__PURE__ */ defineComponent({
...
@@ -9987,7 +9979,7 @@ var index$e = /* @__PURE__ */ defineComponent({
}
}
});
});
watch(() => state2.current, (current) => currentRef.value = current);
watch(() => state2.current, (current) => currentRef.value = current);
watch([() => indicatorHeight.value, () => state2.length], updatesScroller);
watch([() => indicatorHeight.value, () => state2.length
, () => pickerViewState.height
], updatesScroller);
let oldDeltaY = 0;
let oldDeltaY = 0;
function handleWheel(event) {
function handleWheel(event) {
const deltaY = oldDeltaY + event.deltaY;
const deltaY = oldDeltaY + event.deltaY;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录