uview-pro 0.0.1

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 (149) hide show
  1. package/changelog.md +6 -0
  2. package/components/u-action-sheet/u-action-sheet.vue +205 -0
  3. package/components/u-alert-tips/u-alert-tips.vue +241 -0
  4. package/components/u-avatar/u-avatar.vue +220 -0
  5. package/components/u-avatar-cropper/u-avatar-cropper.vue +329 -0
  6. package/components/u-avatar-cropper/weCropper.d.ts +54 -0
  7. package/components/u-avatar-cropper/weCropper.js +1267 -0
  8. package/components/u-avatar-cropper/weCropper.ts +1254 -0
  9. package/components/u-back-top/u-back-top.vue +156 -0
  10. package/components/u-badge/u-badge.vue +189 -0
  11. package/components/u-button/u-button.vue +562 -0
  12. package/components/u-calendar/u-calendar.vue +725 -0
  13. package/components/u-car-keyboard/u-car-keyboard.vue +236 -0
  14. package/components/u-card/u-card.vue +240 -0
  15. package/components/u-cell-group/u-cell-group.vue +56 -0
  16. package/components/u-cell-item/u-cell-item.vue +245 -0
  17. package/components/u-checkbox/u-checkbox.vue +310 -0
  18. package/components/u-checkbox-group/u-checkbox-group.vue +134 -0
  19. package/components/u-circle-progress/u-circle-progress.vue +210 -0
  20. package/components/u-col/u-col.vue +135 -0
  21. package/components/u-collapse/u-collapse.vue +82 -0
  22. package/components/u-collapse-item/u-collapse-item.vue +190 -0
  23. package/components/u-column-notice/u-column-notice.vue +264 -0
  24. package/components/u-count-down/u-count-down.vue +333 -0
  25. package/components/u-count-to/u-count-to.vue +297 -0
  26. package/components/u-divider/u-divider.vue +141 -0
  27. package/components/u-dropdown/u-dropdown.vue +311 -0
  28. package/components/u-dropdown-item/u-dropdown-item.vue +135 -0
  29. package/components/u-empty/u-empty.vue +111 -0
  30. package/components/u-field/u-field.vue +469 -0
  31. package/components/u-form/u-form.vue +162 -0
  32. package/components/u-form-item/u-form-item.vue +476 -0
  33. package/components/u-full-screen/u-full-screen.vue +80 -0
  34. package/components/u-gap/u-gap.vue +48 -0
  35. package/components/u-grid/u-grid.vue +101 -0
  36. package/components/u-grid-item/u-grid-item.vue +136 -0
  37. package/components/u-icon/u-icon.vue +389 -0
  38. package/components/u-image/types.ts +48 -0
  39. package/components/u-image/u-image.vue +218 -0
  40. package/components/u-index-anchor/u-index-anchor.vue +101 -0
  41. package/components/u-index-list/u-index-list.vue +376 -0
  42. package/components/u-input/u-input.vue +462 -0
  43. package/components/u-keyboard/u-keyboard.vue +188 -0
  44. package/components/u-lazy-load/u-lazy-load.vue +288 -0
  45. package/components/u-line/u-line.vue +71 -0
  46. package/components/u-line-progress/u-line-progress.vue +128 -0
  47. package/components/u-link/u-link.vue +87 -0
  48. package/components/u-loading/u-loading.vue +111 -0
  49. package/components/u-loadmore/u-loadmore.vue +205 -0
  50. package/components/u-mask/u-mask.vue +137 -0
  51. package/components/u-message-input/u-message-input.vue +315 -0
  52. package/components/u-modal/u-modal.vue +284 -0
  53. package/components/u-navbar/u-navbar.vue +314 -0
  54. package/components/u-no-network/image.ts +2 -0
  55. package/components/u-no-network/u-no-network.vue +311 -0
  56. package/components/u-notice-bar/u-notice-bar.vue +274 -0
  57. package/components/u-number-box/u-number-box.vue +344 -0
  58. package/components/u-number-keyboard/u-number-keyboard.vue +170 -0
  59. package/components/u-parse/libs/CssHandler.js +100 -0
  60. package/components/u-parse/libs/MpHtmlParser.js +580 -0
  61. package/components/u-parse/libs/config.js +80 -0
  62. package/components/u-parse/libs/handler.wxs +22 -0
  63. package/components/u-parse/libs/trees.vue +505 -0
  64. package/components/u-parse/u-parse.vue +645 -0
  65. package/components/u-picker/u-picker.vue +808 -0
  66. package/components/u-popup/u-popup.vue +404 -0
  67. package/components/u-radio/u-radio.vue +272 -0
  68. package/components/u-radio-group/u-radio-group.vue +116 -0
  69. package/components/u-rate/u-rate.vue +349 -0
  70. package/components/u-read-more/u-read-more.vue +199 -0
  71. package/components/u-row/u-row.vue +95 -0
  72. package/components/u-row-notice/u-row-notice.vue +273 -0
  73. package/components/u-search/u-search.vue +298 -0
  74. package/components/u-section/u-section.vue +175 -0
  75. package/components/u-select/u-select.vue +387 -0
  76. package/components/u-skeleton/u-skeleton.vue +230 -0
  77. package/components/u-slider/u-slider.vue +293 -0
  78. package/components/u-steps/u-steps.vue +200 -0
  79. package/components/u-sticky/u-sticky.vue +189 -0
  80. package/components/u-subsection/u-subsection.vue +388 -0
  81. package/components/u-swipe-action/u-swipe-action.vue +289 -0
  82. package/components/u-swiper/u-swiper.vue +305 -0
  83. package/components/u-switch/u-switch.vue +146 -0
  84. package/components/u-tabbar/u-tabbar.vue +347 -0
  85. package/components/u-table/u-table.vue +104 -0
  86. package/components/u-tabs/u-tabs.vue +322 -0
  87. package/components/u-tabs-swiper/u-tabs-swiper.vue +426 -0
  88. package/components/u-tag/u-tag.vue +270 -0
  89. package/components/u-td/u-td.vue +76 -0
  90. package/components/u-th/u-th.vue +70 -0
  91. package/components/u-time-line/u-time-line.vue +39 -0
  92. package/components/u-time-line-item/u-time-line-item.vue +88 -0
  93. package/components/u-toast/types.ts +4 -0
  94. package/components/u-toast/u-toast.vue +238 -0
  95. package/components/u-top-tips/u-top-tips.vue +118 -0
  96. package/components/u-tr/u-tr.vue +24 -0
  97. package/components/u-upload/u-upload.vue +600 -0
  98. package/components/u-verification-code/u-verification-code.vue +194 -0
  99. package/components/u-waterfall/u-waterfall.vue +186 -0
  100. package/iconfont.css +910 -0
  101. package/index.scss +23 -0
  102. package/index.ts +166 -0
  103. package/libs/config/config.ts +26 -0
  104. package/libs/config/zIndex.ts +37 -0
  105. package/libs/css/color.scss +155 -0
  106. package/libs/css/common.scss +176 -0
  107. package/libs/css/style.components.scss +7 -0
  108. package/libs/css/style.h5.scss +8 -0
  109. package/libs/css/style.mp.scss +72 -0
  110. package/libs/css/style.nvue.scss +3 -0
  111. package/libs/css/style.vue.scss +175 -0
  112. package/libs/function/$parent.ts +22 -0
  113. package/libs/function/addUnit.ts +13 -0
  114. package/libs/function/color.ts +37 -0
  115. package/libs/function/colorGradient.ts +123 -0
  116. package/libs/function/debounce.ts +28 -0
  117. package/libs/function/deepClone.ts +39 -0
  118. package/libs/function/deepMerge.ts +34 -0
  119. package/libs/function/getParent.ts +59 -0
  120. package/libs/function/getRect.ts +26 -0
  121. package/libs/function/guid.ts +42 -0
  122. package/libs/function/md5.ts +397 -0
  123. package/libs/function/parent.ts +21 -0
  124. package/libs/function/queryParams.ts +60 -0
  125. package/libs/function/random.ts +16 -0
  126. package/libs/function/randomArray.ts +11 -0
  127. package/libs/function/route.ts +118 -0
  128. package/libs/function/sys.ts +15 -0
  129. package/libs/function/test.ts +229 -0
  130. package/libs/function/throttle.ts +31 -0
  131. package/libs/function/timeFormat.ts +54 -0
  132. package/libs/function/timeFrom.ts +48 -0
  133. package/libs/function/toast.ts +14 -0
  134. package/libs/function/trim.ts +21 -0
  135. package/libs/function/type2icon.ts +36 -0
  136. package/libs/hooks/useEmitter.ts +77 -0
  137. package/libs/hooks/useParent.ts +29 -0
  138. package/libs/request/index.ts +237 -0
  139. package/libs/store/index.ts +88 -0
  140. package/libs/util/area.ts +1 -0
  141. package/libs/util/async-validator.js +1356 -0
  142. package/libs/util/city.ts +1 -0
  143. package/libs/util/emitter.ts +112 -0
  144. package/libs/util/mitt.ts +118 -0
  145. package/libs/util/parent.ts +20 -0
  146. package/libs/util/province.ts +1 -0
  147. package/package.json +98 -0
  148. package/readme.md +165 -0
  149. package/theme.scss +38 -0
@@ -0,0 +1,175 @@
1
+ <template>
2
+ <view class="u-section">
3
+ <view
4
+ class="u-section__title"
5
+ :style="{
6
+ fontWeight: bold ? 'bold' : 'normal',
7
+ color: color,
8
+ fontSize: fontSize + 'rpx',
9
+ paddingLeft: showLine ? Number(fontSize) * 0.7 + 'rpx' : 0
10
+ }"
11
+ :class="{
12
+ 'u-section--line': showLine
13
+ }"
14
+ >
15
+ <view class="u-section__title__icon-wrap u-flex" :style="lineStyle" v-if="showLine">
16
+ <u-icon top="0" name="column-line" :size="Number(fontSize) * 1.25" bold :color="lineColor ? lineColor : color"></u-icon>
17
+ </view>
18
+ <text class="u-flex u-section__title__text">{{ title }}</text>
19
+ </view>
20
+ <view
21
+ class="u-section__right-info"
22
+ v-if="right || $slots.right"
23
+ :style="{
24
+ color: subColor
25
+ }"
26
+ @tap="rightClick"
27
+ >
28
+ <slot name="right" v-if="$slots.right" />
29
+ <template v-else>
30
+ {{ subTitle }}
31
+ <view class="u-section__right-info__icon-arrow u-flex" v-if="arrow">
32
+ <u-icon name="arrow-right" size="24" :color="subColor"></u-icon>
33
+ </view>
34
+ </template>
35
+ </view>
36
+ </view>
37
+ </template>
38
+
39
+ <script setup lang="ts">
40
+ import { computed } from 'vue';
41
+ import { $u } from '../..';
42
+
43
+ defineOptions({ name: 'u-section' });
44
+
45
+ /**
46
+ * section 查看更多
47
+ * @description 该组件一般用于分类信息有很多,但是限于篇幅只能列出一部分,让用户通过"查看更多"获得更多信息的场景,实际效果见演示。
48
+ * @tutorial https://www.uviewui.com/components/section.html
49
+ * @property {String} title 左边主标题
50
+ * @property {String} subTitle 右边副标题(默认更多)
51
+ * @property {Boolean} right 是否显示右边的内容(默认true)
52
+ * @property {Boolean} showLine 是否显示左边的竖条(默认true)
53
+ * @property {Boolean} arrow 是否显示右边箭头(默认true)
54
+ * @property {String|Number} fontSize 主标题的字体大小(默认28)
55
+ * @property {Boolean} bold 主标题是否加粗(默认true)
56
+ * @property {String} color 主标题颜色(默认#303133)
57
+ * @property {String} subColor 右边副标题颜色(默认#909399)
58
+ * @property {String} lineColor 左边竖线的颜色
59
+ * @event click 组件右侧的内容被点击时触发,用于跳转"更多"
60
+ * @example <u-section title="今日热门" :right="false"></u-section>
61
+ */
62
+
63
+ const props = defineProps({
64
+ /** 标题信息 */
65
+ title: {
66
+ type: String,
67
+ default: ''
68
+ },
69
+ /** 右边副标题内容 */
70
+ subTitle: {
71
+ type: String,
72
+ default: '更多'
73
+ },
74
+ /** 是否显示右边的内容 */
75
+ right: {
76
+ type: Boolean,
77
+ default: true
78
+ },
79
+ /** 主标题的字体大小 */
80
+ fontSize: {
81
+ type: [Number, String],
82
+ default: 28
83
+ },
84
+ /** 主标题是否加粗 */
85
+ bold: {
86
+ type: Boolean,
87
+ default: true
88
+ },
89
+ /** 主标题的颜色 */
90
+ color: {
91
+ type: String,
92
+ default: '#303133'
93
+ },
94
+ /** 右边副标题的颜色 */
95
+ subColor: {
96
+ type: String,
97
+ default: '#909399'
98
+ },
99
+ /** 是否显示左边的竖条 */
100
+ showLine: {
101
+ type: Boolean,
102
+ default: true
103
+ },
104
+ /** 左边竖线的颜色 */
105
+ lineColor: {
106
+ type: String,
107
+ default: ''
108
+ },
109
+ /** 是否显示右边箭头 */
110
+ arrow: {
111
+ type: Boolean,
112
+ default: true
113
+ }
114
+ });
115
+
116
+ const emit = defineEmits(['click']);
117
+
118
+ /**
119
+ * 左边竖条的样式
120
+ * @description 由于安卓和iOS的,需要稍微调整绝对定位的top值,才能让左边的竖线和右边的文字垂直居中
121
+ */
122
+ const lineStyle = computed(() => {
123
+ let isIOS = $u.os && $u.os() === 'ios';
124
+ return {
125
+ // 由于竖线为字体图标,具有比实际线宽更宽的宽度,所以也需要根据字体打下动态调整
126
+ left: -(Number(props.fontSize) * 0.9) + 'rpx',
127
+ top: -(Number(props.fontSize) * (isIOS ? 0.14 : 0.15)) + 'rpx'
128
+ };
129
+ });
130
+
131
+ /**
132
+ * 组件右侧的内容被点击时触发,用于跳转"更多"
133
+ */
134
+ function rightClick() {
135
+ emit('click');
136
+ }
137
+ </script>
138
+
139
+ <style lang="scss" scoped>
140
+ @import '../../libs/css/style.components.scss';
141
+
142
+ .u-section {
143
+ @include vue-flex;
144
+ justify-content: space-between;
145
+ align-items: center;
146
+ width: 100%;
147
+
148
+ &__title {
149
+ position: relative;
150
+ font-size: 28rpx;
151
+ padding-left: 20rpx;
152
+ @include vue-flex;
153
+ align-items: center;
154
+
155
+ &__icon-wrap {
156
+ position: absolute;
157
+ }
158
+
159
+ &__text {
160
+ line-height: 1;
161
+ }
162
+ }
163
+
164
+ &__right-info {
165
+ color: $u-tips-color;
166
+ font-size: 26rpx;
167
+ @include vue-flex;
168
+ align-items: center;
169
+
170
+ &__icon-arrow {
171
+ margin-left: 6rpx;
172
+ }
173
+ }
174
+ }
175
+ </style>
@@ -0,0 +1,387 @@
1
+ <template>
2
+ <view class="u-select">
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="#c0c4cc"></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
+ {{ cancelText }}
32
+ </view>
33
+ <view class="u-select__header__title">
34
+ {{ title }}
35
+ </view>
36
+ <view
37
+ class="u-select__header__confirm u-select__header__btn"
38
+ :style="{ color: moving ? cancelColor : confirmColor }"
39
+ hover-class="u-hover-class"
40
+ :hover-stay-time="150"
41
+ @touchmove.stop=""
42
+ @tap.stop="getResult('confirm')"
43
+ >
44
+ {{ confirmText }}
45
+ </view>
46
+ </view>
47
+ <view class="u-select__body">
48
+ <picker-view @change="columnChange" class="u-select__body__picker-view" :value="defaultSelector" @pickstart="pickstart" @pickend="pickend" v-if="modelValue">
49
+ <picker-view-column v-for="(item, index) in columnData" :key="index">
50
+ <view class="u-select__body__picker-view__item" v-for="(item1, index1) in item" :key="index1">
51
+ <view class="u-line-1">{{ item1[labelName] }}</view>
52
+ </view>
53
+ </picker-view-column>
54
+ </picker-view>
55
+ </view>
56
+ </view>
57
+ </u-popup>
58
+ </view>
59
+ </template>
60
+
61
+ <script setup lang="ts">
62
+ import { ref, computed, watch } from 'vue';
63
+
64
+ defineOptions({
65
+ name: 'u-select'
66
+ });
67
+
68
+ /**
69
+ * select 列选择器
70
+ * @description 此选择器用于单列,多列,多列联动的选择场景。(从1.3.0版本起,不建议使用Picker组件的单列和多列模式,Select组件是专门为列选择而构造的组件,更简单易用。)
71
+ * @tutorial http://uviewui.com/components/select.html
72
+ * @property {String} mode 模式选择,"single-column"-单列模式,"mutil-column"-多列模式,"mutil-column-auto"-多列联动模式
73
+ * @property {Array} list 列数据,数组形式,见官网说明
74
+ * @property {Boolean} v-model 布尔值变量,用于控制选择器的弹出与收起
75
+ * @property {Boolean} safe-area-inset-bottom 是否开启底部安全区适配(默认false)
76
+ * @property {String} cancel-color 取消按钮的颜色(默认#606266)
77
+ * @property {String} confirm-color 确认按钮的颜色(默认#2979ff)
78
+ * @property {String} confirm-text 确认按钮的文字
79
+ * @property {String} cancel-text 取消按钮的文字
80
+ * @property {String} default-value 提供的默认选中的下标,见官网说明
81
+ * @property {Boolean} mask-close-able 是否允许通过点击遮罩关闭Picker(默认true)
82
+ * @property {String Number} z-index 弹出时的z-index值(默认10075)
83
+ * @property {String} value-name 自定义list数据的value属性名 1.3.6
84
+ * @property {String} label-name 自定义list数据的label属性名 1.3.6
85
+ * @property {String} child-name 自定义list数据的children属性名,只对多列联动模式有效 1.3.7
86
+ * @event {Function} confirm 点击确定按钮,返回当前选择的值
87
+ * @example <u-select v-model="show" :list="list"></u-select>
88
+ */
89
+
90
+ const props = defineProps({
91
+ /** 列数据 */
92
+ list: { type: Array, default: () => [] },
93
+ /** 是否显示边框 */
94
+ border: { type: Boolean, default: true },
95
+ /** 通过双向绑定控制组件的弹出与收起 */
96
+ modelValue: { type: Boolean, default: false },
97
+ /** "取消"按钮的颜色 */
98
+ cancelColor: { type: String, default: '#606266' },
99
+ /** "确定"按钮的颜色 */
100
+ confirmColor: { type: String, default: '#2979ff' },
101
+ /** 弹出的z-index值 */
102
+ zIndex: { type: [String, Number], default: 0 },
103
+ /** 是否开启底部安全区适配 */
104
+ safeAreaInsetBottom: { type: Boolean, default: false },
105
+ /** 是否允许通过点击遮罩关闭Picker */
106
+ maskCloseAble: { type: Boolean, default: true },
107
+ /** 提供的默认选中的下标 */
108
+ defaultValue: { type: Array, default: () => [0] },
109
+ /** 模式选择,single-column-单列,mutil-column-多列,mutil-column-auto-多列联动 */
110
+ mode: { type: String, default: 'single-column' },
111
+ /** 自定义value属性名 */
112
+ valueName: { type: String, default: 'value' },
113
+ /** 自定义label属性名 */
114
+ labelName: { type: String, default: 'label' },
115
+ /** 自定义多列联动模式的children属性名 */
116
+ childName: { type: String, default: 'children' },
117
+ /** 顶部标题 */
118
+ title: { type: String, default: '' },
119
+ /** 取消按钮的文字 */
120
+ cancelText: { type: String, default: '取消' },
121
+ /** 确认按钮的文字 */
122
+ confirmText: { type: String, default: '确认' }
123
+ });
124
+ const emit = defineEmits(['update:modelValue', 'confirm', 'cancel', 'click']);
125
+ // 用于列改变时,保存当前的索引,下一次变化时比较得出是哪一列发生了变化
126
+
127
+ const defaultSelector = ref<number[]>([0]);
128
+ // picker-view的数据
129
+ const columnData = ref<any[][]>([]);
130
+ // 每次队列发生变化时,保存选择的结果
131
+ const selectValue = ref<any[]>([]);
132
+ // 上一次列变化时的index
133
+ const lastSelectIndex = ref<number[]>([]);
134
+ // 列数
135
+ const columnNum = ref(0);
136
+ // 列是否还在滑动中,微信小程序如果在滑动中就点确定,结果可能不准确
137
+ const moving = ref(false);
138
+ // 如果用户有传递z-index值,优先使用
139
+ const uZIndex = computed(() => (props.zIndex ? props.zIndex : 10075));
140
+
141
+ const popupValue = computed({
142
+ get: () => props.modelValue,
143
+ set: (val: boolean) => emit('update:modelValue', val)
144
+ });
145
+
146
+ watch(
147
+ () => props.modelValue,
148
+ val => {
149
+ if (val) setTimeout(() => init(), 10);
150
+ },
151
+ { immediate: true }
152
+ );
153
+ // 标识滑动开始,只有微信小程序才有这样的事件
154
+ function pickstart() {
155
+ // #ifdef MP-WEIXIN
156
+ moving.value = true;
157
+ // #endif
158
+ }
159
+ function pickend() {
160
+ // #ifdef MP-WEIXIN
161
+ moving.value = false;
162
+ // #endif
163
+ }
164
+
165
+ function init() {
166
+ setColumnNum();
167
+ setDefaultSelector();
168
+ setColumnData();
169
+ setSelectValue();
170
+ }
171
+
172
+ // 获取默认选中列下标
173
+ function setDefaultSelector() {
174
+ // 如果没有传入默认选中的值,生成长度为columnNum,用0填充的数组
175
+ defaultSelector.value = props.defaultValue.length == columnNum.value ? props.defaultValue : Array(columnNum.value).fill(0);
176
+ lastSelectIndex.value = [...defaultSelector.value];
177
+ }
178
+ // 计算列数
179
+ function setColumnNum() {
180
+ // 单列的列数为1
181
+ if (props.mode == 'single-column') columnNum.value = 1;
182
+ // 多列时,this.list数组长度就是列数
183
+ else if (props.mode == 'mutil-column') columnNum.value = props.list.length;
184
+ // 多列联动时,通过历遍this.list的第一个元素,得出有多少列
185
+ else if (props.mode == 'mutil-column-auto') {
186
+ let num = 1;
187
+ let column: any = props.list;
188
+ // 只要有元素并且第一个元素有children属性,继续遍历
189
+ while (Array.isArray(column) && column[0] && typeof column[0] === 'object' && props.childName in column[0]) {
190
+ column = column[0][props.childName];
191
+ num++;
192
+ }
193
+ columnNum.value = num;
194
+ }
195
+ }
196
+
197
+ // 获取需要展示在picker中的列数据
198
+ function setColumnData() {
199
+ let data: any[][] = [];
200
+ selectValue.value = [];
201
+ if (props.mode == 'mutil-column-auto') {
202
+ // 获得所有数据中的第一个元素
203
+ let column: any = props.list[defaultSelector.value.length ? defaultSelector.value[0] : 0];
204
+ // 通过循环所有的列数,再根据设定列的数组,得出当前需要渲染的整个列数组
205
+ for (let i = 0; i < columnNum.value; i++) {
206
+ // 第一列默认为整个list数组
207
+ if (i == 0) {
208
+ data[i] = props.list;
209
+ column = column && typeof column === 'object' ? column[props.childName] : [];
210
+ } else {
211
+ // 大于第一列时,判断是否有默认选中的,如果没有就用该列的第一项
212
+ data[i] = Array.isArray(column) ? column : [];
213
+ column =
214
+ Array.isArray(column) && column[defaultSelector.value[i]] && typeof column[defaultSelector.value[i]] === 'object'
215
+ ? column[defaultSelector.value[i]][props.childName]
216
+ : [];
217
+ }
218
+ }
219
+ } else if (props.mode == 'single-column') {
220
+ data[0] = props.list;
221
+ } else if (props.mode == 'mutil-column') {
222
+ data = props.list as any[][];
223
+ }
224
+ columnData.value = data;
225
+ }
226
+
227
+ // 获取默认选中的值,如果没有设置defaultValue,就默认选中每列的第一个
228
+ function setSelectValue() {
229
+ for (let i = 0; i < columnNum.value; i++) {
230
+ const tmp = columnData.value[i][defaultSelector.value[i]];
231
+ let data: any = {
232
+ value: tmp ? tmp[props.valueName] : null,
233
+ label: tmp ? tmp[props.labelName] : null
234
+ };
235
+
236
+ // 判断是否存在额外的参数,如果存在,就返回
237
+ if (tmp && tmp.extra !== undefined) data.extra = tmp.extra;
238
+ selectValue.value.push(data);
239
+ }
240
+ }
241
+
242
+ // 列选项
243
+ function columnChange(e: any) {
244
+ let index: number = -1;
245
+ const columnIndex = e.detail.value;
246
+ // 由于后面是需要push进数组的,所以需要先清空数组
247
+ selectValue.value = [];
248
+ defaultSelector.value = columnIndex;
249
+ if (props.mode == 'mutil-column-auto') {
250
+ // 对比前后两个数组,寻找变更的是哪一列,如果某一个元素不同,即可判定该列发生了变化
251
+ lastSelectIndex.value.map((val, idx) => {
252
+ if (val != columnIndex[idx]) index = idx;
253
+ });
254
+ for (let i = index + 1; i < columnNum.value; i++) {
255
+ // 当前变化列的下一列的数据,需要获取上一列的数据,同时需要指定是上一列的第几个的children,再往后的
256
+ // 默认是队列的第一个为默认选项
257
+ const prevCol = columnData.value[i - 1];
258
+ const prevIdx = i - 1 == index ? columnIndex[index] : 0;
259
+ columnData.value[i] = Array.isArray(prevCol) && prevCol[prevIdx] && typeof prevCol[prevIdx] === 'object' ? prevCol[prevIdx][props.childName] : [];
260
+ // 改变的列之后的所有列,默认选中第一个
261
+ defaultSelector.value[i] = 0;
262
+ }
263
+ // 在历遍的过程中,可能由于上一步修改this.columnData,导致产生连锁反应,程序触发columnChange,会有多次调用
264
+ // 只有在最后一次数据稳定后的结果是正确的,此前的历遍中,可能会产生undefined,故需要判断
265
+ columnIndex.map((item: any, idx: number) => {
266
+ let data = columnData.value[idx][columnIndex[idx]];
267
+ let tmp: any = {
268
+ value: data ? data[props.valueName] : null,
269
+ label: data ? data[props.labelName] : null
270
+ };
271
+ // 判断是否有需要额外携带的参数
272
+ if (data && data.extra !== undefined) tmp.extra = data.extra;
273
+ selectValue.value.push(tmp);
274
+ });
275
+ // 保存这一次的结果,用于下次列发生变化时作比较
276
+ lastSelectIndex.value = [...columnIndex];
277
+ } else if (props.mode == 'single-column') {
278
+ let data = columnData.value[0][columnIndex[0]];
279
+ // 初始默认选中值
280
+ let tmp: any = {
281
+ value: data ? data[props.valueName] : null,
282
+ label: data ? data[props.labelName] : null
283
+ };
284
+ // 判断是否有需要额外携带的参数
285
+ if (data && data.extra !== undefined) tmp.extra = data.extra;
286
+ selectValue.value.push(tmp);
287
+ } else if (props.mode == 'mutil-column') {
288
+ // 初始默认选中值
289
+ columnIndex.map((item: any, idx: number) => {
290
+ let data = columnData.value[idx][columnIndex[idx]];
291
+ // 初始默认选中值
292
+ let tmp: any = {
293
+ value: data ? data[props.valueName] : null,
294
+ label: data ? data[props.labelName] : null
295
+ };
296
+ // 判断是否有需要额外携带的参数
297
+ if (data && data.extra !== undefined) tmp.extra = data.extra;
298
+ selectValue.value.push(tmp);
299
+ });
300
+ }
301
+ }
302
+
303
+ function close() {
304
+ emit('update:modelValue', false);
305
+ // 重置default-value默认值
306
+ defaultSelector.value = [0];
307
+ }
308
+ // 点击确定或者取消
309
+ function getResult(event: 'update:modelValue' | 'confirm' | 'cancel' | 'click' | null = null) {
310
+ // #ifdef MP-WEIXIN
311
+ if (moving.value) return;
312
+ // #endif
313
+
314
+ if (event) emit(event, selectValue.value);
315
+ close();
316
+ }
317
+
318
+ function selectHandler() {
319
+ emit('click');
320
+ }
321
+ </script>
322
+
323
+ <style scoped lang="scss">
324
+ @import '../../libs/css/style.components.scss';
325
+
326
+ .u-select {
327
+ &__action {
328
+ position: relative;
329
+ line-height: $u-form-item-height;
330
+ height: $u-form-item-height;
331
+
332
+ &__icon {
333
+ position: absolute;
334
+ right: 20rpx;
335
+ top: 50%;
336
+ transition: transform 0.4s;
337
+ transform: translateY(-50%);
338
+ z-index: 1;
339
+
340
+ &--reverse {
341
+ transform: rotate(-180deg) translateY(50%);
342
+ }
343
+ }
344
+ }
345
+
346
+ &__hader {
347
+ &__title {
348
+ color: $u-content-color;
349
+ }
350
+ }
351
+
352
+ &--border {
353
+ border-radius: 6rpx;
354
+ border-radius: 4px;
355
+ border: 1px solid $u-form-item-border-color;
356
+ }
357
+
358
+ &__header {
359
+ @include vue-flex;
360
+ align-items: center;
361
+ justify-content: space-between;
362
+ height: 80rpx;
363
+ padding: 0 40rpx;
364
+ }
365
+
366
+ &__body {
367
+ width: 100%;
368
+ height: 500rpx;
369
+ overflow: hidden;
370
+ background-color: #fff;
371
+
372
+ &__picker-view {
373
+ height: 100%;
374
+ box-sizing: border-box;
375
+
376
+ &__item {
377
+ @include vue-flex;
378
+ align-items: center;
379
+ justify-content: center;
380
+ font-size: 32rpx;
381
+ color: $u-main-color;
382
+ padding: 0 8rpx;
383
+ }
384
+ }
385
+ }
386
+ }
387
+ </style>