uview-pro 0.6.18 → 0.6.19

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 (278) hide show
  1. package/changelog.md +1778 -1768
  2. package/components/u-action-sheet/types.ts +52 -52
  3. package/components/u-action-sheet/u-action-sheet.vue +196 -196
  4. package/components/u-action-sheet-item/types.ts +35 -35
  5. package/components/u-action-sheet-item/u-action-sheet-item.vue +85 -85
  6. package/components/u-alert-tips/types.ts +49 -49
  7. package/components/u-alert-tips/u-alert-tips.vue +239 -239
  8. package/components/u-avatar/types.ts +44 -44
  9. package/components/u-avatar/u-avatar.vue +218 -218
  10. package/components/u-avatar-cropper/types.ts +23 -23
  11. package/components/u-avatar-cropper/u-avatar-cropper.vue +299 -299
  12. package/components/u-avatar-cropper/weCropper.d.ts +62 -62
  13. package/components/u-avatar-cropper/weCropper.js +1281 -1281
  14. package/components/u-avatar-cropper/weCropper.ts +1276 -1276
  15. package/components/u-back-top/types.ts +44 -44
  16. package/components/u-back-top/u-back-top.vue +141 -141
  17. package/components/u-badge/types.ts +46 -46
  18. package/components/u-badge/u-badge.vue +153 -153
  19. package/components/u-button/types.ts +76 -76
  20. package/components/u-button/u-button.vue +608 -608
  21. package/components/u-calendar/types.ts +126 -126
  22. package/components/u-calendar/u-calendar.vue +1243 -1243
  23. package/components/u-car-keyboard/types.ts +22 -22
  24. package/components/u-car-keyboard/u-car-keyboard.vue +263 -263
  25. package/components/u-card/types.ts +69 -69
  26. package/components/u-card/u-card.vue +210 -210
  27. package/components/u-cell-group/types.ts +27 -27
  28. package/components/u-cell-group/u-cell-group.vue +60 -60
  29. package/components/u-cell-item/types.ts +64 -64
  30. package/components/u-cell-item/u-cell-item.vue +221 -221
  31. package/components/u-checkbox/types.ts +45 -45
  32. package/components/u-checkbox/u-checkbox.vue +363 -363
  33. package/components/u-checkbox-group/types.ts +45 -45
  34. package/components/u-checkbox-group/u-checkbox-group.vue +172 -172
  35. package/components/u-circle-progress/types.ts +63 -63
  36. package/components/u-circle-progress/u-circle-progress.vue +299 -299
  37. package/components/u-city-select/types.ts +30 -30
  38. package/components/u-city-select/u-city-select.vue +281 -281
  39. package/components/u-col/types.ts +40 -40
  40. package/components/u-col/u-col.vue +142 -142
  41. package/components/u-collapse/types.ts +41 -41
  42. package/components/u-collapse/u-collapse.vue +190 -190
  43. package/components/u-collapse-item/types.ts +35 -35
  44. package/components/u-collapse-item/u-collapse-item.vue +291 -291
  45. package/components/u-column-notice/types.ts +58 -58
  46. package/components/u-column-notice/u-column-notice.vue +223 -223
  47. package/components/u-config-provider/types.ts +53 -53
  48. package/components/u-config-provider/u-config-provider.vue +185 -185
  49. package/components/u-count-down/types.ts +52 -52
  50. package/components/u-count-down/u-count-down.vue +288 -288
  51. package/components/u-count-to/types.ts +42 -42
  52. package/components/u-count-to/u-count-to.vue +266 -266
  53. package/components/u-divider/types.ts +41 -41
  54. package/components/u-divider/u-divider.vue +146 -146
  55. package/components/u-dropdown/types.ts +67 -67
  56. package/components/u-dropdown/u-dropdown.vue +436 -436
  57. package/components/u-dropdown-item/types.ts +40 -40
  58. package/components/u-dropdown-item/u-dropdown-item.vue +124 -124
  59. package/components/u-empty/types.ts +46 -46
  60. package/components/u-empty/u-empty.vue +109 -109
  61. package/components/u-fab/types.ts +83 -83
  62. package/components/u-fab/u-fab.vue +330 -330
  63. package/components/u-field/types.ts +81 -81
  64. package/components/u-field/u-field.vue +398 -398
  65. package/components/u-form/types.ts +39 -39
  66. package/components/u-form/u-form.vue +175 -135
  67. package/components/u-form-item/types.ts +95 -95
  68. package/components/u-form-item/u-form-item.vue +563 -563
  69. package/components/u-full-screen/types.ts +26 -26
  70. package/components/u-full-screen/u-full-screen.vue +100 -100
  71. package/components/u-gap/types.ts +28 -28
  72. package/components/u-gap/u-gap.vue +50 -50
  73. package/components/u-grid/types.ts +29 -29
  74. package/components/u-grid/u-grid.vue +91 -91
  75. package/components/u-grid-item/types.ts +24 -24
  76. package/components/u-grid-item/u-grid-item.vue +130 -130
  77. package/components/u-icon/types.ts +69 -69
  78. package/components/u-icon/u-icon.vue +301 -301
  79. package/components/u-image/types.ts +61 -61
  80. package/components/u-image/u-image.vue +245 -245
  81. package/components/u-index-anchor/types.ts +24 -24
  82. package/components/u-index-anchor/u-index-anchor.vue +120 -120
  83. package/components/u-index-list/types.ts +44 -44
  84. package/components/u-index-list/u-index-list.vue +346 -346
  85. package/components/u-input/types.ts +165 -165
  86. package/components/u-input/u-input.vue +453 -453
  87. package/components/u-keyboard/types.ts +40 -40
  88. package/components/u-keyboard/u-keyboard.vue +201 -201
  89. package/components/u-lazy-load/types.ts +37 -37
  90. package/components/u-lazy-load/u-lazy-load.vue +246 -246
  91. package/components/u-line/types.ts +44 -44
  92. package/components/u-line/u-line.vue +68 -68
  93. package/components/u-line-progress/types.ts +58 -58
  94. package/components/u-line-progress/u-line-progress.vue +131 -131
  95. package/components/u-link/types.ts +54 -54
  96. package/components/u-link/u-link.vue +100 -100
  97. package/components/u-loading/types.ts +45 -45
  98. package/components/u-loading/u-loading.vue +106 -106
  99. package/components/u-loading-popup/types.ts +26 -26
  100. package/components/u-loading-popup/u-loading-popup.vue +254 -254
  101. package/components/u-loadmore/types.ts +88 -88
  102. package/components/u-loadmore/u-loadmore.vue +170 -170
  103. package/components/u-mask/types.ts +48 -48
  104. package/components/u-mask/u-mask.vue +113 -113
  105. package/components/u-message-input/types.ts +90 -90
  106. package/components/u-message-input/u-message-input.vue +283 -283
  107. package/components/u-modal/service.ts +48 -48
  108. package/components/u-modal/types.ts +139 -139
  109. package/components/u-modal/u-modal.vue +465 -465
  110. package/components/u-navbar/types.ts +104 -104
  111. package/components/u-navbar/u-navbar.vue +268 -268
  112. package/components/u-no-network/image.ts +2 -2
  113. package/components/u-no-network/types.ts +29 -29
  114. package/components/u-no-network/u-no-network.vue +313 -313
  115. package/components/u-notice-bar/types.ts +111 -111
  116. package/components/u-notice-bar/u-notice-bar.vue +191 -191
  117. package/components/u-number-box/types.ts +42 -42
  118. package/components/u-number-box/u-number-box.vue +322 -322
  119. package/components/u-number-keyboard/types.ts +26 -26
  120. package/components/u-number-keyboard/u-number-keyboard.vue +189 -189
  121. package/components/u-pagination/types.ts +38 -38
  122. package/components/u-pagination/u-pagination.vue +102 -102
  123. package/components/u-picker/types.ts +140 -140
  124. package/components/u-picker/u-picker.vue +854 -854
  125. package/components/u-popup/types.ts +64 -64
  126. package/components/u-popup/u-popup.vue +427 -427
  127. package/components/u-radio/types.ts +39 -39
  128. package/components/u-radio/u-radio.vue +349 -349
  129. package/components/u-radio-group/types.ts +40 -40
  130. package/components/u-radio-group/u-radio-group.vue +96 -96
  131. package/components/u-rate/types.ts +50 -50
  132. package/components/u-rate/u-rate.vue +250 -250
  133. package/components/u-read-more/types.ts +46 -46
  134. package/components/u-read-more/u-read-more.vue +182 -182
  135. package/components/u-root-portal/u-root-portal.vue +55 -55
  136. package/components/u-row/types.ts +30 -30
  137. package/components/u-row/u-row.vue +105 -105
  138. package/components/u-row-notice/types.ts +49 -49
  139. package/components/u-row-notice/u-row-notice.vue +257 -257
  140. package/components/u-safe-bottom/types.ts +19 -19
  141. package/components/u-safe-bottom/u-safe-bottom.vue +55 -55
  142. package/components/u-search/u-search.vue +297 -297
  143. package/components/u-section/types.ts +42 -42
  144. package/components/u-section/u-section.vue +156 -156
  145. package/components/u-select/types.ts +56 -56
  146. package/components/u-select/u-select.vue +447 -447
  147. package/components/u-skeleton/types.ts +89 -89
  148. package/components/u-skeleton/u-skeleton.vue +253 -253
  149. package/components/u-slider/types.ts +55 -55
  150. package/components/u-slider/u-slider.vue +422 -422
  151. package/components/u-status-bar/types.ts +21 -21
  152. package/components/u-status-bar/u-status-bar.vue +64 -64
  153. package/components/u-step/types.ts +37 -37
  154. package/components/u-step/u-step.vue +292 -292
  155. package/components/u-steps/types.ts +39 -39
  156. package/components/u-steps/u-steps.vue +105 -105
  157. package/components/u-sticky/types.ts +33 -33
  158. package/components/u-sticky/u-sticky.vue +177 -177
  159. package/components/u-subsection/types.ts +46 -46
  160. package/components/u-subsection/u-subsection.vue +358 -358
  161. package/components/u-swipe-action/types.ts +60 -60
  162. package/components/u-swipe-action/u-swipe-action.vue +276 -276
  163. package/components/u-swiper/types.ts +57 -57
  164. package/components/u-swiper/u-swiper.vue +308 -308
  165. package/components/u-switch/types.ts +39 -39
  166. package/components/u-switch/u-switch.vue +212 -212
  167. package/components/u-tabbar/types.ts +57 -57
  168. package/components/u-tabbar/u-tabbar.vue +480 -480
  169. package/components/u-table/types.ts +35 -35
  170. package/components/u-table/u-table.vue +67 -67
  171. package/components/u-tabs/types.ts +64 -64
  172. package/components/u-tabs/u-tabs.vue +328 -328
  173. package/components/u-tabs-swiper/types.ts +64 -64
  174. package/components/u-tabs-swiper/u-tabs-swiper.vue +407 -407
  175. package/components/u-tag/types.ts +47 -47
  176. package/components/u-tag/u-tag.vue +276 -276
  177. package/components/u-td/types.ts +22 -22
  178. package/components/u-td/u-td.vue +65 -65
  179. package/components/u-text/types.ts +80 -80
  180. package/components/u-text/u-text.vue +355 -355
  181. package/components/u-textarea/types.ts +105 -105
  182. package/components/u-textarea/u-textarea.vue +450 -450
  183. package/components/u-th/types.ts +22 -22
  184. package/components/u-th/u-th.vue +63 -63
  185. package/components/u-time-line/u-time-line.vue +64 -64
  186. package/components/u-time-line-item/types.ts +24 -24
  187. package/components/u-time-line-item/u-time-line-item.vue +89 -89
  188. package/components/u-toast/service.ts +40 -40
  189. package/components/u-toast/types.ts +54 -54
  190. package/components/u-toast/u-toast.vue +385 -385
  191. package/components/u-top-tips/types.ts +25 -25
  192. package/components/u-top-tips/u-top-tips.vue +130 -130
  193. package/components/u-tr/types.ts +19 -19
  194. package/components/u-tr/u-tr.vue +39 -39
  195. package/components/u-transition/types.ts +43 -43
  196. package/components/u-transition/u-transition.vue +437 -437
  197. package/components/u-upload/types.ts +171 -171
  198. package/components/u-upload/u-upload.vue +1605 -1605
  199. package/components/u-verification-code/types.ts +32 -32
  200. package/components/u-verification-code/u-verification-code.vue +183 -183
  201. package/components/u-waterfall/types.ts +26 -26
  202. package/components/u-waterfall/u-waterfall.vue +188 -188
  203. package/iconfont.css +913 -913
  204. package/index.scss +26 -26
  205. package/libs/config/color.ts +9 -9
  206. package/libs/config/config.ts +59 -59
  207. package/libs/config/theme-tokens.ts +102 -102
  208. package/libs/config/zIndex.ts +32 -32
  209. package/libs/css/color.scss +155 -155
  210. package/libs/css/common.scss +183 -183
  211. package/libs/css/style.components.scss +16 -16
  212. package/libs/css/style.h5.scss +8 -8
  213. package/libs/css/style.mp.scss +68 -68
  214. package/libs/css/style.nvue.scss +15 -15
  215. package/libs/css/style.theme.scss +56 -56
  216. package/libs/css/style.vue.scss +188 -188
  217. package/libs/function/$parent.ts +24 -24
  218. package/libs/function/addUnit.ts +50 -50
  219. package/libs/function/clipboard.ts +73 -73
  220. package/libs/function/color.ts +28 -28
  221. package/libs/function/colorGradient.ts +139 -139
  222. package/libs/function/debounce.ts +28 -28
  223. package/libs/function/deepClone.ts +39 -39
  224. package/libs/function/deepMerge.ts +35 -35
  225. package/libs/function/getParent.ts +63 -63
  226. package/libs/function/getRect.ts +26 -26
  227. package/libs/function/guid.ts +42 -42
  228. package/libs/function/md5.ts +403 -403
  229. package/libs/function/parent.ts +21 -21
  230. package/libs/function/queryParams.ts +64 -64
  231. package/libs/function/random.ts +16 -16
  232. package/libs/function/randomArray.ts +11 -11
  233. package/libs/function/route.ts +118 -118
  234. package/libs/function/styleUtils.ts +83 -83
  235. package/libs/function/sys.ts +15 -15
  236. package/libs/function/test.ts +289 -289
  237. package/libs/function/throttle.ts +31 -31
  238. package/libs/function/timeFormat.ts +55 -55
  239. package/libs/function/timeFrom.ts +48 -48
  240. package/libs/function/toast.ts +14 -14
  241. package/libs/function/trim.ts +21 -21
  242. package/libs/function/type2icon.ts +38 -38
  243. package/libs/hooks/index.ts +10 -10
  244. package/libs/hooks/useColor.ts +61 -61
  245. package/libs/hooks/useCompRelation.ts +424 -424
  246. package/libs/hooks/useDebounce.ts +15 -15
  247. package/libs/hooks/useEmitter.ts +79 -79
  248. package/libs/hooks/useLocale.ts +34 -34
  249. package/libs/hooks/useModal.ts +131 -131
  250. package/libs/hooks/useRect.ts +40 -40
  251. package/libs/hooks/useRouter.ts +173 -173
  252. package/libs/hooks/useTheme.ts +173 -173
  253. package/libs/hooks/useThrottle.ts +16 -16
  254. package/libs/hooks/useToast.ts +115 -115
  255. package/libs/index.ts +349 -349
  256. package/libs/request/auto-http.ts +76 -76
  257. package/libs/request/index.ts +301 -301
  258. package/libs/store/index.ts +88 -88
  259. package/libs/util/async-validator.d.ts +75 -75
  260. package/libs/util/async-validator.js +1 -1
  261. package/libs/util/calendar.d.ts +57 -57
  262. package/libs/util/canvas-2d.ts +182 -182
  263. package/libs/util/config-provider.ts +804 -804
  264. package/libs/util/emitter.ts +112 -112
  265. package/libs/util/mitt.ts +118 -118
  266. package/libs/util/system-theme.ts +25 -25
  267. package/locale/index.ts +2 -2
  268. package/locale/lang/en-US.ts +136 -136
  269. package/locale/lang/zh-CN.ts +136 -136
  270. package/package.json +1 -1
  271. package/plugins/root/page.ts +77 -77
  272. package/plugins/root/root.ts +53 -53
  273. package/theme.scss +149 -149
  274. package/types/components.d.ts +105 -105
  275. package/types/global.d.ts +470 -470
  276. package/types/ignore-errors.d.ts +30 -30
  277. package/types/index.d.ts +15 -15
  278. package/types/uni-app.d.ts +63 -63
@@ -1,447 +1,447 @@
1
- <template>
2
- <view class="u-select" :class="customClass" :style="$u.toStyle(customStyle)">
3
- <!-- <view class="u-select__action" :class="{
4
- 'u-select--border': border
5
- }" @tap.stop="selectHandler">
6
- <view class="u-select__action__icon" :class="{
7
- 'u-select__action__icon--reverse': value == true
8
- }">
9
- <u-icon name="arrow-down-fill" size="26" color="var(--u-light-color)"></u-icon>
10
- </view>
11
- </view> -->
12
- <u-popup
13
- :maskCloseAble="maskCloseAble"
14
- mode="bottom"
15
- :popup="false"
16
- v-model="popupValue"
17
- length="auto"
18
- :safeAreaInsetBottom="safeAreaInsetBottom"
19
- @close="close"
20
- :z-index="uZIndex"
21
- >
22
- <view class="u-select">
23
- <view class="u-select__header" @touchmove.stop.prevent="">
24
- <view
25
- class="u-select__header__cancel u-select__header__btn"
26
- :style="{ color: cancelColor }"
27
- hover-class="u-hover-class"
28
- :hover-stay-time="150"
29
- @tap="getResult('cancel')"
30
- >
31
- {{ getCancelText }}
32
- </view>
33
- <view class="u-select__header__title u-line-1"> {{ title }}</view>
34
- <view
35
- class="u-select__header__confirm u-select__header__btn"
36
- :style="{ color: moving ? cancelColor : confirmColor }"
37
- hover-class="u-hover-class"
38
- :hover-stay-time="150"
39
- @touchmove.stop=""
40
- @tap.stop="getResult('confirm')"
41
- >
42
- {{ getConfirmText }}
43
- </view>
44
- </view>
45
- <view class="u-select__body">
46
- <picker-view
47
- v-if="modelValue && readyToRender"
48
- :value="defaultSelector"
49
- class="u-select__body__picker-view"
50
- mask-class="u-picker-view-mask"
51
- indicator-class="u-picker-view-indicator"
52
- @pickstart="pickstart"
53
- @pickend="pickend"
54
- @change="columnChange"
55
- >
56
- <picker-view-column v-for="(item, index) in columnData" :key="index">
57
- <view
58
- class="u-select__body__picker-view__item"
59
- v-for="(item1, index1) in item"
60
- :key="index1"
61
- >
62
- <view class="u-line-1">{{ item1[labelName] }}</view>
63
- </view>
64
- </picker-view-column>
65
- </picker-view>
66
- </view>
67
- </view>
68
- </u-popup>
69
- </view>
70
- </template>
71
-
72
- <script lang="ts">
73
- export default {
74
- name: 'u-select',
75
- options: {
76
- addGlobalClass: true,
77
- // #ifndef MP-TOUTIAO
78
- virtualHost: true,
79
- // #endif
80
- styleIsolation: 'shared'
81
- }
82
- };
83
- </script>
84
-
85
- <script setup lang="ts">
86
- import { ref, computed, watch, nextTick } from 'vue';
87
- import { SelectProps } from './types';
88
- import type { SelectListItem } from '../../types/global';
89
- import { $u, useLocale } from '../..';
90
- import uPopup from '../u-popup/u-popup.vue';
91
-
92
- /**
93
- * select 列选择器
94
- * @description 此选择器用于单列,多列,多列联动的选择场景。(从1.3.0版本起,不建议使用Picker组件的单列和多列模式,Select组件是专门为列选择而构造的组件,更简单易用。)
95
- * @tutorial https://uviewpro.cn/zh/components/select.html
96
- * @property {String} mode 模式选择,"single-column"-单列模式,"mutil-column"-多列模式,"mutil-column-auto"-多列联动模式
97
- * @property {Array} list 列数据,数组形式,见官网说明
98
- * @property {Boolean} v-model 布尔值变量,用于控制选择器的弹出与收起
99
- * @property {Boolean} safe-area-inset-bottom 是否开启底部安全区适配(默认false)
100
- * @property {String} cancel-color 取消按钮的颜色(默认var(--u-content-color))
101
- * @property {String} confirm-color 确认按钮的颜色(默认主题色primary)
102
- * @property {String} confirm-text 确认按钮的文字
103
- * @property {String} cancel-text 取消按钮的文字
104
- * @property {String} default-value 提供的默认选中的下标,见官网说明
105
- * @property {Boolean} mask-close-able 是否允许通过点击遮罩关闭Picker(默认true)
106
- * @property {String Number} z-index 弹出时的z-index值(默认10075)
107
- * @property {String} value-name 自定义list数据的value属性名 1.3.6
108
- * @property {String} label-name 自定义list数据的label属性名 1.3.6
109
- * @property {String} child-name 自定义list数据的children属性名,只对多列联动模式有效 1.3.7
110
- * @event {Function} confirm 点击确定按钮,返回当前选择的值
111
- * @example <u-select v-model="show" :list="list"></u-select>
112
- */
113
-
114
- const props = defineProps(SelectProps);
115
- const emit = defineEmits(['update:modelValue', 'confirm', 'cancel', 'click']);
116
- const { t } = useLocale();
117
-
118
- // 用于列改变时,保存当前的索引,下一次变化时比较得出是哪一列发生了变化
119
- const defaultSelector = ref<number[]>([0]);
120
- // picker-view的数据
121
- const columnData = ref<SelectListItem[][]>([]);
122
- // 控制 picker 是否渲染(等待初始化完成)
123
- // 初始为 false,确保 picker-view 原生组件在数据就绪后才创建(抖音小程序等平台需要在创建时就有完整数据)
124
- const readyToRender = ref(false);
125
- // 保存用户上次确认的索引,如果用户未确认过,则为 null,首次打开会使用 props.defaultValue
126
- const savedSelector = ref<number[] | null>(
127
- props.defaultValue && props.defaultValue.length ? props.defaultValue.slice() : null
128
- );
129
- // 每次队列发生变化时,保存选择的结果
130
- const selectValue = ref<SelectListItem[]>([]);
131
- // 上一次列变化时的index
132
- const lastSelectIndex = ref<number[]>([]);
133
- // 列数
134
- const columnNum = ref(0);
135
- // 列是否还在滑动中,微信小程序如果在滑动中就点确定,结果可能不准确
136
- const moving = ref(false);
137
- // 如果用户有传递z-index值,优先使用
138
- const uZIndex = computed(() => (props.zIndex ? props.zIndex : $u.zIndex.popup));
139
-
140
- const popupValue = computed({
141
- get: () => props.modelValue,
142
- set: (val: boolean) => emit('update:modelValue', val)
143
- });
144
-
145
- // 国际化计算属性
146
- const getCancelText = computed(() => props.cancelText || t('uSelect.cancelText'));
147
- const getConfirmText = computed(() => props.confirmText || t('uSelect.confirmText'));
148
-
149
- watch(
150
- () => props.modelValue,
151
- async val => {
152
- if (val) {
153
- // 同步调用 init(),确保 columnData 在 picker-view 渲染前就填充完毕
154
- // 这对抖音等小程序平台至关重要:原生 picker-view 需要在创建时就有完整数据
155
- init();
156
- readyToRender.value = true;
157
- // 在 App(APP-PLUS)平台上,原生 picker 可能需要更长时间初始化
158
- // #ifdef APP-PLUS
159
- await nextTick();
160
- await new Promise(resolve => setTimeout(resolve, 20));
161
- // #endif
162
- } else {
163
- // 关闭弹窗时复位,下次打开时 picker-view 会重新创建,确保数据刷新
164
- readyToRender.value = false;
165
- }
166
- },
167
- { immediate: true }
168
- );
169
- // 标识滑动开始,只有微信小程序才有这样的事件
170
- function pickstart() {
171
- // #ifdef MP-WEIXIN
172
- moving.value = true;
173
- // #endif
174
- }
175
- function pickend() {
176
- // #ifdef MP-WEIXIN
177
- moving.value = false;
178
- // #endif
179
- }
180
-
181
- function init() {
182
- // 先计算列数
183
- setColumnNum();
184
- // 根据 columnData 和 columnNum 设置默认选中
185
- setDefaultSelector();
186
- // 准备列数据(部分模式需要依赖 defaultSelector 的值,但我们将先生成columnData的结构)
187
- setColumnData();
188
- // 清空并设置 selectValue
189
- selectValue.value = [];
190
- setSelectValue();
191
- }
192
-
193
- // 获取默认选中列下标
194
- function setDefaultSelector() {
195
- // 根据 preserveSelection 决定优先级:
196
- // - 如果 preserveSelection 为 true(默认),优先使用用户已确认的选择 savedSelector(如果存在),否则使用 props.defaultValue
197
- // - 如果 preserveSelection 为 false,则优先使用外部 props.defaultValue(如果存在),否则使用 savedSelector
198
- let useDefault: number[] | null = null;
199
- if (props.preserveSelection) {
200
- useDefault = savedSelector.value && savedSelector.value.length ? savedSelector.value : props.defaultValue;
201
- } else {
202
- useDefault = props.defaultValue && props.defaultValue.length ? props.defaultValue : savedSelector.value;
203
- }
204
- // 如果没有传入默认选中的值,生成长度为 columnNum,用0填充的数组
205
- defaultSelector.value =
206
- useDefault && useDefault.length == columnNum.value ? useDefault.slice() : Array(columnNum.value).fill(0);
207
- lastSelectIndex.value = [...defaultSelector.value];
208
- }
209
- // 计算列数
210
- function setColumnNum() {
211
- // 单列的列数为1
212
- if (props.mode == 'single-column') columnNum.value = 1;
213
- // 多列时,this.list数组长度就是列数
214
- else if (props.mode == 'mutil-column') columnNum.value = props.list.length;
215
- // 多列联动时,通过历遍this.list的第一个元素,得出有多少列
216
- else if (props.mode == 'mutil-column-auto') {
217
- let num = 1;
218
- let column: any = props.list;
219
- // 只要有元素并且第一个元素有children属性,继续遍历
220
- while (Array.isArray(column) && column[0] && typeof column[0] === 'object' && props.childName in column[0]) {
221
- column = column[0][props.childName];
222
- num++;
223
- }
224
- columnNum.value = num;
225
- }
226
- }
227
-
228
- // 获取需要展示在picker中的列数据
229
- function setColumnData() {
230
- let data: SelectListItem[][] = [];
231
- selectValue.value = [];
232
- if (props.mode == 'mutil-column-auto') {
233
- // 获得所有数据中的第一个元素
234
- let column: any = props.list[defaultSelector.value.length ? defaultSelector.value[0] : 0];
235
- // 通过循环所有的列数,再根据设定列的数组,得出当前需要渲染的整个列数组
236
- for (let i = 0; i < columnNum.value; i++) {
237
- // 第一列默认为整个list数组
238
- if (i == 0) {
239
- data[i] = is2DList(props.list) ? props.list[i] || [] : (props.list as SelectListItem[]);
240
- column = column && typeof column === 'object' ? column[props.childName] : [];
241
- } else {
242
- // 大于第一列时,判断是否有默认选中的,如果没有就用该列的第一项
243
- data[i] = Array.isArray(column) ? column : [];
244
- column =
245
- Array.isArray(column) &&
246
- column[defaultSelector.value[i]] &&
247
- typeof column[defaultSelector.value[i]] === 'object'
248
- ? column[defaultSelector.value[i]][props.childName]
249
- : [];
250
- }
251
- }
252
- } else if (props.mode == 'single-column') {
253
- data[0] = Array.isArray(props.list) && !is2DList(props.list) ? (props.list as SelectListItem[]) : [];
254
- } else if (props.mode == 'mutil-column') {
255
- data = is2DList(props.list) ? props.list : [props.list as SelectListItem[]];
256
- }
257
- columnData.value = data;
258
- }
259
-
260
- // 获取默认选中的值,如果没有设置defaultValue,就默认选中每列的第一个
261
- function setSelectValue() {
262
- for (let i = 0; i < columnNum.value; i++) {
263
- const tmp = columnData.value[i][defaultSelector.value[i]];
264
- let data: any = {
265
- value: tmp ? tmp[props.valueName] : null,
266
- label: tmp ? tmp[props.labelName] : null
267
- };
268
-
269
- // 判断是否存在额外的参数,如果存在,就返回
270
- if (tmp && tmp.extra !== undefined) data.extra = tmp.extra;
271
- selectValue.value.push(data);
272
- }
273
- }
274
-
275
- // 列选项
276
- function columnChange(e: any) {
277
- let index: number = -1;
278
- const columnIndex = e.detail.value;
279
- // 由于后面是需要push进数组的,所以需要先清空数组
280
- selectValue.value = [];
281
- defaultSelector.value = columnIndex;
282
- if (props.mode == 'mutil-column-auto') {
283
- // 对比前后两个数组,寻找变更的是哪一列,如果某一个元素不同,即可判定该列发生了变化
284
- lastSelectIndex.value.map((val, idx) => {
285
- if (val != columnIndex[idx]) index = idx;
286
- });
287
- for (let i = index + 1; i < columnNum.value; i++) {
288
- // 当前变化列的下一列的数据,需要获取上一列的数据,同时需要指定是上一列的第几个的children,再往后的
289
- // 默认是队列的第一个为默认选项
290
- const prevCol = columnData.value[i - 1];
291
- const prevIdx = i - 1 == index ? columnIndex[index] : 0;
292
- columnData.value[i] =
293
- Array.isArray(prevCol) && prevCol[prevIdx] && typeof prevCol[prevIdx] === 'object'
294
- ? prevCol[prevIdx][props.childName]
295
- : [];
296
- // 改变的列之后的所有列,默认选中第一个
297
- defaultSelector.value[i] = 0;
298
- }
299
- // 在历遍的过程中,可能由于上一步修改this.columnData,导致产生连锁反应,程序触发columnChange,会有多次调用
300
- // 只有在最后一次数据稳定后的结果是正确的,此前的历遍中,可能会产生undefined,故需要判断
301
- columnIndex.map((item: any, idx: number) => {
302
- let data = columnData.value[idx][columnIndex[idx]];
303
- let tmp: any = {
304
- value: data ? data[props.valueName] : null,
305
- label: data ? data[props.labelName] : null
306
- };
307
- // 判断是否有需要额外携带的参数
308
- if (data && data.extra !== undefined) tmp.extra = data.extra;
309
- selectValue.value.push(tmp);
310
- });
311
- // 保存这一次的结果,用于下次列发生变化时作比较
312
- lastSelectIndex.value = [...columnIndex];
313
- } else if (props.mode == 'single-column') {
314
- let data = columnData.value[0][columnIndex[0]];
315
- // 初始默认选中值
316
- let tmp: any = {
317
- value: data ? data[props.valueName] : null,
318
- label: data ? data[props.labelName] : null
319
- };
320
- // 判断是否有需要额外携带的参数
321
- if (data && data.extra !== undefined) tmp.extra = data.extra;
322
- selectValue.value.push(tmp);
323
- } else if (props.mode == 'mutil-column') {
324
- // 初始默认选中值
325
- columnIndex.map((item: any, idx: number) => {
326
- let data = columnData.value[idx][columnIndex[idx]];
327
- // 初始默认选中值
328
- let tmp: any = {
329
- value: data ? data[props.valueName] : null,
330
- label: data ? data[props.labelName] : null
331
- };
332
- // 判断是否有需要额外携带的参数
333
- if (data && data.extra !== undefined) tmp.extra = data.extra;
334
- selectValue.value.push(tmp);
335
- });
336
- }
337
- }
338
-
339
- function close() {
340
- emit('update:modelValue', false);
341
- // 重置default-value默认值
342
- // defaultSelector.value = [0];
343
- }
344
- // 点击确定或者取消
345
- function getResult(event: 'update:modelValue' | 'confirm' | 'cancel' | 'click' | null = null) {
346
- // #ifdef MP-WEIXIN
347
- if (moving.value) return;
348
- // #endif
349
-
350
- if (event) emit(event, selectValue.value);
351
- // 如果是用户确认,则保存已确认的索引,作为下次打开时的默认值
352
- if (event === 'confirm') {
353
- // deep copy
354
- savedSelector.value = defaultSelector.value ? defaultSelector.value.slice() : null;
355
- }
356
- close();
357
- }
358
-
359
- function selectHandler() {
360
- emit('click');
361
- }
362
-
363
- // 类型守卫提前声明
364
- function is2DList(list: SelectListItem[] | SelectListItem[][]): list is SelectListItem[][] {
365
- return Array.isArray(list) && list.length > 0 && Array.isArray(list[0]);
366
- }
367
- </script>
368
-
369
- <style scoped lang="scss">
370
- @import '../../libs/css/style.components.scss';
371
-
372
- .u-select {
373
- &__action {
374
- position: relative;
375
- line-height: 70rpx;
376
- height: 70rpx;
377
-
378
- &__icon {
379
- position: absolute;
380
- right: 20rpx;
381
- top: 50%;
382
- transition: transform 0.4s;
383
- transform: translateY(-50%);
384
- z-index: 1;
385
-
386
- &--reverse {
387
- transform: rotate(-180deg) translateY(50%);
388
- }
389
- }
390
- }
391
-
392
- &--border {
393
- border-radius: 6rpx;
394
- border-radius: 4px;
395
- border: 1px solid $u-border-color;
396
- }
397
-
398
- &__header {
399
- @include vue-flex;
400
- align-items: center;
401
- justify-content: space-between;
402
- height: 80rpx;
403
- position: relative;
404
-
405
- &__title {
406
- color: $u-content-color;
407
- }
408
-
409
- &__btn {
410
- min-width: 150rpx;
411
- padding: 20rpx 30rpx;
412
- }
413
- }
414
-
415
- &__header::after {
416
- content: '';
417
- position: absolute;
418
- border-bottom: 1rpx solid var(--u-border-color);
419
- -webkit-transform: scaleY(0.5);
420
- transform: scaleY(0.5);
421
- bottom: 0;
422
- right: 0;
423
- left: 0;
424
- }
425
-
426
- &__body {
427
- width: 100%;
428
- height: 500rpx;
429
- overflow: hidden;
430
- background-color: var(--u-bg-white);
431
-
432
- &__picker-view {
433
- height: 100%;
434
- box-sizing: border-box;
435
-
436
- &__item {
437
- @include vue-flex;
438
- align-items: center;
439
- justify-content: center;
440
- font-size: 32rpx;
441
- color: $u-main-color;
442
- padding: 0 8rpx;
443
- }
444
- }
445
- }
446
- }
447
- </style>
1
+ <template>
2
+ <view class="u-select" :class="customClass" :style="$u.toStyle(customStyle)">
3
+ <!-- <view class="u-select__action" :class="{
4
+ 'u-select--border': border
5
+ }" @tap.stop="selectHandler">
6
+ <view class="u-select__action__icon" :class="{
7
+ 'u-select__action__icon--reverse': value == true
8
+ }">
9
+ <u-icon name="arrow-down-fill" size="26" color="var(--u-light-color)"></u-icon>
10
+ </view>
11
+ </view> -->
12
+ <u-popup
13
+ :maskCloseAble="maskCloseAble"
14
+ mode="bottom"
15
+ :popup="false"
16
+ v-model="popupValue"
17
+ length="auto"
18
+ :safeAreaInsetBottom="safeAreaInsetBottom"
19
+ @close="close"
20
+ :z-index="uZIndex"
21
+ >
22
+ <view class="u-select">
23
+ <view class="u-select__header" @touchmove.stop.prevent="">
24
+ <view
25
+ class="u-select__header__cancel u-select__header__btn"
26
+ :style="{ color: cancelColor }"
27
+ hover-class="u-hover-class"
28
+ :hover-stay-time="150"
29
+ @tap="getResult('cancel')"
30
+ >
31
+ {{ getCancelText }}
32
+ </view>
33
+ <view class="u-select__header__title u-line-1"> {{ title }}</view>
34
+ <view
35
+ class="u-select__header__confirm u-select__header__btn"
36
+ :style="{ color: moving ? cancelColor : confirmColor }"
37
+ hover-class="u-hover-class"
38
+ :hover-stay-time="150"
39
+ @touchmove.stop=""
40
+ @tap.stop="getResult('confirm')"
41
+ >
42
+ {{ getConfirmText }}
43
+ </view>
44
+ </view>
45
+ <view class="u-select__body">
46
+ <picker-view
47
+ v-if="modelValue && readyToRender"
48
+ :value="defaultSelector"
49
+ class="u-select__body__picker-view"
50
+ mask-class="u-picker-view-mask"
51
+ indicator-class="u-picker-view-indicator"
52
+ @pickstart="pickstart"
53
+ @pickend="pickend"
54
+ @change="columnChange"
55
+ >
56
+ <picker-view-column v-for="(item, index) in columnData" :key="index">
57
+ <view
58
+ class="u-select__body__picker-view__item"
59
+ v-for="(item1, index1) in item"
60
+ :key="index1"
61
+ >
62
+ <view class="u-line-1">{{ item1[labelName] }}</view>
63
+ </view>
64
+ </picker-view-column>
65
+ </picker-view>
66
+ </view>
67
+ </view>
68
+ </u-popup>
69
+ </view>
70
+ </template>
71
+
72
+ <script lang="ts">
73
+ export default {
74
+ name: 'u-select',
75
+ options: {
76
+ addGlobalClass: true,
77
+ // #ifndef MP-TOUTIAO
78
+ virtualHost: true,
79
+ // #endif
80
+ styleIsolation: 'shared'
81
+ }
82
+ };
83
+ </script>
84
+
85
+ <script setup lang="ts">
86
+ import { ref, computed, watch, nextTick } from 'vue';
87
+ import { SelectProps } from './types';
88
+ import type { SelectListItem } from '../../types/global';
89
+ import { $u, useLocale } from '../..';
90
+ import uPopup from '../u-popup/u-popup.vue';
91
+
92
+ /**
93
+ * select 列选择器
94
+ * @description 此选择器用于单列,多列,多列联动的选择场景。(从1.3.0版本起,不建议使用Picker组件的单列和多列模式,Select组件是专门为列选择而构造的组件,更简单易用。)
95
+ * @tutorial https://uviewpro.cn/zh/components/select.html
96
+ * @property {String} mode 模式选择,"single-column"-单列模式,"mutil-column"-多列模式,"mutil-column-auto"-多列联动模式
97
+ * @property {Array} list 列数据,数组形式,见官网说明
98
+ * @property {Boolean} v-model 布尔值变量,用于控制选择器的弹出与收起
99
+ * @property {Boolean} safe-area-inset-bottom 是否开启底部安全区适配(默认false)
100
+ * @property {String} cancel-color 取消按钮的颜色(默认var(--u-content-color))
101
+ * @property {String} confirm-color 确认按钮的颜色(默认主题色primary)
102
+ * @property {String} confirm-text 确认按钮的文字
103
+ * @property {String} cancel-text 取消按钮的文字
104
+ * @property {String} default-value 提供的默认选中的下标,见官网说明
105
+ * @property {Boolean} mask-close-able 是否允许通过点击遮罩关闭Picker(默认true)
106
+ * @property {String Number} z-index 弹出时的z-index值(默认10075)
107
+ * @property {String} value-name 自定义list数据的value属性名 1.3.6
108
+ * @property {String} label-name 自定义list数据的label属性名 1.3.6
109
+ * @property {String} child-name 自定义list数据的children属性名,只对多列联动模式有效 1.3.7
110
+ * @event {Function} confirm 点击确定按钮,返回当前选择的值
111
+ * @example <u-select v-model="show" :list="list"></u-select>
112
+ */
113
+
114
+ const props = defineProps(SelectProps);
115
+ const emit = defineEmits(['update:modelValue', 'confirm', 'cancel', 'click']);
116
+ const { t } = useLocale();
117
+
118
+ // 用于列改变时,保存当前的索引,下一次变化时比较得出是哪一列发生了变化
119
+ const defaultSelector = ref<number[]>([0]);
120
+ // picker-view的数据
121
+ const columnData = ref<SelectListItem[][]>([]);
122
+ // 控制 picker 是否渲染(等待初始化完成)
123
+ // 初始为 false,确保 picker-view 原生组件在数据就绪后才创建(抖音小程序等平台需要在创建时就有完整数据)
124
+ const readyToRender = ref(false);
125
+ // 保存用户上次确认的索引,如果用户未确认过,则为 null,首次打开会使用 props.defaultValue
126
+ const savedSelector = ref<number[] | null>(
127
+ props.defaultValue && props.defaultValue.length ? props.defaultValue.slice() : null
128
+ );
129
+ // 每次队列发生变化时,保存选择的结果
130
+ const selectValue = ref<SelectListItem[]>([]);
131
+ // 上一次列变化时的index
132
+ const lastSelectIndex = ref<number[]>([]);
133
+ // 列数
134
+ const columnNum = ref(0);
135
+ // 列是否还在滑动中,微信小程序如果在滑动中就点确定,结果可能不准确
136
+ const moving = ref(false);
137
+ // 如果用户有传递z-index值,优先使用
138
+ const uZIndex = computed(() => (props.zIndex ? props.zIndex : $u.zIndex.popup));
139
+
140
+ const popupValue = computed({
141
+ get: () => props.modelValue,
142
+ set: (val: boolean) => emit('update:modelValue', val)
143
+ });
144
+
145
+ // 国际化计算属性
146
+ const getCancelText = computed(() => props.cancelText || t('uSelect.cancelText'));
147
+ const getConfirmText = computed(() => props.confirmText || t('uSelect.confirmText'));
148
+
149
+ watch(
150
+ () => props.modelValue,
151
+ async val => {
152
+ if (val) {
153
+ // 同步调用 init(),确保 columnData 在 picker-view 渲染前就填充完毕
154
+ // 这对抖音等小程序平台至关重要:原生 picker-view 需要在创建时就有完整数据
155
+ init();
156
+ readyToRender.value = true;
157
+ // 在 App(APP-PLUS)平台上,原生 picker 可能需要更长时间初始化
158
+ // #ifdef APP-PLUS
159
+ await nextTick();
160
+ await new Promise(resolve => setTimeout(resolve, 20));
161
+ // #endif
162
+ } else {
163
+ // 关闭弹窗时复位,下次打开时 picker-view 会重新创建,确保数据刷新
164
+ readyToRender.value = false;
165
+ }
166
+ },
167
+ { immediate: true }
168
+ );
169
+ // 标识滑动开始,只有微信小程序才有这样的事件
170
+ function pickstart() {
171
+ // #ifdef MP-WEIXIN
172
+ moving.value = true;
173
+ // #endif
174
+ }
175
+ function pickend() {
176
+ // #ifdef MP-WEIXIN
177
+ moving.value = false;
178
+ // #endif
179
+ }
180
+
181
+ function init() {
182
+ // 先计算列数
183
+ setColumnNum();
184
+ // 根据 columnData 和 columnNum 设置默认选中
185
+ setDefaultSelector();
186
+ // 准备列数据(部分模式需要依赖 defaultSelector 的值,但我们将先生成columnData的结构)
187
+ setColumnData();
188
+ // 清空并设置 selectValue
189
+ selectValue.value = [];
190
+ setSelectValue();
191
+ }
192
+
193
+ // 获取默认选中列下标
194
+ function setDefaultSelector() {
195
+ // 根据 preserveSelection 决定优先级:
196
+ // - 如果 preserveSelection 为 true(默认),优先使用用户已确认的选择 savedSelector(如果存在),否则使用 props.defaultValue
197
+ // - 如果 preserveSelection 为 false,则优先使用外部 props.defaultValue(如果存在),否则使用 savedSelector
198
+ let useDefault: number[] | null = null;
199
+ if (props.preserveSelection) {
200
+ useDefault = savedSelector.value && savedSelector.value.length ? savedSelector.value : props.defaultValue;
201
+ } else {
202
+ useDefault = props.defaultValue && props.defaultValue.length ? props.defaultValue : savedSelector.value;
203
+ }
204
+ // 如果没有传入默认选中的值,生成长度为 columnNum,用0填充的数组
205
+ defaultSelector.value =
206
+ useDefault && useDefault.length == columnNum.value ? useDefault.slice() : Array(columnNum.value).fill(0);
207
+ lastSelectIndex.value = [...defaultSelector.value];
208
+ }
209
+ // 计算列数
210
+ function setColumnNum() {
211
+ // 单列的列数为1
212
+ if (props.mode == 'single-column') columnNum.value = 1;
213
+ // 多列时,this.list数组长度就是列数
214
+ else if (props.mode == 'mutil-column') columnNum.value = props.list.length;
215
+ // 多列联动时,通过历遍this.list的第一个元素,得出有多少列
216
+ else if (props.mode == 'mutil-column-auto') {
217
+ let num = 1;
218
+ let column: any = props.list;
219
+ // 只要有元素并且第一个元素有children属性,继续遍历
220
+ while (Array.isArray(column) && column[0] && typeof column[0] === 'object' && props.childName in column[0]) {
221
+ column = column[0][props.childName];
222
+ num++;
223
+ }
224
+ columnNum.value = num;
225
+ }
226
+ }
227
+
228
+ // 获取需要展示在picker中的列数据
229
+ function setColumnData() {
230
+ let data: SelectListItem[][] = [];
231
+ selectValue.value = [];
232
+ if (props.mode == 'mutil-column-auto') {
233
+ // 获得所有数据中的第一个元素
234
+ let column: any = props.list[defaultSelector.value.length ? defaultSelector.value[0] : 0];
235
+ // 通过循环所有的列数,再根据设定列的数组,得出当前需要渲染的整个列数组
236
+ for (let i = 0; i < columnNum.value; i++) {
237
+ // 第一列默认为整个list数组
238
+ if (i == 0) {
239
+ data[i] = is2DList(props.list) ? props.list[i] || [] : (props.list as SelectListItem[]);
240
+ column = column && typeof column === 'object' ? column[props.childName] : [];
241
+ } else {
242
+ // 大于第一列时,判断是否有默认选中的,如果没有就用该列的第一项
243
+ data[i] = Array.isArray(column) ? column : [];
244
+ column =
245
+ Array.isArray(column) &&
246
+ column[defaultSelector.value[i]] &&
247
+ typeof column[defaultSelector.value[i]] === 'object'
248
+ ? column[defaultSelector.value[i]][props.childName]
249
+ : [];
250
+ }
251
+ }
252
+ } else if (props.mode == 'single-column') {
253
+ data[0] = Array.isArray(props.list) && !is2DList(props.list) ? (props.list as SelectListItem[]) : [];
254
+ } else if (props.mode == 'mutil-column') {
255
+ data = is2DList(props.list) ? props.list : [props.list as SelectListItem[]];
256
+ }
257
+ columnData.value = data;
258
+ }
259
+
260
+ // 获取默认选中的值,如果没有设置defaultValue,就默认选中每列的第一个
261
+ function setSelectValue() {
262
+ for (let i = 0; i < columnNum.value; i++) {
263
+ const tmp = columnData.value[i][defaultSelector.value[i]];
264
+ let data: any = {
265
+ value: tmp ? tmp[props.valueName] : null,
266
+ label: tmp ? tmp[props.labelName] : null
267
+ };
268
+
269
+ // 判断是否存在额外的参数,如果存在,就返回
270
+ if (tmp && tmp.extra !== undefined) data.extra = tmp.extra;
271
+ selectValue.value.push(data);
272
+ }
273
+ }
274
+
275
+ // 列选项
276
+ function columnChange(e: any) {
277
+ let index: number = -1;
278
+ const columnIndex = e.detail.value;
279
+ // 由于后面是需要push进数组的,所以需要先清空数组
280
+ selectValue.value = [];
281
+ defaultSelector.value = columnIndex;
282
+ if (props.mode == 'mutil-column-auto') {
283
+ // 对比前后两个数组,寻找变更的是哪一列,如果某一个元素不同,即可判定该列发生了变化
284
+ lastSelectIndex.value.map((val, idx) => {
285
+ if (val != columnIndex[idx]) index = idx;
286
+ });
287
+ for (let i = index + 1; i < columnNum.value; i++) {
288
+ // 当前变化列的下一列的数据,需要获取上一列的数据,同时需要指定是上一列的第几个的children,再往后的
289
+ // 默认是队列的第一个为默认选项
290
+ const prevCol = columnData.value[i - 1];
291
+ const prevIdx = i - 1 == index ? columnIndex[index] : 0;
292
+ columnData.value[i] =
293
+ Array.isArray(prevCol) && prevCol[prevIdx] && typeof prevCol[prevIdx] === 'object'
294
+ ? prevCol[prevIdx][props.childName]
295
+ : [];
296
+ // 改变的列之后的所有列,默认选中第一个
297
+ defaultSelector.value[i] = 0;
298
+ }
299
+ // 在历遍的过程中,可能由于上一步修改this.columnData,导致产生连锁反应,程序触发columnChange,会有多次调用
300
+ // 只有在最后一次数据稳定后的结果是正确的,此前的历遍中,可能会产生undefined,故需要判断
301
+ columnIndex.map((item: any, idx: number) => {
302
+ let data = columnData.value[idx][columnIndex[idx]];
303
+ let tmp: any = {
304
+ value: data ? data[props.valueName] : null,
305
+ label: data ? data[props.labelName] : null
306
+ };
307
+ // 判断是否有需要额外携带的参数
308
+ if (data && data.extra !== undefined) tmp.extra = data.extra;
309
+ selectValue.value.push(tmp);
310
+ });
311
+ // 保存这一次的结果,用于下次列发生变化时作比较
312
+ lastSelectIndex.value = [...columnIndex];
313
+ } else if (props.mode == 'single-column') {
314
+ let data = columnData.value[0][columnIndex[0]];
315
+ // 初始默认选中值
316
+ let tmp: any = {
317
+ value: data ? data[props.valueName] : null,
318
+ label: data ? data[props.labelName] : null
319
+ };
320
+ // 判断是否有需要额外携带的参数
321
+ if (data && data.extra !== undefined) tmp.extra = data.extra;
322
+ selectValue.value.push(tmp);
323
+ } else if (props.mode == 'mutil-column') {
324
+ // 初始默认选中值
325
+ columnIndex.map((item: any, idx: number) => {
326
+ let data = columnData.value[idx][columnIndex[idx]];
327
+ // 初始默认选中值
328
+ let tmp: any = {
329
+ value: data ? data[props.valueName] : null,
330
+ label: data ? data[props.labelName] : null
331
+ };
332
+ // 判断是否有需要额外携带的参数
333
+ if (data && data.extra !== undefined) tmp.extra = data.extra;
334
+ selectValue.value.push(tmp);
335
+ });
336
+ }
337
+ }
338
+
339
+ function close() {
340
+ emit('update:modelValue', false);
341
+ // 重置default-value默认值
342
+ // defaultSelector.value = [0];
343
+ }
344
+ // 点击确定或者取消
345
+ function getResult(event: 'update:modelValue' | 'confirm' | 'cancel' | 'click' | null = null) {
346
+ // #ifdef MP-WEIXIN
347
+ if (moving.value) return;
348
+ // #endif
349
+
350
+ if (event) emit(event, selectValue.value);
351
+ // 如果是用户确认,则保存已确认的索引,作为下次打开时的默认值
352
+ if (event === 'confirm') {
353
+ // deep copy
354
+ savedSelector.value = defaultSelector.value ? defaultSelector.value.slice() : null;
355
+ }
356
+ close();
357
+ }
358
+
359
+ function selectHandler() {
360
+ emit('click');
361
+ }
362
+
363
+ // 类型守卫提前声明
364
+ function is2DList(list: SelectListItem[] | SelectListItem[][]): list is SelectListItem[][] {
365
+ return Array.isArray(list) && list.length > 0 && Array.isArray(list[0]);
366
+ }
367
+ </script>
368
+
369
+ <style scoped lang="scss">
370
+ @import '../../libs/css/style.components.scss';
371
+
372
+ .u-select {
373
+ &__action {
374
+ position: relative;
375
+ line-height: 70rpx;
376
+ height: 70rpx;
377
+
378
+ &__icon {
379
+ position: absolute;
380
+ right: 20rpx;
381
+ top: 50%;
382
+ transition: transform 0.4s;
383
+ transform: translateY(-50%);
384
+ z-index: 1;
385
+
386
+ &--reverse {
387
+ transform: rotate(-180deg) translateY(50%);
388
+ }
389
+ }
390
+ }
391
+
392
+ &--border {
393
+ border-radius: 6rpx;
394
+ border-radius: 4px;
395
+ border: 1px solid $u-border-color;
396
+ }
397
+
398
+ &__header {
399
+ @include vue-flex;
400
+ align-items: center;
401
+ justify-content: space-between;
402
+ height: 80rpx;
403
+ position: relative;
404
+
405
+ &__title {
406
+ color: $u-content-color;
407
+ }
408
+
409
+ &__btn {
410
+ min-width: 150rpx;
411
+ padding: 20rpx 30rpx;
412
+ }
413
+ }
414
+
415
+ &__header::after {
416
+ content: '';
417
+ position: absolute;
418
+ border-bottom: 1rpx solid var(--u-border-color);
419
+ -webkit-transform: scaleY(0.5);
420
+ transform: scaleY(0.5);
421
+ bottom: 0;
422
+ right: 0;
423
+ left: 0;
424
+ }
425
+
426
+ &__body {
427
+ width: 100%;
428
+ height: 500rpx;
429
+ overflow: hidden;
430
+ background-color: var(--u-bg-white);
431
+
432
+ &__picker-view {
433
+ height: 100%;
434
+ box-sizing: border-box;
435
+
436
+ &__item {
437
+ @include vue-flex;
438
+ align-items: center;
439
+ justify-content: center;
440
+ font-size: 32rpx;
441
+ color: $u-main-color;
442
+ padding: 0 8rpx;
443
+ }
444
+ }
445
+ }
446
+ }
447
+ </style>