matrix_components 2.0.382 → 2.0.385

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.
@@ -0,0 +1,263 @@
1
+ <template>
2
+ <div class="demo-container">
3
+ <div class="control-panel">
4
+ <h3>Excel 预览演示</h3>
5
+
6
+ <!-- 文件上传方式 -->
7
+ <div class="upload-section">
8
+ <h4>方式一:文件上传</h4>
9
+ <el-form-item label="弹框模式:">
10
+ <el-switch v-model="isShowDialog" @change="hideExcelHandler" />
11
+ </el-form-item>
12
+ <input
13
+ type="file"
14
+ @change="importExcel(($event.target as any)?.files?.[0])"
15
+ accept=".xls,.xlsx"
16
+ />
17
+ <button @click="clearFile" :disabled="!file">清除文件</button>
18
+ </div>
19
+
20
+ <!-- URL方式 -->
21
+ <div class="url-section">
22
+ <h4>方式二:URL地址</h4>
23
+ <input
24
+ v-model="excelUrl"
25
+ type="text"
26
+ placeholder="请输入Excel文件的URL地址"
27
+ class="url-input"
28
+ />
29
+ <button @click="loadFromUrl" :disabled="!excelUrl.trim()">加载URL</button>
30
+ <button @click="clearUrl" :disabled="!excelUrl">清除URL</button>
31
+ </div>
32
+ <button @click="exportExcel" class="export-btn">导出数据</button>
33
+ </div>
34
+
35
+ <!-- Excel组件 -->
36
+ <div class="excel-container">
37
+ <NsExcel
38
+ v-if="counts"
39
+ class="excel"
40
+ :file="file"
41
+ :isShowDialog="isShowDialog"
42
+ dialogWidth="1200px"
43
+ dialogHeight="700px"
44
+ ref="excelRef"
45
+ exportType="2"
46
+ @dialogExport="dialogExport"
47
+ ></NsExcel>
48
+ </div>
49
+ <!-- 导出数据展示 -->
50
+ <div class="data-display">
51
+ <div class="data-section">
52
+ <h4>导出数据格式1 (原始格式)</h4>
53
+ <pre>{{ data1 }}</pre>
54
+ </div>
55
+ <div class="data-section">
56
+ <h4>导出数据格式2 (Excel格式)</h4>
57
+ <pre>{{ data2 }}</pre>
58
+ </div>
59
+ </div>
60
+ </div>
61
+ </template>
62
+ <script setup lang="ts">
63
+ import { nextTick, ref, watch } from 'vue'
64
+
65
+ const counts = ref(true)
66
+ const isShowDialog = ref(false)
67
+ const file = ref()
68
+ const excelRef = ref()
69
+ const data1 = ref()
70
+ const data2 = ref()
71
+ const excelUrl = ref(
72
+ 'https://501351981.github.io/vue-office/examples/dist/static/test-files/test.xlsx',
73
+ )
74
+
75
+ function hideExcelHandler(val: boolean) {
76
+ counts.value = false
77
+ nextTick(() => {
78
+ counts.value = true
79
+ isShowDialog.value = val
80
+ })
81
+ }
82
+
83
+ function importExcel(f: any) {
84
+ // 清除URL,使用文件上传
85
+ excelUrl.value = ''
86
+ file.value = f
87
+ }
88
+
89
+ function loadFromUrl() {
90
+ if (excelUrl.value.trim()) {
91
+ // 清除文件,使用URL
92
+ file.value = excelUrl.value.trim()
93
+ }
94
+ }
95
+
96
+ function clearFile() {
97
+ file.value = null
98
+ data1.value = null
99
+ data2.value = null
100
+ }
101
+
102
+ function clearUrl() {
103
+ excelUrl.value = ''
104
+ data1.value = null
105
+ data2.value = null
106
+ }
107
+
108
+ function dialogExport(data: any) {
109
+ console.warn(`excel导出数据:${data}`)
110
+ }
111
+
112
+ function exportExcel() {
113
+ if (excelRef.value) {
114
+ data1.value = excelRef.value.exportExcel(1)
115
+ data2.value = excelRef.value.exportExcel(2)
116
+ }
117
+ }
118
+ </script>
119
+ <style scoped lang="scss">
120
+ .demo-container {
121
+ padding: 20px;
122
+ max-width: 1400px;
123
+ margin: 0 auto;
124
+ }
125
+
126
+ .control-panel {
127
+ background: #f5f5f5;
128
+ padding: 20px;
129
+ border-radius: 8px;
130
+ margin-bottom: 20px;
131
+
132
+ h3 {
133
+ margin: 0 0 20px 0;
134
+ color: #333;
135
+ }
136
+
137
+ h4 {
138
+ margin: 15px 0 10px 0;
139
+ color: #666;
140
+ font-size: 14px;
141
+ }
142
+ }
143
+
144
+ .upload-section,
145
+ .url-section,
146
+ .example-section {
147
+ margin-bottom: 20px;
148
+ padding: 15px;
149
+ background: white;
150
+ border-radius: 6px;
151
+ border: 1px solid #e0e0e0;
152
+
153
+ input[type='file'] {
154
+ margin-right: 10px;
155
+ }
156
+
157
+ .url-input {
158
+ width: 300px;
159
+ padding: 8px 12px;
160
+ border: 1px solid #ddd;
161
+ border-radius: 4px;
162
+ margin-right: 10px;
163
+ font-size: 14px;
164
+
165
+ &:focus {
166
+ outline: none;
167
+ border-color: #409eff;
168
+ }
169
+ }
170
+
171
+ button {
172
+ padding: 8px 16px;
173
+ background: #409eff;
174
+ color: white;
175
+ border: none;
176
+ border-radius: 4px;
177
+ cursor: pointer;
178
+ margin-right: 10px;
179
+ font-size: 14px;
180
+
181
+ &:hover:not(:disabled) {
182
+ background: #337ecc;
183
+ }
184
+
185
+ &:disabled {
186
+ background: #c0c4cc;
187
+ cursor: not-allowed;
188
+ }
189
+ }
190
+ }
191
+
192
+ .export-btn {
193
+ padding: 10px 20px;
194
+ background: #67c23a;
195
+ color: white;
196
+ border: none;
197
+ border-radius: 4px;
198
+ cursor: pointer;
199
+ font-size: 16px;
200
+ font-weight: bold;
201
+
202
+ &:hover {
203
+ background: #5daf34;
204
+ }
205
+ }
206
+
207
+ .excel {
208
+ width: 100%;
209
+ height: 500px;
210
+ border: 1px solid #e0e0e0;
211
+ border-radius: 8px;
212
+ overflow: hidden;
213
+ margin-bottom: 20px;
214
+ }
215
+
216
+ .data-display {
217
+ display: flex;
218
+ gap: 20px;
219
+ margin-top: 20px;
220
+
221
+ .data-section {
222
+ flex: 1;
223
+ background: #f9f9f9;
224
+ border-radius: 8px;
225
+ padding: 15px;
226
+
227
+ h4 {
228
+ margin: 0 0 10px 0;
229
+ color: #333;
230
+ font-size: 14px;
231
+ }
232
+
233
+ pre {
234
+ background: white;
235
+ padding: 15px;
236
+ border-radius: 4px;
237
+ border: 1px solid #e0e0e0;
238
+ max-height: 300px;
239
+ overflow: auto;
240
+ font-size: 12px;
241
+ line-height: 1.4;
242
+ margin: 0;
243
+ white-space: pre-wrap;
244
+ word-wrap: break-word;
245
+ }
246
+ }
247
+ }
248
+
249
+ .excel-container {
250
+ height: 300px;
251
+ }
252
+
253
+ @media (max-width: 768px) {
254
+ .data-display {
255
+ flex-direction: column;
256
+ }
257
+
258
+ .url-input {
259
+ width: 100% !important;
260
+ margin-bottom: 10px;
261
+ }
262
+ }
263
+ </style>