1e41f4b71Sopenharmony_ci# picker-view
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci嵌入页面的滑动选择器。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 该组件从从API version 4 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## 子组件
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci不支持。
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## 属性
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci| 名称 | 类型 | 默认值 | 必填 | 描述 |
18e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
19e41f4b71Sopenharmony_ci| type | string | text | 否 | 设置滑动选择器的类型,该属性不支持动态修改,可选项有:<br/>-&nbsp;text:文本选择器。<br/>-&nbsp;time:时间选择器。 |
20e41f4b71Sopenharmony_ci| id | string | - | 否 | 组件的唯一标识。 |
21e41f4b71Sopenharmony_ci| style | string | - | 否 | 组件的样式声明。 |
22e41f4b71Sopenharmony_ci| class | string | - | 否 | 组件的样式类,用于引用样式表。 |
23e41f4b71Sopenharmony_ci| ref | string | - | 否 | 用来指定指向子元素的引用信息,该引用将注册到父组件的$refs&nbsp;属性对象上。 |
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci文本选择器:type=text
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci| 名称 | 类型 | 默认值 | 必填 | 描述 |
28e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
29e41f4b71Sopenharmony_ci| range | Array | - | 否 | 设置文本选择器的取值范围。<br/>使用时需要使用数据绑定的方式,如range&nbsp;=&nbsp;{{data}},js中声明相应变量:data:["15",&nbsp;"20",&nbsp;"25"]。 |
30e41f4b71Sopenharmony_ci| selected | string | 0 | 否 | 设置文本选择器的默认选择值,该值需要为range的索引。 |
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci时间选择器:type=time
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci| 名称 | 类型 | 默认值 | 必填 | 描述 |
35e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
36e41f4b71Sopenharmony_ci| selected | string | 00:00 | 否 | 设置时间选择器的默认取值,格式为&nbsp;HH:mm;<br/> |
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci## 事件
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_citype=text:
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci| 名称 | 参数 | 描述 |
44e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
45e41f4b71Sopenharmony_ci| change | {&nbsp;newValue:&nbsp;newValue,&nbsp;newSelected:&nbsp;newSelected&nbsp;} | 文本选择器选定值后触发该事件。 |
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_citype=time:
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci| 名称 | 参数 | 描述 |
50e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
51e41f4b71Sopenharmony_ci| change | {&nbsp;hour:&nbsp;hour,&nbsp;minute:&nbsp;minute} | 时间选择器选定值后触发该事件。<br/> |
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci## 样式
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci| 名称 | 类型 | 默认值 | 必填 | 描述 |
57e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
58e41f4b71Sopenharmony_ci| color | &lt;color&gt; | \#808080<br/> | 否 | 候选项字体颜色。 |
59e41f4b71Sopenharmony_ci| font-size | &lt;length&gt; | 30px<br/> | 否 | 候选项字体尺寸,类型length,单位px。 |
60e41f4b71Sopenharmony_ci| selected-color | &lt;color&gt; | \#ffffff<br/> | 否 | 选中项字体颜色。 |
61e41f4b71Sopenharmony_ci| selected-font-size | &lt;length&gt; | 38px<br/> | 否 | 选中项字体尺寸,类型length,单位px。 |
62e41f4b71Sopenharmony_ci| selected-font-family | string | HYQiHei-65S | 否 | 选中项字体类型。 |
63e41f4b71Sopenharmony_ci| font-family | string | <br/>HYQiHei-65S | 否 | 选项字体类型。 |
64e41f4b71Sopenharmony_ci| width | &lt;length&gt;&nbsp;\|&nbsp;&lt;percentage&gt;<sup>5+</sup> | - | 否 | 设置组件自身的宽度。<br/><br/>未设置时组件宽度默认为0。 |
65e41f4b71Sopenharmony_ci| height | &lt;length&gt;&nbsp;\|&nbsp;&lt;percentage&gt;<sup>5+</sup> | - | 否 | 设置组件自身的高度。<br/><br/>未设置时组件高度默认为0。 |
66e41f4b71Sopenharmony_ci| padding | &lt;length&gt; | 0 | 否 | 使用简写属性设置所有的内边距属性。<br/>&nbsp;&nbsp;该属性可以有1到4个值:<br/>-&nbsp;指定一个值时,该值指定四个边的内边距。<br/>-&nbsp;指定两个值时,第一个值指定上下两边的内边距,第二个指定左右两边的内边距。<br/>-&nbsp;指定三个值时,第一个指定上边的内边距,第二个指定左右两边的内边距,第三个指定下边的内边距。<br/>-&nbsp;指定四个值时分别为上、右、下、左边的内边距(顺时针顺序)。 |
67e41f4b71Sopenharmony_ci| padding-[left\|top\|right\|bottom] | &lt;length&gt; | 0 | 否 | 设置左、上、右、下内边距属性。 |
68e41f4b71Sopenharmony_ci| margin | &lt;length&gt;&nbsp;\|&nbsp;&lt;percentage&gt;<sup>5+</sup> | 0 | 否 | 使用简写属性设置所有的外边距属性,该属性可以有1到4个值。<br/>-&nbsp;只有一个值时,这个值会被指定给全部的四个边。<br/>-&nbsp;两个值时,第一个值被匹配给上和下,第二个值被匹配给左和右。<br/>-&nbsp;三个值时,第一个值被匹配给上,&nbsp;第二个值被匹配给左和右,第三个值被匹配给下。<br/>-&nbsp;四个值时,会依次按上、右、下、左的顺序匹配&nbsp;(即顺时针顺序)。 |
69e41f4b71Sopenharmony_ci| margin-[left\|top\|right\|bottom] | &lt;length&gt;&nbsp;\|&nbsp;&lt;percentage&gt;<sup>5+</sup> | 0 | 否 | 设置左、上、右、下外边距属性。 |
70e41f4b71Sopenharmony_ci| border-width | &lt;length&gt; | 0 | 否 | 使用简写属性设置元素的所有边框宽度。 |
71e41f4b71Sopenharmony_ci| border-color | &lt;color&gt; | black | 否 | 使用简写属性设置元素的所有边框颜色。 |
72e41f4b71Sopenharmony_ci| border-radius | &lt;length&gt; | - | 否 | border-radius属性是设置元素的外边框圆角半径。 |
73e41f4b71Sopenharmony_ci| background-color | &lt;color&gt; | - | 否 | 设置背景颜色。 |
74e41f4b71Sopenharmony_ci| display | string | flex | 否 | 确定一个元素所产生的框的类型,可选值为:<br/>-&nbsp;flex:弹性布局。<br/>-&nbsp;none:不渲染此元素。 |
75e41f4b71Sopenharmony_ci| [left\|top] | &lt;length&gt;&nbsp;\|&nbsp;&lt;percentage&gt;<sup>6+</sup> | - | 否 | left\|top确定元素的偏移位置。<br/>-&nbsp;left属性规定元素的左边缘。该属性定义了定位元素左外边距边界与其包含块左边界之间的偏移。<br/>-&nbsp;top属性规定元素的顶部边缘。该属性定义了一个定位元素的上外边距边界与其包含块上边界之间的偏移。 |
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci## 示例
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci```html
82e41f4b71Sopenharmony_ci<!-- xxx.hml -->
83e41f4b71Sopenharmony_ci<div class="container" @swipe="handleSwipe">
84e41f4b71Sopenharmony_ci  <text class="title">
85e41f4b71Sopenharmony_ci    Selected:{{time}}
86e41f4b71Sopenharmony_ci  </text>
87e41f4b71Sopenharmony_ci  <picker-view class="time-picker" type="time" selected="{{defaultTime}}" @change="handleChange"></picker-view>
88e41f4b71Sopenharmony_ci</div>
89e41f4b71Sopenharmony_ci```
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci```css
93e41f4b71Sopenharmony_ci/* xxx.css */
94e41f4b71Sopenharmony_ci.container {
95e41f4b71Sopenharmony_ci  flex-direction: column;
96e41f4b71Sopenharmony_ci  justify-content: center;
97e41f4b71Sopenharmony_ci  align-items: center;
98e41f4b71Sopenharmony_ci  left: 0px;
99e41f4b71Sopenharmony_ci  top: 0px;
100e41f4b71Sopenharmony_ci  width: 454px;
101e41f4b71Sopenharmony_ci  height: 454px;
102e41f4b71Sopenharmony_ci}
103e41f4b71Sopenharmony_ci.title {
104e41f4b71Sopenharmony_ci  font-size: 30px;
105e41f4b71Sopenharmony_ci  text-align: center;
106e41f4b71Sopenharmony_ci}
107e41f4b71Sopenharmony_ci.time-picker {
108e41f4b71Sopenharmony_ci  width: 500px;
109e41f4b71Sopenharmony_ci  height: 400px;
110e41f4b71Sopenharmony_ci  margin-top: 20px;
111e41f4b71Sopenharmony_ci}
112e41f4b71Sopenharmony_ci```
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci```js
116e41f4b71Sopenharmony_ci/* xxx.js */
117e41f4b71Sopenharmony_ciexport default {
118e41f4b71Sopenharmony_ci  data: {
119e41f4b71Sopenharmony_ci    defaultTime: "",
120e41f4b71Sopenharmony_ci    time: "",
121e41f4b71Sopenharmony_ci  },
122e41f4b71Sopenharmony_ci  onInit() {
123e41f4b71Sopenharmony_ci    this.defaultTime = this.now();
124e41f4b71Sopenharmony_ci  },
125e41f4b71Sopenharmony_ci  handleChange(data) {
126e41f4b71Sopenharmony_ci    this.time = this.concat(data.hour, data.minute);
127e41f4b71Sopenharmony_ci  },
128e41f4b71Sopenharmony_ci  now() {
129e41f4b71Sopenharmony_ci    const date = new Date();
130e41f4b71Sopenharmony_ci    const hours = date.getHours();
131e41f4b71Sopenharmony_ci    const minutes = date.getMinutes();
132e41f4b71Sopenharmony_ci    return this.concat(hours, minutes);
133e41f4b71Sopenharmony_ci  },
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci  fill(value) {
136e41f4b71Sopenharmony_ci    return (value > 9 ? "" : "0") + value;
137e41f4b71Sopenharmony_ci  },
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci  concat(hours, minutes) {
140e41f4b71Sopenharmony_ci    return `${this.fill(hours)}:${this.fill(minutes)}`;
141e41f4b71Sopenharmony_ci  },
142e41f4b71Sopenharmony_ci}
143e41f4b71Sopenharmony_ci```
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci![picker-view](figures/picker-view-lite.png)