zmdms-utils 0.0.49 → 0.0.50

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/es/common.js CHANGED
@@ -195,6 +195,9 @@ function getFileExtension(fileName) {
195
195
  return ["", ""];
196
196
  }
197
197
  var lastPointIndex = fileName.lastIndexOf("."); // 从最后取点
198
+ if (lastPointIndex === -1) {
199
+ return [fileName, ""];
200
+ }
198
201
  var filePreName = fileName.substring(0, lastPointIndex); // 前面的名字
199
202
  var fileExtension = fileName.substring(lastPointIndex + 1).toLowerCase(); // 后面的文件后缀
200
203
  return [filePreName, fileExtension];
package/dist/es/file.d.ts CHANGED
@@ -39,7 +39,7 @@ declare function previewFile(fileId: string, fileName: string, options: IPreview
39
39
  /**
40
40
  * 导出一个文件流
41
41
  * @param response 需要导出的文件流
42
- * @param fileName 文件名称
42
+ * @param fileName 文件名称 可以传后缀名,传后缀名会直接用这个后缀名 如果不传的或者与文件类型的后缀名不同 会取接口中提供的后缀名
43
43
  */
44
44
  declare function exportBolb(response: AxiosResponse, fileName?: string): Promise<unknown>;
45
45
  /**
package/dist/es/file.js CHANGED
@@ -151,7 +151,7 @@ function previewFile(fileId, fileName, options) {
151
151
  /**
152
152
  * 导出一个文件流
153
153
  * @param response 需要导出的文件流
154
- * @param fileName 文件名称
154
+ * @param fileName 文件名称 可以传后缀名,传后缀名会直接用这个后缀名 如果不传的或者与文件类型的后缀名不同 会取接口中提供的后缀名
155
155
  */
156
156
  function exportBolb(response, fileName) {
157
157
  return new Promise(function (resolve, reject) {
@@ -177,7 +177,17 @@ function exportBolb(response, fileName) {
177
177
  }
178
178
  // 可以自定义名称
179
179
  if (fileName) {
180
- elink.download = fileName;
180
+ var _a = getFileExtension(fileName), name_1 = _a[0], extension = _a[1];
181
+ if (copyName) {
182
+ var _b = getFileExtension(decodeURIComponent(copyName)), copyExtension = _b[1];
183
+ elink.download =
184
+ extension === copyExtension
185
+ ? fileName
186
+ : "".concat(name_1, ".").concat(copyExtension);
187
+ }
188
+ else {
189
+ elink.download = fileName;
190
+ }
181
191
  }
182
192
  else if (copyName) {
183
193
  // Content-disposition
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-utils",
3
- "version": "0.0.49",
3
+ "version": "0.0.50",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/common.ts CHANGED
@@ -200,6 +200,9 @@ export function getFileExtension(fileName: string): [string, string] {
200
200
  return ["", ""];
201
201
  }
202
202
  const lastPointIndex = fileName.lastIndexOf("."); // 从最后取点
203
+ if (lastPointIndex === -1) {
204
+ return [fileName, ""];
205
+ }
203
206
  const filePreName = fileName.substring(0, lastPointIndex); // 前面的名字
204
207
  const fileExtension = fileName.substring(lastPointIndex + 1).toLowerCase(); // 后面的文件后缀
205
208
  return [filePreName, fileExtension];
package/src/file.ts CHANGED
@@ -199,7 +199,7 @@ export function previewFile(
199
199
  /**
200
200
  * 导出一个文件流
201
201
  * @param response 需要导出的文件流
202
- * @param fileName 文件名称
202
+ * @param fileName 文件名称 可以传后缀名,传后缀名会直接用这个后缀名 如果不传的或者与文件类型的后缀名不同 会取接口中提供的后缀名
203
203
  */
204
204
  export function exportBolb(response: AxiosResponse, fileName?: string) {
205
205
  return new Promise((resolve, reject) => {
@@ -225,7 +225,18 @@ export function exportBolb(response: AxiosResponse, fileName?: string) {
225
225
  }
226
226
  // 可以自定义名称
227
227
  if (fileName) {
228
- elink.download = fileName;
228
+ const [name, extension] = getFileExtension(fileName);
229
+ if (copyName) {
230
+ const [, copyExtension] = getFileExtension(
231
+ decodeURIComponent(copyName)
232
+ );
233
+ elink.download =
234
+ extension === copyExtension
235
+ ? fileName
236
+ : `${name}.${copyExtension}`;
237
+ } else {
238
+ elink.download = fileName;
239
+ }
229
240
  } else if (copyName) {
230
241
  // Content-disposition
231
242
  elink.download = decodeURIComponent(copyName);