hy-app 0.4.13 → 0.5.0

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 (211) hide show
  1. package/components/hy-action-sheet/hy-action-sheet.vue +155 -238
  2. package/components/hy-action-sheet/props.ts +68 -15
  3. package/components/hy-action-sheet/typing.d.ts +115 -115
  4. package/components/hy-address-picker/hy-address-picker.vue +185 -289
  5. package/components/hy-address-picker/props.ts +97 -21
  6. package/components/hy-address-picker/typing.d.ts +90 -89
  7. package/components/hy-avatar/hy-avatar.vue +121 -204
  8. package/components/hy-avatar/props.ts +76 -18
  9. package/components/hy-avatar/typing.d.ts +63 -62
  10. package/components/hy-back-top/hy-back-top.vue +65 -120
  11. package/components/hy-back-top/props.ts +57 -16
  12. package/components/hy-back-top/typing.d.ts +43 -42
  13. package/components/hy-badge/hy-badge.vue +66 -138
  14. package/components/hy-badge/props.ts +73 -17
  15. package/components/hy-badge/typing.d.ts +59 -58
  16. package/components/hy-button/hy-button.vue +226 -375
  17. package/components/hy-button/props.ts +129 -158
  18. package/components/hy-calendar/header.vue +48 -64
  19. package/components/hy-calendar/hy-calendar.vue +274 -438
  20. package/components/hy-calendar/month.vue +508 -516
  21. package/components/hy-calendar/props.ts +157 -35
  22. package/components/hy-calendar/typing.d.ts +129 -128
  23. package/components/hy-card/hy-card.vue +118 -240
  24. package/components/hy-card/index.scss +1 -2
  25. package/components/hy-card/props.ts +122 -27
  26. package/components/hy-card/typing.d.ts +119 -118
  27. package/components/hy-cell/hy-cell.vue +176 -258
  28. package/components/hy-cell/props.ts +71 -17
  29. package/components/hy-cell/typing.d.ts +87 -86
  30. package/components/hy-check-button/hy-check-button.vue +69 -139
  31. package/components/hy-check-button/props.ts +72 -18
  32. package/components/hy-check-button/typing.d.ts +74 -73
  33. package/components/hy-checkbox/hy-checkbox.vue +170 -263
  34. package/components/hy-checkbox/props.ts +94 -24
  35. package/components/hy-checkbox/typing.d.ts +72 -72
  36. package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
  37. package/components/hy-checkbox-group/props.ts +80 -0
  38. package/components/hy-checkbox-group/typing.d.ts +65 -65
  39. package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
  40. package/components/hy-checkbox-item/props.ts +24 -0
  41. package/components/hy-checkbox-item/typing.d.ts +4 -3
  42. package/components/hy-code-input/hy-code-input.vue +179 -262
  43. package/components/hy-code-input/props.ts +84 -18
  44. package/components/hy-code-input/typing.d.ts +71 -71
  45. package/components/hy-config-provider/hy-config-provider.vue +28 -50
  46. package/components/hy-config-provider/props.ts +26 -11
  47. package/components/hy-config-provider/typing.d.ts +20 -20
  48. package/components/hy-count-down/hy-count-down.vue +103 -131
  49. package/components/hy-count-down/props.ts +30 -8
  50. package/components/hy-count-down/typing.d.ts +25 -25
  51. package/components/hy-count-to/hy-count-to.vue +148 -213
  52. package/components/hy-count-to/props.ts +60 -15
  53. package/components/hy-count-to/typing.d.ts +46 -46
  54. package/components/hy-coupon/README.md +133 -0
  55. package/components/hy-coupon/hy-coupon.vue +180 -0
  56. package/components/hy-coupon/index.scss +553 -0
  57. package/components/hy-coupon/props.ts +129 -0
  58. package/components/hy-coupon/typing.d.ts +146 -0
  59. package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
  60. package/components/hy-datetime-picker/props.ts +142 -32
  61. package/components/hy-datetime-picker/typing.d.ts +132 -132
  62. package/components/hy-divider/hy-divider.vue +90 -169
  63. package/components/hy-divider/props.ts +78 -19
  64. package/components/hy-divider/typing.d.ts +60 -60
  65. package/components/hy-dropdown/hy-dropdown.vue +37 -71
  66. package/components/hy-dropdown/props.ts +38 -15
  67. package/components/hy-dropdown/typing.d.ts +44 -44
  68. package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
  69. package/components/hy-dropdown-item/props.ts +19 -8
  70. package/components/hy-empty/hy-empty.vue +75 -129
  71. package/components/hy-empty/props.ts +57 -15
  72. package/components/hy-empty/typing.d.ts +84 -84
  73. package/components/hy-flex/hy-flex.vue +33 -88
  74. package/components/hy-flex/props.ts +58 -0
  75. package/components/hy-flex/typing.d.ts +14 -16
  76. package/components/hy-float-button/hy-float-button.vue +289 -406
  77. package/components/hy-float-button/props.ts +109 -25
  78. package/components/hy-folding-panel/hy-folding-panel.vue +86 -374
  79. package/components/hy-folding-panel/props.ts +40 -15
  80. package/components/hy-folding-panel/typing.d.ts +52 -63
  81. package/components/hy-folding-panel-item/hy-folding-panel-item.vue +186 -228
  82. package/components/hy-folding-panel-item/index.scss +87 -0
  83. package/components/hy-folding-panel-item/props.ts +81 -0
  84. package/components/hy-folding-panel-item/typing.d.ts +23 -0
  85. package/components/hy-form/hy-form.vue +172 -212
  86. package/components/hy-form/props.ts +37 -0
  87. package/components/hy-form/typing.d.ts +68 -61
  88. package/components/hy-form-group/typing.d.ts +74 -74
  89. package/components/hy-form-item/hy-form-item.vue +100 -129
  90. package/components/hy-form-item/props.ts +25 -0
  91. package/components/hy-form-item/typing.d.ts +40 -37
  92. package/components/hy-grid/hy-grid.vue +76 -132
  93. package/components/hy-grid/props.ts +58 -16
  94. package/components/hy-grid/typing.d.ts +66 -66
  95. package/components/hy-icon/hy-icon.vue +84 -161
  96. package/components/hy-icon/props.ts +76 -22
  97. package/components/hy-icon/typing.d.ts +83 -82
  98. package/components/hy-image/hy-image.vue +142 -272
  99. package/components/hy-image/props.ts +105 -23
  100. package/components/hy-image/typing.d.ts +84 -87
  101. package/components/hy-input/hy-input.vue +230 -421
  102. package/components/hy-input/props.ts +183 -35
  103. package/components/hy-input/typing.d.ts +169 -169
  104. package/components/hy-line/hy-line.vue +34 -72
  105. package/components/hy-line/props.ts +41 -10
  106. package/components/hy-line/typing.d.ts +29 -29
  107. package/components/hy-line-progress/hy-line-progress.vue +66 -101
  108. package/components/hy-line-progress/props.ts +31 -10
  109. package/components/hy-line-progress/typing.d.ts +29 -29
  110. package/components/hy-list/hy-list.vue +151 -220
  111. package/components/hy-list/props.ts +67 -16
  112. package/components/hy-list/typing.d.ts +52 -52
  113. package/components/hy-loading/hy-loading.vue +63 -119
  114. package/components/hy-loading/props.ts +63 -15
  115. package/components/hy-loading/typing.d.ts +49 -49
  116. package/components/hy-menu/hy-menu.vue +124 -166
  117. package/components/hy-menu/props.ts +42 -10
  118. package/components/hy-menu/typing.d.ts +60 -60
  119. package/components/hy-modal/hy-modal.vue +127 -218
  120. package/components/hy-modal/props.ts +89 -24
  121. package/components/hy-navbar/hy-navbar.vue +104 -177
  122. package/components/hy-navbar/props.ts +76 -22
  123. package/components/hy-navbar/typing.d.ts +81 -81
  124. package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
  125. package/components/hy-notice-bar/props.ts +80 -19
  126. package/components/hy-notice-bar/typing.d.ts +62 -62
  127. package/components/hy-notify/hy-notify.vue +128 -177
  128. package/components/hy-notify/props.ts +49 -12
  129. package/components/hy-notify/typing.d.ts +45 -41
  130. package/components/hy-number-step/hy-number-step.vue +281 -394
  131. package/components/hy-number-step/props.ts +110 -27
  132. package/components/hy-number-step/typing.d.ts +120 -120
  133. package/components/hy-overlay/hy-overlay.vue +39 -66
  134. package/components/hy-overlay/props.ts +31 -8
  135. package/components/hy-pagination/hy-pagination.vue +100 -155
  136. package/components/hy-pagination/props.ts +53 -13
  137. package/components/hy-picker/hy-picker.vue +309 -430
  138. package/components/hy-picker/index.scss +8 -12
  139. package/components/hy-picker/props.ts +110 -26
  140. package/components/hy-popover/hy-popover.vue +190 -252
  141. package/components/hy-popover/props.ts +48 -10
  142. package/components/hy-popup/hy-popup.vue +162 -248
  143. package/components/hy-popup/props.ts +82 -18
  144. package/components/hy-price/hy-price.vue +45 -104
  145. package/components/hy-price/props.ts +52 -12
  146. package/components/hy-price/typing.d.ts +41 -36
  147. package/components/hy-qrcode/hy-qrcode.vue +115 -185
  148. package/components/hy-qrcode/props.ts +68 -18
  149. package/components/hy-qrcode/typing.d.ts +67 -66
  150. package/components/hy-radio/hy-radio.vue +161 -259
  151. package/components/hy-radio/props.ts +95 -25
  152. package/components/hy-radio/typing.d.ts +85 -84
  153. package/components/hy-rate/hy-rate.vue +185 -270
  154. package/components/hy-rate/props.ts +76 -18
  155. package/components/hy-rate/typing.d.ts +61 -60
  156. package/components/hy-read-more/hy-read-more.vue +93 -136
  157. package/components/hy-read-more/props.ts +43 -13
  158. package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
  159. package/components/hy-scroll-list/props.ts +22 -11
  160. package/components/hy-search/hy-search.vue +155 -284
  161. package/components/hy-search/props.ts +130 -25
  162. package/components/hy-signature/hy-signature.vue +491 -635
  163. package/components/hy-signature/props.ts +115 -26
  164. package/components/hy-signature/typing.d.ts +138 -138
  165. package/components/hy-slider/hy-slider.vue +388 -477
  166. package/components/hy-slider/props.ts +75 -19
  167. package/components/hy-steps/hy-steps.vue +212 -279
  168. package/components/hy-steps/props.ts +47 -13
  169. package/components/hy-submit-bar/hy-submit-bar.vue +137 -222
  170. package/components/hy-submit-bar/props.ts +89 -20
  171. package/components/hy-submit-bar/typing.d.ts +86 -85
  172. package/components/hy-subsection/hy-subsection.vue +132 -185
  173. package/components/hy-subsection/props.ts +50 -17
  174. package/components/hy-subsection/typing.d.ts +52 -52
  175. package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
  176. package/components/hy-swipe-action/props.ts +43 -18
  177. package/components/hy-swipe-action/typing.d.ts +46 -46
  178. package/components/hy-swiper/hy-swiper.vue +159 -286
  179. package/components/hy-swiper/props.ts +126 -28
  180. package/components/hy-swiper/typing.d.ts +115 -115
  181. package/components/hy-switch/hy-switch.vue +112 -176
  182. package/components/hy-switch/props.ts +60 -15
  183. package/components/hy-switch/typing.d.ts +63 -63
  184. package/components/hy-tabBar/hy-tabBar.vue +64 -60
  185. package/components/hy-tabs/hy-tabs.vue +277 -380
  186. package/components/hy-tabs/props.ts +75 -18
  187. package/components/hy-tag/hy-tag.vue +111 -204
  188. package/components/hy-tag/props.ts +81 -19
  189. package/components/hy-text/hy-text.vue +200 -322
  190. package/components/hy-text/props.ts +107 -28
  191. package/components/hy-textarea/hy-textarea.vue +147 -256
  192. package/components/hy-textarea/props.ts +112 -25
  193. package/components/hy-textarea/typing.d.ts +42 -42
  194. package/components/hy-toast/hy-toast.vue +135 -143
  195. package/components/hy-tooltip/hy-tooltip.vue +220 -306
  196. package/components/hy-tooltip/props.ts +79 -15
  197. package/components/hy-transition/hy-transition.vue +111 -138
  198. package/components/hy-transition/props.ts +30 -8
  199. package/components/hy-upload/hy-upload.vue +320 -469
  200. package/components/hy-upload/props.ts +130 -27
  201. package/components/hy-warn/hy-warn.vue +80 -129
  202. package/components/hy-warn/props.ts +47 -12
  203. package/components/hy-waterfall/hy-waterfall.vue +139 -163
  204. package/components/hy-waterfall/props.ts +19 -7
  205. package/components/hy-watermark/hy-watermark.vue +762 -870
  206. package/components/hy-watermark/props.ts +103 -22
  207. package/global.d.ts +2 -0
  208. package/libs/css/theme.scss +3 -3
  209. package/package.json +2 -2
  210. package/web-types.json +1 -1
  211. package/components/hy-folding-panel/index.scss +0 -9
@@ -1,550 +1,429 @@
1
1
  <template>
2
- <view class="hy-picker">
3
- <view
4
- v-if="hasInput"
5
- class="hy-picker-input cursor-pointer"
6
- @click="onShowByClickInput"
7
- >
8
- <slot>
9
- <HyInput
10
- v-model="inputLabelValue"
11
- :readonly="true"
12
- :disabled="input?.disabled"
13
- :disabledColor="input?.disabledColor"
14
- :shape="input?.shape"
15
- :border="input?.border"
16
- :prefixIcon="input?.prefixIcon"
17
- :suffixIcon="input?.suffixIcon"
18
- :color="input?.color"
19
- :fontSize="input?.fontSize"
20
- :inputAlign="input?.inputAlign"
21
- :placeholder="input?.placeholder || '请选择'"
22
- :placeholderStyle="input?.placeholderStyle"
23
- :placeholderClass="input?.placeholderClass"
24
- :customStyle="
25
- Object.assign({ 'pointer-events': 'none' }, input?.customStyle)
26
- "
27
- ></HyInput>
28
- <div class="input-cover"></div>
29
- </slot>
30
- </view>
31
- <HyPopup
32
- :show="show || (hasInput && showByClickInput)"
33
- :mode="popupMode"
34
- :zIndex="zIndex"
35
- @close="closeHandler"
36
- >
37
- <view class="hy-picker">
38
- <!-- 头部内容 -->
39
- <view class="hy-picker__title" v-if="showToolbar">
40
- <view
41
- class="hy-picker__title--left"
42
- :style="{ color: cancelColor }"
43
- @tap="cancel"
44
- >
45
- {{ cancelText }}
46
- </view>
47
- <view class="hy-picker__title--center">
48
- {{ title }}
49
- </view>
50
- <view
51
- class="hy-picker__title--right"
52
- :style="{ color: confirmColor }"
53
- @tap="onConfirm"
54
- >
55
- <slot name="toolbar-right">
56
- {{ confirmText }}
57
- </slot>
58
- </view>
2
+ <view class="hy-picker">
3
+ <view v-if="hasInput" class="hy-picker-input cursor-pointer" @click="onShowByClickInput">
4
+ <slot v-if="$slots.default"></slot>
5
+ <template v-else>
6
+ <hy-input
7
+ v-model="inputLabelValue"
8
+ :readonly="true"
9
+ :disabled="input?.disabled"
10
+ :disabledColor="input?.disabledColor"
11
+ :shape="input?.shape"
12
+ :border="input?.border"
13
+ :prefixIcon="input?.prefixIcon"
14
+ :suffixIcon="input?.suffixIcon"
15
+ :color="input?.color"
16
+ :fontSize="input?.fontSize"
17
+ :inputAlign="input?.inputAlign"
18
+ :placeholder="input?.placeholder || '请选择'"
19
+ :placeholderStyle="input?.placeholderStyle"
20
+ :placeholderClass="input?.placeholderClass"
21
+ :customStyle="Object.assign({ 'pointer-events': 'none' }, input?.customStyle)"
22
+ ></hy-input>
23
+ <view class="input-cover"></view>
24
+ </template>
59
25
  </view>
60
- <!-- 头部内容 -->
26
+ <hy-popup
27
+ :show="show || (hasInput && showByClickInput)"
28
+ :mode="popupMode"
29
+ :zIndex="zIndex"
30
+ @close="closeHandler"
31
+ >
32
+ <view class="hy-picker">
33
+ <!-- 头部内容 -->
34
+ <view class="hy-picker__title" v-if="showToolbar">
35
+ <view
36
+ class="hy-picker__title--left"
37
+ :style="{ color: cancelColor }"
38
+ @tap="cancel"
39
+ >
40
+ {{ cancelText }}
41
+ </view>
42
+ <view class="hy-picker__title--center">
43
+ {{ title }}
44
+ </view>
45
+ <view
46
+ class="hy-picker__title--right"
47
+ :style="{ color: confirmColor }"
48
+ @tap="onConfirm"
49
+ >
50
+ <slot name="toolbar-right">
51
+ {{ confirmText }}
52
+ </slot>
53
+ </view>
54
+ </view>
55
+ <!-- 头部内容 -->
61
56
 
62
- <slot name="toolbar-bottom"></slot>
57
+ <slot name="toolbar-bottom"></slot>
63
58
 
64
- <!-- 选择器内容 -->
65
- <picker-view
66
- class="hy-picker--view"
67
- :indicatorStyle="`height: ${addUnit(itemHeight)}`"
68
- :value="innerIndex"
69
- :immediateChange="immediateChange"
70
- :style="{
71
- height: `${addUnit(visibleItemCount * itemHeight)}`,
72
- }"
73
- mask-class="hy-picker--view__mask"
74
- maskStyle="backgroundImage: none;"
75
- @change="changeHandler"
76
- >
77
- <picker-view-column
78
- v-for="(item, index) in innerColumns"
79
- :key="index"
80
- class="hy-picker--view__column"
81
- >
82
- <view
83
- v-if="Array.isArray(item)"
84
- :class="[
85
- 'hy-picker--view__column__item',
86
- index1 === innerIndex[index] &&
87
- 'hy-picker--view__column__item--selected',
88
- ]"
89
- v-for="(item1, index1) in item"
90
- :key="index1"
91
- :style="{
92
- height: addUnit(itemHeight),
93
- lineHeight: addUnit(itemHeight),
94
- fontWeight: index1 === innerIndex[index] ? 'bold' : 'normal',
95
- display: 'block',
96
- }"
97
- >
98
- {{ getItemText(item1) }}
99
- </view>
100
- </picker-view-column>
101
- </picker-view>
102
- <!-- 选择器内容 -->
59
+ <!-- 加载loading -->
60
+ <hy-loading
61
+ v-if="loading"
62
+ mode="circle"
63
+ custom-class="hy-picker__loading"
64
+ :custom-style="{
65
+ height: `${addUnit(visibleItemCount * itemHeight)}`
66
+ }"
67
+ ></hy-loading>
68
+ <!-- 加载loading -->
103
69
 
104
- <!-- 加载loading -->
105
- <view v-if="loading" class="hy-picker--loading">
106
- <HyIcon :name="IconConfig.LOADING" :isRotate="loading"></HyIcon>
107
- </view>
108
- <!-- 加载loading -->
109
- </view>
110
- </HyPopup>
111
- </view>
70
+ <!-- 选择器内容 -->
71
+ <picker-view
72
+ v-else
73
+ class="hy-picker--view"
74
+ :indicatorStyle="`height: ${addUnit(itemHeight)}`"
75
+ :value="innerIndex"
76
+ :immediateChange="immediateChange"
77
+ :style="{
78
+ height: `${addUnit(visibleItemCount * itemHeight)}`
79
+ }"
80
+ mask-class="hy-picker--view__mask"
81
+ maskStyle="backgroundImage: none;"
82
+ @change="changeHandler"
83
+ >
84
+ <picker-view-column
85
+ v-for="(item, index) in innerColumns"
86
+ :key="index"
87
+ class="hy-picker--view__column"
88
+ >
89
+ <view
90
+ v-if="Array.isArray(item)"
91
+ :class="[
92
+ 'hy-picker--view__column__item',
93
+ index1 === innerIndex[index] &&
94
+ 'hy-picker--view__column__item--selected'
95
+ ]"
96
+ v-for="(item1, index1) in item"
97
+ :key="index1"
98
+ :style="{
99
+ height: addUnit(itemHeight),
100
+ lineHeight: addUnit(itemHeight),
101
+ fontWeight: index1 === innerIndex[index] ? 'bold' : 'normal',
102
+ display: 'block'
103
+ }"
104
+ >
105
+ {{ getItemText(item1) }}
106
+ </view>
107
+ </picker-view-column>
108
+ </picker-view>
109
+ <!-- 选择器内容 -->
110
+ </view>
111
+ </hy-popup>
112
+ </view>
112
113
  </template>
113
114
 
114
115
  <script lang="ts">
115
116
  export default {
116
- name: "hy-picker",
117
- options: {
118
- addGlobalClass: true,
119
- virtualHost: true,
120
- styleIsolation: "shared",
121
- },
122
- };
117
+ name: 'hy-picker',
118
+ options: {
119
+ addGlobalClass: true,
120
+ virtualHost: true,
121
+ styleIsolation: 'shared'
122
+ }
123
+ }
123
124
  </script>
124
125
 
125
126
  <script setup lang="ts">
126
- import { computed, ref, watch } from "vue";
127
- import type { PropType } from "vue";
128
- import { deepClone, sleep, addUnit, isArray, IconConfig } from "../../libs";
129
- import type { IPickerEmits, PickerColumnVo } from "./typing";
130
- import type HyInputProps from "../hy-input/typing";
127
+ import { computed, ref, watch } from 'vue'
128
+ import { deepClone, sleep, addUnit, isArray } from '../../libs'
129
+ import type { IPickerEmits } from './typing'
130
+ import pickerProps from './props'
131
131
  // 组件
132
- import HyInput from "../hy-input/hy-input.vue";
133
- import HyIcon from "../hy-icon/hy-icon.vue";
134
- import HyPopup from "../hy-popup/hy-popup.vue";
132
+ import HyInput from '../hy-input/hy-input.vue'
133
+ import HyLoading from '../hy-loading/hy-loading.vue'
134
+ import HyPopup from '../hy-popup/hy-popup.vue'
135
135
 
136
136
  /**
137
137
  * 此选择器用于单列,多列,多列联动的选择场景。
138
138
  * @displayName hy-picker
139
139
  */
140
- defineOptions({});
140
+ defineOptions({})
141
141
 
142
- // const props = withDefaults(defineProps<IProps>(), defaultProps)
143
- const props = defineProps({
144
- /** 显示到输入框值 */
145
- modelValue: {
146
- type: [String, Array],
147
- default: "",
148
- },
149
- /** 是否显示弹窗 */
150
- show: {
151
- type: Boolean,
152
- default: false,
153
- },
154
- /** 弹窗弹出模式 */
155
- popupMode: {
156
- type: String,
157
- default: "bottom",
158
- },
159
- /** 分割数组条件 */
160
- separator: {
161
- type: String,
162
- default: "/",
163
- },
164
- /** 是否显示顶部的操作栏 */
165
- showToolbar: {
166
- type: Boolean,
167
- default: true,
168
- },
169
- /** 顶部标题 */
170
- title: String,
171
- /** 二维数组,设置每一列的数据 */
172
- columns: {
173
- type: Array as unknown as PropType<(string | PickerColumnVo)[][]>,
174
- default: [],
175
- },
176
- /** 是否显示加载中状态 */
177
- loading: {
178
- type: Boolean,
179
- default: false,
180
- },
181
- /** 各列中,单个选项的高度 */
182
- itemHeight: {
183
- type: Number,
184
- default: 44,
185
- },
186
- /** 取消按钮的文字 */
187
- cancelText: {
188
- type: String,
189
- default: "取消",
190
- },
191
- /** 确认按钮的文字 */
192
- confirmText: {
193
- type: String,
194
- default: "确定",
195
- },
196
- /** 取消按钮的颜色 */
197
- cancelColor: {
198
- type: String,
199
- default: "#909193",
200
- },
201
- /** 确认按钮的颜色 */
202
- confirmColor: String,
203
- /** 每列中可见选项的数量 */
204
- visibleItemCount: {
205
- type: Number,
206
- default: 5,
207
- },
208
- /** 显示到选项对象中,需要展示的属性键名 */
209
- keyName: {
210
- type: String,
211
- default: "text",
212
- },
213
- /** 是否允许点击遮罩关闭选择器 */
214
- closeOnClickOverlay: {
215
- type: Boolean,
216
- default: false,
217
- },
218
- /** 各列的默认索引 */
219
- defaultIndex: {
220
- type: Array as PropType<number[]>,
221
- default: [],
222
- },
223
- /** 是否在手指松开时立即触发change事件 */
224
- immediateChange: {
225
- type: Boolean,
226
- default: true,
227
- },
228
- /** 最高层级 */
229
- zIndex: {
230
- type: Number,
231
- default: 10076,
232
- },
233
- /** 是否显示输入框 */
234
- hasInput: {
235
- type: Boolean,
236
- default: false,
237
- },
238
- /** 输入框集合属性 */
239
- input: {
240
- type: Object as PropType<HyInputProps>,
241
- default: () => {},
242
- },
243
- /** 是否自定义选择器nav左边内容 */
244
- toolbarRightSlot: {
245
- type: Boolean,
246
- default: false,
247
- },
248
- });
249
- const emit = defineEmits<IPickerEmits>();
142
+ const props = defineProps(pickerProps)
143
+ const emit = defineEmits<IPickerEmits>()
250
144
 
251
145
  // 上一次选择的列索引
252
- const lastIndex = ref([]);
146
+ const lastIndex = ref([])
253
147
  // 索引值 ,对应picker-view的value
254
- const innerIndex = ref<any[]>([]);
148
+ const innerIndex = ref<any[]>([])
255
149
  // 各列的值
256
- const innerColumns = ref<any[][]>([]);
150
+ const innerColumns = ref<any[][]>([])
257
151
  // 上一次的变化列索引
258
- const columnIndex = ref<number>(0);
259
- const showByClickInput = ref<boolean>(false);
260
- const currentActiveValue = ref([]); //当前用户选中,但是还没确认的值,用户没做change操作时候,点击确认可以默认选中第一个
152
+ const columnIndex = ref<number>(0)
153
+ const showByClickInput = ref<boolean>(false)
154
+ const currentActiveValue = ref([]) //当前用户选中,但是还没确认的值,用户没做change操作时候,点击确认可以默认选中第一个
261
155
 
262
156
  /**
263
157
  * @description 设置整体各列的columns的值
264
158
  * */
265
159
  const setColumns = (columns: any[]) => {
266
- innerColumns.value = deepClone(columns);
267
- // 如果在设置各列数据时,没有被设置默认的各列索引defaultIndex,那么用0去填充它,数组长度为列的数量
268
- if (innerIndex.value.length === 0) {
269
- innerIndex.value = new Array(columns.length).fill(0);
270
- }
271
- };
160
+ innerColumns.value = deepClone(columns)
161
+ // 如果在设置各列数据时,没有被设置默认的各列索引defaultIndex,那么用0去填充它,数组长度为列的数量
162
+ if (innerIndex.value.length === 0) {
163
+ innerIndex.value = new Array(columns.length).fill(0)
164
+ }
165
+ }
272
166
 
273
167
  /**
274
168
  * @description 监听默认索引的变化,重新设置对应的值
275
169
  * */
276
170
  watch(
277
- () => props.defaultIndex,
278
- (newValue) => {
279
- setIndexs(newValue, true);
280
- },
281
- );
171
+ () => props.defaultIndex,
172
+ (newValue) => {
173
+ setIndexs(newValue, true)
174
+ }
175
+ )
282
176
 
283
177
  /**
284
178
  * @description 监听columns参数的变化
285
179
  * */
286
180
  watch(
287
- () => props.columns,
288
- (newValue) => {
289
- setColumns(newValue);
290
- },
291
- { deep: true, immediate: true },
292
- );
181
+ () => props.columns,
182
+ (newValue) => {
183
+ setColumns(newValue)
184
+ },
185
+ { deep: true, immediate: true }
186
+ )
293
187
 
294
188
  /**
295
189
  * @description 已选&&已确认的值显示在input上面的文案
296
190
  * */
297
191
  const inputLabelValue = computed((): string => {
298
- let firstItem = innerColumns.value[0] && innerColumns.value[0][0];
299
- // //区分是不是对象数组
300
- if (
301
- firstItem &&
302
- Object.prototype.toString.call(firstItem) === "[object Object]"
303
- ) {
304
- let res: Record<string, any>[] = [];
305
- innerColumns.value.map((ite, i) => {
306
- res.push(
307
- ...innerColumns.value[i]?.filter((item) => {
308
- return (
309
- isArray(props.modelValue) && props.modelValue.includes(item["id"])
310
- );
311
- }),
312
- );
313
- });
314
- res = res.map((item) => item[props.keyName]);
315
- return res.join(props.separator);
316
- } else {
317
- //用户确定的值,才显示到输入框
318
- if (props.modelValue.length && isArray(props.modelValue)) {
319
- return props.modelValue.join(props.separator);
192
+ let firstItem = innerColumns.value[0] && innerColumns.value[0][0]
193
+ // //区分是不是对象数组
194
+ if (firstItem && Object.prototype.toString.call(firstItem) === '[object Object]') {
195
+ let res: Record<string, any>[] = []
196
+ innerColumns.value.map((ite, i) => {
197
+ res.push(
198
+ ...innerColumns.value[i]?.filter((item) => {
199
+ return isArray(props.modelValue) && props.modelValue.includes(item['id'])
200
+ })
201
+ )
202
+ })
203
+ res = res.map((item) => item[props.keyName])
204
+ return res.join(props.separator)
205
+ } else {
206
+ //用户确定的值,才显示到输入框
207
+ if (props.modelValue.length && isArray(props.modelValue)) {
208
+ return props.modelValue.join(props.separator)
209
+ }
210
+ return props.modelValue as string
320
211
  }
321
- return props.modelValue as string;
322
- }
323
- });
212
+ })
324
213
 
325
214
  /**
326
215
  * @description 已选,待确认的值
327
216
  * */
328
217
  const inputValue = computed(() => {
329
- let items = innerColumns.value.map(
330
- (item, index) => item[innerIndex.value[index]],
331
- );
332
- let res: any[] = [];
333
- //区分是不是对象数组
334
- if (
335
- items[0] &&
336
- Object.prototype.toString.call(items[0]) === "[object Object]"
337
- ) {
338
- //对象数组返回id集合
339
- items.forEach((element) => {
340
- res.push(element && element["id"]);
341
- });
342
- } else {
343
- //非对象数组返回元素集合
344
- items.forEach((element) => {
345
- res.push(element);
346
- });
347
- }
348
- return res;
349
- });
218
+ let items = innerColumns.value.map((item, index) => item[innerIndex.value[index]])
219
+ let res: any[] = []
220
+ //区分是不是对象数组
221
+ if (items[0] && Object.prototype.toString.call(items[0]) === '[object Object]') {
222
+ //对象数组返回id集合
223
+ items.forEach((element) => {
224
+ res.push(element && element['id'])
225
+ })
226
+ } else {
227
+ //非对象数组返回元素集合
228
+ items.forEach((element) => {
229
+ res.push(element)
230
+ })
231
+ }
232
+ return res
233
+ })
350
234
 
351
235
  /**
352
236
  * @description 显示
353
237
  * */
354
238
  const onShowByClickInput = () => {
355
- if (!props.input?.disabled) {
356
- showByClickInput.value = !showByClickInput.value;
357
- }
358
- };
239
+ if (!props.input?.disabled) {
240
+ showByClickInput.value = !showByClickInput.value
241
+ }
242
+ }
359
243
 
360
244
  /**
361
245
  * @description 获取item需要显示的文字,判别为对象还是文本
362
246
  * */
363
247
  const getItemText = (item: any) => {
364
- if (
365
- Object.prototype.toString.call(item) === "[object Object]" &&
366
- props.keyName
367
- ) {
368
- return item[props.keyName];
369
- } else {
370
- return item;
371
- }
372
- };
248
+ if (Object.prototype.toString.call(item) === '[object Object]' && props.keyName) {
249
+ return item[props.keyName]
250
+ } else {
251
+ return item
252
+ }
253
+ }
373
254
 
374
255
  /**
375
256
  * @description 关闭选择器
376
257
  * */
377
258
  const closeHandler = () => {
378
- if (props.closeOnClickOverlay) {
379
- if (props.hasInput) {
380
- showByClickInput.value = false;
259
+ if (props.closeOnClickOverlay) {
260
+ if (props.hasInput) {
261
+ showByClickInput.value = false
262
+ }
263
+ emit('update:show', false)
264
+ emit('close')
381
265
  }
382
- emit("update:show", false);
383
- emit("close");
384
- }
385
- };
266
+ }
386
267
 
387
268
  /**
388
269
  * @description 点击工具栏的取消按钮
389
270
  * */
390
271
  const cancel = () => {
391
- if (props.hasInput) {
392
- showByClickInput.value = false;
393
- }
394
- emit("update:show", false);
395
- emit("cancel");
396
- };
272
+ if (props.hasInput) {
273
+ showByClickInput.value = false
274
+ }
275
+ emit('update:show', false)
276
+ emit('cancel')
277
+ }
397
278
 
398
279
  /**
399
280
  * @description 点击工具栏的确定按钮
400
281
  * */
401
282
  const onConfirm = () => {
402
- //如果用户有没有触发过change
403
- if (!currentActiveValue.value.length) {
404
- let arr = [0];
405
- //如果有默认值&&默认值的数组长度是正确的,就用默认值
406
- if (
407
- Array.isArray(props.defaultIndex) &&
408
- props.defaultIndex.length == innerColumns.value.length
409
- ) {
410
- arr = [...props.defaultIndex];
411
- } else {
412
- //否则默认都选中第一个
413
- arr = Array(innerColumns.value.length).fill(0);
283
+ //如果用户有没有触发过change
284
+ if (!currentActiveValue.value.length) {
285
+ let arr = [0]
286
+ //如果有默认值&&默认值的数组长度是正确的,就用默认值
287
+ if (
288
+ Array.isArray(props.defaultIndex) &&
289
+ props.defaultIndex.length == innerColumns.value.length
290
+ ) {
291
+ arr = [...props.defaultIndex]
292
+ } else {
293
+ //否则默认都选中第一个
294
+ arr = Array(innerColumns.value.length).fill(0)
295
+ }
296
+ setLastIndex(arr)
297
+ setIndexs(arr)
298
+ }
299
+ emit('update:modelValue', inputValue.value)
300
+ if (props.hasInput) {
301
+ showByClickInput.value = false
414
302
  }
415
- setLastIndex(arr);
416
- setIndexs(arr);
417
- }
418
- emit("update:modelValue", inputValue.value);
419
- if (props.hasInput) {
420
- showByClickInput.value = false;
421
- }
422
- emit("update:show", false);
423
- emit("confirm", {
424
- indexs: innerIndex.value,
425
- value: innerColumns.value.map(
426
- (item, index) => item[innerIndex.value[index]],
427
- ),
428
- values: innerColumns.value,
429
- });
430
- };
303
+ emit('update:show', false)
304
+ emit('confirm', {
305
+ indexs: innerIndex.value,
306
+ value: innerColumns.value.map((item, index) => item[innerIndex.value[index]]),
307
+ values: innerColumns.value
308
+ })
309
+ }
431
310
 
432
311
  /**
433
312
  * @description 选择器某一列的数据发生变化时触发
434
313
  * */
435
314
  const changeHandler = (e: any) => {
436
- const { value } = e.detail;
437
- let index = 0,
438
- columnI = 0;
439
- //记录用户选中但是还没确认的值
440
- currentActiveValue.value = value;
441
- // 通过对比前后两次的列索引,得出当前变化的是哪一列
442
- for (let i = 0; i < value.length; i++) {
443
- let item = value[i];
444
- if (item !== (lastIndex.value[i] || 0)) {
445
- // 把undefined转为合法假值0
446
- // 设置columnIndex为当前变化列的索引
447
- columnI = i;
448
- // index则为变化列中的变化项的索引
449
- index = item;
450
- break; // 终止循环,即使少一次循环,也是性能的提升
315
+ const { value } = e.detail
316
+ let index = 0,
317
+ columnI = 0
318
+ //记录用户选中但是还没确认的值
319
+ currentActiveValue.value = value
320
+ // 通过对比前后两次的列索引,得出当前变化的是哪一列
321
+ for (let i = 0; i < value.length; i++) {
322
+ let item = value[i]
323
+ if (item !== (lastIndex.value[i] || 0)) {
324
+ // 把undefined转为合法假值0
325
+ // 设置columnIndex为当前变化列的索引
326
+ columnI = i
327
+ // index则为变化列中的变化项的索引
328
+ index = item
329
+ break // 终止循环,即使少一次循环,也是性能的提升
330
+ }
451
331
  }
452
- }
453
- columnIndex.value = columnI;
454
- const values = innerColumns.value;
455
- const params = {
456
- value: innerColumns.value.map((item, index) => item[value[index]]),
457
- index,
458
- indexs: value,
459
- // values为当前变化列的数组内容
460
- values,
461
- columnIndex: columnI,
462
- };
463
- // 将当前的各项变化索引,设置为"上一次"的索引变化值
464
- setLastIndex(value);
465
- setIndexs(value);
466
- //如果是非自带输入框才会在change时候触发v-model绑值的变化
467
- //否则会非常的奇怪,用户未确认,值就变了
468
- if (!props.hasInput) {
469
- emit("update:modelValue", inputValue.value);
470
- }
471
- emit("change", params);
472
- };
332
+ columnIndex.value = columnI
333
+ const values = innerColumns.value
334
+ const params = {
335
+ value: innerColumns.value.map((item, index) => item[value[index]]),
336
+ index,
337
+ indexs: value,
338
+ // values为当前变化列的数组内容
339
+ values,
340
+ columnIndex: columnI
341
+ }
342
+ // 将当前的各项变化索引,设置为"上一次"的索引变化值
343
+ setLastIndex(value)
344
+ setIndexs(value)
345
+ //如果是非自带输入框才会在change时候触发v-model绑值的变化
346
+ //否则会非常的奇怪,用户未确认,值就变了
347
+ if (!props.hasInput) {
348
+ emit('update:modelValue', inputValue.value)
349
+ }
350
+ emit('change', params)
351
+ }
473
352
 
474
353
  /**
475
354
  * @description 设置index索引,此方法可被外部调用设置
476
355
  * */
477
356
  const setIndexs = (index: number[], isSetLastIndex?: boolean) => {
478
- innerIndex.value = deepClone(index);
479
- if (isSetLastIndex) {
480
- setLastIndex(index);
481
- }
482
- };
357
+ innerIndex.value = deepClone(index)
358
+ if (isSetLastIndex) {
359
+ setLastIndex(index)
360
+ }
361
+ }
483
362
 
484
363
  /**
485
364
  * @description 记录上一次的各列索引位置
486
365
  * */
487
366
  const setLastIndex = (index: number[]) => {
488
- // 当能进入此方法,意味着当前设置的各列默认索引,即为“上一次”的选中值,需要记录,是因为changeHandler中
489
- // 需要拿前后的变化值进行对比,得出当前发生改变的是哪一列
490
- lastIndex.value = deepClone(index);
491
- };
367
+ // 当能进入此方法,意味着当前设置的各列默认索引,即为“上一次”的选中值,需要记录,是因为changeHandler中
368
+ // 需要拿前后的变化值进行对比,得出当前发生改变的是哪一列
369
+ lastIndex.value = deepClone(index)
370
+ }
492
371
 
493
372
  /**
494
373
  * @description 设置对应列选项的所有值
495
374
  * */
496
375
  const setColumnValues = (columnI: number, values: AnyObject[]) => {
497
- // 替换innerColumns数组中columnIndex索引的值为values,使用的是数组的splice方法
498
- innerColumns.value.splice(columnI, 1, values);
499
- // 替换完成之后将修改列之后的已选值置空
500
- setLastIndex(innerIndex.value.slice(0, columnI));
501
- // 拷贝一份原有的innerIndex做临时变量,将大于当前变化列的所有的列的默认索引设置为0
502
- let tmpIndex = deepClone(innerIndex.value);
503
- for (let i = 0; i < innerColumns.value.length; i++) {
504
- if (i > columnIndex.value) {
505
- tmpIndex[i] = 0;
376
+ // 替换innerColumns数组中columnIndex索引的值为values,使用的是数组的splice方法
377
+ innerColumns.value.splice(columnI, 1, values)
378
+ // 替换完成之后将修改列之后的已选值置空
379
+ setLastIndex(innerIndex.value.slice(0, columnI))
380
+ // 拷贝一份原有的innerIndex做临时变量,将大于当前变化列的所有的列的默认索引设置为0
381
+ let tmpIndex = deepClone(innerIndex.value)
382
+ for (let i = 0; i < innerColumns.value.length; i++) {
383
+ if (i > columnIndex.value) {
384
+ tmpIndex[i] = 0
385
+ }
506
386
  }
507
- }
508
- // 一次性赋值,不能单个修改,否则无效
509
- setIndexs(tmpIndex);
510
- };
387
+ // 一次性赋值,不能单个修改,否则无效
388
+ setIndexs(tmpIndex)
389
+ }
511
390
 
512
391
  /**
513
392
  * @description 获取对应列的所有选项
514
393
  * */
515
394
  const getColumnValues = (columnI: number) => {
516
- // 进行同步阻塞,因为外部得到change事件之后,可能需要执行setColumnValues更新列的值
517
- // 索引如果在外部change的回调中调用getColumnValues的话,可能无法得到变更后的列值,这里进行一定延时,保证值的准确性
518
- (async () => {
519
- await sleep();
520
- })();
521
- return innerColumns.value[columnI];
522
- };
395
+ // 进行同步阻塞,因为外部得到change事件之后,可能需要执行setColumnValues更新列的值
396
+ // 索引如果在外部change的回调中调用getColumnValues的话,可能无法得到变更后的列值,这里进行一定延时,保证值的准确性
397
+ ;(async () => {
398
+ await sleep()
399
+ })()
400
+ return innerColumns.value[columnI]
401
+ }
523
402
 
524
403
  /**
525
404
  * @description 获取各列选中值对应的索引
526
405
  * */
527
406
  const getIndexs = () => {
528
- return innerIndex.value;
529
- };
407
+ return innerIndex.value
408
+ }
530
409
 
531
410
  /**
532
411
  * @description 获取各列选中的值
533
412
  * */
534
413
  const getValues = () => {
535
- // 进行同步阻塞,因为外部得到change事件之后,可能需要执行setColumnValues更新列的值
536
- // 索引如果在外部change的回调中调用getValues的话,可能无法得到变更后的列值,这里进行一定延时,保证值的准确性
537
- (async () => {
538
- await sleep();
539
- })();
540
- return innerColumns.value.map((item, index) => item[innerIndex.value[index]]);
541
- };
414
+ // 进行同步阻塞,因为外部得到change事件之后,可能需要执行setColumnValues更新列的值
415
+ // 索引如果在外部change的回调中调用getValues的话,可能无法得到变更后的列值,这里进行一定延时,保证值的准确性
416
+ ;(async () => {
417
+ await sleep()
418
+ })()
419
+ return innerColumns.value.map((item, index) => item[innerIndex.value[index]])
420
+ }
542
421
 
543
422
  defineExpose({
544
- setColumnValues,
545
- });
423
+ setColumnValues
424
+ })
546
425
  </script>
547
426
 
548
427
  <style lang="scss" scoped>
549
- @import "./index.scss";
428
+ @import './index.scss';
550
429
  </style>