sadais-piui 1.2.7-beta91 → 1.2.7-beta92
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.
|
@@ -10,11 +10,7 @@
|
|
|
10
10
|
<template>
|
|
11
11
|
<view class="pi-select-input">
|
|
12
12
|
<!-- 输入框 -->
|
|
13
|
-
<view
|
|
14
|
-
v-if="$slots.default || $slots.$default"
|
|
15
|
-
class="pi-w-100P"
|
|
16
|
-
@click="show = true"
|
|
17
|
-
>
|
|
13
|
+
<view v-if="$slots.default || $slots.$default" class="pi-w-100P" @click="show = true">
|
|
18
14
|
<slot />
|
|
19
15
|
</view>
|
|
20
16
|
<pi-input
|
|
@@ -85,60 +81,60 @@
|
|
|
85
81
|
</template>
|
|
86
82
|
|
|
87
83
|
<script>
|
|
88
|
-
import ValueSync from
|
|
89
|
-
import { getConfig } from
|
|
84
|
+
import ValueSync from '../../mixin/value-sync'
|
|
85
|
+
import { getConfig } from '../../config'
|
|
90
86
|
|
|
91
|
-
const TAG =
|
|
92
|
-
const { selectInput } = getConfig()
|
|
87
|
+
const TAG = 'PiSelectInput'
|
|
88
|
+
const { selectInput } = getConfig()
|
|
93
89
|
|
|
94
|
-
const PI_DEFAULT_FN_FLAG =
|
|
90
|
+
const PI_DEFAULT_FN_FLAG = 'PI_DEFAULT_FN_FLAG'
|
|
95
91
|
|
|
96
92
|
export default {
|
|
97
|
-
name:
|
|
93
|
+
name: 'PiSelectInput',
|
|
98
94
|
// 混入v-model
|
|
99
95
|
mixins: [ValueSync],
|
|
100
96
|
props: {
|
|
101
97
|
// 初始值
|
|
102
98
|
value: {
|
|
103
|
-
required: false
|
|
99
|
+
required: false
|
|
104
100
|
},
|
|
105
101
|
// 自定义样式,对象形式
|
|
106
102
|
customStyle: {
|
|
107
103
|
type: Object,
|
|
108
104
|
// {}
|
|
109
105
|
default() {
|
|
110
|
-
return selectInput.customStyle
|
|
111
|
-
}
|
|
106
|
+
return selectInput.customStyle
|
|
107
|
+
}
|
|
112
108
|
},
|
|
113
109
|
// 自定义样式类,字符串形式
|
|
114
110
|
customClass: {
|
|
115
111
|
type: String,
|
|
116
112
|
// ''
|
|
117
113
|
default() {
|
|
118
|
-
return selectInput.customClass
|
|
119
|
-
}
|
|
114
|
+
return selectInput.customClass
|
|
115
|
+
}
|
|
120
116
|
},
|
|
121
117
|
// input输入设置
|
|
122
118
|
input: {
|
|
123
119
|
type: Object,
|
|
124
120
|
default() {
|
|
125
121
|
// 参照select
|
|
126
|
-
return selectInput.input
|
|
127
|
-
}
|
|
122
|
+
return selectInput.input
|
|
123
|
+
}
|
|
128
124
|
},
|
|
129
125
|
// 日历弹窗参数设置
|
|
130
126
|
select: {
|
|
131
127
|
type: Object,
|
|
132
128
|
default() {
|
|
133
129
|
// 参照select
|
|
134
|
-
return selectInput.select
|
|
135
|
-
}
|
|
130
|
+
return selectInput.select
|
|
131
|
+
}
|
|
136
132
|
},
|
|
137
133
|
// 范围选择时间分隔符,默认(',')
|
|
138
134
|
rangeSplit: {
|
|
139
135
|
type: String,
|
|
140
136
|
// ','
|
|
141
|
-
default: selectInput.rangeSplit
|
|
137
|
+
default: selectInput.rangeSplit
|
|
142
138
|
},
|
|
143
139
|
// 解析值的方法,如果配置了,则读取该函数的返回值作为显示的内容
|
|
144
140
|
parseValueFn: {
|
|
@@ -146,106 +142,95 @@ export default {
|
|
|
146
142
|
default() {
|
|
147
143
|
return {
|
|
148
144
|
[PI_DEFAULT_FN_FLAG]: true,
|
|
149
|
-
fn: selectInput.parseValueFn
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
145
|
+
fn: selectInput.parseValueFn
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
153
149
|
},
|
|
154
150
|
data() {
|
|
155
151
|
return {
|
|
156
|
-
show: false
|
|
157
|
-
}
|
|
152
|
+
show: false
|
|
153
|
+
}
|
|
158
154
|
},
|
|
159
155
|
computed: {
|
|
160
156
|
getSelect() {
|
|
161
|
-
return this.$pi.lang.mergeDeep(selectInput.select, this.select)
|
|
157
|
+
return this.$pi.lang.mergeDeep(selectInput.select, this.select)
|
|
162
158
|
},
|
|
163
159
|
getInput() {
|
|
164
|
-
return this.$pi.lang.mergeDeep(selectInput.input, this.input)
|
|
160
|
+
return this.$pi.lang.mergeDeep(selectInput.input, this.input)
|
|
165
161
|
},
|
|
166
162
|
getInputValue() {
|
|
167
163
|
const parseValueFn = this.parseValueFn[PI_DEFAULT_FN_FLAG]
|
|
168
164
|
? this.parseValueFn.fn
|
|
169
|
-
: this.parseValueFn
|
|
165
|
+
: this.parseValueFn
|
|
170
166
|
if (this.$pi.lang.isFunction(parseValueFn)) {
|
|
171
|
-
const parseValue = parseValueFn(this.val)
|
|
172
|
-
return parseValue
|
|
167
|
+
const parseValue = parseValueFn(this.val)
|
|
168
|
+
return parseValue
|
|
173
169
|
}
|
|
174
|
-
if (this.$pi.lang.isEmpty(this.val)) return
|
|
175
|
-
const getItems =
|
|
176
|
-
this.$refs["pi-select"]?.getItems || this.getSelect.items || [];
|
|
170
|
+
if (this.$pi.lang.isEmpty(this.val)) return ''
|
|
171
|
+
const getItems = this.$refs['pi-select']?.getItems || this.getSelect.items || []
|
|
177
172
|
if (this.getSelect.keyDefaultValue) {
|
|
178
173
|
if (this.getSelect.isMulti) {
|
|
179
174
|
return getItems
|
|
180
|
-
.filter(
|
|
181
|
-
.map(
|
|
182
|
-
.join(this.rangeSplit)
|
|
175
|
+
.filter(item => this.val.includes(item[this.getSelect.keyField]))
|
|
176
|
+
.map(item => item[this.getSelect.displayField])
|
|
177
|
+
.join(this.rangeSplit)
|
|
183
178
|
} else {
|
|
184
|
-
const val = getItems.find(
|
|
185
|
-
|
|
186
|
-
);
|
|
187
|
-
return val ? val[this.getSelect.displayField] : "";
|
|
179
|
+
const val = getItems.find(item => item[this.getSelect.keyField] === this.val)
|
|
180
|
+
return val ? val[this.getSelect.displayField] : ''
|
|
188
181
|
}
|
|
189
182
|
} else {
|
|
190
183
|
// 这里需要从items再次获取,防止用户设置的默认值没有设置displayField的情况
|
|
191
184
|
if (this.getSelect.isMulti) {
|
|
192
185
|
return getItems
|
|
193
|
-
.filter(
|
|
194
|
-
this.val.some(
|
|
195
|
-
(v) =>
|
|
196
|
-
v[this.getSelect.keyField] === item[this.getSelect.keyField]
|
|
197
|
-
)
|
|
186
|
+
.filter(item =>
|
|
187
|
+
this.val.some(v => v[this.getSelect.keyField] === item[this.getSelect.keyField])
|
|
198
188
|
)
|
|
199
|
-
.map(
|
|
200
|
-
.join(this.rangeSplit)
|
|
189
|
+
.map(item => item[this.getSelect.displayField])
|
|
190
|
+
.join(this.rangeSplit)
|
|
201
191
|
} else {
|
|
202
192
|
const val = getItems.find(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
);
|
|
207
|
-
return val ? val[this.getSelect.displayField] : "";
|
|
193
|
+
item => item[this.getSelect.keyField] === this.val[this.getSelect.keyField]
|
|
194
|
+
)
|
|
195
|
+
return val ? val[this.getSelect.displayField] : ''
|
|
208
196
|
}
|
|
209
197
|
}
|
|
210
|
-
}
|
|
198
|
+
}
|
|
211
199
|
},
|
|
212
200
|
created() {
|
|
213
|
-
this.initRemoteSelectData()
|
|
201
|
+
this.initRemoteSelectData()
|
|
214
202
|
},
|
|
215
203
|
methods: {
|
|
216
204
|
initRemoteSelectData() {
|
|
217
205
|
// 如果开启了远程搜索 则在创建之初 先触发一次搜索 让代码触发到用户自定义的parseRemoteSearchResult方法中
|
|
218
206
|
// 目的为了回显数据
|
|
219
|
-
if (
|
|
220
|
-
this.getSelect.remoteSearchConfig.enable &&
|
|
221
|
-
this.getSelect.parseRemoteSearchResult
|
|
222
|
-
) {
|
|
207
|
+
if (this.getSelect.remoteSearchConfig.enable && this.getSelect.parseRemoteSearchResult) {
|
|
223
208
|
this.$nextTick(() => {
|
|
224
|
-
this.$refs[
|
|
225
|
-
})
|
|
209
|
+
this.$refs['pi-select'].handleRemoteSearch()
|
|
210
|
+
})
|
|
226
211
|
}
|
|
227
212
|
},
|
|
228
213
|
handlePopupClose() {
|
|
229
|
-
this.val = false
|
|
214
|
+
this.val = false
|
|
230
215
|
// 关闭
|
|
231
|
-
this.$emit(
|
|
232
|
-
this.handleEmitChange()
|
|
216
|
+
this.$emit('close')
|
|
217
|
+
this.handleEmitChange()
|
|
233
218
|
},
|
|
234
219
|
handleSelectConfirm(value) {
|
|
235
|
-
this.val = value
|
|
236
|
-
this.handleEmitChange()
|
|
220
|
+
this.val = value
|
|
221
|
+
this.handleEmitChange()
|
|
237
222
|
},
|
|
238
223
|
handleClearValue() {
|
|
239
224
|
if (this.getSelect.isMulti) {
|
|
240
|
-
this.handleSelectConfirm([])
|
|
225
|
+
this.handleSelectConfirm([])
|
|
241
226
|
} else {
|
|
242
227
|
this.$pi.lang.isObject(this.val)
|
|
243
|
-
? this.handleSelectConfirm({ [this.getSelect.keyField]:
|
|
244
|
-
: this.handleSelectConfirm(
|
|
228
|
+
? this.handleSelectConfirm({ [this.getSelect.keyField]: '' })
|
|
229
|
+
: this.handleSelectConfirm('')
|
|
245
230
|
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
249
234
|
</script>
|
|
250
235
|
|
|
251
236
|
<style lang="scss" scoped>
|
|
@@ -266,13 +266,14 @@ export default {
|
|
|
266
266
|
left: 0,
|
|
267
267
|
width: 0
|
|
268
268
|
}
|
|
269
|
-
if (
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
269
|
+
if (this.tabRects.length) {
|
|
270
|
+
const activeIndex =
|
|
271
|
+
this.activeIndex >= this.tabRects.length ? this.tabRects.length - 1 : this.activeIndex
|
|
272
|
+
rect.left = this.tabRects.slice(0, activeIndex).reduce((previous, current) => {
|
|
273
|
+
return previous + current.width
|
|
274
|
+
}, 0)
|
|
275
|
+
rect.width = this.tabRects[activeIndex].width
|
|
276
|
+
}
|
|
276
277
|
return rect
|
|
277
278
|
},
|
|
278
279
|
scrollLeft() {
|
|
@@ -287,6 +288,7 @@ export default {
|
|
|
287
288
|
height: this.getSliderBarHeight,
|
|
288
289
|
borderRadius: this.getSliderBarRadius,
|
|
289
290
|
transitionDuration: duration.css,
|
|
291
|
+
transform: `translate(${this.activeRect.left}px, -25%)`,
|
|
290
292
|
...this.sliderBarStyle
|
|
291
293
|
}
|
|
292
294
|
let sliderScrollLeft = this.activeRect.left
|
|
@@ -337,7 +339,7 @@ export default {
|
|
|
337
339
|
methods: {
|
|
338
340
|
clearTimer() {
|
|
339
341
|
if (timer) {
|
|
340
|
-
|
|
342
|
+
clearInterval(timer)
|
|
341
343
|
timer = null
|
|
342
344
|
MAX_RETRY = 10
|
|
343
345
|
}
|
|
@@ -347,6 +349,7 @@ export default {
|
|
|
347
349
|
if (srollWrapRect) {
|
|
348
350
|
this.tabsWidth = srollWrapRect.width
|
|
349
351
|
}
|
|
352
|
+
this.initTabRects()
|
|
350
353
|
this.clearTimer()
|
|
351
354
|
timer = setInterval(() => {
|
|
352
355
|
this.initTabRects()
|
|
@@ -354,11 +357,12 @@ export default {
|
|
|
354
357
|
},
|
|
355
358
|
async initTabRects() {
|
|
356
359
|
MAX_RETRY--
|
|
357
|
-
|
|
358
|
-
console.log(TAG, '计算.pi-tab布局', this.tabRects)
|
|
360
|
+
const tabRects = await this.$pi.common.queryRect(this, '.pi-tab', true)
|
|
359
361
|
const tabWidth = this.tabRects.reduce((previous, current) => {
|
|
360
362
|
return previous + current.width
|
|
361
363
|
}, 0)
|
|
364
|
+
this.tabRects = tabRects
|
|
365
|
+
this.$forceUpdate()
|
|
362
366
|
if (tabWidth || MAX_RETRY <= 0) {
|
|
363
367
|
this.clearTimer()
|
|
364
368
|
}
|