@ebiz/designer-components 0.1.20 → 0.1.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebiz/designer-components",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -133,20 +133,33 @@ const getFullUrl = (url) => {
133
133
  return props.baseUrl + url;
134
134
  };
135
135
 
136
- // 提取文件名
137
- const extractFileName = (url) => {
138
- if (!url) return '未知文件';
139
- const parts = url.split('/');
140
- return parts[parts.length - 1] || '未知文件';
141
- };
142
-
143
136
  // 获取文件扩展名
144
137
  const getFileExtension = (filename) => {
145
138
  if (!filename) return '';
146
- const parts = filename.split('.');
139
+ // 移除查询参数和锚点
140
+ const cleanFilename = filename.split('?')[0].split('#')[0];
141
+ const parts = cleanFilename.split('.');
147
142
  return parts.length > 1 ? parts.pop().toLowerCase() : '';
148
143
  };
149
144
 
145
+ // 提取文件名
146
+ const extractFileName = (url) => {
147
+ if (!url) return '未知文件';
148
+
149
+ // 移除查询参数和锚点
150
+ const cleanUrl = url.split('?')[0].split('#')[0];
151
+ const parts = cleanUrl.split('/');
152
+ let fileName = parts[parts.length - 1] || '未知文件';
153
+
154
+ // 如果文件名为空或只是扩展名,生成一个默认名称
155
+ if (!fileName || fileName.startsWith('.')) {
156
+ const extension = getFileExtension(fileName || url);
157
+ fileName = extension ? `文件.${extension}` : '未知文件';
158
+ }
159
+
160
+ return fileName;
161
+ };
162
+
150
163
  // 解析文件信息
151
164
  const parseFileInfo = (url) => {
152
165
  const fullUrl = getFullUrl(url);
@@ -166,24 +179,45 @@ const computedFiles = computed(() => {
166
179
  let fileList = [];
167
180
 
168
181
  if (typeof props.files === 'string') {
169
- // 字符串格式,按逗号分割
170
- const urls = props.files.split(',').map(url => url.trim()).filter(url => url);
171
- fileList = urls.map(url => parseFileInfo(url));
182
+ if (!props.files.trim()) {
183
+ return [];
184
+ }
185
+
186
+ // 判断是单个URL还是逗号分隔的多个URL
187
+ if (props.files.includes(',')) {
188
+ // 逗号分隔的多个URL
189
+ const urls = props.files.split(',').map(url => url.trim()).filter(url => url);
190
+ fileList = urls.map(url => parseFileInfo(url));
191
+ } else {
192
+ // 单个URL
193
+ fileList = [parseFileInfo(props.files.trim())];
194
+ }
172
195
  } else if (Array.isArray(props.files)) {
173
196
  // 数组格式
174
197
  fileList = props.files.map(file => {
175
198
  if (typeof file === 'string') {
199
+ // 数组中的字符串元素,直接作为URL处理
176
200
  return parseFileInfo(file);
177
- } else {
201
+ } else if (file && typeof file === 'object') {
202
+ // 对象格式的文件信息
203
+ const url = file.url || file.src || file.path || '';
178
204
  return {
179
- name: file.name || extractFileName(file.url),
180
- url: getFullUrl(file.url),
181
- size: file.size,
182
- extension: file.extension || getFileExtension(file.url || file.name),
205
+ name: file.name || extractFileName(url),
206
+ url: getFullUrl(url),
207
+ size: file.size || null,
208
+ extension: file.extension || getFileExtension(url || file.name || ''),
183
209
  ...file
184
210
  };
211
+ } else {
212
+ // 其他情况,返回默认对象
213
+ return {
214
+ name: '未知文件',
215
+ url: '',
216
+ extension: '',
217
+ size: null
218
+ };
185
219
  }
186
- });
220
+ }).filter(file => file.url); // 过滤掉没有URL的文件
187
221
  }
188
222
 
189
223
  return fileList;
@@ -23,6 +23,24 @@
23
23
  @file-download="handleFileDownload"
24
24
  />
25
25
  </div>
26
+
27
+ <div class="demo-block">
28
+ <h3>单个URL字符串</h3>
29
+ <EbizFileList
30
+ :files="singleUrlFile"
31
+ @file-click="handleFileClick"
32
+ @file-download="handleFileDownload"
33
+ />
34
+ </div>
35
+
36
+ <div class="demo-block">
37
+ <h3>纯URL数组</h3>
38
+ <EbizFileList
39
+ :files="urlArrayFiles"
40
+ @file-click="handleFileClick"
41
+ @file-download="handleFileDownload"
42
+ />
43
+ </div>
26
44
  </div>
27
45
 
28
46
  <div class="demo-section">
@@ -118,6 +136,18 @@ const arrayFiles = ref([
118
136
 
119
137
  const stringFiles = ref('https://picsum.photos/300/200?random=2,https://picsum.photos/300/200?random=3,https://example.com/document.pdf,https://example.com/music.mp3');
120
138
 
139
+ // 单个URL字符串
140
+ const singleUrlFile = ref('https://picsum.photos/400/300?random=6');
141
+
142
+ // 纯URL数组
143
+ const urlArrayFiles = ref([
144
+ 'https://picsum.photos/300/200?random=7',
145
+ 'https://picsum.photos/300/200?random=8',
146
+ 'https://example.com/sample-document.pdf',
147
+ 'https://example.com/presentation.pptx',
148
+ 'https://example.com/data-export.xlsx'
149
+ ]);
150
+
121
151
  const mixedFiles = ref([
122
152
  {
123
153
  name: '技术文档.pdf',