sadais-piui 1.2.5 → 1.2.6-beta11

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 (35) hide show
  1. package/components/pi-calendar/index.vue +4 -0
  2. package/components/pi-calendar-input/index.vue +199 -0
  3. package/components/pi-calendar-panel/index.vue +5 -6
  4. package/components/pi-checkbox/index.vue +22 -3
  5. package/components/pi-checkbox-group/index.vue +8 -6
  6. package/components/pi-date-picker/index.vue +83 -86
  7. package/components/pi-date-picker-input/index.vue +188 -0
  8. package/components/pi-form/index.vue +20 -0
  9. package/components/pi-form-item/index.vue +57 -9
  10. package/components/pi-input/index.vue +56 -7
  11. package/components/pi-popup-select/index.vue +2 -0
  12. package/components/pi-radio/index.vue +24 -5
  13. package/components/pi-radio-group/index.vue +16 -2
  14. package/components/pi-regions-select/index.vue +32 -6
  15. package/components/pi-regions-select-input/index.vue +192 -0
  16. package/components/pi-section/index.vue +1 -1
  17. package/components/pi-select/index.vue +79 -7
  18. package/components/pi-select-input/index.vue +208 -0
  19. package/components/pi-subsection/index.vue +403 -0
  20. package/config/calendarInput.js +18 -0
  21. package/config/checkbox.js +2 -1
  22. package/config/checkboxGroup.js +2 -1
  23. package/config/datePicker.js +1 -0
  24. package/config/datePickerInput.js +17 -0
  25. package/config/form.js +2 -0
  26. package/config/formItem.js +2 -0
  27. package/config/input.js +11 -1
  28. package/config/radio.js +4 -3
  29. package/config/radioGroup.js +3 -2
  30. package/config/regionsSelect.js +2 -1
  31. package/config/regionsSelectInput.js +28 -0
  32. package/config/select.js +1 -0
  33. package/config/selectInput.js +28 -0
  34. package/config/subsection.js +14 -0
  35. package/package.json +2 -2
@@ -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>
@@ -29,8 +29,10 @@ export default {
29
29
  'labelWidth',
30
30
  'labelAlign',
31
31
  'labelStyle',
32
+ 'itemVerticalAlign',
32
33
  'inputAlign',
33
34
  'wrap',
35
+ 'wrapBottomGap',
34
36
  'labelWrapBorder',
35
37
  'colon',
36
38
  'disabled',
@@ -129,6 +131,18 @@ export default {
129
131
  return form.labelStyle
130
132
  }
131
133
  },
134
+ // 表单项垂直对齐方式,可选值为 top center bottom
135
+ itemVerticalAlign: {
136
+ // `'top'` `'center'` `'bottom'`
137
+ type: String,
138
+ // 'center'
139
+ default() {
140
+ return form.itemVerticalAlign
141
+ },
142
+ validator: function(value) {
143
+ return [null, 'top', 'center', 'bottom'].includes(value)
144
+ }
145
+ },
132
146
  // 表单输入区域 label 对齐方式
133
147
  inputAlign: {
134
148
  // `'left'` `'center'` `'right'`
@@ -147,6 +161,12 @@ export default {
147
161
  // null
148
162
  default: form.wrap
149
163
  },
164
+ // wrap模式下是否在底部增加表单项之间的间距
165
+ wrapBottomGap: {
166
+ type: Boolean,
167
+ // null
168
+ default: form.wrapBottomGap
169
+ },
150
170
  // wrap样式label是否显示边框
151
171
  labelWrapBorder: {
152
172
  type: Boolean,
@@ -2,18 +2,13 @@
2
2
  <view
3
3
  class="pi-form-item"
4
4
  :style="[customStyle, itemStyle]"
5
- :class="[
6
- { disabled: getDisabled },
7
- { border: getBorder },
8
- { 'pi-align-center': !getWrap },
9
- customClass
10
- ]"
5
+ :class="getFormItemClass"
11
6
  @tap="handleItemClick"
12
7
  >
13
8
  <!-- 表单标题 -->
14
9
  <view
15
10
  v-if="label || $slots.label"
16
- class="form-label pi-align-start pi-flex-nowrap"
11
+ class="form-label pi-pd-tb-8 pi-align-start pi-flex-nowrap"
17
12
  :style="[computedLabelStyle, getLabelStyle]"
18
13
  :class="[{ border: getWrap && getLabelWrapBorder }]"
19
14
  >
@@ -30,7 +25,11 @@
30
25
  <!-- 内容区域 -->
31
26
  <view
32
27
  class="content-wrap"
33
- :class="[{ 'pi-flex-sub': !getWrap }, getInputAlign, { wrap: getWrap, nowrap: !getWrap }]"
28
+ :class="[
29
+ { 'pi-flex-sub': !getWrap },
30
+ getInputAlign,
31
+ { 'wrap': getWrap, 'nowrap': !getWrap, 'wrap-bottom': getWrap && getWrapBottomGap }
32
+ ]"
34
33
  :style="[contentWrapStyle]"
35
34
  >
36
35
  <view
@@ -86,6 +85,12 @@ const alignFlexMap = {
86
85
  right: 'flex-end'
87
86
  }
88
87
 
88
+ const verticalAlignFlexMap = {
89
+ top: 'pi-align-start',
90
+ center: 'pi-align-center',
91
+ bottom: 'pi-align-end'
92
+ }
93
+
89
94
  export default {
90
95
  name: 'PiFormItem',
91
96
  mixins: [extendPiFrom, Emitter], // 注入inheritProps
@@ -166,6 +171,18 @@ export default {
166
171
  return formItem.labelStyle
167
172
  }
168
173
  },
174
+ // 表单项垂直对齐方式,可选值为 top center bottom
175
+ itemVerticalAlign: {
176
+ // `'top'` `'center'` `'bottom'`
177
+ type: String,
178
+ // 'center'
179
+ default() {
180
+ return formItem.itemVerticalAlign
181
+ },
182
+ validator: function(value) {
183
+ return [null, 'top', 'center', 'bottom'].includes(value)
184
+ }
185
+ },
169
186
  // 表单label区域 label 对齐方式
170
187
  labelAlign: {
171
188
  // `'left'` `'center'` `'right'`
@@ -196,6 +213,12 @@ export default {
196
213
  // false
197
214
  default: formItem.wrap
198
215
  },
216
+ // wrap模式下是否在底部增加表单项之间的间距
217
+ wrapBottomGap: {
218
+ type: Boolean,
219
+ // null
220
+ default: formItem.wrapBottomGap
221
+ },
199
222
  // wrap样式label是否显示边框
200
223
  labelWrapBorder: {
201
224
  type: Boolean,
@@ -258,6 +281,9 @@ export default {
258
281
  getWrap() {
259
282
  return this.$pi.expand.getPropValue(this.inheritProps.wrap, this.wrap)
260
283
  },
284
+ getWrapBottomGap() {
285
+ return this.$pi.expand.getPropValue(this.inheritProps.wrapBottomGap, this.wrapBottomGap)
286
+ },
261
287
  getLabelWrapBorder() {
262
288
  return this.inheritProps.labelWrapBorder !== null
263
289
  ? this.inheritProps.labelWrapBorder
@@ -296,6 +322,12 @@ export default {
296
322
  getLabelStyle() {
297
323
  return this.$pi.expand.getPropValue(this.inheritProps.labelStyle, this.labelStyle)
298
324
  },
325
+ getItemVerticalAlign() {
326
+ return this.$pi.expand.getPropValue(
327
+ this.inheritProps.itemVerticalAlign,
328
+ this.itemVerticalAlign
329
+ )
330
+ },
299
331
  computedLabelStyle() {
300
332
  const style = {}
301
333
  if (this.getWrap) {
@@ -324,6 +356,19 @@ export default {
324
356
  return {
325
357
  justifyContent: alignFlexMap[this.getInputAlign]
326
358
  }
359
+ },
360
+ getFormItemClass() {
361
+ const classList = [this.customClass]
362
+ if (this.getDisabled) {
363
+ classList.push('disabled')
364
+ }
365
+ if (this.getBorder) {
366
+ classList.push('border')
367
+ }
368
+ if (!this.getWrap && this.getItemVerticalAlign) {
369
+ classList.push(verticalAlignFlexMap[this.getItemVerticalAlign])
370
+ }
371
+ return classList
327
372
  }
328
373
  },
329
374
  mounted() {
@@ -462,7 +507,7 @@ export default {
462
507
  &.nowrap {
463
508
  margin-left: 24rpx;
464
509
  }
465
- &.wrap {
510
+ &.wrap-bottom {
466
511
  margin-bottom: 24rpx;
467
512
  }
468
513
  .form-valid {
@@ -530,5 +575,8 @@ export default {
530
575
  text-align: right;
531
576
  }
532
577
  }
578
+ ::v-deep pi-calendar-input {
579
+ width: 100%;
580
+ }
533
581
  }
534
582
  </style>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <view class="pi-input-wrap">
2
+ <view class="pi-input-wrap" :style="[getInputWrapStyle]">
3
3
  <textarea
4
4
  v-if="type === 'textarea'"
5
5
  class="pi-input-textarea"
@@ -14,7 +14,6 @@
14
14
  :maxlength="maxlength"
15
15
  :cursor-spacing="cursorSpacing"
16
16
  :focus="focus"
17
- :confirmType="confirmType"
18
17
  :confirm-hold="confirmHold"
19
18
  :cursor="cursor"
20
19
  :selection-start="selectionStart"
@@ -48,7 +47,6 @@
48
47
  :maxlength="maxlength"
49
48
  :cursor-spacing="cursorSpacing"
50
49
  :focus="focus"
51
- :confirmType="confirmType"
52
50
  :confirm-hold="confirmHold"
53
51
  :cursor="cursor"
54
52
  :selection-start="selectionStart"
@@ -63,6 +61,20 @@
63
61
  @confirm="handleConfirm"
64
62
  @keyboardheightchange="$emit('keyboardheightchange', $event)"
65
63
  />
64
+ <!-- 清空icon -->
65
+ <pi-icon
66
+ v-if="clearable && val"
67
+ :custom-style="clearIcon.customStyle"
68
+ :custom-class="`pi-pd-left-8 ${clearIcon.customClass}`"
69
+ :name="clearIcon.name"
70
+ :dot="clearIcon.dot"
71
+ :dot-radius="clearIcon.dotRadius"
72
+ :badge="clearIcon.badge"
73
+ :color="clearIcon.color"
74
+ :size="clearIcon.size"
75
+ :class-prefix="clearIcon.classPrefix"
76
+ @tap="handleChange('')"
77
+ />
66
78
  </view>
67
79
  </template>
68
80
 
@@ -145,6 +157,12 @@ export default {
145
157
  // false
146
158
  default: input.disabled
147
159
  },
160
+ // 边框样式设置
161
+ border: {
162
+ type: [Boolean, String],
163
+ // false
164
+ default: input.border
165
+ },
148
166
  // 最大输入长度,设置为 -1 的时候不限制最大长度
149
167
  maxlength: {
150
168
  type: [Number, String],
@@ -235,6 +253,19 @@ export default {
235
253
  type: Boolean,
236
254
  // false
237
255
  default: input.disableDefaultPadding
256
+ },
257
+ // 是否可清空
258
+ clearable: {
259
+ type: Boolean,
260
+ // false
261
+ default: input.clearable
262
+ },
263
+ // 清空图标设置
264
+ clearIcon: {
265
+ type: Object,
266
+ default() {
267
+ return input.clearIcon
268
+ }
238
269
  }
239
270
  },
240
271
  data() {
@@ -247,6 +278,19 @@ export default {
247
278
  const parentFormItem = this.$pi.parent(this, 'PiFormItem')
248
279
  const disabled = this.disabled || (parentFormItem && parentFormItem.getDisabled)
249
280
  return disabled
281
+ },
282
+ getInputWrapStyle() {
283
+ const style = {}
284
+ if (this.border) {
285
+ style.padding = '8rpx 14rpx'
286
+ style.borderRadius = '4rpx'
287
+ if (this.$pi.lang.isString(this.border)) {
288
+ style.border = this.border
289
+ } else {
290
+ style.border = '1Px solid #d9d9d9'
291
+ }
292
+ }
293
+ return style
250
294
  }
251
295
  },
252
296
  methods: {
@@ -256,10 +300,7 @@ export default {
256
300
  handleInput: debounce(function(e) {
257
301
  let value = e.detail.value
258
302
  // 输入内容
259
- this.val = value
260
- this.handleEmitChange()
261
- this.dispatch('PiForm', 'form-change', value)
262
- this.dispatch('PiFormItem', 'form-change', value)
303
+ this.handleChange(value)
263
304
  }, 50),
264
305
  handleFocus() {
265
306
  this.focused = true
@@ -283,6 +324,12 @@ export default {
283
324
  handleConfirm(e) {
284
325
  // 输入完成事件
285
326
  this.$emit('confirm', e.detail.value)
327
+ },
328
+ handleChange(value) {
329
+ this.val = value
330
+ this.handleEmitChange()
331
+ this.dispatch('PiForm', 'form-change', value)
332
+ this.dispatch('PiFormItem', 'form-change', value)
286
333
  }
287
334
  }
288
335
  }
@@ -291,6 +338,8 @@ export default {
291
338
  <style lang="scss" scoped>
292
339
  .pi-input-wrap {
293
340
  width: 100%;
341
+ display: flex;
342
+ align-items: center;
294
343
  .pi-input,
295
344
  .pi-input-textarea {
296
345
  width: 100%;
@@ -281,6 +281,8 @@ export default {
281
281
  <style lang="scss" scoped>
282
282
  .pi-popup-select {
283
283
  height: 100%;
284
+ max-width: 960rpx;
285
+ margin: 0 auto;
284
286
  .pi-button-wrap {
285
287
  flex: 1;
286
288
  &:nth-child(2) {
@@ -10,9 +10,14 @@
10
10
  { stretch: getStretch },
11
11
  customClass
12
12
  ]"
13
- @tap="handleRadioToggle"
13
+ @tap="handleRadioToggle(true)"
14
14
  >
15
- <view v-if="!['text', 'button'].includes(getShape)" class="radio-icon" :style="[radioStyle]">
15
+ <view
16
+ v-if="!['text', 'button'].includes(getShape)"
17
+ class="radio-icon"
18
+ :style="[radioStyle]"
19
+ @tap.stop="handleRadioToggle(false)"
20
+ >
16
21
  <view v-if="getShape === 'dot'" class="dot" />
17
22
  <pi-icon v-else name="blod-check" :size="getIconSize" />
18
23
  </view>
@@ -133,6 +138,12 @@ export default {
133
138
  type: Boolean,
134
139
  // false
135
140
  default: radio.canCancel
141
+ },
142
+ // 是否点击图标才能选中,默认点击整行都能选中
143
+ onlyIconSelect: {
144
+ type: [Boolean],
145
+ // null
146
+ default: radio.onlyIconSelect
136
147
  }
137
148
  },
138
149
  data() {
@@ -150,8 +161,8 @@ export default {
150
161
  return this.inheritProps.stretch
151
162
  },
152
163
  getBorderRadius() {
153
- return this._parent && this._parent.borderRadius
154
- ? this.$pi.common.addUnit(this._parent.borderRadius)
164
+ return this.inheritProps.borderRadius
165
+ ? this.$pi.common.addUnit(this.inheritProps.borderRadius)
155
166
  : this.$pi.common.addUnit(this.borderRadius)
156
167
  },
157
168
  getBorder() {
@@ -181,6 +192,11 @@ export default {
181
192
  getCanCancel() {
182
193
  return this.inheritProps.canCancel !== null ? this.inheritProps.canCancel : this.canCancel
183
194
  },
195
+ getOnlyIconSelect() {
196
+ return this.inheritProps.onlyIconSelect !== null
197
+ ? this.inheritProps.onlyIconSelect
198
+ : this.onlyIconSelect
199
+ },
184
200
  radioStyle() {
185
201
  const style = {
186
202
  width: this.getSize,
@@ -227,7 +243,8 @@ export default {
227
243
  }
228
244
  },
229
245
  methods: {
230
- handleRadioToggle() {
246
+ handleRadioToggle(isTapRow) {
247
+ if (this.getOnlyIconSelect && isTapRow) return
231
248
  if (this.getDisable) return
232
249
  if (this.readonly) return
233
250
  this._parent && this._parent.emitChange(this.name)
@@ -243,6 +260,8 @@ $unactive-color: #cccccc;
243
260
  .pi-radio-wrap {
244
261
  display: inline-flex;
245
262
  align-items: center;
263
+ cursor: pointer;
264
+
246
265
  .radio-icon {
247
266
  position: relative;
248
267
  display: inline-flex;
@@ -31,6 +31,7 @@ export default {
31
31
  parentInit([
32
32
  'val',
33
33
  'shape',
34
+ 'borderRadius',
34
35
  'stretch',
35
36
  'border',
36
37
  'disabled',
@@ -38,7 +39,8 @@ export default {
38
39
  'iconSize',
39
40
  'activeColor',
40
41
  'activeMode',
41
- 'canCancel'
42
+ 'canCancel',
43
+ 'onlyIconSelect'
42
44
  ])
43
45
  ], // 注入value与val,进行双向绑定
44
46
  options: {
@@ -91,6 +93,12 @@ export default {
91
93
  return ['', 'square', 'round', 'dot', 'text', 'button'].includes(value)
92
94
  }
93
95
  },
96
+ // 当shape为square的时候,设置圆角,值为数字时,单位默认rpx
97
+ borderRadius: {
98
+ type: [null, String, Number],
99
+ // 8
100
+ default: radioGroup.borderRadius
101
+ },
94
102
  // 当shape为button的时候,选项否均分布局,可选值 `true`
95
103
  stretch: {
96
104
  type: Boolean,
@@ -141,9 +149,15 @@ export default {
141
149
  },
142
150
  // 能否取消选中状态
143
151
  canCancel: {
144
- type: Boolean,
152
+ type: [Boolean, null],
145
153
  // null
146
154
  default: radioGroup.canCancel
155
+ },
156
+ // 是否点击图标才能选中,默认点击整行都能选中
157
+ onlyIconSelect: {
158
+ type: [Boolean, null],
159
+ // null
160
+ default: radioGroup.onlyIconSelect
147
161
  }
148
162
  },
149
163
  methods: {
@@ -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
  }