@tuya-miniapp/smart-ui 2.6.4-beta-8 → 2.6.4-beta-9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,4 +22,3 @@ export declare function replacePlaceholders(template: any, values: any): any;
22
22
  export declare const getSafeAreaInsetMin: () => number;
23
23
  export declare function getSafeBottomOffset(): number;
24
24
  export declare const getDateString: (date: Date) => string | undefined;
25
- export declare function generateRangeArray(start: number, end: number): number[];
@@ -111,10 +111,3 @@ export const getDateString = (date) => {
111
111
  const formattedDate = `${year}/${month}/${day}`;
112
112
  return formattedDate;
113
113
  };
114
- export function generateRangeArray(start, end) {
115
- const resultArray = [];
116
- for (let i = start; i < end; i++) {
117
- resultArray.push(i);
118
- }
119
- return resultArray;
120
- }
@@ -199,7 +199,8 @@ SmartComponent({
199
199
  unit: locale === null || locale === void 0 ? void 0 : locale[column.type],
200
200
  style: columnStyles === null || columnStyles === void 0 ? void 0 : columnStyles[column.type],
201
201
  fontStyle: fontStyles === null || fontStyles === void 0 ? void 0 : fontStyles[column.type],
202
- activeIndex,
202
+ activeIndex: activeIndex === -1 ? 0 : activeIndex,
203
+ loop: !['12HourClock', 'year'].includes(column.type),
203
204
  };
204
205
  });
205
206
  return this.setData({ columns: results });
@@ -393,7 +394,6 @@ SmartComponent({
393
394
  }
394
395
  else {
395
396
  const originColumns = this.getOriginColumns();
396
- const indexes = picker.getIndexes();
397
397
  const values = indexes.map((value, index) => originColumns[index].values[value]);
398
398
  const year = getTrueValue(values[0]);
399
399
  const month = getTrueValue(values[1]);
@@ -36,7 +36,7 @@ SmartComponent({
36
36
  },
37
37
  showLoading: {
38
38
  type: Boolean,
39
- value: true,
39
+ value: false,
40
40
  },
41
41
  tintColor: {
42
42
  type: String,
@@ -1 +1 @@
1
- @import '../common/index.css';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-dialog-background:#fff;--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-dialog-background:#333;--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0))}.smart-picker{-webkit-text-size-adjust:100%;background-color:var(--picker-background-color,var(--app-B4,#fff));overflow:hidden;position:relative;-webkit-user-select:none;user-select:none}.smart-picker__toolbar{display:flex;height:var(--picker-toolbar-height,44px);justify-content:space-between;line-height:var(--picker-toolbar-height,44px)}.smart-picker__cancel,.smart-picker__confirm{font-size:var(--picker-action-font-size,14px);padding:var(--picker-action-padding,0 16px)}.smart-picker__cancel--hover,.smart-picker__confirm--hover{opacity:.7}.smart-picker__confirm{color:var(--picker-confirm-action-color,#576b95)}.smart-picker__cancel{color:var(--picker-cancel-action-color,#969799)}.smart-picker__title{font-size:var(--picker-option-font-size,16px);font-weight:var(--font-weight-bolder,700);max-width:50%;text-align:center}.smart-picker__columns{display:flex;justify-content:center;-webkit-mask-image:linear-gradient(0deg,transparent,#000 50%,transparent);mask-image:linear-gradient(0deg,transparent,#000 50%,transparent);-webkit-mask-position:top,bottom;mask-position:top,bottom;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;overflow:hidden;padding:0 var(--picker-padding,16px);position:relative}.smart-picker__column{flex:1 1;width:0}.smart-picker__loading{align-items:center;background-color:var(--picker-loading-mask-color,var(--app-B4,#fff));bottom:0;display:flex;justify-content:center;left:0;opacity:.9;position:absolute;right:0;top:0;z-index:4}.smart-picker__frame{left:var(--picker-padding,16px);pointer-events:none;position:absolute;right:var(--picker-padding,16px);top:50%;transform:translateY(-50%);z-index:1}
1
+ @import '../common/index.css';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-dialog-background:#fff;--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-dialog-background:#333;--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0))}.smart-picker{-webkit-text-size-adjust:100%;background-color:var(--picker-background-color,var(--app-B4,#fff));overflow:hidden;position:relative;-webkit-user-select:none;user-select:none}.smart-picker__toolbar{display:flex;height:var(--picker-toolbar-height,44px);justify-content:space-between;line-height:var(--picker-toolbar-height,44px)}.smart-picker__cancel,.smart-picker__confirm{font-size:var(--picker-action-font-size,14px);padding:var(--picker-action-padding,0 16px)}.smart-picker__cancel--hover,.smart-picker__confirm--hover{opacity:.7}.smart-picker__confirm{color:var(--picker-confirm-action-color,#576b95)}.smart-picker__cancel{color:var(--picker-cancel-action-color,#969799)}.smart-picker__title{font-size:var(--picker-option-font-size,16px);font-weight:var(--font-weight-bolder,700);max-width:50%;text-align:center}.smart-picker__columns{align-items:center;display:flex;justify-content:center;-webkit-mask-image:linear-gradient(0deg,transparent,#000 50%,transparent);mask-image:linear-gradient(0deg,transparent,#000 50%,transparent);-webkit-mask-position:top,bottom;mask-position:top,bottom;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;overflow:hidden;padding:0 var(--picker-padding,16px);position:relative}.smart-picker__column{flex:1 1;width:0}.smart-picker__loading{align-items:center;background-color:var(--picker-loading-mask-color,var(--app-B4,#fff));bottom:0;display:flex;justify-content:center;left:0;opacity:.9;position:absolute;right:0;top:0;z-index:4}.smart-picker__frame{left:var(--picker-padding,16px);pointer-events:none;position:absolute;right:var(--picker-padding,16px);top:50%;transform:translateY(-50%);z-index:1}
@@ -8,12 +8,14 @@ SmartComponent({
8
8
  }, toolbarPosition: {
9
9
  type: String,
10
10
  value: 'top',
11
+ }, fullHeight: {
12
+ type: Boolean,
13
+ value: false,
11
14
  }, defaultIndex: {
12
15
  type: Number,
13
16
  value: 0,
14
17
  }, activeIndex: {
15
- type: Number,
16
- value: -1,
18
+ type: null,
17
19
  }, unit: {
18
20
  type: String,
19
21
  value: '',
@@ -35,6 +37,11 @@ SmartComponent({
35
37
  get: () => this.selectAllComponents('.smart-picker__column') || [],
36
38
  });
37
39
  },
40
+ mounted() {
41
+ if (![3, 5, 7, 9].includes(this.data.visibleItemCount)) {
42
+ console.error('visibleItemCount 的值必须为 3, 5, 7, 9');
43
+ }
44
+ },
38
45
  methods: {
39
46
  noop() { },
40
47
  setColumns() {
@@ -93,7 +100,7 @@ SmartComponent({
93
100
  },
94
101
  // get column option index by column index
95
102
  getColumnIndex(columnIndex) {
96
- return (this.getColumn(columnIndex) || {}).data.currentIndex;
103
+ return (this.getColumn(columnIndex) || {}).data.activeIndex;
97
104
  },
98
105
  // set column option index by column index
99
106
  setColumnIndex(columnIndex, optionIndex) {
@@ -134,7 +141,7 @@ SmartComponent({
134
141
  },
135
142
  // get indexes of all columns
136
143
  getIndexes() {
137
- return this.children.map(child => child.data.currentIndex);
144
+ return this.children.map(child => child.data.activeIndex === null ? child.data.defaultIndex : child.data.activeIndex);
138
145
  },
139
146
  // set indexes of all columns
140
147
  setIndexes(indexes) {
@@ -9,7 +9,7 @@
9
9
 
10
10
  <view
11
11
  class="smart-picker__columns"
12
- style="{{ computed.columnsStyle({ itemHeight, visibleItemCount }) }}"
12
+ style="{{ computed.columnsStyle({ itemHeight, visibleItemCount, fullHeight }) }}"
13
13
  catch:touchmove="noop"
14
14
  >
15
15
  <picker-column
@@ -22,14 +22,15 @@
22
22
  value-key="{{ valueKey }}"
23
23
  style="order: {{ item.order }}; {{ computed.style(item.style) }}"
24
24
  active-style="{{ activeStyle }}"
25
- font-style="{{computed.style(item.fontStyle)}}"
25
+ font-style="{{fontStyle ? fontStyle + ';' + computed.style(item.fontStyle): computed.style(item.fontStyle)}}"
26
26
  options="{{ item.values }}"
27
27
  disabled="{{ item.disabled || false }}"
28
28
  unit="{{ item.unit || unit }}"
29
29
  changeAnimation="{{ changeAnimation }}"
30
30
  default-index="{{ item.defaultIndex || defaultIndex }}"
31
- active-index="{{ item.activeIndex || activeIndex }}"
31
+ active-index="{{ item.activeIndex === null ? activeIndex : item.activeIndex }}"
32
32
  item-height="{{ itemHeight }}"
33
+ loop="{{ loop || item.loop || false }}"
33
34
  visible-item-count="{{ visibleItemCount }}"
34
35
  active-class="active-class"
35
36
  bind:change="onChange"
@@ -5,7 +5,7 @@ var array = require('../wxs/array.wxs');
5
5
 
6
6
  function columnsStyle(data) {
7
7
  return style({
8
- height: addUnit(data.itemHeight * data.visibleItemCount),
8
+ height: addUnit(data.itemHeight * data.visibleItemCount * (data.fullHeight ? 1 : 0.9)),
9
9
  });
10
10
  }
11
11
 
@@ -1 +1 @@
1
- @import '../common/index.wxss';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-dialog-background:#fff;--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-dialog-background:#333;--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0))}.smart-picker{-webkit-text-size-adjust:100%;background-color:var(--picker-background-color,var(--app-B4,#fff));overflow:hidden;position:relative;-webkit-user-select:none;user-select:none}.smart-picker__toolbar{display:flex;height:var(--picker-toolbar-height,44px);justify-content:space-between;line-height:var(--picker-toolbar-height,44px)}.smart-picker__cancel,.smart-picker__confirm{font-size:var(--picker-action-font-size,14px);padding:var(--picker-action-padding,0 16px)}.smart-picker__cancel--hover,.smart-picker__confirm--hover{opacity:.7}.smart-picker__confirm{color:var(--picker-confirm-action-color,#576b95)}.smart-picker__cancel{color:var(--picker-cancel-action-color,#969799)}.smart-picker__title{font-size:var(--picker-option-font-size,16px);font-weight:var(--font-weight-bolder,700);max-width:50%;text-align:center}.smart-picker__columns{display:flex;justify-content:center;-webkit-mask-image:linear-gradient(0deg,transparent,#000 50%,transparent);mask-image:linear-gradient(0deg,transparent,#000 50%,transparent);-webkit-mask-position:top,bottom;mask-position:top,bottom;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;overflow:hidden;padding:0 var(--picker-padding,16px);position:relative}.smart-picker__column{flex:1 1;width:0}.smart-picker__loading{align-items:center;background-color:var(--picker-loading-mask-color,var(--app-B4,#fff));bottom:0;display:flex;justify-content:center;left:0;opacity:.9;position:absolute;right:0;top:0;z-index:4}.smart-picker__frame{left:var(--picker-padding,16px);pointer-events:none;position:absolute;right:var(--picker-padding,16px);top:50%;transform:translateY(-50%);z-index:1}
1
+ @import '../common/index.wxss';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-dialog-background:#fff;--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-dialog-background:#333;--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0))}.smart-picker{-webkit-text-size-adjust:100%;background-color:var(--picker-background-color,var(--app-B4,#fff));overflow:hidden;position:relative;-webkit-user-select:none;user-select:none}.smart-picker__toolbar{display:flex;height:var(--picker-toolbar-height,44px);justify-content:space-between;line-height:var(--picker-toolbar-height,44px)}.smart-picker__cancel,.smart-picker__confirm{font-size:var(--picker-action-font-size,14px);padding:var(--picker-action-padding,0 16px)}.smart-picker__cancel--hover,.smart-picker__confirm--hover{opacity:.7}.smart-picker__confirm{color:var(--picker-confirm-action-color,#576b95)}.smart-picker__cancel{color:var(--picker-cancel-action-color,#969799)}.smart-picker__title{font-size:var(--picker-option-font-size,16px);font-weight:var(--font-weight-bolder,700);max-width:50%;text-align:center}.smart-picker__columns{align-items:center;display:flex;justify-content:center;-webkit-mask-image:linear-gradient(0deg,transparent,#000 50%,transparent);mask-image:linear-gradient(0deg,transparent,#000 50%,transparent);-webkit-mask-position:top,bottom;mask-position:top,bottom;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;overflow:hidden;padding:0 var(--picker-padding,16px);position:relative}.smart-picker__column{flex:1 1;width:0}.smart-picker__loading{align-items:center;background-color:var(--picker-loading-mask-color,var(--app-B4,#fff));bottom:0;display:flex;justify-content:center;left:0;opacity:.9;position:absolute;right:0;top:0;z-index:4}.smart-picker__frame{left:var(--picker-padding,16px);pointer-events:none;position:absolute;right:var(--picker-padding,16px);top:50%;transform:translateY(-50%);z-index:1}
@@ -10,6 +10,9 @@ export declare const pickerProps: {
10
10
  type: StringConstructor;
11
11
  value: string;
12
12
  };
13
+ /**
14
+ * 可见的选项个数 3 5 7 9
15
+ */
13
16
  visibleItemCount: {
14
17
  type: NumberConstructor;
15
18
  value: number;
@@ -30,4 +33,12 @@ export declare const pickerProps: {
30
33
  type: StringConstructor;
31
34
  value: string;
32
35
  };
36
+ fontStyle: {
37
+ type: StringConstructor;
38
+ value: string;
39
+ };
40
+ loop: {
41
+ type: BooleanConstructor;
42
+ value: boolean;
43
+ };
33
44
  };
@@ -10,6 +10,9 @@ export const pickerProps = {
10
10
  type: String,
11
11
  value: 'Confirm',
12
12
  },
13
+ /**
14
+ * 可见的选项个数 3 5 7 9
15
+ */
13
16
  visibleItemCount: {
14
17
  type: Number,
15
18
  value: 5,
@@ -30,4 +33,12 @@ export const pickerProps = {
30
33
  type: String,
31
34
  value: '',
32
35
  },
36
+ fontStyle: {
37
+ type: String,
38
+ value: '',
39
+ },
40
+ loop: {
41
+ type: Boolean,
42
+ value: false,
43
+ },
33
44
  };
@@ -1 +1 @@
1
- @import '../common/index.css';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-dialog-background:#fff;--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-dialog-background:#333;--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0))}.smart-picker-column{color:var(--picker-option-selected-text-color,var(--app-B6-N1,#000));font-size:var(--picker-option-font-size,16px);font-weight:var(--font-weight-bold,500);text-align:center}.smart-picker-column,.smart-picker-column__offset{position:relative;width:100%}.smart-picker-column__visual{position:absolute;top:0;width:100%}.smart-picker-column__item--selected{color:var(--picker-option-selected-text-color,var(--app-B6-N1,#000));font-weight:var(--picker-option-selected-font-weight-bold,var(--font-weight-bold,700))}.smart-picker-column__item--disabled{opacity:var(--picker-option-disabled-opacity,.3);pointer-events:none}.smart-picker-column__mask{background:transparent;display:flex;flex-direction:column;height:100%;position:absolute;top:0;width:100%;z-index:10}.smart-picker-column__mask__item{flex:1}.smart-picker-column__unit{align-items:center;display:flex;justify-content:center;position:absolute;top:50%;transform:translateY(-50%);width:100%}.smart-picker-column__unit_text{color:var(--picker-option-unit-text-color,var(--app-B6-N4,rgba(0,0,0,.4)));font-size:var(--picker-option-unit-font-size,12px);left:100%;margin-left:var(--picker-option-unit-mid-size,4px);position:absolute;text-align:left;top:50%;transform:translateY(-50%);white-space:nowrap}.smart-picker-column__max-text{color:transparent;font-size:var(--picker-option-font-size,16px);font-weight:var(--font-weight-bold,500);position:relative}.smart-picker-column--disabled{opacity:var(--picker-option-disabled-opacity,.3)}.smart-picker-column__item_0 .smart-picker-column__item__text:after{content:var(--picker-item-content_0,"")}.smart-picker-column__item_1 .smart-picker-column__item__text:after{content:var(--picker-item-content_1,"")}.smart-picker-column__item_2 .smart-picker-column__item__text:after{content:var(--picker-item-content_2,"")}.smart-picker-column__item_3 .smart-picker-column__item__text:after{content:var(--picker-item-content_3,"")}.smart-picker-column__item_4 .smart-picker-column__item__text:after{content:var(--picker-item-content_4,"")}.smart-picker-column__item_5 .smart-picker-column__item__text:after{content:var(--picker-item-content_5,"")}.smart-picker-column__item_6 .smart-picker-column__item__text:after{content:var(--picker-item-content_6,"")}.smart-picker-column__item_7 .smart-picker-column__item__text:after{content:var(--picker-item-content_7,"")}.smart-picker-column__item_8 .smart-picker-column__item__text:after{content:var(--picker-item-content_8,"")}.smart-picker-column__item_9 .smart-picker-column__item__text:after{content:var(--picker-item-content_9,"")}.smart-picker-column__item_10 .smart-picker-column__item__text:after{content:var(--picker-item-content_10,"")}.smart-picker-column__item_11 .smart-picker-column__item__text:after{content:var(--picker-item-content_11,"")}.smart-picker-column__item_12 .smart-picker-column__item__text:after{content:var(--picker-item-content_12,"")}.smart-picker-column__item_13 .smart-picker-column__item__text:after{content:var(--picker-item-content_13,"")}.smart-picker-column__item_14 .smart-picker-column__item__text:after{content:var(--picker-item-content_14,"")}.smart-picker-column__item_15 .smart-picker-column__item__text:after{content:var(--picker-item-content_15,"")}.smart-picker-column__item_16 .smart-picker-column__item__text:after{content:var(--picker-item-content_16,"")}.smart-picker-column__item_17 .smart-picker-column__item__text:after{content:var(--picker-item-content_17,"")}.smart-picker-column__item_18 .smart-picker-column__item__text:after{content:var(--picker-item-content_18,"")}.smart-picker-column__item_19 .smart-picker-column__item__text:after{content:var(--picker-item-content_19,"")}.smart-picker-column__item_20 .smart-picker-column__item__text:after{content:var(--picker-item-content_20,"")}
1
+ @import '../common/index.css';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-dialog-background:#fff;--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-dialog-background:#333;--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0))}.smart-picker-column{backface-visibility:hidden;-webkit-backface-visibility:hidden;color:var(--picker-option-selected-text-color,var(--app-B6-N1,#000));font-size:var(--picker-option-font-size,16px);font-weight:var(--font-weight-bold,500);perspective:900px;position:relative;text-align:center;transform:translateZ(0);width:100%;will-change:transform}.smart-picker-column__offset{cursor:-webkit-grab;cursor:grab;height:100%;overflow:visible;position:relative;touch-action:none;transform:rotateX(-108deg);transform-origin:center center;transform-style:preserve-3d;width:100%}.smart-picker-column__visual{position:absolute;top:0;width:100%}.smart-picker-column__item{align-items:center;backface-visibility:hidden;-webkit-backface-visibility:hidden;display:flex;justify-content:center;left:50%;position:absolute;top:50%;transform-origin:center center;width:100%}.smart-picker-column__item--selected{color:var(--picker-option-selected-text-color,var(--app-B6-N1,#000));font-weight:var(--picker-option-selected-font-weight-bold,var(--font-weight-bold,700))}.smart-picker-column__item--disabled{opacity:var(--picker-option-disabled-opacity,.3);pointer-events:none}.smart-picker-column__mask{background:transparent;display:flex;flex-direction:column;height:100%;position:absolute;top:0;width:100%;z-index:10}.smart-picker-column__mask__item{flex:1}.smart-picker-column__unit{align-items:center;display:flex;justify-content:center;position:absolute;top:50%;transform:translateY(-50%);width:100%}.smart-picker-column__unit_text{color:var(--picker-option-unit-text-color,var(--app-B6-N4,rgba(0,0,0,.4)));font-size:var(--picker-option-unit-font-size,12px);left:100%;margin-left:var(--picker-option-unit-mid-size,4px);position:absolute;text-align:left;top:50%;transform:translateY(-50%);white-space:nowrap}.smart-picker-column__max-text{color:transparent;font-size:var(--picker-option-font-size,16px);font-weight:var(--font-weight-bold,500);position:relative}.smart-picker-column--disabled{opacity:var(--picker-option-disabled-opacity,.3);pointer-events:none}.smart-picker-column__item_0:after{content:var(--picker-item-content_0,"")}.smart-picker-column__item_1:after{content:var(--picker-item-content_1,"")}.smart-picker-column__item_2:after{content:var(--picker-item-content_2,"")}.smart-picker-column__item_3:after{content:var(--picker-item-content_3,"")}.smart-picker-column__item_4:after{content:var(--picker-item-content_4,"")}.smart-picker-column__item_5:after{content:var(--picker-item-content_5,"")}.smart-picker-column__item_6:after{content:var(--picker-item-content_6,"")}.smart-picker-column__item_7:after{content:var(--picker-item-content_7,"")}.smart-picker-column__item_8:after{content:var(--picker-item-content_8,"")}.smart-picker-column__item_9:after{content:var(--picker-item-content_9,"")}.smart-picker-column__item_10:after{content:var(--picker-item-content_10,"")}.smart-picker-column__item_11:after{content:var(--picker-item-content_11,"")}.smart-picker-column__item_12:after{content:var(--picker-item-content_12,"")}.smart-picker-column__item_13:after{content:var(--picker-item-content_13,"")}.smart-picker-column__item_14:after{content:var(--picker-item-content_14,"")}.smart-picker-column__item_15:after{content:var(--picker-item-content_15,"")}.smart-picker-column__item_16:after{content:var(--picker-item-content_16,"")}.smart-picker-column__item_17:after{content:var(--picker-item-content_17,"")}.smart-picker-column__item_18:after{content:var(--picker-item-content_18,"")}.smart-picker-column__item_19:after{content:var(--picker-item-content_19,"")}.smart-picker-column__item_20:after{content:var(--picker-item-content_20,"")}.smart-picker-column__item_21:after{content:var(--picker-item-content_21,"")}.smart-picker-column__item_22:after{content:var(--picker-item-content_22,"")}.smart-picker-column__item_23:after{content:var(--picker-item-content_23,"")}.smart-picker-column__item_24:after{content:var(--picker-item-content_24,"")}.smart-picker-column__item_25:after{content:var(--picker-item-content_25,"")}.smart-picker-column__item_26:after{content:var(--picker-item-content_26,"")}.smart-picker-column__item_27:after{content:var(--picker-item-content_27,"")}.smart-picker-column__item_28:after{content:var(--picker-item-content_28,"")}.smart-picker-column__item_29:after{content:var(--picker-item-content_29,"")}.smart-picker-column__item_30:after{content:var(--picker-item-content_30,"")}.smart-picker-column__item_31:after{content:var(--picker-item-content_31,"")}.smart-picker-column__item_32:after{content:var(--picker-item-content_32,"")}.smart-picker-column__item_33:after{content:var(--picker-item-content_33,"")}.smart-picker-column__item_34:after{content:var(--picker-item-content_34,"")}
@@ -1,7 +1,8 @@
1
1
  import { SmartComponent } from '../common/component';
2
- import { generateRangeArray, range } from '../common/utils';
2
+ import { range } from '../common/utils';
3
3
  import { isObj } from '../common/validator';
4
4
  import ty from '../common/ty';
5
+ const DEFAULT_DURATION = 400;
5
6
  const compIdList = [];
6
7
  const getId = () => {
7
8
  const id = 'smart-picker-column-' + compIdList.length;
@@ -26,8 +27,8 @@ SmartComponent({
26
27
  observer(value) {
27
28
  if (!this.data.isInit)
28
29
  return;
29
- this.updateViewOptions();
30
30
  this.updateUint(value);
31
+ this.checkIndexUpdateList();
31
32
  },
32
33
  },
33
34
  defaultIndex: {
@@ -36,19 +37,18 @@ SmartComponent({
36
37
  },
37
38
  changeAnimation: {
38
39
  type: Boolean,
39
- value: true,
40
+ value: false,
40
41
  },
41
42
  fontStyle: {
42
43
  type: String,
43
44
  value: '',
44
45
  },
45
46
  activeIndex: {
46
- type: Number,
47
- value: -1,
47
+ type: null,
48
48
  observer() {
49
49
  if (!this.data.isInit)
50
50
  return;
51
- this.updateViewOptions();
51
+ this.checkIndexUpdateList();
52
52
  },
53
53
  },
54
54
  unit: {
@@ -65,85 +65,74 @@ SmartComponent({
65
65
  },
66
66
  },
67
67
  data: {
68
- startY: 0,
69
- offset: 0,
70
- duration: 0,
71
- startOffset: 0,
72
- optionsV: [],
73
- currentIndex: -1,
74
- renderNum: 0,
75
- renderStart: 0,
76
- animate: false,
77
- playing: false,
78
68
  isInit: false,
79
69
  maxText: '',
80
- instanceId: '',
81
- timer: null,
82
- preOffsetList: [],
83
- viewOptions: [],
70
+ optionsVIndexList: [],
71
+ offsetActiveIndex: 0,
72
+ endTimer: null,
73
+ offsetList: [],
74
+ moving: false,
75
+ movingDirection: 'down',
76
+ startY: 0,
77
+ offsetting: 0,
78
+ animationIndex: 0,
79
+ isDestroy: false,
84
80
  },
85
81
  created() {
86
82
  this.setData({
87
83
  instanceId: getId(),
88
84
  });
89
- this.checkIndex();
90
- this.updateViewOptions();
91
- const { options } = this.data;
92
- this.updateUint(options);
85
+ this.updateUint(this.data.options);
86
+ this.checkIndexUpdateList();
93
87
  this.setData({
94
88
  isInit: true,
95
89
  });
96
90
  },
91
+ destroyed() {
92
+ this.setData({
93
+ isDestroy: true,
94
+ });
95
+ },
97
96
  methods: {
98
- checkIndex() {
99
- const { activeIndex } = this.data;
100
- const index = this.adjustIndex(activeIndex);
101
- if (activeIndex === index)
102
- return;
97
+ checkIndexUpdateList() {
98
+ const { activeIndex, defaultIndex } = this.data;
99
+ const count = this.data.options.length;
100
+ const currIndex = activeIndex !== null ? activeIndex : defaultIndex;
101
+ let animationIndex = this.getAnimationIndex(currIndex);
102
+ animationIndex = this.adjustIndex(animationIndex);
103
+ let currActiveIndex = this.data.loop ? ((animationIndex + 1) % count) - 1 : animationIndex;
104
+ if (currActiveIndex < 0) {
105
+ currActiveIndex += count;
106
+ }
107
+ const optionsVIndexList = this.getVisibleOptions(animationIndex);
103
108
  this.setData({
104
- activeIndex: index,
109
+ activeIndex: currActiveIndex,
110
+ animationIndex: animationIndex,
111
+ optionsVIndexList: optionsVIndexList,
105
112
  });
113
+ // if (currActiveIndex !== activeIndex) {
114
+ // this.$emit('change', currActiveIndex);
115
+ // }
106
116
  },
107
- adjustIndex(index) {
108
- const { data } = this;
109
- const count = this.data.options.length;
110
- index = range(index, 0, count);
111
- for (let i = index; i < count; i++) {
112
- if (!this.isDisabled(data.options[i]))
113
- return i;
114
- }
115
- for (let i = index - 1; i >= 0; i--) {
116
- if (!this.isDisabled(data.options[i]))
117
- return i;
117
+ getAnimationIndex(activeIndex) {
118
+ const { animationIndex } = this.data;
119
+ const length = this.data.options.length || 1;
120
+ if (this.data.loop) {
121
+ const newAnimationIndex = this.getNewAnimationIndex(animationIndex, activeIndex, length, this.data.loop);
122
+ return newAnimationIndex;
118
123
  }
124
+ return activeIndex;
119
125
  },
120
- isDisabled(option) {
121
- return isObj(option) && option.disabled;
126
+ getCount() {
127
+ return this.data.options.length;
122
128
  },
123
- updateViewOptions() {
124
- const currActiveIndex = this.data.activeIndex < 0 ? 0 : this.data.activeIndex;
125
- let partNum = Math.floor(currActiveIndex / 10);
126
- const lastNum = this.data.activeIndex - partNum * 10;
127
- if (lastNum < 5 && partNum > 0) {
128
- partNum -= 1;
129
+ vibrateShort(count, time = DEFAULT_DURATION) {
130
+ if (this.data.vibrateTimer) {
131
+ clearInterval(this.data.vibrateTimer);
132
+ this.setData({
133
+ vibrateTimer: null,
134
+ });
129
135
  }
130
- const part2Times = Math.floor(partNum / 2);
131
- const part2Percent = partNum % 2;
132
- const onePartOffset = part2Percent + part2Times;
133
- const twoPartOffset = part2Times;
134
- const isReverse = onePartOffset > twoPartOffset;
135
- const startPart = twoPartOffset + onePartOffset;
136
- const viewIndexList = !isReverse
137
- ? generateRangeArray(startPart * 10, startPart * 10 + 20)
138
- : [
139
- ...generateRangeArray(startPart * 10 + 10, startPart * 10 + 20),
140
- ...generateRangeArray(startPart * 10, startPart * 10 + 10),
141
- ];
142
- this.setData({
143
- viewOptions: viewIndexList,
144
- });
145
- },
146
- vibrateShort(count, time) {
147
136
  if (!count) {
148
137
  ty.vibrateShort({ type: 'light' });
149
138
  return;
@@ -155,8 +144,11 @@ SmartComponent({
155
144
  return;
156
145
  }
157
146
  has++;
158
- this.vibrateShort();
159
- }, (time || this.data.animationTime) / count - 20);
147
+ ty.vibrateShort({ type: 'light' });
148
+ }, time / count - 20);
149
+ this.setData({
150
+ vibrateTimer: timer,
151
+ });
160
152
  },
161
153
  updateUint(options) {
162
154
  const { unit, valueKey } = this.data;
@@ -172,6 +164,115 @@ SmartComponent({
172
164
  this.setData({ maxText });
173
165
  }
174
166
  },
167
+ getVisibleOptions(currentIndex) {
168
+ let animationIndex = Math.round(currentIndex !== undefined ? currentIndex : this.data.animationIndex);
169
+ const vOptionLength = this.data.visibleItemCount * 4 - 2;
170
+ const rotateAngle = 360 / vOptionLength;
171
+ const partCount = Math.floor(this.data.visibleItemCount / 2) + 3;
172
+ const newArr = new Array(vOptionLength).fill('');
173
+ const newValueArr = new Array(partCount * 2 + 1).fill('');
174
+ if (this.data.loop) {
175
+ // 循环模式:根据 options 首尾填充 newValueArr 数组
176
+ const optionsLength = this.data.options.length;
177
+ if (optionsLength === 0) {
178
+ // 如果没有选项,填充空值
179
+ newValueArr.fill('');
180
+ }
181
+ else {
182
+ newValueArr.forEach((item, index) => {
183
+ // 计算相对于中心的偏移量
184
+ const offset = index - partCount;
185
+ // 计算目标索引,支持循环
186
+ const targetAnimationIndex = animationIndex + offset;
187
+ let targetIndex = ((targetAnimationIndex + 1) % optionsLength) - 1;
188
+ if (targetIndex < 0) {
189
+ targetIndex += optionsLength;
190
+ }
191
+ newValueArr[index] = targetIndex;
192
+ });
193
+ }
194
+ }
195
+ else {
196
+ if (animationIndex < 0) {
197
+ animationIndex = 0;
198
+ }
199
+ if (animationIndex > this.data.options.length - 1) {
200
+ animationIndex = this.data.options.length - 1;
201
+ }
202
+ newValueArr.forEach((item, index) => {
203
+ const valueIndex = animationIndex - partCount + index >= 0
204
+ ? animationIndex - partCount + index
205
+ : undefined;
206
+ if (valueIndex === undefined) {
207
+ return;
208
+ }
209
+ newValueArr[index] = valueIndex;
210
+ });
211
+ }
212
+ let rotate = (animationIndex * rotateAngle) % 360;
213
+ if (rotate < 0) {
214
+ rotate += 360;
215
+ }
216
+ const rotateIndex = Math.round(rotate / rotateAngle);
217
+ // 环形结构填充:以rotateIndex为中心,向两边扩展填充newValueArr
218
+ const centerIndex = rotateIndex; // 中心位置
219
+ const halfLength = Math.floor(newValueArr.length / 2); // newValueArr的一半长度
220
+ // 从中心位置开始,向两边填充
221
+ for (let i = 0; i < newValueArr.length; i++) {
222
+ const targetIndex = (centerIndex - halfLength + i + vOptionLength) % vOptionLength; // 确保索引在0-17范围内
223
+ newArr[targetIndex] = newValueArr[i];
224
+ }
225
+ return newArr;
226
+ },
227
+ getNewAnimationIndex(animationIndex, activeIndex, length, loop) {
228
+ const curOptionsNewIndex = Math.floor((animationIndex + 1) / length) * length + activeIndex;
229
+ const preOptionsNewIndex = curOptionsNewIndex - length;
230
+ const afterOptionsNewIndex = curOptionsNewIndex + length;
231
+ const newAnimationIndex = !loop
232
+ ? activeIndex
233
+ : Math.abs(preOptionsNewIndex - animationIndex) >
234
+ Math.abs(curOptionsNewIndex - animationIndex)
235
+ ? Math.abs(curOptionsNewIndex - animationIndex) >
236
+ Math.abs(afterOptionsNewIndex - animationIndex)
237
+ ? afterOptionsNewIndex
238
+ : curOptionsNewIndex
239
+ : Math.abs(preOptionsNewIndex - animationIndex) >
240
+ Math.abs(afterOptionsNewIndex - animationIndex)
241
+ ? afterOptionsNewIndex
242
+ : preOptionsNewIndex;
243
+ return newAnimationIndex;
244
+ },
245
+ adjustIndex(index) {
246
+ const { data } = this;
247
+ const count = this.getCount();
248
+ if (this.data.loop) {
249
+ for (let i = 0; i < count; i++) {
250
+ const targetIndex = index + i;
251
+ let optionIndex = ((targetIndex + 1) % count) - 1;
252
+ if (optionIndex < 0) {
253
+ optionIndex += count;
254
+ }
255
+ if (!this.isDisabled(data.options[optionIndex]) &&
256
+ data.options[optionIndex] !== undefined) {
257
+ return targetIndex;
258
+ }
259
+ }
260
+ return 0;
261
+ }
262
+ const activeIndex = range(index, 0, count);
263
+ for (let i = activeIndex; i < count; i++) {
264
+ if (!this.isDisabled(data.options[i]) && data.options[i] !== undefined)
265
+ return i;
266
+ }
267
+ for (let i = activeIndex - 1; i >= 0; i--) {
268
+ if (!this.isDisabled(data.options[i]) && data.options[i] !== undefined)
269
+ return i;
270
+ }
271
+ return 0;
272
+ },
273
+ isDisabled(option) {
274
+ return isObj(option) && option.disabled;
275
+ },
175
276
  getOptionText(option) {
176
277
  const { data } = this;
177
278
  return isObj(option) && data.valueKey in option ? option[data.valueKey] : option;
@@ -186,29 +287,43 @@ SmartComponent({
186
287
  return Promise.resolve();
187
288
  },
188
289
  setIndex(index) {
290
+ let activeIndex = ((index + 1) % this.data.options.length) - 1;
291
+ if (activeIndex < 0) {
292
+ activeIndex += this.data.options.length;
293
+ }
189
294
  this.setData({
190
- activeIndex: index,
295
+ activeIndex: activeIndex,
296
+ animationIndex: index,
191
297
  });
192
298
  },
193
299
  getValue() {
194
300
  const { data } = this;
195
- return data.options[data.activeIndex < 0 ? 0 : data.activeIndex];
196
- },
197
- viewOptionsChange(list) {
198
- this.setData({
199
- viewOptions: list,
200
- });
301
+ return isObj(data.options[data.activeIndex])
302
+ ? data.options[data.activeIndex][data.valueKey]
303
+ : data.options[data.activeIndex];
201
304
  },
202
305
  activeIndexChange(index) {
306
+ let activeIndex = ((index + 1) % this.data.options.length) - 1;
307
+ if (activeIndex < 0) {
308
+ activeIndex += this.data.options.length;
309
+ }
310
+ const isSame = activeIndex === this.data.activeIndex;
203
311
  this.setData({
204
- activeIndex: index,
312
+ activeIndex: activeIndex,
313
+ animationIndex: index,
205
314
  });
206
- this.$emit('change', index);
315
+ !isSame && this.$emit('change', index);
207
316
  },
208
317
  animationIndexChange(index) {
209
318
  this.setData({
210
319
  animationIndex: index,
211
320
  });
212
321
  },
322
+ animationStart() {
323
+ this.$emit('animation-start');
324
+ },
325
+ animationEnd() {
326
+ this.$emit('animation-end');
327
+ },
213
328
  },
214
329
  });