sadais-piui 1.2.7-beta91 → 1.2.7-beta93

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: 2024-01-12 11:09:10
4
+ * @LastEditTime: 2024-01-15 14:50:23
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 选择输入
7
7
  * @FilePath: /piui/components/pi-select-input/index.vue
@@ -10,17 +10,13 @@
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
21
17
  v-else
22
18
  type="text"
23
- :value="getInputValue"
19
+ :value="getInputValue || remoteVal"
24
20
  :custom-class="getInput.customClass"
25
21
  :custom-style="getInput.customStyle"
26
22
  :placeholder="getInput.placeholder"
@@ -85,60 +81,60 @@
85
81
  </template>
86
82
 
87
83
  <script>
88
- import ValueSync from "../../mixin/value-sync";
89
- import { getConfig } from "../../config";
84
+ import ValueSync from '../../mixin/value-sync'
85
+ import { getConfig } from '../../config'
90
86
 
91
- const TAG = "PiSelectInput";
92
- const { selectInput } = getConfig();
87
+ const TAG = 'PiSelectInput'
88
+ const { selectInput } = getConfig()
93
89
 
94
- const PI_DEFAULT_FN_FLAG = "PI_DEFAULT_FN_FLAG";
90
+ const PI_DEFAULT_FN_FLAG = 'PI_DEFAULT_FN_FLAG'
95
91
 
96
92
  export default {
97
- name: "PiSelectInput",
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,104 @@ 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
152
  show: false,
157
- };
153
+ remoteVal: ''
154
+ }
158
155
  },
159
156
  computed: {
160
157
  getSelect() {
161
- return this.$pi.lang.mergeDeep(selectInput.select, this.select);
158
+ return this.$pi.lang.mergeDeep(selectInput.select, this.select)
162
159
  },
163
160
  getInput() {
164
- return this.$pi.lang.mergeDeep(selectInput.input, this.input);
161
+ return this.$pi.lang.mergeDeep(selectInput.input, this.input)
165
162
  },
166
163
  getInputValue() {
164
+ return this.handleGetInputValue()
165
+ }
166
+ },
167
+ created() {
168
+ this.initRemoteSelectData()
169
+ },
170
+ methods: {
171
+ initRemoteSelectData() {
172
+ // 如果开启了远程搜索 则在创建之初 先触发一次搜索 让代码触发到用户自定义的parseRemoteSearchResult方法中
173
+ // 目的为了回显数据
174
+ if (
175
+ this.getSelect.remoteSearchConfig.enable &&
176
+ this.getSelect.parseRemoteSearchResult &&
177
+ this.val
178
+ ) {
179
+ this.$nextTick(async () => {
180
+ await this.$refs['pi-select'].handleRemoteSearch()
181
+ this.remoteVal = this.handleGetInputValue()
182
+ })
183
+ }
184
+ },
185
+ handleGetInputValue() {
167
186
  const parseValueFn = this.parseValueFn[PI_DEFAULT_FN_FLAG]
168
187
  ? this.parseValueFn.fn
169
- : this.parseValueFn;
188
+ : this.parseValueFn
170
189
  if (this.$pi.lang.isFunction(parseValueFn)) {
171
- const parseValue = parseValueFn(this.val);
172
- return parseValue;
190
+ const parseValue = parseValueFn(this.val)
191
+ return parseValue
173
192
  }
174
- if (this.$pi.lang.isEmpty(this.val)) return "";
175
- const getItems =
176
- this.$refs["pi-select"]?.getItems || this.getSelect.items || [];
193
+ if (this.$pi.lang.isEmpty(this.val)) return ''
194
+ const getItems = this.$refs['pi-select']?.getItems || this.getSelect.items || []
177
195
  if (this.getSelect.keyDefaultValue) {
178
196
  if (this.getSelect.isMulti) {
179
197
  return getItems
180
- .filter((item) => this.val.includes(item[this.getSelect.keyField]))
181
- .map((item) => item[this.getSelect.displayField])
182
- .join(this.rangeSplit);
198
+ .filter(item => this.val.includes(item[this.getSelect.keyField]))
199
+ .map(item => item[this.getSelect.displayField])
200
+ .join(this.rangeSplit)
183
201
  } else {
184
- const val = getItems.find(
185
- (item) => item[this.getSelect.keyField] === this.val
186
- );
187
- return val ? val[this.getSelect.displayField] : "";
202
+ const val = getItems.find(item => item[this.getSelect.keyField] === this.val)
203
+ return val ? val[this.getSelect.displayField] : ''
188
204
  }
189
205
  } else {
190
206
  // 这里需要从items再次获取,防止用户设置的默认值没有设置displayField的情况
191
207
  if (this.getSelect.isMulti) {
192
208
  return getItems
193
- .filter((item) =>
194
- this.val.some(
195
- (v) =>
196
- v[this.getSelect.keyField] === item[this.getSelect.keyField]
197
- )
209
+ .filter(item =>
210
+ this.val.some(v => v[this.getSelect.keyField] === item[this.getSelect.keyField])
198
211
  )
199
- .map((item) => item[this.getSelect.displayField])
200
- .join(this.rangeSplit);
212
+ .map(item => item[this.getSelect.displayField])
213
+ .join(this.rangeSplit)
201
214
  } else {
202
215
  const val = getItems.find(
203
- (item) =>
204
- item[this.getSelect.keyField] ===
205
- this.val[this.getSelect.keyField]
206
- );
207
- return val ? val[this.getSelect.displayField] : "";
216
+ item => item[this.getSelect.keyField] === this.val[this.getSelect.keyField]
217
+ )
218
+ return val ? val[this.getSelect.displayField] : ''
208
219
  }
209
220
  }
210
221
  },
211
- },
212
- created() {
213
- this.initRemoteSelectData();
214
- },
215
- methods: {
216
- initRemoteSelectData() {
217
- // 如果开启了远程搜索 则在创建之初 先触发一次搜索 让代码触发到用户自定义的parseRemoteSearchResult方法中
218
- // 目的为了回显数据
219
- if (
220
- this.getSelect.remoteSearchConfig.enable &&
221
- this.getSelect.parseRemoteSearchResult
222
- ) {
223
- this.$nextTick(() => {
224
- this.$refs["pi-select"].handleRemoteSearch();
225
- });
226
- }
227
- },
228
222
  handlePopupClose() {
229
- this.val = false;
223
+ this.val = false
230
224
  // 关闭
231
- this.$emit("close");
232
- this.handleEmitChange();
225
+ this.$emit('close')
226
+ this.handleEmitChange()
233
227
  },
234
228
  handleSelectConfirm(value) {
235
- this.val = value;
236
- this.handleEmitChange();
229
+ this.val = value
230
+ this.handleEmitChange()
237
231
  },
238
232
  handleClearValue() {
239
233
  if (this.getSelect.isMulti) {
240
- this.handleSelectConfirm([]);
234
+ this.handleSelectConfirm([])
241
235
  } else {
242
236
  this.$pi.lang.isObject(this.val)
243
- ? this.handleSelectConfirm({ [this.getSelect.keyField]: "" })
244
- : this.handleSelectConfirm("");
237
+ ? this.handleSelectConfirm({ [this.getSelect.keyField]: '' })
238
+ : this.handleSelectConfirm('')
245
239
  }
246
- },
247
- },
248
- };
240
+ }
241
+ }
242
+ }
249
243
  </script>
250
244
 
251
245
  <style lang="scss" scoped>
@@ -266,13 +266,14 @@ export default {
266
266
  left: 0,
267
267
  width: 0
268
268
  }
269
- if (!this.tabRects.length) return rect
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
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
- clearTimeout(timer)
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
- this.tabRects = await this.$pi.common.queryRect(this, '.pi-tab', true)
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta91",
3
+ "version": "1.2.7-beta93",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {