basic.vue
7.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<script setup lang="ts">
import { ref } from 'vue';
import { ElMessage } from 'element-plus';
import { VButton, VSearchBox } from '../src';
// 搜索示例
const searchText = ref('');
const handleSearch = (value: string) => {
console.log('搜索内容:', value);
ElMessage.success(`正在搜索: ${value || '空'}`);
};
const handleClear = () => {
ElMessage.info('搜索框已清空');
};
// 按钮示例
const loading = ref(false);
const handleSubmit = async () => {
loading.value = true;
ElMessage.info('提交中...');
// 模拟 API 调用
await new Promise((resolve) => setTimeout(resolve, 2000));
loading.value = false;
ElMessage.success('提交成功!');
};
const handleDelete = () => {
ElMessage.success('删除成功!');
};
const handleSave = () => {
ElMessage.success('保存成功!');
};
const handleQuickClick = () => {
ElMessage.info('点击事件触发');
};
</script>
<template>
<div class="example-container">
<h1>@venus/common-ui 组件示例</h1>
<!-- 搜索框示例 -->
<section class="section">
<h2>VSearchBox - 搜索框组件</h2>
<div class="demo-block">
<h3>基础用法</h3>
<VSearchBox
v-model="searchText"
placeholder="请输入搜索内容..."
@search="handleSearch"
@clear="handleClear"
/>
<p class="hint">当前搜索值: {{ searchText }}</p>
</div>
<div class="demo-block">
<h3>不显示搜索按钮</h3>
<VSearchBox
v-model="searchText"
:show-search-button="false"
placeholder="输入后回车搜索"
@search="handleSearch"
/>
</div>
<div class="demo-block">
<h3>不同尺寸</h3>
<div class="size-group">
<VSearchBox
v-model="searchText"
size="large"
placeholder="大尺寸"
@search="handleSearch"
/>
<VSearchBox
v-model="searchText"
size="default"
placeholder="默认尺寸"
@search="handleSearch"
/>
<VSearchBox
v-model="searchText"
size="small"
placeholder="小尺寸"
@search="handleSearch"
/>
</div>
</div>
<div class="demo-block">
<h3>禁用状态</h3>
<VSearchBox v-model="searchText" disabled placeholder="禁用状态" />
</div>
<div class="demo-block">
<h3>自定义防抖时间</h3>
<VSearchBox
v-model="searchText"
:debounce="1000"
placeholder="1秒防抖"
@search="handleSearch"
/>
<p class="hint">输入后 1 秒才会触发搜索</p>
</div>
</section>
<!-- 按钮示例 -->
<section class="section">
<h2>VButton - 按钮组件</h2>
<div class="demo-block">
<h3>按钮类型</h3>
<div class="button-group">
<VButton>默认按钮</VButton>
<VButton type="primary">主要按钮</VButton>
<VButton type="success">成功按钮</VButton>
<VButton type="warning">警告按钮</VButton>
<VButton type="danger">危险按钮</VButton>
<VButton type="info">信息按钮</VButton>
</div>
</div>
<div class="demo-block">
<h3>加载状态</h3>
<div class="button-group">
<VButton type="primary" :loading="loading" @click="handleSubmit">
{{ loading ? '提交中...' : '提交表单' }}
</VButton>
<VButton type="primary" loading> 加载中 </VButton>
</div>
</div>
<div class="demo-block">
<h3>禁用状态</h3>
<div class="button-group">
<VButton disabled>默认按钮</VButton>
<VButton type="primary" disabled>主要按钮</VButton>
<VButton type="success" disabled>成功按钮</VButton>
</div>
</div>
<div class="demo-block">
<h3>确认提示</h3>
<div class="button-group">
<VButton
type="danger"
confirm-text="确定要删除这条数据吗?此操作不可恢复!"
@click="handleDelete"
>
删除数据
</VButton>
<VButton
type="warning"
confirm-text="确定要重置所有设置吗?"
@click="handleSave"
>
重置设置
</VButton>
</div>
<p class="hint">点击按钮会弹出确认对话框</p>
</div>
<div class="demo-block">
<h3>防抖功能</h3>
<div class="button-group">
<VButton type="primary" :debounce="500" @click="handleQuickClick">
500ms 防抖
</VButton>
<VButton type="success" :debounce="1000" @click="handleQuickClick">
1000ms 防抖
</VButton>
</div>
<p class="hint">快速连续点击,只会触发一次</p>
</div>
<div class="demo-block">
<h3>按钮尺寸</h3>
<div class="button-group">
<VButton type="primary" size="large">大型按钮</VButton>
<VButton type="primary" size="default">默认按钮</VButton>
<VButton type="primary" size="small">小型按钮</VButton>
</div>
</div>
<div class="demo-block">
<h3>图标按钮</h3>
<div class="button-group">
<VButton type="primary" icon="Search">搜索</VButton>
<VButton type="success" icon="Check">确认</VButton>
<VButton type="warning" icon="Edit">编辑</VButton>
<VButton type="danger" icon="Delete">删除</VButton>
</div>
</div>
</section>
<!-- 组合示例 -->
<section class="section">
<h2>组合示例</h2>
<div class="demo-block">
<h3>搜索和操作</h3>
<div class="combined-demo">
<VSearchBox
v-model="searchText"
placeholder="搜索用户..."
style="flex: 1"
@search="handleSearch"
/>
<div class="button-group" style="margin-left: 12px">
<VButton type="primary" icon="Plus">新增</VButton>
<VButton type="success" icon="Upload">导入</VButton>
<VButton type="warning" icon="Download">导出</VButton>
</div>
</div>
</div>
</section>
</div>
</template>
<style scoped>
/* 响应式 */
@media (max-width: 768px) {
.example-container {
padding: 16px;
}
.button-group {
gap: 8px;
}
.combined-demo {
flex-direction: column;
align-items: stretch;
}
.combined-demo .button-group {
margin-top: 12px;
margin-left: 0 !important;
}
}
.example-container {
max-width: 1200px;
padding: 24px;
margin: 0 auto;
}
h1 {
margin-bottom: 32px;
font-size: 32px;
font-weight: bold;
color: #303133;
}
.section {
margin-bottom: 48px;
}
.section h2 {
padding-bottom: 8px;
margin-bottom: 24px;
font-size: 24px;
font-weight: 600;
color: #409eff;
border-bottom: 2px solid #409eff;
}
.demo-block {
padding: 24px;
margin-bottom: 32px;
background: #f5f7fa;
border-radius: 8px;
}
.demo-block h3 {
margin-bottom: 16px;
font-size: 16px;
font-weight: 600;
color: #606266;
}
.button-group {
display: flex;
flex-wrap: wrap;
gap: 12px;
align-items: center;
}
.size-group {
display: flex;
flex-direction: column;
gap: 12px;
}
.hint {
margin-top: 12px;
font-size: 14px;
color: #909399;
}
.combined-demo {
display: flex;
gap: 12px;
align-items: center;
}
</style>