stellar-ui-v2 1.35.3

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.
Files changed (141) hide show
  1. package/common/css/common.scss +61 -0
  2. package/components/ste-animate/README.md +117 -0
  3. package/components/ste-animate/animate.scss +247 -0
  4. package/components/ste-animate/ste-animate.vue +200 -0
  5. package/components/ste-badge/README.md +171 -0
  6. package/components/ste-badge/ste-badge.vue +238 -0
  7. package/components/ste-barcode/README.md +36 -0
  8. package/components/ste-barcode/encode2.js +317 -0
  9. package/components/ste-barcode/ste-barcode.vue +213 -0
  10. package/components/ste-button/README.md +129 -0
  11. package/components/ste-button/ste-button.vue +345 -0
  12. package/components/ste-calendar/README.md +304 -0
  13. package/components/ste-calendar/self-date.js +119 -0
  14. package/components/ste-calendar/ste-calendar.vue +578 -0
  15. package/components/ste-checkbox/README.md +297 -0
  16. package/components/ste-checkbox/ste-checkbox.vue +305 -0
  17. package/components/ste-checkbox-group/ste-checkbox-group.vue +133 -0
  18. package/components/ste-code-input/README.md +67 -0
  19. package/components/ste-code-input/ste-code-input.vue +302 -0
  20. package/components/ste-date-picker/README.md +135 -0
  21. package/components/ste-date-picker/ste-date-picker.vue +407 -0
  22. package/components/ste-drag/README.md +103 -0
  23. package/components/ste-drag/ste-drag.vue +203 -0
  24. package/components/ste-dropdown-menu/README.md +358 -0
  25. package/components/ste-dropdown-menu/ste-dropdown-menu.vue +405 -0
  26. package/components/ste-dropdown-menu-item/ste-dropdown-menu-item.vue +176 -0
  27. package/components/ste-icon/README.md +90 -0
  28. package/components/ste-icon/iconfont.css +8 -0
  29. package/components/ste-icon/ste-icon.vue +147 -0
  30. package/components/ste-image/README.md +154 -0
  31. package/components/ste-image/ste-image.vue +218 -0
  32. package/components/ste-index-item/ste-index-item.vue +96 -0
  33. package/components/ste-index-list/README.md +153 -0
  34. package/components/ste-index-list/ste-index-list.vue +128 -0
  35. package/components/ste-input/README.md +146 -0
  36. package/components/ste-input/ste-input.vue +480 -0
  37. package/components/ste-loading/README.md +81 -0
  38. package/components/ste-loading/ste-loading.vue +166 -0
  39. package/components/ste-media-preview/README.md +243 -0
  40. package/components/ste-media-preview/TouchScaleing.js +102 -0
  41. package/components/ste-media-preview/ste-media-preview.vue +267 -0
  42. package/components/ste-message-box/README.md +217 -0
  43. package/components/ste-message-box/ste-message-box.js +72 -0
  44. package/components/ste-message-box/ste-message-box.vue +380 -0
  45. package/components/ste-notice-bar/README.md +129 -0
  46. package/components/ste-notice-bar/ste-notice-bar.vue +331 -0
  47. package/components/ste-number-keyboard/README.md +246 -0
  48. package/components/ste-number-keyboard/keyboard.vue +140 -0
  49. package/components/ste-number-keyboard/ste-number-keyboard.vue +240 -0
  50. package/components/ste-picker/ste-picker.vue +258 -0
  51. package/components/ste-popup/README.md +148 -0
  52. package/components/ste-popup/ste-popup.vue +337 -0
  53. package/components/ste-price/README.md +129 -0
  54. package/components/ste-price/ste-price.vue +258 -0
  55. package/components/ste-progress/README.md +87 -0
  56. package/components/ste-progress/ste-progress.vue +200 -0
  57. package/components/ste-qrcode/README.md +50 -0
  58. package/components/ste-qrcode/ste-qrcode.vue +164 -0
  59. package/components/ste-qrcode/uqrcode.js +34 -0
  60. package/components/ste-radio/README.md +286 -0
  61. package/components/ste-radio/ste-radio.vue +293 -0
  62. package/components/ste-radio-group/ste-radio-group.vue +128 -0
  63. package/components/ste-rate/README.md +115 -0
  64. package/components/ste-rate/ste-rate.vue +202 -0
  65. package/components/ste-read-more/README.md +111 -0
  66. package/components/ste-read-more/ste-read-more.vue +133 -0
  67. package/components/ste-rich-text/README.md +31 -0
  68. package/components/ste-rich-text/ste-rich-text.vue +70 -0
  69. package/components/ste-scroll-to/README.md +68 -0
  70. package/components/ste-scroll-to/mixin.js +173 -0
  71. package/components/ste-scroll-to/ste-scroll-to.vue +45 -0
  72. package/components/ste-scroll-to-item/ste-scroll-to-item.vue +25 -0
  73. package/components/ste-search/README.md +262 -0
  74. package/components/ste-search/ste-search.vue +547 -0
  75. package/components/ste-select/README.md +434 -0
  76. package/components/ste-select/datapager.vue +62 -0
  77. package/components/ste-select/datetime.vue +106 -0
  78. package/components/ste-select/defaultDate.js +142 -0
  79. package/components/ste-select/ste-select.vue +843 -0
  80. package/components/ste-signature/README.md +105 -0
  81. package/components/ste-signature/ste-signature.vue +220 -0
  82. package/components/ste-slider/README.md +165 -0
  83. package/components/ste-slider/ste-slider.vue +544 -0
  84. package/components/ste-step/ste-step.vue +264 -0
  85. package/components/ste-stepper/README.md +170 -0
  86. package/components/ste-stepper/ste-stepper.vue +373 -0
  87. package/components/ste-steps/README.md +132 -0
  88. package/components/ste-steps/ste-steps.vue +65 -0
  89. package/components/ste-sticky/README.md +52 -0
  90. package/components/ste-sticky/ste-sticky.vue +127 -0
  91. package/components/ste-swipe-action/README.md +197 -0
  92. package/components/ste-swipe-action/ste-swipe-action.vue +303 -0
  93. package/components/ste-swipe-action-group/ste-swipe-action-group.vue +104 -0
  94. package/components/ste-swiper/README.md +173 -0
  95. package/components/ste-swiper/ste-swiper.vue +462 -0
  96. package/components/ste-swiper-item/ste-swiper-item.vue +41 -0
  97. package/components/ste-switch/README.md +110 -0
  98. package/components/ste-switch/ste-switch.vue +144 -0
  99. package/components/ste-tab/ste-tab.vue +87 -0
  100. package/components/ste-table/README.md +785 -0
  101. package/components/ste-table/common.js +8 -0
  102. package/components/ste-table/ste-table.vue +666 -0
  103. package/components/ste-table/utils.js +20 -0
  104. package/components/ste-table-column/checkbox-icon.vue +65 -0
  105. package/components/ste-table-column/common.scss +65 -0
  106. package/components/ste-table-column/radio-icon.vue +110 -0
  107. package/components/ste-table-column/ste-table-column.vue +255 -0
  108. package/components/ste-table-column/sub-table.vue +116 -0
  109. package/components/ste-table-column/table-popover.vue +204 -0
  110. package/components/ste-table-column/var.scss +1 -0
  111. package/components/ste-tabs/README.md +475 -0
  112. package/components/ste-tabs/props.js +212 -0
  113. package/components/ste-tabs/ste-tabs.vue +758 -0
  114. package/components/ste-text/README.md +66 -0
  115. package/components/ste-text/ste-text.vue +72 -0
  116. package/components/ste-toast/README.md +243 -0
  117. package/components/ste-toast/ste-toast.js +69 -0
  118. package/components/ste-toast/ste-toast.vue +231 -0
  119. package/components/ste-touch-swipe/README.md +104 -0
  120. package/components/ste-touch-swipe/TouchEvent.js +72 -0
  121. package/components/ste-touch-swipe/ste-touch-swipe.vue +327 -0
  122. package/components/ste-touch-swipe-item/ste-touch-swipe-item.vue +33 -0
  123. package/components/ste-tour/README.md +194 -0
  124. package/components/ste-tour/ste-tour.vue +355 -0
  125. package/components/ste-tree/README.md +240 -0
  126. package/components/ste-tree/ste-tree.vue +350 -0
  127. package/components/ste-upload/README.md +276 -0
  128. package/components/ste-upload/ReadFile.js +229 -0
  129. package/components/ste-upload/ste-upload.vue +526 -0
  130. package/components/ste-video/README.md +60 -0
  131. package/components/ste-video/props.js +149 -0
  132. package/components/ste-video/ste-video.vue +647 -0
  133. package/config/color.js +22 -0
  134. package/index.js +2 -0
  135. package/package.json +19 -0
  136. package/utils/Color.js +66 -0
  137. package/utils/System.js +110 -0
  138. package/utils/dayjs.min.js +1 -0
  139. package/utils/mixin.js +67 -0
  140. package/utils/store.js +7 -0
  141. package/utils/utils.js +604 -0
@@ -0,0 +1,140 @@
1
+ <template>
2
+ <view class="number-keyboard" :style="[cmpRootStyle]">
3
+ <view class="number-keyboard-left">
4
+ <block v-for="(num, index) in list" :key="num">
5
+ <view
6
+ class="number-keyboard-item"
7
+ :class="{
8
+ span3: list.length % 3 == 1 && index === list.length - 1,
9
+ span2: list.length % 3 == 2 && index === list.length - 2,
10
+ clear: num === 'clear',
11
+ }"
12
+ @click="onChange(num)"
13
+ >
14
+ <view v-if="['backspace', 'clear'].indexOf(num) !== -1">
15
+ <ste-icon v-if="num === 'backspace'" code="&#xe6a7;" :color="textColor" :size="textSize" />
16
+ <text v-else-if="num === 'clear'">清除</text>
17
+ </view>
18
+ <view v-else>
19
+ {{ num }}
20
+ </view>
21
+ </view>
22
+ </block>
23
+ </view>
24
+ <view class="number-keyboard-right" v-if="rightKeys">
25
+ <view class="number-keyboard-item" @click="onChange('backspace')">
26
+ <ste-icon code="&#xe6a7;" :color="textColor" :size="textSize" />
27
+ </view>
28
+ <view class="number-keyboard-item clear" v-if="showClear" @click="onChange('clear')">清除</view>
29
+ <view class="number-keyboard-item confirm" :class="{ disabled }" @click="onChange('confirm')">
30
+ {{ confirmText }}
31
+ </view>
32
+ </view>
33
+ </view>
34
+ </template>
35
+
36
+ <script>
37
+ export default {
38
+ options: {
39
+ virtualHost: true,
40
+ },
41
+ props: {
42
+ list: { type: [Array, null] },
43
+ confirmText: { type: String },
44
+ disabled: { type: Boolean },
45
+ showClear: { type: Boolean },
46
+ textColor: { type: String },
47
+ textSize: { type: [Number, String] },
48
+ rightKeys: { type: Boolean },
49
+ },
50
+ computed: {
51
+ cmpRootStyle() {
52
+ let width = 8,
53
+ height = 5;
54
+ if (!this.rightKeys) {
55
+ width = 7;
56
+ height = 3;
57
+ }
58
+ // 向上取整,保证每行至少有3个按钮
59
+ const rows = Math.ceil(this.list.length / 3);
60
+ const w = width * (this.rightKeys ? 4 : 3);
61
+ const h = height * rows;
62
+ return {
63
+ '--ste-number-keyboard-aspect': `${w} / ${h}`,
64
+ '--ste-number-keyboard-columns': this.rightKeys ? '3fr 1fr' : '1fr',
65
+ '--ste-number-keyboard-rows': `repeat(${rows}, 1fr)`,
66
+ '--ste-number-keyboard-confirm-rows': `span ${this.showClear ? rows - 2 : rows - 1}`,
67
+ };
68
+ },
69
+ },
70
+ methods: {
71
+ onChange(v) {
72
+ if (v === 'confirm' && this.disabled) return;
73
+ this.$emit('change', v);
74
+ },
75
+ },
76
+ };
77
+ </script>
78
+
79
+ <style lang="scss" scoped>
80
+ .number-keyboard {
81
+ width: 100%;
82
+ aspect-ratio: var(--ste-number-keyboard-aspect);
83
+ grid-template-columns: var(--ste-number-keyboard-columns);
84
+ display: grid;
85
+ background-color: #f9f9f9;
86
+ column-gap: 16rpx;
87
+ .number-keyboard-left {
88
+ display: grid;
89
+ grid-template-columns: repeat(3, 1fr);
90
+ gap: 16rpx;
91
+ }
92
+ .number-keyboard-right {
93
+ display: grid;
94
+ row-gap: 16rpx;
95
+ grid-template-rows: var(--ste-number-keyboard-rows);
96
+ }
97
+ .number-keyboard-item {
98
+ background-color: #fff;
99
+ width: 100%;
100
+ height: 100%;
101
+ display: flex;
102
+ align-items: center;
103
+ justify-content: center;
104
+ font-family: DIN, DIN;
105
+ font-weight: bold;
106
+ font-size: var(--ste-number-keyboard-text-size);
107
+ color: var(--ste-number-keyboard-text-color);
108
+ border-radius: 8rpx;
109
+
110
+ &:active {
111
+ background-color: #f1f1f1;
112
+ }
113
+
114
+ &.clear {
115
+ font-size: var(--ste-number-keyboard-clear-text-size);
116
+ }
117
+
118
+ &.confirm {
119
+ flex-direction: column;
120
+ grid-row: var(--ste-number-keyboard-confirm-rows);
121
+ font-size: var(--ste-number-keyboard-confirm-text-size);
122
+ background: var(--ste-number-keyboard-confirm-bg);
123
+ color: #fff;
124
+ &:active {
125
+ background-color: var(--ste-number-keyboard-confirm-bg-active);
126
+ }
127
+
128
+ &.disabled {
129
+ background: rgba(238, 238, 238, 0.4) !important;
130
+ }
131
+ }
132
+ &.span2 {
133
+ grid-column: span 2;
134
+ }
135
+ &.span3 {
136
+ grid-column: span 3;
137
+ }
138
+ }
139
+ }
140
+ </style>
@@ -0,0 +1,240 @@
1
+ <template>
2
+ <view class="ste-number-keyboard-root" :style="[cmpRootStyle]">
3
+ <block v-if="mode === 'popup'">
4
+ <ste-popup :show.sync="dataShow" @close="onClose" position="bottom" :show-close="false" @open="onOpen">
5
+ <view style="padding: 30rpx 30rpx 60rpx 30rpx; background-color: #f5f5f5">
6
+ <view class="keyboard-popup-head">
7
+ <view></view>
8
+ <view class="keyboard-title">
9
+ <slot>数字键盘</slot>
10
+ </view>
11
+ <view class="keyboard-close" @click="onClose">
12
+ <ste-icon code="&#xe676;" size="36" />
13
+ </view>
14
+ </view>
15
+ <keyboard
16
+ :list="cmpNumbers"
17
+ :confirmText="confirmText"
18
+ :disabled="confirmDisabled"
19
+ :showClear="showClear"
20
+ :textColor="textColor"
21
+ :textSize="textSize"
22
+ :rightKeys="rightKeys"
23
+ @change="onChange"
24
+ />
25
+ </view>
26
+ </ste-popup>
27
+ </block>
28
+ <block v-else>
29
+ <keyboard
30
+ :list="cmpNumbers"
31
+ :confirmText="confirmText"
32
+ :disabled="confirmDisabled"
33
+ :showClear="showClear"
34
+ :textColor="textColor"
35
+ :textSize="textSize"
36
+ :rightKeys="rightKeys"
37
+ @change="onChange"
38
+ />
39
+ </block>
40
+ </view>
41
+ </template>
42
+
43
+ <script>
44
+ import keyboard from './keyboard.vue';
45
+ import utils from '../../utils/utils.js';
46
+ import useColor from '../../config/color.js';
47
+ let color = useColor();
48
+ /**
49
+ * ste-number-keyboard 数字键盘
50
+ * @description 数字键盘
51
+ * @tutorial https://stellar-ui.intecloud.com.cn/pc/index/index?name=ste-number-keyboard
52
+ * @property {String} mode 键盘模式,默认 popup弹窗模式
53
+ * @value popup 弹窗模式(默认)
54
+ * @value page 在dom文档流中直接展示
55
+ * @property {String} value 输入值,支持v-model双向绑定
56
+ * @property {Number,String} maxlength 输入最大长度
57
+ * @property {String} show 是否显示键盘,支持.sync绑定,mode="popup"时生效
58
+ * @property {Boolean} rightKeys 是否显示右侧功能键,默认true
59
+ * @property {Boolean} randomKeys 按键是否随机排列,默认false
60
+ * @property {String} confirmText 右侧确认按钮文本,默认'确认'
61
+ * @property {Boolean} confirmDisabled 右侧确认是否禁用,默认false
62
+ * @property {Array<String>} customKeys 自定义按键,建议数量不大于2
63
+ * @property {Boolean} showClear 是否显示清空按钮,默认true
64
+ * @property {String} textColor 按键文字颜色,默认#000000
65
+ * @property {String|Number} textSize 按键文字大小,默认48,单位rpx
66
+ * @property {String} confirmBg 确认按钮背景颜色,默认#0090FF
67
+ * @property {String} confirmColor 确认按钮文字颜色,默认#FFFFFF
68
+
69
+ * @event {Function} change 输入值改变时触发
70
+ * @event {Function} clear 清空按钮点击事件
71
+ * @event {Function} backspace 删除按钮点击事件
72
+ * @event {Function} confirm 确认按钮点击事件
73
+ * @event {Function} click 点击功能键(确认/删除/清除)之外的键盘触发
74
+ * @event {Function} beforeinput 输入之前触发,功能键之外的键盘点击时为输入(参数1为当前点击的按钮,参数2为开启等待的回调函数,参数3为执行后续操作的回调函数,参数4为阻止后续执行的回调函数)
75
+ * @event {Function} close 关闭弹窗键盘触发
76
+ * @event {Function} open 打开弹窗键盘触发
77
+ */
78
+
79
+ export default {
80
+ group: '展示组件',
81
+ title: 'NumberKeyboard 数字键盘',
82
+ name: 'ste-number-keyboard',
83
+ components: { keyboard },
84
+ props: {
85
+ mode: { type: [String, null], default: () => 'popup' },
86
+ value: { type: [String, null], default: () => '' },
87
+ maxlength: { type: [Number, String, null], default: () => null },
88
+ show: { type: [Boolean, null], default: () => false },
89
+ rightKeys: { type: [Boolean, null], default: () => true },
90
+ randomKeys: { type: [Boolean, null], default: () => false },
91
+ confirmText: { type: [String, null], default: () => '确定' },
92
+ confirmDisabled: { type: [Boolean, null], default: () => false },
93
+ customKeys: { type: [Array, null], default: () => [] },
94
+ showClear: { type: [Boolean, null], default: () => true },
95
+ textColor: { type: [String, null], default: () => '#000' },
96
+ textSize: { type: [Number, String, null], default: () => 48 },
97
+ confirmBg: { type: [String, null], default: () => '' },
98
+ confirmColor: { type: [String, null], default: () => '#fff' },
99
+ },
100
+ data() {
101
+ return {
102
+ dataValue: '',
103
+ dataShow: false,
104
+ };
105
+ },
106
+ computed: {
107
+ cmpNumbers() {
108
+ let keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
109
+ if (this.randomKeys) {
110
+ utils.randomArray(keys, this.dataShow);
111
+ }
112
+
113
+ if (Array.isArray(this.customKeys)) {
114
+ keys.push(...this.customKeys);
115
+ }
116
+
117
+ if (!this.rightKeys) {
118
+ if (!this.showClear) {
119
+ keys.push('backspace');
120
+ return;
121
+ }
122
+ const d = keys.length % 3;
123
+ if (d === 1) {
124
+ const end = keys.pop();
125
+ keys.push('clear', end, 'backspace');
126
+ } else {
127
+ keys.push('clear', 'backspace');
128
+ }
129
+ }
130
+
131
+ return keys;
132
+ },
133
+
134
+ cmpRootStyle() {
135
+ const fontsize = utils.formatPx(this.textSize, 'num');
136
+ return {
137
+ '--ste-number-keyboard-text-color': this.textColor,
138
+ '--ste-number-keyboard-text-size': isNaN(fontsize) ? fontsize : `${fontsize}px`,
139
+ '--ste-number-keyboard-clear-text-size': isNaN(fontsize) ? fontsize : `${fontsize - 8}px`,
140
+ '--ste-number-keyboard-confirm-text-size': isNaN(fontsize) ? fontsize : `${fontsize - 3}px`,
141
+ '--ste-number-keyboard-confirm-bg': this.confirmBg ? this.confirmBg : color.getColor().steThemeColor,
142
+ '--ste-number-keyboard-confirm-bg-active': utils.Color.formatColor(
143
+ this.confirmBg ? this.confirmBg : color.getColor().steThemeColor,
144
+ 0.8
145
+ ),
146
+ '--ste-number-keyboard-confirm-color': this.confirmColor,
147
+ };
148
+ },
149
+ },
150
+ watch: {
151
+ show: {
152
+ handler(v) {
153
+ this.dataShow = v;
154
+ },
155
+ immutable: true,
156
+ },
157
+ value: {
158
+ handler(v) {
159
+ if (v === null || v === undefined) this.dataValue = '';
160
+ else if (typeof v === 'string') this.dataValue = v;
161
+ else this.dataValue = String(v);
162
+ },
163
+ immutable: true,
164
+ },
165
+ },
166
+
167
+ methods: {
168
+ async onChange(v) {
169
+ try {
170
+ if (v === 'confirm') {
171
+ this.$emit('confirm', this.dataValue);
172
+ this.onClose();
173
+ return;
174
+ }
175
+ switch (v) {
176
+ case 'backspace':
177
+ this.dataValue = this.dataValue.slice(0, this.dataValue.length - 1);
178
+ this.$emit('backspace');
179
+ break;
180
+ case 'clear':
181
+ this.dataValue = '';
182
+ this.$emit('clear');
183
+ break;
184
+ default:
185
+ await this.beforInput(v);
186
+ this.$emit('click', v);
187
+ if (this.maxlength && this.dataValue.length >= this.maxlength) return;
188
+ this.dataValue += v;
189
+ break;
190
+ }
191
+ this.$emit('input', this.dataValue);
192
+ this.$emit('change', this.dataValue);
193
+ this.$emit('update:value', this.dataValue);
194
+ } catch (e) {
195
+ if (e) console.error(e);
196
+ }
197
+ },
198
+ onClose() {
199
+ this.dataShow = false;
200
+ this.$emit('update:show', false);
201
+ this.$emit('close');
202
+ },
203
+ onOpen() {
204
+ this.$emit('open');
205
+ },
206
+ async beforInput(v) {
207
+ let next = true;
208
+ const stop = new Promise((resolve, reject) => {
209
+ this.$emit(
210
+ 'beforeinput',
211
+ v,
212
+ () => (next = false),
213
+ () => resolve(),
214
+ () => reject()
215
+ );
216
+ });
217
+ if (!next) {
218
+ await stop;
219
+ }
220
+ },
221
+ },
222
+ };
223
+ </script>
224
+
225
+ <style lang="scss" scoped>
226
+ .ste-number-keyboard-root {
227
+ .keyboard-popup-head {
228
+ width: 100%;
229
+ display: flex;
230
+ justify-content: space-between;
231
+ padding-bottom: 30rpx;
232
+ color: #888;
233
+ .keyboard-close {
234
+ &:active {
235
+ background: rgba(200, 200, 200, 0.5);
236
+ }
237
+ }
238
+ }
239
+ }
240
+ </style>
@@ -0,0 +1,258 @@
1
+ <template>
2
+ <view class="ste-picker-root" :class="[rootClass]">
3
+ <view class="ste-picker-toolbar" v-if="showToolbar">
4
+ <text @click="cancel" class="cancel" :style="{ color: cancelColor }">{{ cancelText }}</text>
5
+ <text class="title">{{ title }}</text>
6
+ <text @click="confirm" class="confirm" :style="{ color: confirmColor }">{{ confirmText }}</text>
7
+ </view>
8
+ <picker-view
9
+ @change="change"
10
+ :indicatorStyle="cmpIndicatorStyle"
11
+ class="ste-picker-view"
12
+ :style="[cmpPickerViewStyle]"
13
+ :value="innerIndex"
14
+ >
15
+ <picker-view-column v-for="(col, key) in innerColumns" :key="key" class="ste-picker-column">
16
+ <view class="item" v-for="(item, index) in col" :key="index" :style="[cmpPickerItemStyle]">
17
+ {{ item }}
18
+ </view>
19
+ </picker-view-column>
20
+ </picker-view>
21
+ </view>
22
+ </template>
23
+
24
+ <script>
25
+ import utils from '../../utils/utils.js';
26
+ /**
27
+ * ste-picker
28
+ * @description 选择器
29
+ * @property {Boolean} show 是否显示picker弹窗(默认 false )
30
+ * @property {Boolean} showToolbar 是否显示顶部的操作栏(默认 true )
31
+ * @property {String} title 顶部标题
32
+ * @property {Array} columns 对象数组,设置每一列的数据
33
+ * @property {Boolean} loading 是否显示加载中状态(默认 false )
34
+ * @property {String | Number} itemHeight 各列中,单个选项的高度(默认 44 )
35
+ * @property {String} cancelText 取消按钮的文字(默认 '取消' )
36
+ * @property {String} confirmText 确认按钮的文字(默认 '确定' )
37
+ * @property {String} cancelColor 取消按钮的颜色(默认 '#909193' )
38
+ * @property {String} confirmColor 确认按钮的颜色(默认 '#3c9cff' )
39
+ * @property {String | Number} visibleItemCount 每列中可见选项的数量(默认 6 )
40
+ * @property {String} keyName 选项对象中,需要展示的属性键名(默认 'text' )
41
+ * @property {Array} defaultIndex 各列的默认索引
42
+ * @event {Function} close 关闭选择器时触发
43
+ * @event {Function} cancel 点击取消按钮触发
44
+ * @event {Function} change 当选择值变化时触发
45
+ * @event {Function} confirm 点击确定按钮,返回当前选择的值
46
+ */
47
+ export default {
48
+ props: {
49
+ columns: {
50
+ type: [Array, null],
51
+ default: () => [],
52
+ },
53
+ itemHeight: {
54
+ type: [String, Number, null],
55
+ default: 44,
56
+ },
57
+ visibleItemCount: {
58
+ type: [Number, null],
59
+ default: 5,
60
+ },
61
+ showToolbar: {
62
+ type: [Boolean, null],
63
+ default: true,
64
+ },
65
+ title: {
66
+ type: [String, null],
67
+ default: '',
68
+ },
69
+ cancelText: {
70
+ type: [String, null],
71
+ default: '取消',
72
+ },
73
+ cancelColor: {
74
+ type: [String, null],
75
+ default: '#969799',
76
+ },
77
+ confirmText: {
78
+ type: [String, null],
79
+ default: '确认',
80
+ },
81
+ confirmColor: {
82
+ type: [String, null],
83
+ default: '#0090FF',
84
+ },
85
+ defaultIndex: {
86
+ type: [Array, null],
87
+ default: () => [],
88
+ },
89
+ rootClass: {
90
+ type: [String, null],
91
+ default: '',
92
+ },
93
+ },
94
+ data() {
95
+ return {
96
+ // 上一次选择的列索引
97
+ lastIndex: [],
98
+ // 索引值 ,对应picker-view的value
99
+ innerIndex: [],
100
+ // 各列的值
101
+ innerColumns: [],
102
+ // 上一次的变化列索引
103
+ columnIndex: 0,
104
+ };
105
+ },
106
+ computed: {
107
+ cmpIndicatorStyle() {
108
+ // let style = `height: ${utils.addUnit(this.itemHeight)}`;
109
+ let style = `height: ${this.itemHeight}px`;
110
+ return style;
111
+ },
112
+ cmpPickerViewStyle() {
113
+ let borderRadius = utils.formatPx('12rpx');
114
+ let style = {
115
+ // height: utils.addUnit(this.visibleItemCount * this.itemHeight),
116
+ height: this.visibleItemCount * this.itemHeight + 'px',
117
+ '--border-radius': this.showToolbar ? `0 0 ${borderRadius} ${borderRadius}` : borderRadius,
118
+ };
119
+ return style;
120
+ },
121
+ cmpPickerItemStyle() {
122
+ let style = {
123
+ // height: utils.addUnit(this.itemHeight),
124
+ height: this.itemHeight + 'px',
125
+ };
126
+ return style;
127
+ },
128
+ },
129
+ watch: {
130
+ // 监听默认索引的变化,重新设置对应的值
131
+ defaultIndex: {
132
+ immediate: true,
133
+ handler(n) {
134
+ this.setIndexs(n, true);
135
+ },
136
+ },
137
+ // 监听columns参数的变化
138
+ columns: {
139
+ immediate: true,
140
+ handler(n) {
141
+ this.setColumns(n);
142
+ },
143
+ },
144
+ },
145
+ methods: {
146
+ addUnit: utils.addUnit,
147
+ change(e) {
148
+ const { value } = e.detail;
149
+ let index = 0,
150
+ columnIndex = 0;
151
+ // 通过对比前后两次的列索引,得出当前变化的是哪一列
152
+ for (let i = 0; i < value.length; i++) {
153
+ let item = value[i];
154
+ if (item !== (this.lastIndex[i] || 0)) {
155
+ // 把undefined转为合法假值0
156
+ // 设置columnIndex为当前变化列的索引
157
+ columnIndex = i;
158
+ // index则为变化列中的变化项的索引
159
+ index = item;
160
+ break; // 终止循环,即使少一次循环,也是性能的提升
161
+ }
162
+ }
163
+ this.columnIndex = columnIndex;
164
+ const values = this.innerColumns;
165
+ // 将当前的各项变化索引,设置为"上一次"的索引变化值
166
+ this.setLastIndex(value);
167
+ this.setIndexs(value);
168
+
169
+ const changeObj = {
170
+ value: this.innerColumns.map((item, index) => item[value[index]]),
171
+ index,
172
+ indexs: value,
173
+ values,
174
+ columnIndex, // 变化的列的索引
175
+ };
176
+ this.$emit('change', changeObj);
177
+ },
178
+ // 设置index索引,此方法可被外部调用设置
179
+ setIndexs(index, setLastIndex) {
180
+ this.innerIndex = utils.deepClone(index);
181
+ if (setLastIndex) {
182
+ this.setLastIndex(index);
183
+ }
184
+ },
185
+ // 记录上一次的各列索引位置
186
+ setLastIndex(index) {
187
+ // 当能进入此方法,意味着当前设置的各列默认索引,即为“上一次”的选中值,需要记录,是因为changeHandler中
188
+ // 需要拿前后的变化值进行对比,得出当前发生改变的是哪一列
189
+ this.lastIndex = utils.deepClone(index);
190
+ },
191
+ // 设置整体各列的columns的值
192
+ setColumns(columns) {
193
+ this.innerColumns = utils.deepClone(columns);
194
+ // 如果在设置各列数据时,没有被设置默认的各列索引defaultIndex,那么用0去填充它,数组长度为列的数量
195
+ if (this.innerIndex.length === 0) {
196
+ this.innerIndex = new Array(columns.length).fill(0);
197
+ }
198
+ },
199
+ cancel() {
200
+ this.$emit('cancel');
201
+ },
202
+ confirm() {
203
+ this.$emit('confirm');
204
+ },
205
+ },
206
+ };
207
+ </script>
208
+
209
+ <style lang="scss" scoped>
210
+ .ste-picker-root {
211
+ width: 100%;
212
+ background-color: #fff;
213
+ border-radius: 12rpx;
214
+
215
+ &.ste-date-picker-view {
216
+ padding: 0 38rpx;
217
+ .ste-picker-toolbar {
218
+ padding-left: 0;
219
+ padding-right: 0;
220
+ }
221
+ }
222
+
223
+ .ste-picker-view {
224
+ width: 100%;
225
+ border-radius: var(--border-radius);
226
+ /deep/ .uni-picker-view-wrapper {
227
+ border-radius: var(--border-radius);
228
+ }
229
+ /deep/ .ste-picker-column {
230
+ border-radius: var(--border-radius);
231
+ }
232
+ }
233
+ .ste-picker-toolbar {
234
+ padding: 30rpx 40rpx;
235
+ display: flex;
236
+ align-items: center;
237
+ justify-content: space-between;
238
+ font-size: 28rpx;
239
+ .cancel {
240
+ cursor: pointer;
241
+ }
242
+
243
+ .title {
244
+ font-size: 32rpx;
245
+ }
246
+
247
+ .confirm {
248
+ cursor: pointer;
249
+ }
250
+ }
251
+ .item {
252
+ font-size: 26rpx;
253
+ display: flex;
254
+ align-items: center;
255
+ justify-content: center;
256
+ }
257
+ }
258
+ </style>