web-component-gallery 2.3.32 → 2.3.34
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/dist/js.umd.js +1 -1
- package/lib/directory/Directory.js +0 -1
- package/lib/form-comp/ASelectCustom.vue +199 -280
- package/lib/search/index.vue +72 -26
- package/lib/search/style/index.less +1 -2
- package/package.json +1 -1
package/lib/search/index.vue
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
:key="i"
|
|
7
7
|
:prop="node.model"
|
|
8
8
|
:label="node.label"
|
|
9
|
-
:style="getFormWidth(node
|
|
9
|
+
:style="getFormWidth(node)"
|
|
10
10
|
>
|
|
11
11
|
<RenderComp
|
|
12
12
|
v-on="node.event"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
<slot name="actions" />
|
|
22
22
|
<Button type="primary" html-type="submit">{{ actionsText.primary }}</Button>
|
|
23
23
|
<Button @click="handleReset">{{ actionsText.cancel }}</Button>
|
|
24
|
-
<a @click="advanced = !advanced" v-if="
|
|
24
|
+
<a @click="advanced = !advanced" v-if="showToggleBtn">
|
|
25
25
|
{{ advanced ? '收起' : '展开' }}
|
|
26
26
|
<Icon :type="advanced ? 'up' : 'down'" />
|
|
27
27
|
</a>
|
|
@@ -46,7 +46,7 @@ export default {
|
|
|
46
46
|
data() {
|
|
47
47
|
return {
|
|
48
48
|
advanced: false,
|
|
49
|
-
matchMediaSize:
|
|
49
|
+
matchMediaSize: 1
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
model: {
|
|
@@ -68,9 +68,7 @@ export default {
|
|
|
68
68
|
layoutSize: {
|
|
69
69
|
type: Number,
|
|
70
70
|
default: 4,
|
|
71
|
-
validator: value =>
|
|
72
|
-
return value <= 5
|
|
73
|
-
}
|
|
71
|
+
validator: value => value <= 5
|
|
74
72
|
},
|
|
75
73
|
// 紧凑型和宽松型
|
|
76
74
|
// default 宽松型
|
|
@@ -91,6 +89,11 @@ export default {
|
|
|
91
89
|
autoCall: {
|
|
92
90
|
type: Boolean,
|
|
93
91
|
default: false
|
|
92
|
+
},
|
|
93
|
+
/* 是否默认全展开 */
|
|
94
|
+
defaultExpanded: {
|
|
95
|
+
type: Boolean,
|
|
96
|
+
default: false
|
|
94
97
|
}
|
|
95
98
|
},
|
|
96
99
|
computed: {
|
|
@@ -105,45 +108,88 @@ export default {
|
|
|
105
108
|
matchMedia() {
|
|
106
109
|
return {
|
|
107
110
|
'(max-width: 576px)': 1,
|
|
108
|
-
'(min-width: 576px) and (max-width: 992px)': this.layoutSize - 2,
|
|
111
|
+
'(min-width: 576px) and (max-width: 992px)': Math.max(this.layoutSize - 2, 1),
|
|
109
112
|
'(min-width: 992px)': this.layoutSize
|
|
110
113
|
}
|
|
111
114
|
},
|
|
112
115
|
copyFormSetting() {
|
|
113
116
|
return this.formSetting.filter(node => !node.hidden)
|
|
114
117
|
},
|
|
118
|
+
// 是否显示切换按钮:默认全展开时不显示,其他情况根据是否需要折叠来判断
|
|
119
|
+
showToggleBtn() {
|
|
120
|
+
// 默认全展开时不显示切换按钮
|
|
121
|
+
if (this.defaultExpanded) {
|
|
122
|
+
return false
|
|
123
|
+
}
|
|
124
|
+
// 其他情况:当表单项数量超过当前屏幕能显示的数量时才显示
|
|
125
|
+
return this.copyFormSetting.length > this.matchMediaSize - 1
|
|
126
|
+
},
|
|
115
127
|
count() {
|
|
116
|
-
|
|
128
|
+
// 默认全展开时,显示所有项
|
|
129
|
+
if (this.defaultExpanded) {
|
|
130
|
+
return this.copyFormSetting.length
|
|
131
|
+
}
|
|
132
|
+
// 否则根据展开状态和响应式尺寸计算显示数量
|
|
133
|
+
return this.advanced ? this.copyFormSetting.length : Math.max(this.matchMediaSize - 1, 1)
|
|
117
134
|
}
|
|
118
135
|
},
|
|
119
136
|
mounted() {
|
|
137
|
+
// 初始化展开状态
|
|
138
|
+
this.advanced = this.defaultExpanded
|
|
139
|
+
// 自动查询
|
|
120
140
|
this.autoCall && this.handleSearch()
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
)
|
|
141
|
+
// 初始化响应式尺寸
|
|
142
|
+
this.updateMatchMediaSize()
|
|
143
|
+
// 监听媒体查询变化
|
|
144
|
+
this.bindMediaListeners()
|
|
145
|
+
},
|
|
146
|
+
beforeDestroy() {
|
|
147
|
+
// 清理事件监听器,防止内存泄漏
|
|
148
|
+
this.unbindMediaListeners()
|
|
125
149
|
},
|
|
126
150
|
methods: {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
151
|
+
// 绑定媒体查询监听器
|
|
152
|
+
bindMediaListeners() {
|
|
153
|
+
Object.keys(this.matchMedia).forEach(media =>
|
|
154
|
+
window.matchMedia(media).addEventListener('change', this.handleResize)
|
|
155
|
+
)
|
|
156
|
+
},
|
|
157
|
+
// 解绑媒体查询监听器
|
|
158
|
+
unbindMediaListeners() {
|
|
159
|
+
Object.keys(this.matchMedia).forEach(media =>
|
|
160
|
+
window.matchMedia(media).removeEventListener('change', this.handleResize)
|
|
161
|
+
)
|
|
162
|
+
},
|
|
163
|
+
// 更新响应式尺寸
|
|
164
|
+
updateMatchMediaSize() {
|
|
165
|
+
const size = Object.keys(this.matchMedia).find(media =>
|
|
166
|
+
window.matchMedia(media).matches
|
|
167
|
+
)
|
|
168
|
+
this.matchMediaSize = Math.max(size ? this.matchMedia[size] : this.layoutSize, 1)
|
|
169
|
+
},
|
|
170
|
+
// 处理窗口尺寸变化
|
|
171
|
+
handleResize({ matches, media }) {
|
|
172
|
+
if (matches) {
|
|
173
|
+
this.matchMediaSize = Math.max(this.matchMedia[media], 1)
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
// 计算表单宽度
|
|
177
|
+
getFormWidth({ size }) {
|
|
178
|
+
const gapMap = { middle: '16px', default: '24px' }
|
|
179
|
+
const gap = gapMap[this.searchStyle]
|
|
180
|
+
const percentage = (100 / this.matchMediaSize) * (size ?? 1)
|
|
181
|
+
return `width: calc(${percentage}% - ${gap}); margin-right: ${gap};`
|
|
138
182
|
},
|
|
183
|
+
// 处理搜索
|
|
139
184
|
handleSearch(e) {
|
|
140
|
-
e
|
|
185
|
+
e?.preventDefault()
|
|
141
186
|
const searchForm = {}
|
|
142
|
-
this.copyFormSetting.forEach(
|
|
143
|
-
this.$set(
|
|
187
|
+
this.copyFormSetting.forEach(({ model }) =>
|
|
188
|
+
this.$set(searchForm, model, this.form[model]))
|
|
144
189
|
this.form = { ...searchForm }
|
|
145
190
|
this.$emit('handleSearch', searchForm)
|
|
146
191
|
},
|
|
192
|
+
// 处理重置
|
|
147
193
|
handleReset() {
|
|
148
194
|
this.form = resetFields(this.form)
|
|
149
195
|
this.$refs.searchForm.clearValidate()
|