sadais-piui 1.2.7-beta90 → 1.2.7-beta91

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,16 +1,20 @@
1
1
  <!--
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2022-05-18 11:08:49
4
- * @LastEditTime: 2023-12-05 09:41:08
4
+ * @LastEditTime: 2024-01-12 11:09:10
5
5
  * @LastEditors: zhangzhenfei
6
6
  * @Description: 选择输入
7
- * @FilePath: /piui-awesome/src/piui/components/pi-select-input/index.vue
7
+ * @FilePath: /piui/components/pi-select-input/index.vue
8
8
  -->
9
9
 
10
10
  <template>
11
11
  <view class="pi-select-input">
12
12
  <!-- 输入框 -->
13
- <view v-if="$slots.default || $slots.$default" class="pi-w-100P" @click="show = true">
13
+ <view
14
+ v-if="$slots.default || $slots.$default"
15
+ class="pi-w-100P"
16
+ @click="show = true"
17
+ >
14
18
  <slot />
15
19
  </view>
16
20
  <pi-input
@@ -81,60 +85,60 @@
81
85
  </template>
82
86
 
83
87
  <script>
84
- import ValueSync from '../../mixin/value-sync'
85
- import { getConfig } from '../../config'
88
+ import ValueSync from "../../mixin/value-sync";
89
+ import { getConfig } from "../../config";
86
90
 
87
- const TAG = 'PiSelectInput'
88
- const { selectInput } = getConfig()
91
+ const TAG = "PiSelectInput";
92
+ const { selectInput } = getConfig();
89
93
 
90
- const PI_DEFAULT_FN_FLAG = 'PI_DEFAULT_FN_FLAG'
94
+ const PI_DEFAULT_FN_FLAG = "PI_DEFAULT_FN_FLAG";
91
95
 
92
96
  export default {
93
- name: 'PiSelectInput',
97
+ name: "PiSelectInput",
94
98
  // 混入v-model
95
99
  mixins: [ValueSync],
96
100
  props: {
97
101
  // 初始值
98
102
  value: {
99
- required: false
103
+ required: false,
100
104
  },
101
105
  // 自定义样式,对象形式
102
106
  customStyle: {
103
107
  type: Object,
104
108
  // {}
105
109
  default() {
106
- return selectInput.customStyle
107
- }
110
+ return selectInput.customStyle;
111
+ },
108
112
  },
109
113
  // 自定义样式类,字符串形式
110
114
  customClass: {
111
115
  type: String,
112
116
  // ''
113
117
  default() {
114
- return selectInput.customClass
115
- }
118
+ return selectInput.customClass;
119
+ },
116
120
  },
117
121
  // input输入设置
118
122
  input: {
119
123
  type: Object,
120
124
  default() {
121
125
  // 参照select
122
- return selectInput.input
123
- }
126
+ return selectInput.input;
127
+ },
124
128
  },
125
129
  // 日历弹窗参数设置
126
130
  select: {
127
131
  type: Object,
128
132
  default() {
129
133
  // 参照select
130
- return selectInput.select
131
- }
134
+ return selectInput.select;
135
+ },
132
136
  },
133
137
  // 范围选择时间分隔符,默认(',')
134
138
  rangeSplit: {
135
139
  type: String,
136
140
  // ','
137
- default: selectInput.rangeSplit
141
+ default: selectInput.rangeSplit,
138
142
  },
139
143
  // 解析值的方法,如果配置了,则读取该函数的返回值作为显示的内容
140
144
  parseValueFn: {
@@ -142,83 +146,106 @@ export default {
142
146
  default() {
143
147
  return {
144
148
  [PI_DEFAULT_FN_FLAG]: true,
145
- fn: selectInput.parseValueFn
146
- }
147
- }
148
- }
149
+ fn: selectInput.parseValueFn,
150
+ };
151
+ },
152
+ },
149
153
  },
150
154
  data() {
151
155
  return {
152
- show: false
153
- }
156
+ show: false,
157
+ };
154
158
  },
155
159
  computed: {
156
160
  getSelect() {
157
- return this.$pi.lang.mergeDeep(selectInput.select, this.select)
161
+ return this.$pi.lang.mergeDeep(selectInput.select, this.select);
158
162
  },
159
163
  getInput() {
160
- return this.$pi.lang.mergeDeep(selectInput.input, this.input)
164
+ return this.$pi.lang.mergeDeep(selectInput.input, this.input);
161
165
  },
162
166
  getInputValue() {
163
167
  const parseValueFn = this.parseValueFn[PI_DEFAULT_FN_FLAG]
164
168
  ? this.parseValueFn.fn
165
- : this.parseValueFn
169
+ : this.parseValueFn;
166
170
  if (this.$pi.lang.isFunction(parseValueFn)) {
167
- const parseValue = parseValueFn(this.val)
168
- return parseValue
171
+ const parseValue = parseValueFn(this.val);
172
+ return parseValue;
169
173
  }
170
- if (this.$pi.lang.isEmpty(this.val)) return ''
171
- const getItems = this.$refs['pi-select']?.getItems || this.getSelect.items
174
+ if (this.$pi.lang.isEmpty(this.val)) return "";
175
+ const getItems =
176
+ this.$refs["pi-select"]?.getItems || this.getSelect.items || [];
172
177
  if (this.getSelect.keyDefaultValue) {
173
178
  if (this.getSelect.isMulti) {
174
179
  return getItems
175
- .filter(item => this.val.includes(item[this.getSelect.keyField]))
176
- .map(item => item[this.getSelect.displayField])
177
- .join(this.rangeSplit)
180
+ .filter((item) => this.val.includes(item[this.getSelect.keyField]))
181
+ .map((item) => item[this.getSelect.displayField])
182
+ .join(this.rangeSplit);
178
183
  } else {
179
- const val = getItems.find(item => item[this.getSelect.keyField] === this.val)
180
- return val ? val[this.getSelect.displayField] : ''
184
+ const val = getItems.find(
185
+ (item) => item[this.getSelect.keyField] === this.val
186
+ );
187
+ return val ? val[this.getSelect.displayField] : "";
181
188
  }
182
189
  } else {
183
190
  // 这里需要从items再次获取,防止用户设置的默认值没有设置displayField的情况
184
191
  if (this.getSelect.isMulti) {
185
192
  return getItems
186
- .filter(item =>
187
- this.val.some(v => v[this.getSelect.keyField] === item[this.getSelect.keyField])
193
+ .filter((item) =>
194
+ this.val.some(
195
+ (v) =>
196
+ v[this.getSelect.keyField] === item[this.getSelect.keyField]
197
+ )
188
198
  )
189
- .map(item => item[this.getSelect.displayField])
190
- .join(this.rangeSplit)
199
+ .map((item) => item[this.getSelect.displayField])
200
+ .join(this.rangeSplit);
191
201
  } else {
192
202
  const val = getItems.find(
193
- item => item[this.getSelect.keyField] === this.val[this.getSelect.keyField]
194
- )
195
- return val ? val[this.getSelect.displayField] : ''
203
+ (item) =>
204
+ item[this.getSelect.keyField] ===
205
+ this.val[this.getSelect.keyField]
206
+ );
207
+ return val ? val[this.getSelect.displayField] : "";
196
208
  }
197
209
  }
198
- }
210
+ },
211
+ },
212
+ created() {
213
+ this.initRemoteSelectData();
199
214
  },
200
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
+ },
201
228
  handlePopupClose() {
202
- this.val = false
229
+ this.val = false;
203
230
  // 关闭
204
- this.$emit('close')
205
- this.handleEmitChange()
231
+ this.$emit("close");
232
+ this.handleEmitChange();
206
233
  },
207
234
  handleSelectConfirm(value) {
208
- this.val = value
209
- this.handleEmitChange()
235
+ this.val = value;
236
+ this.handleEmitChange();
210
237
  },
211
238
  handleClearValue() {
212
239
  if (this.getSelect.isMulti) {
213
- this.handleSelectConfirm([])
240
+ this.handleSelectConfirm([]);
214
241
  } else {
215
242
  this.$pi.lang.isObject(this.val)
216
- ? this.handleSelectConfirm({ [this.getSelect.keyField]: '' })
217
- : this.handleSelectConfirm('')
243
+ ? this.handleSelectConfirm({ [this.getSelect.keyField]: "" })
244
+ : this.handleSelectConfirm("");
218
245
  }
219
- }
220
- }
221
- }
246
+ },
247
+ },
248
+ };
222
249
  </script>
223
250
 
224
251
  <style lang="scss" scoped>
@@ -15,7 +15,7 @@
15
15
  @tap="handleChange(-1)"
16
16
  />
17
17
  <input
18
- :value="value"
18
+ :value="val"
19
19
  type="digit"
20
20
  class="step-input"
21
21
  :disabled="disabled || disableInput"
@@ -49,6 +49,9 @@ import { parseDuration } from '@sadais/piui-tool/tools/common'
49
49
  const TAG = 'PiTabs'
50
50
  const { tabs } = getConfig()
51
51
 
52
+ let MAX_RETRY = 10
53
+ let timer = null
54
+
52
55
  export default {
53
56
  name: 'PiTabs',
54
57
  // 混入v-model
@@ -328,14 +331,37 @@ export default {
328
331
  mounted() {
329
332
  this.init()
330
333
  },
334
+ beforeDestroy() {
335
+ this.clearTimer()
336
+ },
331
337
  methods: {
338
+ clearTimer() {
339
+ if (timer) {
340
+ clearTimeout(timer)
341
+ timer = null
342
+ MAX_RETRY = 10
343
+ }
344
+ },
332
345
  async init() {
333
346
  const srollWrapRect = await this.$pi.common.queryRect(this, '.pi-tabs', false)
334
347
  if (srollWrapRect) {
335
348
  this.tabsWidth = srollWrapRect.width
336
349
  }
350
+ this.clearTimer()
351
+ timer = setInterval(() => {
352
+ this.initTabRects()
353
+ }, 200)
354
+ },
355
+ async initTabRects() {
356
+ MAX_RETRY--
337
357
  this.tabRects = await this.$pi.common.queryRect(this, '.pi-tab', true)
338
358
  console.log(TAG, '计算.pi-tab布局', this.tabRects)
359
+ const tabWidth = this.tabRects.reduce((previous, current) => {
360
+ return previous + current.width
361
+ }, 0)
362
+ if (tabWidth || MAX_RETRY <= 0) {
363
+ this.clearTimer()
364
+ }
339
365
  },
340
366
  handleSelectItem(item) {
341
367
  if (item[this.disabledField]) return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta90",
3
+ "version": "1.2.7-beta91",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {