@weitutech/by-components 1.1.2 → 1.1.4

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,417 +0,0 @@
1
- <template>
2
- <div class="b-form">
3
- <div class="header">
4
- <slot name="header" />
5
- </div>
6
- <el-form
7
- ref="formRef"
8
- class="myForm"
9
- :label-position="labelPosition"
10
- :rules="rules"
11
- :label-width="labelWidth"
12
- :inline="inline"
13
- :model="value"
14
- label-suffix=":"
15
- @submit.native.prevent="submit"
16
- @reset.native.prevent="reset"
17
- >
18
- <el-row>
19
- <template v-for="item in formItems">
20
- <el-col v-if="!item.isHidden" v-show="showFold(item)" :key="item.label" v-bind="item.colLayout || colLayout">
21
- <el-form-item
22
- :label="item.label || ''"
23
- :rules="item.rules"
24
- :style="item.itemStyle || itemStyle"
25
- :prop="item.field"
26
- :label-width="item.labelWidth || labelWidth"
27
- >
28
- <!-- 输入框 -->
29
- <template v-if="item.type === 'input' || item.type === 'password'">
30
- <el-input
31
- :placeholder="item.placeholder"
32
- clearable
33
- v-bind="item.otherOptions"
34
- style="width: 100%"
35
- :show-password="item.type === 'password'"
36
- :value="value[`${item.field}`]"
37
- :size="elSize"
38
- @input="handleValueChange($event, item)"
39
- >
40
- <slot v-if="item.otherOptions && item.otherOptions.isPrefix" name="prefix">
41
- <el-select
42
- v-if="item.otherOptions.prefixType === 'select'"
43
- slot="prepend"
44
- :value="value[`${item.otherOptions.prefixField}`]"
45
- placeholder="请选择"
46
- :style="{
47
- width: '100px'
48
- }"
49
- @input="handleValueChange($event, item.otherOptions)"
50
- >
51
- <el-option
52
- v-for="p in item.otherOptions.prefixOption"
53
- :key="p.value"
54
- :label="p.label"
55
- :value="p.value"
56
- />
57
- </el-select>
58
- </slot>
59
- <slot name="suffix" />
60
- <slot name="prepend" />
61
- <slot name="append" />
62
- </el-input>
63
- </template>
64
- <!-- 选择器 -->
65
- <template v-else-if="item.type === 'select'">
66
- <by-select
67
- :value="value[`${item.field}`]"
68
- :config="item"
69
- v-bind="item.otherOptions"
70
- style="width: 100%"
71
- clearable
72
- filterable
73
- :size="elSize"
74
- :options="item.options"
75
- @input="handleValueChange($event, item)"
76
- />
77
- <slot :name="item.field" />
78
- </template>
79
- <!-- 日期选择器 -->
80
- <template v-else-if="item.type === 'datepicker'">
81
- <el-date-picker
82
- style="width: 100%"
83
- v-bind="item.otherOptions"
84
- :placeholder="item.placeholder"
85
- :value="value[`${item.field}`]"
86
- :size="elSize"
87
- @input="handleValueChange($event, item)"
88
- />
89
- </template>
90
- <!-- 级联 -->
91
- <template v-else-if="item.type === 'cascader'">
92
- <el-cascader
93
- style="width: 100%"
94
- v-bind="item.otherOptions"
95
- :placeholder="item.placeholder"
96
- :options="item.options"
97
- clearable
98
- filterable
99
- :value="value[`${item.field}`]"
100
- :size="elSize"
101
- @input="handleValueChange($event, item)"
102
- />
103
- </template>
104
- <!-- 开关 -->
105
- <template v-else-if="item.type === 'switch'">
106
- <el-switch
107
- v-bind="item.otherOptions"
108
- :value="value[`${item.field}`]"
109
- :size="elSize"
110
- @input="handleValueChange($event, item)"
111
- />
112
- </template>
113
- <!-- 单选框 -->
114
- <template v-else-if="item.type === 'radioGroup'">
115
- <el-radio-group
116
- v-if="item.cGOptions.type === 'button'"
117
- v-bind="item.otherOptions"
118
- :value="value[`${item.field}`]"
119
- :size="elSize"
120
- @input="handleValueChange($event, item)"
121
- >
122
- <el-radio-button
123
- v-for="cgb in item.cGOptions.options"
124
- :key="cgb.value"
125
- :label="cgb.value"
126
- :disabled="!!cgb.disabled"
127
- >
128
- {{ cgb.label }}
129
- </el-radio-button>
130
- </el-radio-group>
131
- <el-radio-group
132
- v-if="item.cGOptions.type === 'checkbox'"
133
- v-bind="item.otherOptions"
134
- :value="value[`${item.field}`]"
135
- :size="elSize"
136
- @input="handleValueChange($event, item)"
137
- >
138
- <el-radio
139
- v-for="cg in item.cGOptions.options"
140
- :key="cg.value"
141
- :label="cg.value"
142
- :disabled="!!cg.disabled"
143
- >
144
- {{ cg.label }}
145
- </el-radio>
146
- </el-radio-group>
147
- </template>
148
- <!-- 多选框 -->
149
- <template v-else-if="item.type === 'checkboxGroup'">
150
- <el-checkbox-group
151
- v-if="item.cGOptions.type === 'button'"
152
- v-bind="item.otherOptions"
153
- :value="value[`${item.field}`]"
154
- :size="elSize"
155
- @input="handleValueChange($event, item)"
156
- >
157
- <el-checkbox-button v-for="cgb in item.cGOptions.options" :key="cgb.value" :label="cgb.value">
158
- {{ cgb.label }}
159
- </el-checkbox-button>
160
- </el-checkbox-group>
161
- <el-checkbox-group
162
- v-if="item.cGOptions.type === 'checkbox'"
163
- v-bind="item.otherOptions"
164
- :value="value[`${item.field}`]"
165
- :size="elSize"
166
- @input="handleValueChange($event, item)"
167
- >
168
- <el-checkbox v-for="cg in item.cGOptions.options" :key="cg.value" :label="cg.value">
169
- {{ cg.label }}
170
- </el-checkbox>
171
- </el-checkbox-group>
172
- </template>
173
- <!-- 文本类型 -->
174
- <template v-else-if="item.type === 'text'">
175
- <slot :name="item.slotName">
176
- <div>{{ `${item.defaultValue}` }}</div>
177
- </slot>
178
- </template>
179
- <!-- 双数字输入框 -->
180
- <template v-else-if="item.type === 'pairNumberInput'">
181
- <PairNumberInput
182
- :value="value[`${item.field}`]"
183
- :earliest-placeholder="item.earliestPlaceholder"
184
- :latest-placeholder="item.latestPlaceholder"
185
- @input="handleValueChange($event, item)"
186
- />
187
- </template>
188
- <!-- 时间范围自定义选择器 -->
189
- <template v-else-if="item.type === 'customDatePicker'">
190
- <CustomDatePicker
191
- :value="value[`${item.field}`]"
192
- v-bind="item"
193
- @input="handleValueChange($event, item)"
194
- @range-change="handleRangeChange($event, item)"
195
- />
196
- </template>
197
- <!-- 自定义 -->
198
- <template v-else-if="item.type === 'custom'">
199
- <slot :name="item.field" :row="item" />
200
- </template>
201
- <!-- 搜索按钮 -->
202
- <template v-else-if="item.type === 'search'">
203
- <el-button
204
- :size="elSize || 'mini'"
205
- type="primary"
206
- icon="el-icon-search"
207
- v-bind="item.otherOptions ?? {}"
208
- @click="handleQueryClick"
209
- >
210
- {{ (item.otherOptions || {}).text || '搜索' }}
211
- </el-button>
212
- </template>
213
- <!-- 重置、搜索 按钮 -->
214
- <template v-else-if="item.type === 'formButtons'">
215
- <el-button
216
- v-if="!item.otherOptions || item.otherOptions.reset !== false"
217
- native-type="reset"
218
- :size="elSize || 'mini'"
219
- v-bind="item.otherOptions ?? {}"
220
- >
221
- {{ (item.otherOptions || {}).resetText || '重置' }}
222
- </el-button>
223
- <el-button
224
- v-if="!item.otherOptions || item.otherOptions.submit !== false"
225
- native-type="submit"
226
- :size="elSize || 'mini'"
227
- type="primary"
228
- :icon="!item.otherOptions || item.otherOptions.showSubmitIcon !== false ? 'el-icon-search' : ''"
229
- v-bind="item.otherOptions ?? {}"
230
- >
231
- {{ (item.otherOptions || {}).submitText || '搜索' }}
232
- </el-button>
233
- </template>
234
- </el-form-item>
235
- </el-col>
236
- </template>
237
- <slot name="btn" :formData="formData" />
238
- </el-row>
239
- </el-form>
240
- <div class="footer">
241
- <slot name="footer" />
242
- </div>
243
- </div>
244
- </template>
245
-
246
- <script>
247
- import PairNumberInput from './comps/pair-number-input.vue'
248
- import CustomDatePicker from './comps/custom-date-picker.vue'
249
-
250
- export default {
251
- name: 'ByForm',
252
- components: {
253
- PairNumberInput,
254
- CustomDatePicker
255
- },
256
-
257
- props: {
258
- value: {
259
- type: Object,
260
- required: true
261
- },
262
- labelPosition: {
263
- type: String,
264
- default: 'right'
265
- },
266
- formItems: {
267
- type: Array,
268
- default: () => []
269
- },
270
- flexible: {
271
- type: Object,
272
- default: () => {
273
- return {
274
- foldField: 'none', // 需要折叠字段
275
- unfold: false // 默认展开?
276
- }
277
- }
278
- },
279
- labelWidth: {
280
- type: String,
281
- default: '100px'
282
- },
283
- itemStyle: {
284
- type: Object,
285
- default: () => ({ padding: '10px 40px' })
286
- },
287
- colLayout: {
288
- type: Object,
289
- default: () => ({
290
- xl: 4, // >1920px 4个
291
- lg: 6,
292
- md: 6,
293
- sm: 8,
294
- xs: 12
295
- })
296
- },
297
- // 是否收起
298
- isFlexible: {
299
- type: Boolean,
300
- default: true
301
- },
302
- inline: {
303
- type: Boolean,
304
- default: false
305
- },
306
- rules: {
307
- type: Object,
308
- default: () => {}
309
- },
310
- elSize: {
311
- type: String,
312
- default: 'mini'
313
- }
314
- },
315
-
316
- data() {
317
- return {
318
- formData: this.value,
319
- // 数据替换
320
- replacementData: undefined,
321
- // 存储初始值
322
- initialValues: { ...this.value }
323
- }
324
- },
325
-
326
- computed: {
327
- showFold() {
328
- return item => {
329
- if (this.isFlexible) {
330
- return true
331
- } else {
332
- if (this.flexible && this.flexible.foldField.length) {
333
- if (this.flexible.foldField.includes(item.id) || this.flexible.foldField.includes(item.field)) {
334
- return false
335
- } else {
336
- return true
337
- }
338
- } else {
339
- return true
340
- }
341
- }
342
- }
343
- }
344
- },
345
-
346
- watch: {
347
- value: {
348
- handler(newValue, oldValue) {
349
- this.formData = newValue
350
- this.replacementData = {
351
- ...(this.replacementData ? this.replacementData : {}),
352
- ...newValue
353
- }
354
- },
355
- deep: true,
356
- immediate: true
357
- }
358
- },
359
-
360
- methods: {
361
- validate(cb = () => {}) {
362
- this.$refs.formRef.validate((valid, obj) => {
363
- cb(valid, obj)
364
- })
365
- },
366
- clearValidate() {
367
- this.$refs.formRef.clearValidate()
368
- },
369
- handleValueChange(value, item) {
370
- if (this.replacementData) {
371
- this.replacementData[item.field] = value
372
- } else {
373
- this.replacementData = { ...this.value, [item.field]: value }
374
- }
375
- this.$emit('change', { ...item, value })
376
- this.$emit('input', this.replacementData)
377
- },
378
- handleRangeChange({ startTime, endTime }, item) {
379
- if (!item.startTimeField || !item.endTimeField) return
380
-
381
- if (this.replacementData) {
382
- this.replacementData[item.startTimeField] = startTime
383
- this.replacementData[item.endTimeField] = endTime
384
- } else {
385
- this.replacementData = {
386
- ...this.value,
387
- [item.startTimeField]: startTime,
388
- [item.endTimeField]: endTime
389
- }
390
- }
391
-
392
- this.$emit('input', this.replacementData)
393
- },
394
- handleQueryClick() {
395
- this.$emit('queryBtnClick')
396
- },
397
-
398
- // 表单提交
399
- submit() {
400
- this.$refs.formRef.validate(valid => {
401
- if (valid) {
402
- this.$emit('submit', this.formData)
403
- } else {
404
- return false
405
- }
406
- })
407
- },
408
- // 重置
409
- reset() {
410
- // 重置为初始值
411
- this.$refs.formRef.resetFields()
412
- this.$emit('input', { ...this.initialValues })
413
- this.$emit('reset')
414
- }
415
- }
416
- }
417
- </script>
@@ -1,122 +0,0 @@
1
- <template>
2
- <div class="b-page-search">
3
- <by-form
4
- :value="formData"
5
- v-bind="searchFormConfig"
6
- :is-flexible="unfold"
7
- @input="handleInput"
8
- @change="handleChange"
9
- @queryBtnClick="handleQueryClick"
10
- @submit="submit"
11
- @reset="reset"
12
- >
13
- <template #header>
14
- <slot name="header"></slot>
15
- </template>
16
- <template #footer>
17
- <div v-if="isShowUnfoldBtn" class="fold">
18
- <by-fold-search @change="handleFlexible" />
19
- </div>
20
- </template>
21
- <template v-for="item in getCustomItem" #[item]>
22
- <slot :name="item"></slot>
23
- </template>
24
- </by-form>
25
- </div>
26
- </template>
27
-
28
- <script>
29
- export default {
30
- props: {
31
- searchFormConfig: {
32
- type: Object,
33
- required: true,
34
- default: () => {}
35
- },
36
- value: {
37
- type: Object,
38
- default: () => {}
39
- }
40
- },
41
-
42
- data() {
43
- return {
44
- formItems: this.searchFormConfig?.formItems ?? [],
45
- formOriginData: {}, // 最初的初始化数据
46
- formData: {}, // 双向绑定的
47
- unfold: false // 是否展开
48
- }
49
- },
50
-
51
- computed: {
52
- isShowUnfoldBtn() {
53
- const formItems = this.searchFormConfig?.formItems ?? []
54
- const flexible = this.searchFormConfig?.flexible ?? undefined
55
- // 如果没有配置flexible, 则默认为true
56
- if (flexible) {
57
- if (formItems.length > flexible.foldField.length) {
58
- return true
59
- } else {
60
- return false
61
- }
62
- } else {
63
- return false
64
- }
65
- },
66
- // 所有需要自定义的插槽
67
- getCustomItem() {
68
- return this.formItems.filter(f => f.type === 'custom').map(item => item.field)
69
- }
70
- },
71
-
72
- watch: {
73
- value: {
74
- handler(newValue, oldValue) {
75
- this.formData = newValue
76
- },
77
- deep: true,
78
- immediate: true
79
- }
80
- },
81
-
82
- mounted() {
83
- this.formOriginData = this.value
84
- this.unfold = this.searchFormConfig.flexible?.unfold ?? false
85
- },
86
-
87
- // 双向绑定的属性应该是由配置文件的field来决定
88
- // 1.优化一: formData中的属性应该动态来决定
89
- methods: {
90
- // 2.优化二: 当用户点击重置
91
- handleResetClick() {
92
- this.formData = { ...this.formOriginData }
93
- this.$emit('input', { ...this.formOriginData })
94
- this.$emit('resetBtnClick')
95
- },
96
-
97
- // 3.优化三: 当用户点击搜索
98
- handleQueryClick() {
99
- this.$emit('queryBtnClick')
100
- },
101
-
102
- // 4.优化四: 当用户点击展开
103
- handleFlexible() {
104
- this.unfold = !this.unfold
105
- },
106
- handleInput(value) {
107
- this.formData = value
108
- this.$emit('input', { ...this.formData })
109
- },
110
- handleChange(event) {
111
- this.$emit('change', event)
112
- },
113
-
114
- submit() {
115
- this.$emit('submit', this.formData)
116
- },
117
- reset() {
118
- this.$emit('reset')
119
- }
120
- }
121
- }
122
- </script>
@@ -1,87 +0,0 @@
1
- <template>
2
- <div
3
- id="pager"
4
- class="pager fixed bottom-0 right-0 w-full flex justify-center items-center z-50"
5
- >
6
- <el-pagination
7
- :current-page="pager['page']"
8
- :page-size="pager['limit']"
9
- :page-sizes="pageSizes"
10
- background
11
- layout="total, prev, pager, next,sizes, jumper"
12
- :total="totalCount"
13
- @size-change="value => handleValueChange(value, 'limit')"
14
- @current-change="value => handleValueChange(value, 'page')"
15
- />
16
- </div>
17
- </template>
18
-
19
- <script>
20
- export default {
21
- name: 'BYPager',
22
- props: {
23
- limit: {
24
- type: Number,
25
- default: 15
26
- },
27
- page: {
28
- type: Number,
29
- default: 1
30
- },
31
- totalCount: {
32
- type: Number,
33
- required: true,
34
- default: 25
35
- },
36
- pageSizes: {
37
- type: Array,
38
- default: () => [10, 15, 20, 25, 30, 50, 100]
39
- }
40
- },
41
-
42
- data() {
43
- return {
44
- pager: {
45
- page: this.page,
46
- limit: this.limit
47
- }
48
- }
49
- },
50
-
51
- watch: {
52
- page: {
53
- handler: function (val, oldVal) {
54
- this.pager.page = val
55
- },
56
- immediate: true
57
- },
58
- limit: {
59
- handler: function (val, oldVal) {
60
- this.pager.limit = val
61
- },
62
- immediate: true
63
- }
64
- },
65
- mounted() {
66
- // 修改分页文案
67
- document.getElementsByClassName(
68
- 'el-pagination__jump'
69
- )[0].childNodes[0].nodeValue = '跳至'
70
- document.getElementsByClassName(
71
- 'el-pagination__jump'
72
- )[0].childNodes[2].nodeValue = ''
73
- },
74
-
75
- methods: {
76
- handleValueChange(value, field) {
77
- if (!value) return
78
- const values = {
79
- ...this.pager,
80
- [field]: value,
81
- page: field === 'limit' ? 1 : value
82
- }
83
- this.$emit('onChange', values)
84
- }
85
- }
86
- }
87
- </script>