sadais-piui 1.2.6-beta7 → 1.2.6-beta8

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.
@@ -1,7 +1,7 @@
1
1
  <!--
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2022-05-18 11:08:49
4
- * @LastEditTime: 2022-05-18 16:38:07
4
+ * @LastEditTime: 2022-05-21 15:00:48
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 日历输入
7
7
  * @FilePath: /hfmp-checkin-front/Users/feilin/workspace/piui/piui-awesome/src/piui/components/pi-calendar-input/index.vue
@@ -152,7 +152,6 @@ export default {
152
152
  ? this.parseValueFn.fn
153
153
  : this.parseValueFn
154
154
  if (this.$pi.lang.isFunction(parseValueFn)) {
155
- // 删除之前的钩子, 如果定义了则使用钩子删除文件
156
155
  const parseValue = parseValueFn(this.val)
157
156
  return parseValue
158
157
  }
@@ -173,7 +172,7 @@ export default {
173
172
  .map(date => {
174
173
  return this.$pi.date.formatDate(new Date(date), this.dateFormat)
175
174
  })
176
- .join(` ${this.rangeSplit} `)
175
+ .join(this.rangeSplit)
177
176
  }
178
177
  return ''
179
178
  }
@@ -58,7 +58,6 @@
58
58
  <view
59
59
  class="pi-abso-center pi-fw-500 pi-light-gray"
60
60
  style="
61
-
62
61
  z-index: 1;
63
62
  font-size: 300rpx;
64
63
  pointer-events: none;
@@ -267,6 +266,11 @@ export default {
267
266
  const inRange =
268
267
  start && end && day.timestamp > start.timestamp && day.timestamp < end.timestamp
269
268
  const activeStyle = {}
269
+ // 处理中间范围的样式
270
+ if (inRange) {
271
+ activeStyle.color = this.rangeColor
272
+ activeStyle.background = this.rangeBg
273
+ }
270
274
  // 处理两端
271
275
  if (isBegin || isEnd) {
272
276
  activeStyle.color = this.activeColor
@@ -275,11 +279,6 @@ export default {
275
279
  : `0 ${this.getActiveBorderRadius} ${this.getActiveBorderRadius} 0`
276
280
  if (this.activeBg) activeStyle.background = this.activeBg
277
281
  }
278
- // 处理中间范围的样式
279
- if (inRange) {
280
- activeStyle.color = this.rangeColor
281
- activeStyle.background = this.rangeBg
282
- }
283
282
  day.activeStyle = activeStyle
284
283
  // type 为 range 开始和结束的提示
285
284
  if (isBegin) day.tip = this.startText
@@ -29,32 +29,9 @@
29
29
  @pickend="handlePickend"
30
30
  @change="handleDateChange"
31
31
  >
32
- <picker-view-column>
33
- <view v-for="(item, index) in years" :key="index" :style="indicatorStyle">
34
- {{ item }}年
35
- </view>
36
- </picker-view-column>
37
- <picker-view-column v-if="showMonth">
38
- <view v-for="(item, index) in months" :key="index" :style="indicatorStyle">
39
- {{ item + 1 }}月
40
- </view>
41
- </picker-view-column>
42
- <picker-view-column v-if="showDay">
43
- <view v-for="(item, index) in days" :key="index" :style="indicatorStyle">{{ item }}日</view>
44
- </picker-view-column>
45
- <picker-view-column v-if="showHour">
46
- <view v-for="(item, index) in hours" :key="index" :style="indicatorStyle">
47
- {{ item }}时
48
- </view>
49
- </picker-view-column>
50
- <picker-view-column v-if="showMinute">
51
- <view v-for="(item, index) in minutes" :key="index" :style="indicatorStyle">
52
- {{ item }}分
53
- </view>
54
- </picker-view-column>
55
- <picker-view-column v-if="showSecond">
56
- <view v-for="(item, index) in seconds" :key="index" :style="indicatorStyle">
57
- {{ item }}秒
32
+ <picker-view-column v-for="col in columns" :key="col.field">
33
+ <view v-for="item in col.items" :key="item" :style="indicatorStyle">
34
+ {{ item }}{{ col.unit }}
58
35
  </view>
59
36
  </picker-view-column>
60
37
  </picker-view>
@@ -68,14 +45,7 @@ import { getConfig } from '../../config'
68
45
 
69
46
  const TAG = 'PiDatePicker'
70
47
  const { datePicker } = getConfig()
71
- const FIELD_MAPS = [
72
- { field: 'year', getMethod: 'years', setMethod: 'setYear' },
73
- { field: 'month', getMethod: 'months', setMethod: 'setMonth' },
74
- { field: 'day', getMethod: 'days', setMethod: 'setDate' },
75
- { field: 'hour', getMethod: 'hours', setMethod: 'setHours' },
76
- { field: 'minute', getMethod: 'minutes', setMethod: 'setMinutes' },
77
- { field: 'second', getMethod: 'seconds', setMethod: 'setSeconds' }
78
- ]
48
+ const FIELDS = ['year', 'month', 'day', 'hour', 'minute', 'second']
79
49
 
80
50
  export default {
81
51
  name: 'PiDatePicker',
@@ -124,13 +94,25 @@ export default {
124
94
  type: String,
125
95
  validator: function(value) {
126
96
  // 这个值必须匹配下列字符串中的一个
127
- return ['year', 'month', 'day', 'hour', 'minute', 'second'].includes(value)
97
+ return FIELDS.includes(value)
128
98
  },
129
99
  // 'day'
130
100
  default() {
131
101
  return datePicker.field
132
102
  }
133
103
  },
104
+ // 日期类型,date、datetime、time
105
+ dateType: {
106
+ // `'date'` `'datetime'` `'time'`
107
+ type: String,
108
+ validator: function(value) {
109
+ return ['date', 'datetime', 'time'].includes(value)
110
+ },
111
+ // 'datetime'
112
+ default() {
113
+ return datePicker.dateType
114
+ }
115
+ },
134
116
  // 日期默认值
135
117
  defaultValue: {
136
118
  type: [Number, String, Date],
@@ -245,61 +227,75 @@ export default {
245
227
  const itemHeight = uni.upx2px(this.itemHeight)
246
228
  return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
247
229
  },
248
- showYear() {
249
- return ['year', 'month', 'day', 'hour', 'minute', 'second'].includes(this.field)
250
- },
251
- showMonth() {
252
- return ['month', 'day', 'hour', 'minute', 'second'].includes(this.field)
253
- },
254
- showDay() {
255
- return ['day', 'hour', 'minute', 'second'].includes(this.field)
256
- },
257
- showHour() {
258
- return ['hour', 'minute', 'second'].includes(this.field)
259
- },
260
- showMinute() {
261
- return ['minute', 'second'].includes(this.field)
262
- },
263
- showSecond() {
264
- return ['second'].includes(this.field)
265
- },
266
- years() {
267
- return this.$pi.common.generateArray(this.startYear, this.endYear)
268
- },
269
- months() {
270
- return this.$pi.common.generateArray(0, 11)
271
- },
272
- days() {
230
+ columns() {
273
231
  const monthDays = new Date(this.date.year, this.date.month, 0).getDate()
274
- return this.$pi.common.generateArray(1, monthDays)
275
- },
276
- hours() {
277
- return this.$pi.common.generateArray(0, 23)
278
- },
279
- minutes() {
280
- return this.$pi.common.generateArray(0, 59)
281
- },
282
- seconds() {
283
- return this.$pi.common.generateArray(0, 59)
232
+ let columns = [
233
+ {
234
+ field: 'year',
235
+ unit: '年',
236
+ key: 'year',
237
+ setMethod: 'setYear',
238
+ items: this.$pi.common.generateArray(this.startYear, this.endYear)
239
+ },
240
+ {
241
+ field: 'month',
242
+ unit: '月',
243
+ key: 'month',
244
+ setMethod: 'setMonth',
245
+ items: this.$pi.common.generateArray(1, 12)
246
+ },
247
+ {
248
+ field: 'day',
249
+ unit: '日',
250
+ key: 'date',
251
+ setMethod: 'setDate',
252
+ items: this.$pi.common.generateArray(1, monthDays)
253
+ },
254
+ {
255
+ field: 'hour',
256
+ unit: '时',
257
+ key: 'hour',
258
+ setMethod: 'setHours',
259
+ type: 'time',
260
+ items: this.$pi.common.generateArray(0, 23)
261
+ },
262
+ {
263
+ field: 'minute',
264
+ unit: '分',
265
+ key: 'minute',
266
+ setMethod: 'setMinutes',
267
+ type: 'time',
268
+ items: this.$pi.common.generateArray(0, 59)
269
+ },
270
+ {
271
+ field: 'second',
272
+ unit: '秒',
273
+ key: 'second',
274
+ setMethod: 'setSeconds',
275
+ type: 'time',
276
+ items: this.$pi.common.generateArray(0, 59)
277
+ }
278
+ ]
279
+
280
+ columns = columns.filter((col, index) => {
281
+ return FIELDS.slice(index).includes(this.field)
282
+ })
283
+
284
+ if (this.dateType === 'time') {
285
+ columns = columns.filter(col => col.type === 'time')
286
+ }
287
+
288
+ return columns
284
289
  },
285
290
  pickerValue() {
286
- const dateFieldMaps = [
287
- { key: 'year', dataKey: 'years', showKey: 'showYear' },
288
- { key: 'month', dataKey: 'months', showKey: 'showMonth' },
289
- { key: 'date', dataKey: 'days', showKey: 'showDay' },
290
- { key: 'hour', dataKey: 'hours', showKey: 'showHour' },
291
- { key: 'minute', dataKey: 'minutes', showKey: 'showMinute' },
292
- { key: 'second', dataKey: 'seconds', showKey: 'showSecond' }
293
- ]
294
291
  const pickerValue = []
295
- dateFieldMaps.forEach(map => {
292
+ this.columns.forEach(col => {
296
293
  // 当前日期字段
297
- let value = this.date[map.key]
298
- if (this[map.showKey] && value) {
299
- if (map.key === 'month') value--
294
+ const value = this.date[col.key]
295
+ if (value !== null) {
300
296
  // 查找当前picker中索引对应的真实值
301
297
  const intValue = parseInt(value, 10)
302
- const val = this[map.dataKey].findIndex(m => m === intValue)
298
+ const val = col.items.findIndex(m => m === intValue)
303
299
  pickerValue.push(val)
304
300
  }
305
301
  })
@@ -338,9 +334,10 @@ export default {
338
334
  values.forEach((value, index) => {
339
335
  if (value !== null) {
340
336
  // value为picker列的索引值
341
- const field = FIELD_MAPS[index] // day
342
- const val = this[field.getMethod][value] // days[index] 取出对应picker值
343
- time[field.setMethod](val) // 调用原生date方法赋值
337
+ const col = this.columns[index]
338
+ let val = col.items[value] // 取出对应picker值
339
+ if (col.field === 'month') val--
340
+ time[col.setMethod](val) // 调用原生date方法赋值
344
341
  }
345
342
  })
346
343
  // 重新解析
@@ -0,0 +1,188 @@
1
+ <!--
2
+ * @Author: zhangzhenfei
3
+ * @Date: 2022-05-18 11:08:49
4
+ * @LastEditTime: 2022-05-20 17:52:51
5
+ * @LastEditors: zhangzhenfei
6
+ * @Description: 日历输入
7
+ * @FilePath: /hfmp-checkin-front/Users/feilin/workspace/piui/piui-awesome/src/piui/components/pi-date-picker-input/index.vue
8
+ -->
9
+
10
+ <template>
11
+ <view class="pi-datePicker-input">
12
+ <!-- 输入框 -->
13
+ <view v-if="$slots.default || $slots.$default" class="pi-w-100P" @click="show = true">
14
+ <slot />
15
+ </view>
16
+ <pi-input
17
+ v-else
18
+ type="text"
19
+ :value="getInputValue"
20
+ :custom-class="input.customClass"
21
+ :custom-style="input.customStyle"
22
+ :placeholder="input.placeholder"
23
+ :placeholder-style="input.placeholderStyle"
24
+ :placeholder-class="input.placeholderClass"
25
+ :disabled="input.disabled"
26
+ :border="input.border"
27
+ :maxlength="input.maxlength"
28
+ :password="input.password"
29
+ :cursor-spacing="input.cursorSpacing"
30
+ :focus="input.focus"
31
+ :confirm-type="input.confirmType"
32
+ :confirm-hold="input.confirmHold"
33
+ :cursor="input.cursor"
34
+ :selection-start="input.selectionStart"
35
+ :selection-end="input.selectionEnd"
36
+ :adjust-position="input.adjustPosition"
37
+ :hold-keyboard="input.holdKeyboard"
38
+ :auto-blur="input.autoBlur"
39
+ :show-confirmbar="input.showConfirmbar"
40
+ :auto-height="input.autoHeight"
41
+ :fixed="input.fixed"
42
+ :disable-default-padding="input.disableDefaultPadding"
43
+ :clearable="input.clearable"
44
+ :clear-icon="input.clearIcon"
45
+ @click="show = true"
46
+ />
47
+
48
+ <!-- 日期弹出框 -->
49
+ <pi-date-picker
50
+ v-model="show"
51
+ :default-value="val"
52
+ :custom-class="getDatePicker.customClass"
53
+ :custom-style="getDatePicker.customStyle"
54
+ :start-year="getDatePicker.startYear"
55
+ :end-year="getDatePicker.endYear"
56
+ :field="getDatePicker.field"
57
+ :date-type="getDatePicker.dateType"
58
+ :format="dateFormat"
59
+ :item-height="getDatePicker.itemHeight"
60
+ :item-style="getDatePicker.itemStyle"
61
+ :show-item-bottom-border="getDatePicker.showItemBottomBorder"
62
+ :popup="getDatePicker.popup"
63
+ :popup-select="getDatePicker.popupSelect"
64
+ :confirm-btn="getDatePicker.confirmBtn"
65
+ :cancel-btn="getDatePicker.cancelBtn"
66
+ @confirm="handleDatePickerConfirm"
67
+ />
68
+ </view>
69
+ </template>
70
+
71
+ <script>
72
+ import ValueSync from '../../mixin/value-sync'
73
+ import { getConfig } from '../../config'
74
+
75
+ const TAG = 'PiDatePickerInput'
76
+ const { datePickerInput } = getConfig()
77
+
78
+ const PI_DEFAULT_FN_FLAG = 'PI_DEFAULT_FN_FLAG'
79
+
80
+ export default {
81
+ name: 'PiDatePickerInput',
82
+ // 混入v-model
83
+ mixins: [ValueSync],
84
+ props: {
85
+ // 初始值
86
+ value: {
87
+ required: false
88
+ },
89
+ // 自定义样式,对象形式
90
+ customStyle: {
91
+ type: Object,
92
+ // {}
93
+ default() {
94
+ return datePickerInput.customStyle
95
+ }
96
+ },
97
+ // 自定义样式类,字符串形式
98
+ customClass: {
99
+ type: String,
100
+ // ''
101
+ default() {
102
+ return datePickerInput.customClass
103
+ }
104
+ },
105
+ // input输入设置
106
+ input: {
107
+ type: Object,
108
+ default() {
109
+ // 参照datePicker
110
+ return datePickerInput.input
111
+ }
112
+ },
113
+ // 日期弹窗参数设置
114
+ datePicker: {
115
+ type: Object,
116
+ default() {
117
+ // 参照datePicker
118
+ return datePickerInput.datePicker
119
+ }
120
+ },
121
+ // 已选择的时间格式化显示规则,默认('YYYY-MM-DD')
122
+ dateFormat: {
123
+ type: String,
124
+ // 'YYYY-MM-DD'
125
+ default: datePickerInput.dateFormat
126
+ },
127
+ // 范围选择时间分隔符,默认('至')
128
+ rangeSplit: {
129
+ type: String,
130
+ // '至'
131
+ default: datePickerInput.rangeSplit
132
+ },
133
+ // 解析值的方法,如果配置了,则读取该函数的返回值作为显示的内容
134
+ parseValueFn: {
135
+ type: [Object, Function],
136
+ default() {
137
+ return {
138
+ [PI_DEFAULT_FN_FLAG]: true,
139
+ fn: datePickerInput.parseValueFn
140
+ }
141
+ }
142
+ }
143
+ },
144
+ data() {
145
+ return {
146
+ show: false
147
+ }
148
+ },
149
+ computed: {
150
+ getDatePicker() {
151
+ return this.$pi.lang.mergeDeep(datePickerInput.datePicker, this.datePicker)
152
+ },
153
+ getInputValue() {
154
+ const parseValueFn = this.parseValueFn[PI_DEFAULT_FN_FLAG]
155
+ ? this.parseValueFn.fn
156
+ : this.parseValueFn
157
+ if (this.$pi.lang.isFunction(parseValueFn)) {
158
+ const parseValue = parseValueFn(this.val)
159
+ return parseValue
160
+ }
161
+ if (!this.dateFormat) {
162
+ console.warn('使用pi-datePicker-input组件,请设置.dateFormat,否则无法正常显示')
163
+ }
164
+ if (this.$pi.lang.isEmpty(this.val)) return ''
165
+ const date = this.$pi.date.parseDate(this.val)
166
+ return date.format(this.dateFormat)
167
+ }
168
+ },
169
+ methods: {
170
+ handlePopupClose() {
171
+ this.val = false
172
+ // 关闭
173
+ this.$emit('close')
174
+ this.handleEmitChange()
175
+ },
176
+ handleDatePickerConfirm(value) {
177
+ this.val = value
178
+ this.handleEmitChange()
179
+ }
180
+ }
181
+ }
182
+ </script>
183
+
184
+ <style lang="scss" scoped>
185
+ .pi-datePicker-input {
186
+ width: 100%;
187
+ }
188
+ </style>
@@ -59,8 +59,6 @@ const TAG = 'PiRegionsSelect'
59
59
  const { regionsSelect } = getConfig()
60
60
  const PLEASE_SELECT_TIP = '请选择'
61
61
 
62
-
63
-
64
62
  export default {
65
63
  name: 'PiRegionsSelect',
66
64
  // 混入v-model
@@ -107,10 +105,14 @@ export default {
107
105
  },
108
106
  // 默认值
109
107
  defaultValue: {
110
- type: Object,
111
- // `null`,单选是传`Object`,多选时传`Array`
108
+ type: [Object, String],
112
109
  default: regionsSelect.defaultValue
113
110
  },
111
+ // 是否只绑定keyField的默认值,默认false
112
+ keyDefaultValue: {
113
+ type: Boolean,
114
+ default: regionsSelect.keyDefaultValue
115
+ },
114
116
  // 行高
115
117
  itemHeight: {
116
118
  type: [String, Number],
@@ -247,9 +249,28 @@ export default {
247
249
  }
248
250
  },
249
251
  methods: {
252
+ valid() {
253
+ if (!this.$pi.lang.isEmpty(this.defaultValue)) {
254
+ if (this.keyDefaultValue && this.$pi.lang.isObject(this.defaultValue)) {
255
+ console.error(TAG, 'keyDefaultValue模式下defaultValue不能为对象类型')
256
+ return false
257
+ }
258
+ if (!this.keyDefaultValue && !this.$pi.lang.isObject(this.defaultValue)) {
259
+ console.error(TAG, '非keyDefaultValue模式下defaultValue必须为对象类型')
260
+ return false
261
+ }
262
+ }
263
+ return true
264
+ },
250
265
  init() {
266
+ if (!this.valid()) {
267
+ return console.error(TAG, '默认值校验失败,跳过初始化')
268
+ }
251
269
  console.log(TAG, '地区选择组件初始化')
252
- const defaultCode = this.defaultValue ? this.defaultValue.code : ''
270
+ let defaultCode = ''
271
+ if (!this.$pi.lang.isEmpty(this.defaultValue)) {
272
+ defaultCode = this.keyDefaultValue ? this.defaultValue : this.defaultValue.code
273
+ }
253
274
  const regions = this.$pi.regions.parseRegions(defaultCode, this.regionsData)
254
275
  this.regions = regions
255
276
  // 默认都是展示tab最后一个列表
@@ -302,9 +323,14 @@ export default {
302
323
  * 确认选择
303
324
  */
304
325
  handleConfirm() {
326
+ let selected = this.regions
327
+ // 返回前生成一下name,方便使用
305
328
  this.regions.generateName()
329
+ if (this.keyDefaultValue) {
330
+ selected = selected[this.keyField]
331
+ }
306
332
  // 点击确认事件
307
- this.$emit('confirm', this.regions)
333
+ this.$emit('confirm', selected, this.regions)
308
334
  this.onConfirmClose && this.handlePopupClose()
309
335
  }
310
336
  }
@@ -0,0 +1,192 @@
1
+ <!--
2
+ * @Author: zhangzhenfei
3
+ * @Date: 2022-05-18 11:08:49
4
+ * @LastEditTime: 2022-05-23 09:24:53
5
+ * @LastEditors: zhangzhenfei
6
+ * @Description: 日历输入
7
+ * @FilePath: /hfmp-checkin-front/Users/feilin/workspace/piui/piui-awesome/src/piui/components/pi-regions-select-input/index.vue
8
+ -->
9
+
10
+ <template>
11
+ <view class="pi-regions-select-input">
12
+ <!-- 输入框 -->
13
+ <view v-if="$slots.default || $slots.$default" class="pi-w-100P" @click="show = true">
14
+ <slot />
15
+ </view>
16
+ <pi-input
17
+ v-else
18
+ type="text"
19
+ :value="getInputValue"
20
+ :custom-class="input.customClass"
21
+ :custom-style="input.customStyle"
22
+ :placeholder="input.placeholder"
23
+ :placeholder-style="input.placeholderStyle"
24
+ :placeholder-class="input.placeholderClass"
25
+ :disabled="input.disabled"
26
+ :border="input.border"
27
+ :maxlength="input.maxlength"
28
+ :password="input.password"
29
+ :cursor-spacing="input.cursorSpacing"
30
+ :focus="input.focus"
31
+ :confirm-type="input.confirmType"
32
+ :confirm-hold="input.confirmHold"
33
+ :cursor="input.cursor"
34
+ :selection-start="input.selectionStart"
35
+ :selection-end="input.selectionEnd"
36
+ :adjust-position="input.adjustPosition"
37
+ :hold-keyboard="input.holdKeyboard"
38
+ :auto-blur="input.autoBlur"
39
+ :show-confirmbar="input.showConfirmbar"
40
+ :auto-height="input.autoHeight"
41
+ :fixed="input.fixed"
42
+ :disable-default-padding="input.disableDefaultPadding"
43
+ :clearable="input.clearable"
44
+ :clear-icon="input.clearIcon"
45
+ @click="show = true"
46
+ />
47
+
48
+ <!-- 地区弹出框 -->
49
+ <pi-regions-select
50
+ v-model="show"
51
+ :default-value="val"
52
+ :custom-class="getRegionsSelect.customClass"
53
+ :custom-style="getRegionsSelect.customStyle"
54
+ :regions-data="getRegionsSelect.regionsData"
55
+ :key-field="getRegionsSelect.keyField"
56
+ :display-field="getRegionsSelect.displayField"
57
+ :key-default-value="getRegionsSelect.keyDefaultValue"
58
+ :item-height="getRegionsSelect.itemHeight"
59
+ :show-item-bottom-border="getRegionsSelect.showItemBottomBorder"
60
+ :item-style="getRegionsSelect.itemStyle"
61
+ :popup-select="getRegionsSelect.popupSelect"
62
+ :popup="getRegionsSelect.popup"
63
+ :confirm-btn="getRegionsSelect.confirmBtn"
64
+ :cancel-btn="getRegionsSelect.cancelBtn"
65
+ @confirm="handleRegionsSelectConfirm"
66
+ />
67
+ </view>
68
+ </template>
69
+
70
+ <script>
71
+ import ValueSync from '../../mixin/value-sync'
72
+ import { getConfig } from '../../config'
73
+
74
+ const TAG = 'PiRegionsSelectInput'
75
+ const { regionsSelectInput } = getConfig()
76
+
77
+ const PI_DEFAULT_FN_FLAG = 'PI_DEFAULT_FN_FLAG'
78
+
79
+ export default {
80
+ name: 'PiRegionsSelectInput',
81
+ // 混入v-model
82
+ mixins: [ValueSync],
83
+ props: {
84
+ // 初始值
85
+ value: {
86
+ required: false
87
+ },
88
+ // 自定义样式,对象形式
89
+ customStyle: {
90
+ type: Object,
91
+ // {}
92
+ default() {
93
+ return regionsSelectInput.customStyle
94
+ }
95
+ },
96
+ // 自定义样式类,字符串形式
97
+ customClass: {
98
+ type: String,
99
+ // ''
100
+ default() {
101
+ return regionsSelectInput.customClass
102
+ }
103
+ },
104
+ // input输入设置
105
+ input: {
106
+ type: Object,
107
+ default() {
108
+ // 参照RegionsSelect
109
+ return regionsSelectInput.input
110
+ }
111
+ },
112
+ // 日历弹窗参数设置
113
+ regionsSelect: {
114
+ type: Object,
115
+ default() {
116
+ // 参照RegionsSelect
117
+ return regionsSelectInput.RegionsSelect
118
+ }
119
+ },
120
+ // 地区分隔符,默认('/')
121
+ rangeSplit: {
122
+ type: String,
123
+ // '/'
124
+ default: regionsSelectInput.rangeSplit
125
+ },
126
+ // 解析值的方法,如果配置了,则读取该函数的返回值作为显示的内容
127
+ parseValueFn: {
128
+ type: [Object, Function],
129
+ default() {
130
+ return {
131
+ [PI_DEFAULT_FN_FLAG]: true,
132
+ fn: regionsSelectInput.parseValueFn
133
+ }
134
+ }
135
+ }
136
+ },
137
+ data() {
138
+ return {
139
+ show: false
140
+ }
141
+ },
142
+ computed: {
143
+ getRegionsSelect() {
144
+ return this.$pi.lang.mergeDeep(regionsSelectInput.regionsSelect, this.regionsSelect)
145
+ },
146
+ getInputValue() {
147
+ const parseValueFn = this.parseValueFn[PI_DEFAULT_FN_FLAG]
148
+ ? this.parseValueFn.fn
149
+ : this.parseValueFn
150
+ if (this.$pi.lang.isFunction(parseValueFn)) {
151
+ const parseValue = parseValueFn(this.val)
152
+ return parseValue
153
+ }
154
+ if (this.$pi.lang.isEmpty(this.val)) return ''
155
+ // 常规字段正常返回
156
+ const code = this.getRegionsSelect.keyDefaultValue
157
+ ? this.val
158
+ : this.val[this.getRegionsSelect.keyField]
159
+ const regions = this.$pi.regions.parseRegions(code, this.getRegionsSelect.regionsData)
160
+ return this.generateRegionsName(regions)
161
+ }
162
+ },
163
+ methods: {
164
+ generateRegionsName(regions) {
165
+ const addressFields = ['province', 'city', 'county', 'street']
166
+ return addressFields
167
+ .reduce((prev, curr) => {
168
+ const name = regions[curr][this.getRegionsSelect.displayField]
169
+ name && prev.push(name)
170
+ return prev
171
+ }, [])
172
+ .join(this.rangeSplit)
173
+ },
174
+ handlePopupClose() {
175
+ this.val = false
176
+ // 关闭
177
+ this.$emit('close')
178
+ this.handleEmitChange()
179
+ },
180
+ handleRegionsSelectConfirm(value) {
181
+ this.val = value
182
+ this.handleEmitChange()
183
+ }
184
+ }
185
+ }
186
+ </script>
187
+
188
+ <style lang="scss" scoped>
189
+ .pi-regions-select-input {
190
+ width: 100%;
191
+ }
192
+ </style>
@@ -137,12 +137,17 @@ export default {
137
137
  // 'text'
138
138
  default: select.displayField
139
139
  },
140
- // 默认值,单选是传Object,多选时传Array
140
+ // 默认值,单选是传Number, String, Object,多选时传Array
141
141
  defaultValue: {
142
- type: [Object, Array],
142
+ type: [Number, String, Object, Array],
143
143
  // null
144
144
  default: select.defaultValue
145
145
  },
146
+ // 是否只绑定keyField的默认值,默认false
147
+ keyDefaultValue: {
148
+ type: Boolean,
149
+ default: select.keyDefaultValue
150
+ },
146
151
  // 是否多选
147
152
  isMulti: {
148
153
  type: Boolean,
@@ -230,6 +235,7 @@ export default {
230
235
  },
231
236
  data() {
232
237
  return {
238
+ // 当前选中的值
233
239
  selected: {}
234
240
  }
235
241
  },
@@ -293,11 +299,64 @@ export default {
293
299
  }
294
300
  },
295
301
  methods: {
302
+ valid() {
303
+ if (!this.$pi.lang.isEmpty(this.defaultValue)) {
304
+ if (this.isMulti && !this.$pi.lang.isArray(this.defaultValue)) {
305
+ console.error(TAG, '多选模式下defaultValue必须为数组类型')
306
+ return false
307
+ }
308
+ if (this.isMulti && this.$pi.lang.isArray(this.defaultValue)) {
309
+ const isArrayObject = this.defaultValue.every(item => {
310
+ return this.$pi.lang.isObject(item)
311
+ })
312
+ if (this.keyDefaultValue && isArrayObject) {
313
+ console.error(TAG, 'keyDefaultValue模式下defaultValue不能为对象数组类型')
314
+ return false
315
+ }
316
+ if (!this.keyDefaultValue && !isArrayObject) {
317
+ console.error(TAG, '非keyDefaultValue模式下defaultValue必须为对象数组类型')
318
+ return false
319
+ }
320
+ }
321
+ if (!this.isMulti) {
322
+ if (this.keyDefaultValue && this.$pi.lang.isObject(this.defaultValue)) {
323
+ console.error(TAG, 'keyDefaultValue模式下defaultValue不能为对象类型')
324
+ return false
325
+ }
326
+ if (
327
+ !this.keyDefaultValue &&
328
+ (!this.$pi.lang.isObject(this.defaultValue) || this.$pi.lang.isArray(this.defaultValue))
329
+ ) {
330
+ console.error(TAG, '非keyDefaultValue模式下defaultValue必须为对象类型')
331
+ return false
332
+ }
333
+ }
334
+ }
335
+ return true
336
+ },
296
337
  init() {
338
+ if (!this.valid()) {
339
+ return console.error(TAG, '默认值校验失败,跳过初始化')
340
+ }
297
341
  console.log(TAG, '初始化')
298
- let selected = this.$pi.lang.cloneDeep(this.defaultValue)
299
- if (!selected) {
300
- selected = this.isMulti ? [] : {}
342
+ let selected = this.isMulti ? [] : {}
343
+ if (!this.$pi.lang.isEmpty(this.defaultValue)) {
344
+ // 如果有默认值,进行初始化
345
+ if (!this.keyDefaultValue) {
346
+ selected = this.$pi.lang.cloneDeep(this.defaultValue)
347
+ } else {
348
+ // 非对象类型构造成对象类型处理
349
+ if (this.isMulti && this.$pi.lang.isArray(this.defaultValue)) {
350
+ selected = this.defaultValue.map(item => ({
351
+ [this.keyField]: item
352
+ }))
353
+ }
354
+ if (!this.isMulti && !this.$pi.lang.isObject(this.defaultValue)) {
355
+ selected = {
356
+ [this.keyField]: this.defaultValue
357
+ }
358
+ }
359
+ }
301
360
  }
302
361
  this.selected = selected
303
362
  },
@@ -313,7 +372,11 @@ export default {
313
372
  // 单选
314
373
  if (!this.singleCancel) {
315
374
  this.selected = item
316
- this.singleConfirm && this.handleConfirm()
375
+ if (this.singleConfirm) {
376
+ setTimeout(() => {
377
+ this.handleConfirm()
378
+ }, 300)
379
+ }
317
380
  return
318
381
  }
319
382
  // 如果单选允许取消,需要判断是否点击了同一个选项
@@ -369,7 +432,16 @@ export default {
369
432
  * 确认选择
370
433
  */
371
434
  handleConfirm() {
372
- this.$emit('confirm', this.selected)
435
+ let selected = this.selected
436
+ if (!this.$pi.lang.isEmpty(selected) && this.keyDefaultValue) {
437
+ // 非对象类型返回值,返回值处理成非对象类型
438
+ if (this.$pi.lang.isArray(selected)) {
439
+ selected = selected.map(item => item[this.keyField])
440
+ } else if (this.$pi.lang.isObject(selected)) {
441
+ selected = selected[this.keyField]
442
+ }
443
+ }
444
+ this.$emit('confirm', selected, this.selected)
373
445
  this.getPopupSelect.onConfirmClose && this.handlePopupClose()
374
446
  }
375
447
  }
@@ -0,0 +1,208 @@
1
+ <!--
2
+ * @Author: zhangzhenfei
3
+ * @Date: 2022-05-18 11:08:49
4
+ * @LastEditTime: 2022-05-21 15:00:18
5
+ * @LastEditors: zhangzhenfei
6
+ * @Description: 选择输入
7
+ * @FilePath: /hfmp-checkin-front/Users/feilin/workspace/piui/piui-awesome/src/piui/components/pi-select-input/index.vue
8
+ -->
9
+
10
+ <template>
11
+ <view class="pi-select-input">
12
+ <!-- 输入框 -->
13
+ <view v-if="$slots.default || $slots.$default" class="pi-w-100P" @click="show = true">
14
+ <slot />
15
+ </view>
16
+ <pi-input
17
+ v-else
18
+ type="text"
19
+ :value="getInputValue"
20
+ :custom-class="input.customClass"
21
+ :custom-style="input.customStyle"
22
+ :placeholder="input.placeholder"
23
+ :placeholder-style="input.placeholderStyle"
24
+ :placeholder-class="input.placeholderClass"
25
+ :disabled="input.disabled"
26
+ :border="input.border"
27
+ :maxlength="input.maxlength"
28
+ :password="input.password"
29
+ :cursor-spacing="input.cursorSpacing"
30
+ :focus="input.focus"
31
+ :confirm-type="input.confirmType"
32
+ :confirm-hold="input.confirmHold"
33
+ :cursor="input.cursor"
34
+ :selection-start="input.selectionStart"
35
+ :selection-end="input.selectionEnd"
36
+ :adjust-position="input.adjustPosition"
37
+ :hold-keyboard="input.holdKeyboard"
38
+ :auto-blur="input.autoBlur"
39
+ :show-confirmbar="input.showConfirmbar"
40
+ :auto-height="input.autoHeight"
41
+ :fixed="input.fixed"
42
+ :disable-default-padding="input.disableDefaultPadding"
43
+ :clearable="input.clearable"
44
+ :clear-icon="input.clearIcon"
45
+ @click="show = true"
46
+ />
47
+
48
+ <!-- 选择弹出框 -->
49
+ <pi-select
50
+ v-model="show"
51
+ :default-value="val"
52
+ :key-default-value="getSelect.keyDefaultValue"
53
+ :custom-class="getSelect.customClass"
54
+ :custom-style="getSelect.customStyle"
55
+ :items="getSelect.items"
56
+ :key-field="getSelect.keyField"
57
+ :display-field="getSelect.displayField"
58
+ :is-multi="getSelect.isMulti"
59
+ :single-cancel="getSelect.singleCancel"
60
+ :single-confirm="getSelect.singleConfirm"
61
+ :item-height="getSelect.itemHeight"
62
+ :show-item-bottom-border="getSelect.showItemBottomBorder"
63
+ :item-style="getSelect.itemStyle"
64
+ :selected-img="getSelect.selectedImg"
65
+ :selected-checkbox="getSelect.selectedCheckbox"
66
+ :popup-select="getSelect.popupSelect"
67
+ :popup="getSelect.popup"
68
+ :confirm-btn="getSelect.confirmBtn"
69
+ :cancel-btn="getSelect.cancelBtn"
70
+ @confirm="handleSelectConfirm"
71
+ />
72
+ </view>
73
+ </template>
74
+
75
+ <script>
76
+ import ValueSync from '../../mixin/value-sync'
77
+ import { getConfig } from '../../config'
78
+
79
+ const TAG = 'PiSelectInput'
80
+ const { selectInput } = getConfig()
81
+
82
+ const PI_DEFAULT_FN_FLAG = 'PI_DEFAULT_FN_FLAG'
83
+
84
+ export default {
85
+ name: 'PiSelectInput',
86
+ // 混入v-model
87
+ mixins: [ValueSync],
88
+ props: {
89
+ // 初始值
90
+ value: {
91
+ required: false
92
+ },
93
+ // 自定义样式,对象形式
94
+ customStyle: {
95
+ type: Object,
96
+ // {}
97
+ default() {
98
+ return selectInput.customStyle
99
+ }
100
+ },
101
+ // 自定义样式类,字符串形式
102
+ customClass: {
103
+ type: String,
104
+ // ''
105
+ default() {
106
+ return selectInput.customClass
107
+ }
108
+ },
109
+ // input输入设置
110
+ input: {
111
+ type: Object,
112
+ default() {
113
+ // 参照select
114
+ return selectInput.input
115
+ }
116
+ },
117
+ // 日历弹窗参数设置
118
+ select: {
119
+ type: Object,
120
+ default() {
121
+ // 参照select
122
+ return selectInput.select
123
+ }
124
+ },
125
+ // 范围选择时间分隔符,默认(',')
126
+ rangeSplit: {
127
+ type: String,
128
+ // ','
129
+ default: selectInput.rangeSplit
130
+ },
131
+ // 解析值的方法,如果配置了,则读取该函数的返回值作为显示的内容
132
+ parseValueFn: {
133
+ type: [Object, Function],
134
+ default() {
135
+ return {
136
+ [PI_DEFAULT_FN_FLAG]: true,
137
+ fn: selectInput.parseValueFn
138
+ }
139
+ }
140
+ }
141
+ },
142
+ data() {
143
+ return {
144
+ show: false
145
+ }
146
+ },
147
+ computed: {
148
+ getSelect() {
149
+ return this.$pi.lang.mergeDeep(selectInput.select, this.select)
150
+ },
151
+ getInputValue() {
152
+ const parseValueFn = this.parseValueFn[PI_DEFAULT_FN_FLAG]
153
+ ? this.parseValueFn.fn
154
+ : this.parseValueFn
155
+ if (this.$pi.lang.isFunction(parseValueFn)) {
156
+ const parseValue = parseValueFn(this.val)
157
+ return parseValue
158
+ }
159
+ if (this.$pi.lang.isEmpty(this.val)) return ''
160
+ if (this.getSelect.keyDefaultValue) {
161
+ if (this.getSelect.isMulti) {
162
+ return this.getSelect.items
163
+ .filter(item => this.val.includes(item[this.getSelect.keyField]))
164
+ .map(item => item[this.getSelect.displayField])
165
+ .join(this.rangeSplit)
166
+ } else {
167
+ const val = this.getSelect.items.find(item => item[this.getSelect.keyField] === this.val)
168
+ return val ? val[this.getSelect.displayField] : ''
169
+ }
170
+ } else {
171
+ // 这里需要从items再次获取,防止用户设置的默认值没有设置displayField的情况
172
+ if (this.getSelect.isMulti) {
173
+ return this.getSelect.items
174
+ .filter(item =>
175
+ this.val.some(v => v[this.getSelect.keyField] === item[this.getSelect.keyField])
176
+ )
177
+ .map(item => item[this.getSelect.displayField])
178
+ .join(this.rangeSplit)
179
+ } else {
180
+ const val = this.getSelect.items.find(
181
+ item => item[this.getSelect.keyField] === this.val[this.getSelect.keyField]
182
+ )
183
+ return val ? val[this.getSelect.displayField] : ''
184
+ }
185
+ }
186
+ }
187
+ },
188
+ methods: {
189
+ handlePopupClose() {
190
+ this.val = false
191
+ // 关闭
192
+ this.$emit('close')
193
+ this.handleEmitChange()
194
+ },
195
+ handleSelectConfirm(value) {
196
+ console.log(value)
197
+ this.val = value
198
+ this.handleEmitChange()
199
+ }
200
+ }
201
+ }
202
+ </script>
203
+
204
+ <style lang="scss" scoped>
205
+ .pi-select-input {
206
+ width: 100%;
207
+ }
208
+ </style>
@@ -10,6 +10,7 @@ export default {
10
10
  startYear, // 开始年份(默认当前年份 - 30)
11
11
  endYear, // 结束年份(默认当前年份)
12
12
  field: 'day', // 选择器的粒度 year、month、day、hour、minute、second
13
+ dateType: 'datetime', // 日期类型,date、datetime、time(默认值:datetime)
13
14
  defaultValue: '', // 日期默认值
14
15
  format: '', // 返回的日期格式,为空的时候,返回的是日期对象
15
16
  itemHeight: 110, // 行高(默认:'110rpx')
@@ -0,0 +1,17 @@
1
+ import input from './input'
2
+ import datePicker from './datePicker'
3
+
4
+ export default {
5
+ customClass: '', // 自定义样式类,字符串形式('')
6
+ customStyle: {}, // 自定义样式,对象形式(默认值:{})
7
+ // input输入设置
8
+ input: {
9
+ ...input,
10
+ placeholder: '请选择',
11
+ disabled: true // 是否禁用
12
+ },
13
+ // 日期弹窗的配置,默认选项请参照datePicker
14
+ datePicker,
15
+ dateFormat: 'YYYY-MM-DD', // 已选择的时间格式化显示规则,默认('YYYY-MM-DD')
16
+ parseValueFn: null // 解析值的方法,如果配置了,则读取该函数的返回值作为显示的内容
17
+ }
@@ -7,7 +7,8 @@ export default {
7
7
  regionsData, // 区域数据(考虑到体积,只包含了部分演示数据)
8
8
  keyField: 'code', // 选项id字段,默认为code
9
9
  displayField: 'name', // 选项显示字段,默认为name
10
- defaultValue: null, // 默认值,单选是传Object,多选时传Array,默认null
10
+ keyDefaultValue: false, // 是否只绑定keyField的默认值,默认false
11
+ defaultValue: null, // 默认值
11
12
  itemHeight: 110, // 行高(默认:'110rpx')
12
13
  showItemBottomBorder: true, // 是否显示item下边框(默认:'true')
13
14
  itemStyle: {}, // 行样式(默认:'{}')
@@ -0,0 +1,28 @@
1
+ /*
2
+ * @Author: zhangzhenfei
3
+ * @Date: 2022-05-20 16:47:46
4
+ * @LastEditTime: 2022-05-20 17:54:52
5
+ * @LastEditors: zhangzhenfei
6
+ * @Description:
7
+ * @FilePath: /hfmp-checkin-front/Users/feilin/workspace/piui/piui-awesome/src/piui/config/regionsSelectInput.js
8
+ */
9
+ import input from './input'
10
+ import regionsSelect from './regionsSelect'
11
+
12
+ export default {
13
+ customClass: '', // 自定义样式类,字符串形式('')
14
+ customStyle: {}, // 自定义样式,对象形式(默认值:{})
15
+ // input输入设置
16
+ input: {
17
+ ...input,
18
+ placeholder: '请选择',
19
+ disabled: true // 是否禁用
20
+ },
21
+ // 地区弹窗的配置,默认选项请参照regionsSelect
22
+ regionsSelect: {
23
+ ...regionsSelect,
24
+ keyDefaultValue: true
25
+ },
26
+ rangeSplit: '/', // 地区分隔符,默认('/')
27
+ parseValueFn: null // 解析值的方法,如果配置了,则读取该函数的返回值作为显示的内容
28
+ }
package/config/select.js CHANGED
@@ -8,6 +8,7 @@ export default {
8
8
  items: [], // 选项列表,默认([])
9
9
  keyField: 'id', // 选项id字段,默认为id
10
10
  displayField: 'text', // 选项显示字段,默认为text
11
+ keyDefaultValue: false, // 是否只绑定keyField的默认值,默认false
11
12
  defaultValue: null, // 默认值,单选是传Object,多选时传Array,默认null
12
13
  isMulti: false, // 是否多选,(默认:false)
13
14
  singleCancel: true, // 单选模式下,是否可取消选中
@@ -0,0 +1,28 @@
1
+ /*
2
+ * @Author: zhangzhenfei
3
+ * @Date: 2022-05-18 16:52:21
4
+ * @LastEditTime: 2022-05-19 11:53:43
5
+ * @LastEditors: zhangzhenfei
6
+ * @Description:
7
+ * @FilePath: /hfmp-checkin-front/Users/feilin/workspace/piui/piui-awesome/src/piui/config/selectInput.js
8
+ */
9
+ import input from './input'
10
+ import select from './select'
11
+
12
+ export default {
13
+ customClass: '', // 自定义样式类,字符串形式('')
14
+ customStyle: {}, // 自定义样式,对象形式(默认值:{})
15
+ // input输入设置
16
+ input: {
17
+ ...input,
18
+ placeholder: '请选择',
19
+ disabled: true // 是否禁用
20
+ },
21
+ // select弹窗的配置,默认选项请参照select
22
+ select: {
23
+ ...select,
24
+ keyDefaultValue: true
25
+ },
26
+ rangeSplit: ',', // 范围选择时间分隔符,默认(',')
27
+ parseValueFn: null // 解析值的方法,如果配置了,则读取该函数的返回值作为显示的内容
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.6beta7",
3
+ "version": "1.2.6beta8",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {