@kengic/uni 0.5.1 → 0.5.2-beta.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 (146) hide show
  1. package/dist/uni/uni-ui/uni-badge/uni-badge.vue +222 -219
  2. package/dist/uni/uni-ui/uni-breadcrumb/uni-breadcrumb.vue +29 -29
  3. package/dist/uni/uni-ui/uni-breadcrumb-item/uni-breadcrumb-item.vue +88 -88
  4. package/dist/uni/uni-ui/uni-calendar/calendar.js +936 -532
  5. package/dist/uni/uni-ui/uni-calendar/i18n/en.json +10 -10
  6. package/dist/uni/uni-ui/uni-calendar/i18n/index.js +8 -7
  7. package/dist/uni/uni-ui/uni-calendar/i18n/zh-Hans.json +10 -10
  8. package/dist/uni/uni-ui/uni-calendar/i18n/zh-Hant.json +10 -10
  9. package/dist/uni/uni-ui/uni-calendar/uni-calendar-item.vue +190 -168
  10. package/dist/uni/uni-ui/uni-calendar/uni-calendar.vue +459 -459
  11. package/dist/uni/uni-ui/uni-calendar/util.js +324 -340
  12. package/dist/uni/uni-ui/uni-card/uni-card.vue +8 -1
  13. package/dist/uni/uni-ui/uni-col/uni-col.vue +294 -287
  14. package/dist/uni/uni-ui/uni-collapse/uni-collapse.vue +139 -140
  15. package/dist/uni/uni-ui/uni-collapse-item/uni-collapse-item.vue +381 -378
  16. package/dist/uni/uni-ui/uni-combox/uni-combox.vue +280 -272
  17. package/dist/uni/uni-ui/uni-countdown/i18n/en.json +4 -4
  18. package/dist/uni/uni-ui/uni-countdown/i18n/index.js +8 -7
  19. package/dist/uni/uni-ui/uni-countdown/i18n/zh-Hans.json +4 -4
  20. package/dist/uni/uni-ui/uni-countdown/i18n/zh-Hant.json +4 -4
  21. package/dist/uni/uni-ui/uni-countdown/uni-countdown.vue +249 -257
  22. package/dist/uni/uni-ui/uni-data-checkbox/uni-data-checkbox.vue +832 -813
  23. package/dist/uni/uni-ui/uni-data-picker/keypress.js +42 -42
  24. package/dist/uni/uni-ui/uni-data-picker/uni-data-picker.vue +535 -516
  25. package/dist/uni/uni-ui/uni-data-pickerview/uni-data-picker.js +623 -618
  26. package/dist/uni/uni-ui/uni-data-pickerview/uni-data-pickerview.vue +293 -288
  27. package/dist/uni/uni-ui/uni-data-select/uni-data-select.vue +495 -509
  28. package/dist/uni/uni-ui/uni-dateformat/date-format.js +181 -184
  29. package/dist/uni/uni-ui/uni-dateformat/uni-dateformat.vue +81 -82
  30. package/dist/uni/uni-ui/uni-datetime-picker/calendar-item.vue +176 -170
  31. package/dist/uni/uni-ui/uni-datetime-picker/calendar.vue +926 -920
  32. package/dist/uni/uni-ui/uni-datetime-picker/i18n/en.json +20 -20
  33. package/dist/uni/uni-ui/uni-datetime-picker/i18n/index.js +8 -7
  34. package/dist/uni/uni-ui/uni-datetime-picker/i18n/zh-Hans.json +21 -21
  35. package/dist/uni/uni-ui/uni-datetime-picker/i18n/zh-Hant.json +21 -21
  36. package/dist/uni/uni-ui/uni-datetime-picker/time-picker.vue +921 -926
  37. package/dist/uni/uni-ui/uni-datetime-picker/uni-datetime-picker.vue +1059 -1012
  38. package/dist/uni/uni-ui/uni-datetime-picker/util.js +366 -377
  39. package/dist/uni/uni-ui/uni-drawer/keypress.js +42 -42
  40. package/dist/uni/uni-ui/uni-drawer/uni-drawer.vue +176 -167
  41. package/dist/uni/uni-ui/uni-easyinput/common.js +40 -42
  42. package/dist/uni/uni-ui/uni-easyinput/uni-easyinput.vue +628 -547
  43. package/dist/uni/uni-ui/uni-fab/uni-fab.vue +507 -483
  44. package/dist/uni/uni-ui/uni-fav/i18n/en.json +2 -2
  45. package/dist/uni/uni-ui/uni-fav/i18n/index.js +8 -7
  46. package/dist/uni/uni-ui/uni-fav/i18n/zh-Hans.json +2 -2
  47. package/dist/uni/uni-ui/uni-fav/i18n/zh-Hant.json +2 -2
  48. package/dist/uni/uni-ui/uni-fav/uni-fav.vue +155 -147
  49. package/dist/uni/uni-ui/uni-file-picker/choose-and-upload-file.js +172 -198
  50. package/dist/uni/uni-ui/uni-file-picker/uni-file-picker.vue +636 -634
  51. package/dist/uni/uni-ui/uni-file-picker/upload-file.vue +294 -293
  52. package/dist/uni/uni-ui/uni-file-picker/upload-image.vue +267 -270
  53. package/dist/uni/uni-ui/uni-file-picker/utils.js +81 -82
  54. package/dist/uni/uni-ui/uni-forms/uni-forms.vue +360 -372
  55. package/dist/uni/uni-ui/uni-forms/utils.js +170 -174
  56. package/dist/uni/uni-ui/uni-forms/validate.js +447 -456
  57. package/dist/uni/uni-ui/uni-forms-item/uni-forms-item.vue +497 -497
  58. package/dist/uni/uni-ui/uni-goods-nav/i18n/en.json +4 -4
  59. package/dist/uni/uni-ui/uni-goods-nav/i18n/index.js +8 -7
  60. package/dist/uni/uni-ui/uni-goods-nav/i18n/zh-Hans.json +4 -4
  61. package/dist/uni/uni-ui/uni-goods-nav/i18n/zh-Hant.json +4 -4
  62. package/dist/uni/uni-ui/uni-goods-nav/uni-goods-nav.vue +238 -222
  63. package/dist/uni/uni-ui/uni-grid/uni-grid.vue +134 -134
  64. package/dist/uni/uni-ui/uni-grid-item/uni-grid-item.vue +121 -119
  65. package/dist/uni/uni-ui/uni-group/uni-group.vue +121 -121
  66. package/dist/uni/uni-ui/uni-icons/icons.js +1170 -1168
  67. package/dist/uni/uni-ui/uni-icons/uni-icons.vue +91 -86
  68. package/dist/uni/uni-ui/uni-icons/uniicons.css +166 -166
  69. package/dist/uni/uni-ui/uni-indexed-list/uni-indexed-list-item.vue +129 -129
  70. package/dist/uni/uni-ui/uni-indexed-list/uni-indexed-list.vue +352 -347
  71. package/dist/uni/uni-ui/uni-link/uni-link.vue +134 -119
  72. package/dist/uni/uni-ui/uni-list/uni-list.vue +119 -110
  73. package/dist/uni/uni-ui/uni-list/uni-refresh.vue +14 -14
  74. package/dist/uni/uni-ui/uni-list/uni-refresh.wxs +14 -14
  75. package/dist/uni/uni-ui/uni-list-ad/uni-list-ad.vue +101 -95
  76. package/dist/uni/uni-ui/uni-list-chat/uni-list-chat.scss +18 -18
  77. package/dist/uni/uni-ui/uni-list-chat/uni-list-chat.vue +602 -586
  78. package/dist/uni/uni-ui/uni-list-item/uni-list-item.vue +507 -503
  79. package/dist/uni/uni-ui/uni-load-more/i18n/en.json +3 -3
  80. package/dist/uni/uni-ui/uni-load-more/i18n/index.js +8 -7
  81. package/dist/uni/uni-ui/uni-load-more/i18n/zh-Hans.json +3 -3
  82. package/dist/uni/uni-ui/uni-load-more/i18n/zh-Hant.json +3 -3
  83. package/dist/uni/uni-ui/uni-load-more/uni-load-more.vue +402 -392
  84. package/dist/uni/uni-ui/uni-nav-bar/uni-nav-bar.vue +328 -330
  85. package/dist/uni/uni-ui/uni-nav-bar/uni-status-bar.vue +17 -17
  86. package/dist/uni/uni-ui/uni-notice-bar/uni-notice-bar.vue +422 -401
  87. package/dist/uni/uni-ui/uni-number-box/uni-number-box.vue +211 -205
  88. package/dist/uni/uni-ui/uni-pagination/i18n/en.json +3 -3
  89. package/dist/uni/uni-ui/uni-pagination/i18n/es.json +3 -3
  90. package/dist/uni/uni-ui/uni-pagination/i18n/fr.json +3 -3
  91. package/dist/uni/uni-ui/uni-pagination/i18n/index.js +12 -11
  92. package/dist/uni/uni-ui/uni-pagination/i18n/zh-Hans.json +3 -3
  93. package/dist/uni/uni-ui/uni-pagination/i18n/zh-Hant.json +3 -3
  94. package/dist/uni/uni-ui/uni-pagination/uni-pagination.vue +450 -433
  95. package/dist/uni/uni-ui/uni-popup/uni-popup.vue +404 -404
  96. package/dist/uni/uni-ui/uni-popup-dialog/keypress.js +42 -42
  97. package/dist/uni/uni-ui/uni-popup-dialog/uni-popup-dialog.vue +1 -0
  98. package/dist/uni/uni-ui/uni-popup-message/uni-popup-message.vue +126 -125
  99. package/dist/uni/uni-ui/uni-popup-share/uni-popup-share.vue +172 -172
  100. package/dist/uni/uni-ui/uni-rate/uni-rate.vue +343 -347
  101. package/dist/uni/uni-ui/uni-row/uni-row.vue +180 -182
  102. package/dist/uni/uni-ui/uni-scss/changelog.md +11 -4
  103. package/dist/uni/uni-ui/uni-scss/package.json +73 -73
  104. package/dist/uni/uni-ui/uni-scss/readme.md +2 -1
  105. package/dist/uni/uni-ui/uni-scss/styles/setting/_border.scss +2 -2
  106. package/dist/uni/uni-ui/uni-scss/styles/setting/_color.scss +46 -47
  107. package/dist/uni/uni-ui/uni-scss/styles/setting/_radius.scss +49 -49
  108. package/dist/uni/uni-ui/uni-scss/styles/setting/_space.scss +52 -53
  109. package/dist/uni/uni-ui/uni-scss/styles/setting/_styles.scss +142 -147
  110. package/dist/uni/uni-ui/uni-scss/styles/setting/_text.scss +20 -20
  111. package/dist/uni/uni-ui/uni-scss/styles/setting/_variables.scss +111 -95
  112. package/dist/uni/uni-ui/uni-scss/styles/tools/functions.scss +28 -18
  113. package/dist/uni/uni-ui/uni-scss/theme.scss +10 -7
  114. package/dist/uni/uni-ui/uni-scss/variables.scss +42 -24
  115. package/dist/uni/uni-ui/uni-search-bar/i18n/en.json +3 -3
  116. package/dist/uni/uni-ui/uni-search-bar/i18n/index.js +8 -7
  117. package/dist/uni/uni-ui/uni-search-bar/i18n/zh-Hans.json +2 -2
  118. package/dist/uni/uni-ui/uni-search-bar/i18n/zh-Hant.json +2 -2
  119. package/dist/uni/uni-ui/uni-search-bar/uni-search-bar.vue +290 -281
  120. package/dist/uni/uni-ui/uni-section/uni-section.vue +149 -146
  121. package/dist/uni/uni-ui/uni-segmented-control/uni-segmented-control.vue +141 -131
  122. package/dist/uni/uni-ui/uni-steps/uni-steps.vue +255 -236
  123. package/dist/uni/uni-ui/uni-swipe-action/uni-swipe-action.vue +51 -51
  124. package/dist/uni/uni-ui/uni-swipe-action-item/bindingx.js +276 -282
  125. package/dist/uni/uni-ui/uni-swipe-action-item/isPC.js +10 -10
  126. package/dist/uni/uni-ui/uni-swipe-action-item/mpalipay.js +182 -187
  127. package/dist/uni/uni-ui/uni-swipe-action-item/mpother.js +235 -244
  128. package/dist/uni/uni-ui/uni-swipe-action-item/mpwxs.js +70 -75
  129. package/dist/uni/uni-ui/uni-swipe-action-item/render.js +238 -247
  130. package/dist/uni/uni-ui/uni-swipe-action-item/uni-swipe-action-item.vue +392 -313
  131. package/dist/uni/uni-ui/uni-swipe-action-item/wx.wxs +206 -215
  132. package/dist/uni/uni-ui/uni-swiper-dot/uni-swiper-dot.vue +241 -197
  133. package/dist/uni/uni-ui/uni-table/uni-table.vue +445 -447
  134. package/dist/uni/uni-ui/uni-tag/uni-tag.vue +234 -244
  135. package/dist/uni/uni-ui/uni-tbody/uni-tbody.vue +20 -23
  136. package/dist/uni/uni-ui/uni-td/uni-td.vue +79 -80
  137. package/dist/uni/uni-ui/uni-th/filter-dropdown.vue +510 -503
  138. package/dist/uni/uni-ui/uni-th/uni-th.vue +289 -273
  139. package/dist/uni/uni-ui/uni-thead/uni-thead.vue +115 -114
  140. package/dist/uni/uni-ui/uni-title/uni-title.vue +151 -154
  141. package/dist/uni/uni-ui/uni-tooltip/uni-tooltip.vue +55 -60
  142. package/dist/uni/uni-ui/uni-tr/table-checkbox.vue +162 -163
  143. package/dist/uni/uni-ui/uni-tr/uni-tr.vue +158 -157
  144. package/dist/uni/uni-ui/uni-transition/createAnimation.js +130 -113
  145. package/dist/uni/uni-ui/uni-transition/uni-transition.vue +274 -272
  146. package/package.json +1 -1
@@ -1,517 +1,503 @@
1
1
  <template>
2
- <view class="uni-stat__select">
3
- <span v-if="label" class="uni-label-text hide-on-phone">{{label + ':'}}</span>
4
- <view class="uni-stat-box" :class="{'uni-stat__actived': current}">
5
- <view class="uni-select" :class="{'uni-select--disabled':disabled}">
6
- <view class="uni-select__input-box" @click="toggleSelector">
7
- <view v-if="current" class="uni-select__input-text">{{current}}</view>
8
- <view v-else class="uni-select__input-text uni-select__input-placeholder">{{typePlaceholder}}</view>
9
- <view v-if="current && clear && !disabled" @click.stop="clearVal" >
10
- <uni-icons type="clear" color="#c0c4cc" size="24"/>
11
- </view>
12
- <view v-else>
13
- <uni-icons :type="showSelector? 'top' : 'bottom'" size="14" color="#999" />
14
- </view>
15
- </view>
16
- <view class="uni-select--mask" v-if="showSelector" @click="toggleSelector" />
17
- <view class="uni-select__selector" v-if="showSelector">
18
- <view class="uni-popper__arrow"></view>
19
- <scroll-view scroll-y="true" class="uni-select__selector-scroll">
20
- <view class="uni-select__selector-empty" v-if="mixinDatacomResData.length === 0">
21
- <text>{{emptyTips}}</text>
22
- </view>
23
- <view v-else class="uni-select__selector-item" v-for="(item,index) in mixinDatacomResData" :key="index"
24
- @click="change(item)">
25
- <text :class="{'uni-select__selector__disabled': item.disable}">{{formatItemName(item)}}</text>
26
- </view>
27
- </scroll-view>
28
- </view>
29
- </view>
30
- </view>
31
- </view>
2
+ <view class="uni-stat__select">
3
+ <span v-if="label" class="uni-label-text hide-on-phone">{{ label + ':' }}</span>
4
+ <view class="uni-stat-box" :class="{ 'uni-stat__actived': current }">
5
+ <view class="uni-select" :class="{ 'uni-select--disabled': disabled }">
6
+ <view class="uni-select__input-box" @click="toggleSelector">
7
+ <view v-if="current" class="uni-select__input-text">{{ current }}</view>
8
+ <view v-else class="uni-select__input-text uni-select__input-placeholder">{{ typePlaceholder }}</view>
9
+ <view v-if="current && clear && !disabled" @click.stop="clearVal">
10
+ <uni-icons type="clear" color="#c0c4cc" size="24" />
11
+ </view>
12
+ <view v-else>
13
+ <uni-icons :type="showSelector ? 'top' : 'bottom'" size="14" color="#999" />
14
+ </view>
15
+ </view>
16
+ <view class="uni-select--mask" v-if="showSelector" @click="toggleSelector" />
17
+ <view class="uni-select__selector" v-if="showSelector">
18
+ <view class="uni-popper__arrow"></view>
19
+ <scroll-view scroll-y="true" class="uni-select__selector-scroll">
20
+ <view class="uni-select__selector-empty" v-if="mixinDatacomResData.length === 0">
21
+ <text>{{ emptyTips }}</text>
22
+ </view>
23
+ <view v-else class="uni-select__selector-item" v-for="(item, index) in mixinDatacomResData" :key="index" @click="change(item)">
24
+ <text :class="{ 'uni-select__selector__disabled': item.disable }">{{ formatItemName(item) }}</text>
25
+ </view>
26
+ </scroll-view>
27
+ </view>
28
+ </view>
29
+ </view>
30
+ </view>
32
31
  </template>
33
32
 
34
33
  <script>
35
- /**
36
- * DataChecklist 数据选择器
37
- * @description 通过数据渲染的下拉框组件
38
- * @tutorial https://uniapp.dcloud.io/component/uniui/uni-data-select
39
- * @property {String} value 默认值
40
- * @property {Array} localdata 本地数据 ,格式 [{text:'',value:''}]
41
- * @property {Boolean} clear 是否可以清空已选项
42
- * @property {Boolean} emptyText 没有数据时显示的文字 ,本地数据无效
43
- * @property {String} label 左侧标题
44
- * @property {String} placeholder 输入框的提示文字
45
- * @property {Boolean} disabled 是否禁用
46
- * @event {Function} change 选中发生变化触发
47
- */
48
-
49
- export default {
50
- name: "UniDataSelect",
51
- mixins: [uniCloud.mixinDatacom || {}],
52
- props: {
53
- localdata: {
54
- type: Array,
55
- default () {
56
- return []
57
- }
58
- },
59
- value: {
60
- type: [String, Number],
61
- default: ''
62
- },
63
- modelValue: {
64
- type: [String, Number],
65
- default: ''
66
- },
67
- label: {
68
- type: String,
69
- default: ''
70
- },
71
- placeholder: {
72
- type: String,
73
- default: '请选择'
74
- },
75
- emptyTips: {
76
- type: String,
77
- default: '无选项'
78
- },
79
- clear: {
80
- type: Boolean,
81
- default: true
82
- },
83
- defItem: {
84
- type: Number,
85
- default: 0
86
- },
87
- disabled: {
88
- type: Boolean,
89
- default: false
90
- },
91
- // 格式化输出 用法 field="_id as value, version as text, uni_platform as label" format="{label} - {text}"
92
- format: {
93
- type: String,
94
- default: ''
95
- },
96
- },
97
- data() {
98
- return {
99
- showSelector: false,
100
- current: '',
101
- mixinDatacomResData: [],
102
- apps: [],
103
- channels: [],
104
- cacheKey: "uni-data-select-lastSelectedValue",
105
- };
106
- },
107
- created() {
108
- this.debounceGet = this.debounce(() => {
109
- this.query();
110
- }, 300);
111
- if (this.collection && !this.localdata.length) {
112
- this.debounceGet();
113
- }
114
- },
115
- computed: {
116
- typePlaceholder() {
117
- const text = {
118
- 'opendb-stat-app-versions': '版本',
119
- 'opendb-app-channels': '渠道',
120
- 'opendb-app-list': '应用'
121
- }
122
- const common = this.placeholder
123
- const placeholder = text[this.collection]
124
- return placeholder ?
125
- common + placeholder :
126
- common
127
- },
128
- valueCom(){
129
- // #ifdef VUE3
130
- return this.modelValue;
131
- // #endif
132
- // #ifndef VUE3
133
- return this.value;
134
- // #endif
135
- }
136
- },
137
- watch: {
138
- localdata: {
139
- immediate: true,
140
- handler(val, old) {
141
- if (Array.isArray(val) && old !== val) {
142
- this.mixinDatacomResData = val
143
- }
144
- }
145
- },
146
- valueCom(val, old) {
147
- this.initDefVal()
148
- },
149
- mixinDatacomResData: {
150
- immediate: true,
151
- handler(val) {
152
- if (val.length) {
153
- this.initDefVal()
154
- }
155
- }
156
- }
157
- },
158
- methods: {
159
- debounce(fn, time = 100){
160
- let timer = null
161
- return function(...args) {
162
- if (timer) clearTimeout(timer)
163
- timer = setTimeout(() => {
164
- fn.apply(this, args)
165
- }, time)
166
- }
167
- },
168
- // 执行数据库查询
169
- query(){
170
- this.mixinDatacomEasyGet();
171
- },
172
- // 监听查询条件变更事件
173
- onMixinDatacomPropsChange(){
174
- if (this.collection) {
175
- this.debounceGet();
176
- }
177
- },
178
- initDefVal() {
179
- let defValue = ''
180
- if ((this.valueCom || this.valueCom === 0) && !this.isDisabled(this.valueCom)) {
181
- defValue = this.valueCom
182
- } else {
183
- let strogeValue
184
- if (this.collection) {
185
- strogeValue = this.getCache()
186
- }
187
- if (strogeValue || strogeValue === 0) {
188
- defValue = strogeValue
189
- } else {
190
- let defItem = ''
191
- if (this.defItem > 0 && this.defItem <= this.mixinDatacomResData.length) {
192
- defItem = this.mixinDatacomResData[this.defItem - 1].value
193
- }
194
- defValue = defItem
195
- }
196
- if (defValue || defValue === 0) {
197
- this.emit(defValue)
198
- }
199
- }
200
- const def = this.mixinDatacomResData.find(item => item.value === defValue)
201
- this.current = def ? this.formatItemName(def) : ''
202
- },
203
-
204
- /**
205
- * @param {[String, Number]} value
206
- * 判断用户给的 value 是否同时为禁用状态
207
- */
208
- isDisabled(value) {
209
- let isDisabled = false;
210
-
211
- this.mixinDatacomResData.forEach(item => {
212
- if (item.value === value) {
213
- isDisabled = item.disable
214
- }
215
- })
216
-
217
- return isDisabled;
218
- },
219
-
220
- clearVal() {
221
- this.emit('')
222
- if (this.collection) {
223
- this.removeCache()
224
- }
225
- },
226
- change(item) {
227
- if (!item.disable) {
228
- this.showSelector = false
229
- this.current = this.formatItemName(item)
230
- this.emit(item.value)
231
- }
232
- },
233
- emit(val) {
234
- this.$emit('input', val)
235
- this.$emit('update:modelValue', val)
236
- this.$emit('change', val)
237
- if (this.collection) {
238
- this.setCache(val);
239
- }
240
- },
241
- toggleSelector() {
242
- if (this.disabled) {
243
- return
244
- }
245
-
246
- this.showSelector = !this.showSelector
247
- },
248
- formatItemName(item) {
249
- let {
250
- text,
251
- value,
252
- channel_code
253
- } = item
254
- channel_code = channel_code ? `(${channel_code})` : ''
255
-
256
- if (this.format) {
257
- // 格式化输出
258
- let str = "";
259
- str = this.format;
260
- for (let key in item) {
261
- str = str.replace(new RegExp(`{${key}}`,"g"),item[key]);
262
- }
263
- return str;
264
- } else {
265
- return this.collection.indexOf('app-list') > 0 ?
266
- `${text}(${value})` :
267
- (
268
- text ?
269
- text :
270
- `未命名${channel_code}`
271
- )
272
- }
273
- },
274
- // 获取当前加载的数据
275
- getLoadData(){
276
- return this.mixinDatacomResData;
277
- },
278
- // 获取当前缓存key
279
- getCurrentCacheKey(){
280
- return this.collection;
281
- },
282
- // 获取缓存
283
- getCache(name=this.getCurrentCacheKey()){
284
- let cacheData = uni.getStorageSync(this.cacheKey) || {};
285
- return cacheData[name];
286
- },
287
- // 设置缓存
288
- setCache(value, name=this.getCurrentCacheKey()){
289
- let cacheData = uni.getStorageSync(this.cacheKey) || {};
290
- cacheData[name] = value;
291
- uni.setStorageSync(this.cacheKey, cacheData);
292
- },
293
- // 删除缓存
294
- removeCache(name=this.getCurrentCacheKey()){
295
- let cacheData = uni.getStorageSync(this.cacheKey) || {};
296
- delete cacheData[name];
297
- uni.setStorageSync(this.cacheKey, cacheData);
298
- },
299
- }
300
- }
34
+ /**
35
+ * DataChecklist 数据选择器
36
+ * @description 通过数据渲染的下拉框组件
37
+ * @tutorial https://uniapp.dcloud.io/component/uniui/uni-data-select
38
+ * @property {String} value 默认值
39
+ * @property {Array} localdata 本地数据 ,格式 [{text:'',value:''}]
40
+ * @property {Boolean} clear 是否可以清空已选项
41
+ * @property {Boolean} emptyText 没有数据时显示的文字 ,本地数据无效
42
+ * @property {String} label 左侧标题
43
+ * @property {String} placeholder 输入框的提示文字
44
+ * @property {Boolean} disabled 是否禁用
45
+ * @event {Function} change 选中发生变化触发
46
+ */
47
+
48
+ export default {
49
+ name: 'UniDataSelect',
50
+ mixins: [uniCloud.mixinDatacom || {}],
51
+ props: {
52
+ localdata: {
53
+ type: Array,
54
+ default() {
55
+ return [];
56
+ },
57
+ },
58
+ value: {
59
+ type: [String, Number],
60
+ default: '',
61
+ },
62
+ modelValue: {
63
+ type: [String, Number],
64
+ default: '',
65
+ },
66
+ label: {
67
+ type: String,
68
+ default: '',
69
+ },
70
+ placeholder: {
71
+ type: String,
72
+ default: '请选择',
73
+ },
74
+ emptyTips: {
75
+ type: String,
76
+ default: '无选项',
77
+ },
78
+ clear: {
79
+ type: Boolean,
80
+ default: true,
81
+ },
82
+ defItem: {
83
+ type: Number,
84
+ default: 0,
85
+ },
86
+ disabled: {
87
+ type: Boolean,
88
+ default: false,
89
+ },
90
+ // 格式化输出 用法 field="_id as value, version as text, uni_platform as label" format="{label} - {text}"
91
+ format: {
92
+ type: String,
93
+ default: '',
94
+ },
95
+ },
96
+ data() {
97
+ return {
98
+ showSelector: false,
99
+ current: '',
100
+ mixinDatacomResData: [],
101
+ apps: [],
102
+ channels: [],
103
+ cacheKey: 'uni-data-select-lastSelectedValue',
104
+ };
105
+ },
106
+ created() {
107
+ this.debounceGet = this.debounce(() => {
108
+ this.query();
109
+ }, 300);
110
+ if (this.collection && !this.localdata.length) {
111
+ this.debounceGet();
112
+ }
113
+ },
114
+ computed: {
115
+ typePlaceholder() {
116
+ const text = {
117
+ 'opendb-stat-app-versions': '版本',
118
+ 'opendb-app-channels': '渠道',
119
+ 'opendb-app-list': '应用',
120
+ };
121
+ const common = this.placeholder;
122
+ const placeholder = text[this.collection];
123
+ return placeholder ? common + placeholder : common;
124
+ },
125
+ valueCom() {
126
+ // #ifdef VUE3
127
+ return this.modelValue;
128
+ // #endif
129
+ // #ifndef VUE3
130
+ return this.value;
131
+ // #endif
132
+ },
133
+ },
134
+ watch: {
135
+ localdata: {
136
+ immediate: true,
137
+ handler(val, old) {
138
+ if (Array.isArray(val) && old !== val) {
139
+ this.mixinDatacomResData = val;
140
+ }
141
+ },
142
+ },
143
+ valueCom(val, old) {
144
+ this.initDefVal();
145
+ },
146
+ mixinDatacomResData: {
147
+ immediate: true,
148
+ handler(val) {
149
+ if (val.length) {
150
+ this.initDefVal();
151
+ }
152
+ },
153
+ },
154
+ },
155
+ methods: {
156
+ debounce(fn, time = 100) {
157
+ let timer = null;
158
+ return function (...args) {
159
+ if (timer) clearTimeout(timer);
160
+ timer = setTimeout(() => {
161
+ fn.apply(this, args);
162
+ }, time);
163
+ };
164
+ },
165
+ // 执行数据库查询
166
+ query() {
167
+ this.mixinDatacomEasyGet();
168
+ },
169
+ // 监听查询条件变更事件
170
+ onMixinDatacomPropsChange() {
171
+ if (this.collection) {
172
+ this.debounceGet();
173
+ }
174
+ },
175
+ initDefVal() {
176
+ let defValue = '';
177
+ if ((this.valueCom || this.valueCom === 0) && !this.isDisabled(this.valueCom)) {
178
+ defValue = this.valueCom;
179
+ } else {
180
+ let strogeValue;
181
+ if (this.collection) {
182
+ strogeValue = this.getCache();
183
+ }
184
+ if (strogeValue || strogeValue === 0) {
185
+ defValue = strogeValue;
186
+ } else {
187
+ let defItem = '';
188
+ if (this.defItem > 0 && this.defItem <= this.mixinDatacomResData.length) {
189
+ defItem = this.mixinDatacomResData[this.defItem - 1].value;
190
+ }
191
+ defValue = defItem;
192
+ }
193
+ if (defValue || defValue === 0) {
194
+ this.emit(defValue);
195
+ }
196
+ }
197
+ const def = this.mixinDatacomResData.find((item) => item.value === defValue);
198
+ this.current = def ? this.formatItemName(def) : '';
199
+ },
200
+
201
+ /**
202
+ * @param {[String, Number]} value
203
+ * 判断用户给的 value 是否同时为禁用状态
204
+ */
205
+ isDisabled(value) {
206
+ let isDisabled = false;
207
+
208
+ this.mixinDatacomResData.forEach((item) => {
209
+ if (item.value === value) {
210
+ isDisabled = item.disable;
211
+ }
212
+ });
213
+
214
+ return isDisabled;
215
+ },
216
+
217
+ clearVal() {
218
+ this.emit('');
219
+ if (this.collection) {
220
+ this.removeCache();
221
+ }
222
+ },
223
+ change(item) {
224
+ if (!item.disable) {
225
+ this.showSelector = false;
226
+ this.current = this.formatItemName(item);
227
+ this.emit(item.value);
228
+ }
229
+ },
230
+ emit(val) {
231
+ this.$emit('input', val);
232
+ this.$emit('update:modelValue', val);
233
+ this.$emit('change', val);
234
+ if (this.collection) {
235
+ this.setCache(val);
236
+ }
237
+ },
238
+ toggleSelector() {
239
+ if (this.disabled) {
240
+ return;
241
+ }
242
+
243
+ this.showSelector = !this.showSelector;
244
+ },
245
+ formatItemName(item) {
246
+ let { text, value, channel_code } = item;
247
+ channel_code = channel_code ? `(${channel_code})` : '';
248
+
249
+ if (this.format) {
250
+ // 格式化输出
251
+ let str = '';
252
+ str = this.format;
253
+ for (let key in item) {
254
+ str = str.replace(new RegExp(`{${key}}`, 'g'), item[key]);
255
+ }
256
+ return str;
257
+ } else {
258
+ return this.collection.indexOf('app-list') > 0 ? `${text}(${value})` : text ? text : `未命名${channel_code}`;
259
+ }
260
+ },
261
+ // 获取当前加载的数据
262
+ getLoadData() {
263
+ return this.mixinDatacomResData;
264
+ },
265
+ // 获取当前缓存key
266
+ getCurrentCacheKey() {
267
+ return this.collection;
268
+ },
269
+ // 获取缓存
270
+ getCache(name = this.getCurrentCacheKey()) {
271
+ let cacheData = uni.getStorageSync(this.cacheKey) || {};
272
+ return cacheData[name];
273
+ },
274
+ // 设置缓存
275
+ setCache(value, name = this.getCurrentCacheKey()) {
276
+ let cacheData = uni.getStorageSync(this.cacheKey) || {};
277
+ cacheData[name] = value;
278
+ uni.setStorageSync(this.cacheKey, cacheData);
279
+ },
280
+ // 删除缓存
281
+ removeCache(name = this.getCurrentCacheKey()) {
282
+ let cacheData = uni.getStorageSync(this.cacheKey) || {};
283
+ delete cacheData[name];
284
+ uni.setStorageSync(this.cacheKey, cacheData);
285
+ },
286
+ },
287
+ };
301
288
  </script>
302
289
 
303
290
  <style lang="scss">
304
- $uni-base-color: #6a6a6a !default;
305
- $uni-main-color: #333 !default;
306
- $uni-secondary-color: #909399 !default;
307
- $uni-border-3: #e5e5e5;
308
-
309
-
310
- /* #ifndef APP-NVUE */
311
- @media screen and (max-width: 500px) {
312
- .hide-on-phone {
313
- display: none;
314
- }
315
- }
316
-
317
- /* #endif */
318
- .uni-stat__select {
319
- display: flex;
320
- align-items: center;
321
- // padding: 15px;
322
- /* #ifdef H5 */
323
- cursor: pointer;
324
- /* #endif */
325
- width: 100%;
326
- flex: 1;
327
- box-sizing: border-box;
328
- }
329
-
330
- .uni-stat-box {
331
- width: 100%;
332
- flex: 1;
333
- }
334
-
335
- .uni-stat__actived {
336
- width: 100%;
337
- flex: 1;
338
- // outline: 1px solid #2979ff;
339
- }
340
-
341
- .uni-label-text {
342
- font-size: 14px;
343
- font-weight: bold;
344
- color: $uni-base-color;
345
- margin: auto 0;
346
- margin-right: 5px;
347
- }
348
-
349
- .uni-select {
350
- font-size: 14px;
351
- border: 1px solid $uni-border-3;
352
- box-sizing: border-box;
353
- border-radius: 4px;
354
- padding: 0 5px;
355
- padding-left: 10px;
356
- position: relative;
357
- /* #ifndef APP-NVUE */
358
- display: flex;
359
- user-select: none;
360
- /* #endif */
361
- flex-direction: row;
362
- align-items: center;
363
- border-bottom: solid 1px $uni-border-3;
364
- width: 100%;
365
- flex: 1;
366
- height: 35px;
367
-
368
- &--disabled {
369
- background-color: #f5f7fa;
370
- cursor: not-allowed;
371
- }
372
- }
373
-
374
- .uni-select__label {
375
- font-size: 16px;
376
- // line-height: 22px;
377
- height: 35px;
378
- padding-right: 10px;
379
- color: $uni-secondary-color;
380
- }
381
-
382
- .uni-select__input-box {
383
- height: 35px;
384
- position: relative;
385
- /* #ifndef APP-NVUE */
386
- display: flex;
387
- /* #endif */
388
- flex: 1;
389
- flex-direction: row;
390
- align-items: center;
391
- }
392
-
393
- .uni-select__input {
394
- flex: 1;
395
- font-size: 14px;
396
- height: 22px;
397
- line-height: 22px;
398
- }
399
-
400
- .uni-select__input-plac {
401
- font-size: 14px;
402
- color: $uni-secondary-color;
403
- }
404
-
405
- .uni-select__selector {
406
- /* #ifndef APP-NVUE */
407
- box-sizing: border-box;
408
- /* #endif */
409
- position: absolute;
410
- top: calc(100% + 12px);
411
- left: 0;
412
- width: 100%;
413
- background-color: #FFFFFF;
414
- border: 1px solid #EBEEF5;
415
- border-radius: 6px;
416
- box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
417
- z-index: 3;
418
- padding: 4px 0;
419
- }
420
-
421
- .uni-select__selector-scroll {
422
- /* #ifndef APP-NVUE */
423
- max-height: 200px;
424
- box-sizing: border-box;
425
- /* #endif */
426
- }
427
-
428
- /* #ifdef H5 */
429
- @media (min-width: 768px) {
430
- .uni-select__selector-scroll {
431
- max-height: 600px;
432
- }
433
- }
434
- /* #endif */
435
-
436
- .uni-select__selector-empty,
437
- .uni-select__selector-item {
438
- /* #ifndef APP-NVUE */
439
- display: flex;
440
- cursor: pointer;
441
- /* #endif */
442
- line-height: 35px;
443
- font-size: 14px;
444
- text-align: center;
445
- /* border-bottom: solid 1px $uni-border-3; */
446
- padding: 0px 10px;
447
- }
448
-
449
- .uni-select__selector-item:hover {
450
- background-color: #f9f9f9;
451
- }
452
-
453
- .uni-select__selector-empty:last-child,
454
- .uni-select__selector-item:last-child {
455
- /* #ifndef APP-NVUE */
456
- border-bottom: none;
457
- /* #endif */
458
- }
459
-
460
- .uni-select__selector__disabled {
461
- opacity: 0.4;
462
- cursor: default;
463
- }
464
-
465
- /* picker 弹出层通用的指示小三角 */
466
- .uni-popper__arrow,
467
- .uni-popper__arrow::after {
468
- position: absolute;
469
- display: block;
470
- width: 0;
471
- height: 0;
472
- border-color: transparent;
473
- border-style: solid;
474
- border-width: 6px;
475
- }
476
-
477
- .uni-popper__arrow {
478
- filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
479
- top: -6px;
480
- left: 10%;
481
- margin-right: 3px;
482
- border-top-width: 0;
483
- border-bottom-color: #EBEEF5;
484
- }
485
-
486
- .uni-popper__arrow::after {
487
- content: " ";
488
- top: 1px;
489
- margin-left: -6px;
490
- border-top-width: 0;
491
- border-bottom-color: #fff;
492
- }
493
-
494
- .uni-select__input-text {
495
- // width: 280px;
496
- width: 100%;
497
- color: $uni-main-color;
498
- white-space: nowrap;
499
- text-overflow: ellipsis;
500
- -o-text-overflow: ellipsis;
501
- overflow: hidden;
502
- }
503
-
504
- .uni-select__input-placeholder {
505
- color: $uni-base-color;
506
- font-size: 12px;
507
- }
508
-
509
- .uni-select--mask {
510
- position: fixed;
511
- top: 0;
512
- bottom: 0;
513
- right: 0;
514
- left: 0;
515
- z-index: 2;
516
- }
291
+ $uni-base-color: #6a6a6a !default;
292
+ $uni-main-color: #333 !default;
293
+ $uni-secondary-color: #909399 !default;
294
+ $uni-border-3: #e5e5e5;
295
+
296
+ /* #ifndef APP-NVUE */
297
+ @media screen and (max-width: 500px) {
298
+ .hide-on-phone {
299
+ display: none;
300
+ }
301
+ }
302
+
303
+ /* #endif */
304
+ .uni-stat__select {
305
+ display: flex;
306
+ align-items: center;
307
+ // padding: 15px;
308
+ /* #ifdef H5 */
309
+ cursor: pointer;
310
+ /* #endif */
311
+ width: 100%;
312
+ flex: 1;
313
+ box-sizing: border-box;
314
+ }
315
+
316
+ .uni-stat-box {
317
+ width: 100%;
318
+ flex: 1;
319
+ }
320
+
321
+ .uni-stat__actived {
322
+ width: 100%;
323
+ flex: 1;
324
+ // outline: 1px solid #2979ff;
325
+ }
326
+
327
+ .uni-label-text {
328
+ font-size: 14px;
329
+ font-weight: bold;
330
+ color: $uni-base-color;
331
+ margin: auto 0;
332
+ margin-right: 5px;
333
+ }
334
+
335
+ .uni-select {
336
+ font-size: 14px;
337
+ border: 1px solid $uni-border-3;
338
+ box-sizing: border-box;
339
+ border-radius: 4px;
340
+ padding: 0 5px;
341
+ padding-left: 10px;
342
+ position: relative;
343
+ /* #ifndef APP-NVUE */
344
+ display: flex;
345
+ user-select: none;
346
+ /* #endif */
347
+ flex-direction: row;
348
+ align-items: center;
349
+ border-bottom: solid 1px $uni-border-3;
350
+ width: 100%;
351
+ flex: 1;
352
+ height: 35px;
353
+
354
+ &--disabled {
355
+ background-color: #f5f7fa;
356
+ cursor: not-allowed;
357
+ }
358
+ }
359
+
360
+ .uni-select__label {
361
+ font-size: 16px;
362
+ // line-height: 22px;
363
+ height: 35px;
364
+ padding-right: 10px;
365
+ color: $uni-secondary-color;
366
+ }
367
+
368
+ .uni-select__input-box {
369
+ height: 35px;
370
+ position: relative;
371
+ /* #ifndef APP-NVUE */
372
+ display: flex;
373
+ /* #endif */
374
+ flex: 1;
375
+ flex-direction: row;
376
+ align-items: center;
377
+ }
378
+
379
+ .uni-select__input {
380
+ flex: 1;
381
+ font-size: 14px;
382
+ height: 22px;
383
+ line-height: 22px;
384
+ }
385
+
386
+ .uni-select__input-plac {
387
+ font-size: 14px;
388
+ color: $uni-secondary-color;
389
+ }
390
+
391
+ .uni-select__selector {
392
+ /* #ifndef APP-NVUE */
393
+ box-sizing: border-box;
394
+ /* #endif */
395
+ position: absolute;
396
+ top: calc(100% + 12px);
397
+ left: 0;
398
+ width: 100%;
399
+ background-color: #ffffff;
400
+ border: 1px solid #ebeef5;
401
+ border-radius: 6px;
402
+ box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
403
+ z-index: 3;
404
+ padding: 4px 0;
405
+ }
406
+
407
+ .uni-select__selector-scroll {
408
+ /* #ifndef APP-NVUE */
409
+ max-height: 200px;
410
+ box-sizing: border-box;
411
+ /* #endif */
412
+ }
413
+
414
+ /* #ifdef H5 */
415
+ @media (min-width: 768px) {
416
+ .uni-select__selector-scroll {
417
+ max-height: 600px;
418
+ }
419
+ }
420
+ /* #endif */
421
+
422
+ .uni-select__selector-empty,
423
+ .uni-select__selector-item {
424
+ /* #ifndef APP-NVUE */
425
+ display: flex;
426
+ cursor: pointer;
427
+ /* #endif */
428
+ line-height: 35px;
429
+ font-size: 14px;
430
+ text-align: center;
431
+ /* border-bottom: solid 1px $uni-border-3; */
432
+ padding: 0px 10px;
433
+ }
434
+
435
+ .uni-select__selector-item:hover {
436
+ background-color: #f9f9f9;
437
+ }
438
+
439
+ .uni-select__selector-empty:last-child,
440
+ .uni-select__selector-item:last-child {
441
+ /* #ifndef APP-NVUE */
442
+ border-bottom: none;
443
+ /* #endif */
444
+ }
445
+
446
+ .uni-select__selector__disabled {
447
+ opacity: 0.4;
448
+ cursor: default;
449
+ }
450
+
451
+ /* picker 弹出层通用的指示小三角 */
452
+ .uni-popper__arrow,
453
+ .uni-popper__arrow::after {
454
+ position: absolute;
455
+ display: block;
456
+ width: 0;
457
+ height: 0;
458
+ border-color: transparent;
459
+ border-style: solid;
460
+ border-width: 6px;
461
+ }
462
+
463
+ .uni-popper__arrow {
464
+ filter: drop-shadow(0 2px 12px rgba(0, 0, 0, 0.03));
465
+ top: -6px;
466
+ left: 10%;
467
+ margin-right: 3px;
468
+ border-top-width: 0;
469
+ border-bottom-color: #ebeef5;
470
+ }
471
+
472
+ .uni-popper__arrow::after {
473
+ content: ' ';
474
+ top: 1px;
475
+ margin-left: -6px;
476
+ border-top-width: 0;
477
+ border-bottom-color: #fff;
478
+ }
479
+
480
+ .uni-select__input-text {
481
+ // width: 280px;
482
+ width: 100%;
483
+ color: $uni-main-color;
484
+ white-space: nowrap;
485
+ text-overflow: ellipsis;
486
+ -o-text-overflow: ellipsis;
487
+ overflow: hidden;
488
+ }
489
+
490
+ .uni-select__input-placeholder {
491
+ color: $uni-base-color;
492
+ font-size: 12px;
493
+ }
494
+
495
+ .uni-select--mask {
496
+ position: fixed;
497
+ top: 0;
498
+ bottom: 0;
499
+ right: 0;
500
+ left: 0;
501
+ z-index: 2;
502
+ }
517
503
  </style>