fast-vue-multi-pages 1.0.10 → 1.0.11

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.
@@ -6,10 +6,10 @@ export declare class FastVueMultiFile {
6
6
  static showUploadImage(multi: boolean): Promise<any>;
7
7
  /**
8
8
  * 将base64转为file对象
9
- * @param base64Content base64内容
9
+ * @param content base64内容
10
10
  * @param fileName 文件名
11
11
  */
12
- static base64ToFile(base64Content: string, fileName: string): Promise<File>;
12
+ static base64ToFile(content: string, fileName: string): Promise<File>;
13
13
  /**
14
14
  * 将file对象转为base64
15
15
  * @param file
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FastVueMultiFile = void 0;
4
- const file64_1 = require("file64");
5
4
  class FastVueMultiFile {
6
5
  /**
7
6
  * 弹出上传文件的选择框
@@ -44,18 +43,41 @@ class FastVueMultiFile {
44
43
  }
45
44
  /**
46
45
  * 将base64转为file对象
47
- * @param base64Content base64内容
46
+ * @param content base64内容
48
47
  * @param fileName 文件名
49
48
  */
50
- static async base64ToFile(base64Content, fileName) {
51
- return await (0, file64_1.base64ToFile)(base64Content, fileName);
49
+ static base64ToFile(content, fileName) {
50
+ return new Promise(function (resolved, rejected) {
51
+ // 将base64的数据部分提取出来
52
+ const parts = content.split(';base64,');
53
+ const contentType = parts[0].split(':')[1];
54
+ const raw = window.atob(parts[1]);
55
+ // 将原始数据转换为Uint8Array
56
+ const rawLength = raw.length;
57
+ const uInt8Array = new Uint8Array(rawLength);
58
+ for (let i = 0; i < rawLength; ++i) {
59
+ uInt8Array[i] = raw.charCodeAt(i);
60
+ }
61
+ // 使用Blob对象创建File对象
62
+ const blob = new Blob([uInt8Array], { type: contentType });
63
+ blob.lastModifiedDate = new Date();
64
+ blob.name = fileName;
65
+ resolved(new File([blob], fileName, { type: contentType }));
66
+ });
52
67
  }
53
68
  /**
54
69
  * 将file对象转为base64
55
70
  * @param file
56
71
  */
57
72
  static async fileToBase64(file) {
58
- return await (0, file64_1.fileToBase64)(file);
73
+ return new Promise(function (resolved, rejected) {
74
+ const fileReader = new FileReader();
75
+ fileReader.onload = function (readEvent) {
76
+ let base64 = readEvent.target.result;
77
+ resolved(base64);
78
+ };
79
+ fileReader.readAsDataURL(file);
80
+ });
59
81
  }
60
82
  }
61
83
  exports.FastVueMultiFile = FastVueMultiFile;
@@ -6,10 +6,10 @@ export declare class FastVueMultiFile {
6
6
  static showUploadImage(multi: boolean): Promise<any>;
7
7
  /**
8
8
  * 将base64转为file对象
9
- * @param base64Content base64内容
9
+ * @param content base64内容
10
10
  * @param fileName 文件名
11
11
  */
12
- static base64ToFile(base64Content: string, fileName: string): Promise<File>;
12
+ static base64ToFile(content: string, fileName: string): Promise<File>;
13
13
  /**
14
14
  * 将file对象转为base64
15
15
  * @param file
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "tslib", "file64"], function (require, exports, tslib_1, file64_1) {
1
+ define(["require", "exports", "tslib"], function (require, exports, tslib_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.FastVueMultiFile = void 0;
@@ -53,17 +53,26 @@ define(["require", "exports", "tslib", "file64"], function (require, exports, ts
53
53
  };
54
54
  /**
55
55
  * 将base64转为file对象
56
- * @param base64Content base64内容
56
+ * @param content base64内容
57
57
  * @param fileName 文件名
58
58
  */
59
- FastVueMultiFile.base64ToFile = function (base64Content, fileName) {
60
- return tslib_1.__awaiter(this, void 0, void 0, function () {
61
- return tslib_1.__generator(this, function (_a) {
62
- switch (_a.label) {
63
- case 0: return [4 /*yield*/, (0, file64_1.base64ToFile)(base64Content, fileName)];
64
- case 1: return [2 /*return*/, _a.sent()];
65
- }
66
- });
59
+ FastVueMultiFile.base64ToFile = function (content, fileName) {
60
+ return new Promise(function (resolved, rejected) {
61
+ // 将base64的数据部分提取出来
62
+ var parts = content.split(';base64,');
63
+ var contentType = parts[0].split(':')[1];
64
+ var raw = window.atob(parts[1]);
65
+ // 将原始数据转换为Uint8Array
66
+ var rawLength = raw.length;
67
+ var uInt8Array = new Uint8Array(rawLength);
68
+ for (var i = 0; i < rawLength; ++i) {
69
+ uInt8Array[i] = raw.charCodeAt(i);
70
+ }
71
+ // 使用Blob对象创建File对象
72
+ var blob = new Blob([uInt8Array], { type: contentType });
73
+ blob.lastModifiedDate = new Date();
74
+ blob.name = fileName;
75
+ resolved(new File([blob], fileName, { type: contentType }));
67
76
  });
68
77
  };
69
78
  /**
@@ -73,10 +82,14 @@ define(["require", "exports", "tslib", "file64"], function (require, exports, ts
73
82
  FastVueMultiFile.fileToBase64 = function (file) {
74
83
  return tslib_1.__awaiter(this, void 0, void 0, function () {
75
84
  return tslib_1.__generator(this, function (_a) {
76
- switch (_a.label) {
77
- case 0: return [4 /*yield*/, (0, file64_1.fileToBase64)(file)];
78
- case 1: return [2 /*return*/, _a.sent()];
79
- }
85
+ return [2 /*return*/, new Promise(function (resolved, rejected) {
86
+ var fileReader = new FileReader();
87
+ fileReader.onload = function (readEvent) {
88
+ var base64 = readEvent.target.result;
89
+ resolved(base64);
90
+ };
91
+ fileReader.readAsDataURL(file);
92
+ })];
80
93
  });
81
94
  });
82
95
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-vue-multi-pages",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "author": "janesen",
5
5
  "description": "快速搭建VUE项目工具类的基本库,主要用于每个功能页面独立生成html",
6
6
  "main": "./dist/cjs/index.js",