sadais-piui 1.2.6-beta6 → 1.2.6
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.
- package/components/pi-bubble/index.vue +174 -0
- package/components/pi-calendar-input/index.vue +199 -0
- package/components/pi-calendar-panel/index.vue +5 -6
- package/components/pi-checkbox/index.vue +22 -3
- package/components/pi-checkbox-group/index.vue +8 -6
- package/components/pi-date-picker/index.vue +83 -86
- package/components/pi-date-picker-input/index.vue +188 -0
- package/components/pi-form-item/index.vue +5 -2
- package/components/pi-input/index.vue +36 -6
- package/components/pi-radio/index.vue +24 -5
- package/components/pi-radio-group/index.vue +16 -2
- package/components/pi-regions-select/index.vue +32 -6
- package/components/pi-regions-select-input/index.vue +192 -0
- package/components/pi-select/index.vue +79 -7
- package/components/pi-select-input/index.vue +208 -0
- package/components/pi-subsection/index.vue +37 -33
- package/config/bubble.js +6 -0
- package/config/calendarInput.js +18 -0
- package/config/checkbox.js +2 -1
- package/config/checkboxGroup.js +2 -1
- package/config/datePicker.js +1 -0
- package/config/datePickerInput.js +17 -0
- package/config/input.js +10 -1
- package/config/radio.js +4 -3
- package/config/radioGroup.js +3 -2
- package/config/regionsSelect.js +2 -1
- package/config/regionsSelectInput.js +28 -0
- package/config/select.js +1 -0
- package/config/selectInput.js +28 -0
- package/config/subsection.js +2 -2
- package/package.json +2 -2
|
@@ -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
|
-
|
|
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
|
|
299
|
-
if (!
|
|
300
|
-
|
|
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
|
|
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
|
-
|
|
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>
|