js_ryl 1.0.30 → 1.0.32

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": "js_ryl",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "private": false,
5
5
  "description": "自定义通用js",
6
6
  "author": "renyuliang <785788909@qq.com>",
@@ -10,8 +10,6 @@
10
10
  },
11
11
  "main": "dist/build.js",
12
12
  "dependencies": {
13
- "file-saver": "^2.0.5",
14
- "script-loader": "^0.7.2",
15
13
  "vue": "^2.6.12",
16
14
  "xlsx": "^0.16.9"
17
15
  },
package/src/App.vue CHANGED
@@ -163,14 +163,14 @@ export default {
163
163
  },
164
164
  methods: {
165
165
  downloadExcel(){
166
- const head = [
167
- "订单编号",
168
- "金额(元)",
169
- ];
170
- const body = [
171
- "client_order_number",
172
- "amount"
173
- ];
166
+ // const head = [
167
+ // "订单编号",
168
+ // "金额(元)",
169
+ // ];
170
+ // const body = [
171
+ // "client_order_number",
172
+ // "amount"
173
+ // ];
174
174
  let list = [
175
175
  {
176
176
  client_order_number: '354615',
@@ -178,14 +178,10 @@ export default {
178
178
  },
179
179
  {
180
180
  client_order_number: '9735',
181
- amount: 230
181
+ amount: 22130
182
182
  },
183
183
  ]
184
- downExcel(
185
- head,
186
- body,
187
- list
188
- );
184
+ downExcel(list,'沙拉2','滚犊子2')
189
185
  },
190
186
  shopToCart(event){
191
187
  flyToCart(event,'https://v2-saas-1259468876.cos.ap-shanghai.myqcloud.com//system//admin//7c7ec8b02b009d2385db1faae95b9ab0.png',document.querySelector('#shoppps'),()=>{
@@ -0,0 +1,54 @@
1
+ // 处理字符串中的base64图片上传和替换
2
+ export default function base64Img(content, apiUrl, token, data) {
3
+ // 匹配所有 base64 图片(支持多种格式)
4
+ const base64Regex = /<img [^>]*src=['"](data:image[^'"]+base64,[^'"]+)['"][^>]*>/gi;
5
+ let match;
6
+ const replacements = [];
7
+
8
+ // 第一步:收集所有需要替换的 base64 数据
9
+ while ((match = base64Regex.exec(content)) !== null) {
10
+ replacements.push({
11
+ original: match[1],
12
+ base64: match[1]
13
+ });
14
+ }
15
+
16
+ // 第二步:并行上传所有图片
17
+ if (replacements.length > 0) {
18
+ const uploadPromises = replacements.map((replacement) => {
19
+ return fetch(apiUrl, {
20
+ method: "POST",
21
+ headers: {
22
+ "Authorization": "Bearer " + token,
23
+ "Content-Type": "application/json"
24
+ },
25
+ body: JSON.stringify({image: replacement.base64,...data})
26
+ })
27
+ .then(res => res.json())
28
+ .then(data => {
29
+ if (data.code === 200) {
30
+ replacement.url = data.data.url;
31
+ }
32
+ return replacement;
33
+ })
34
+ .catch(error => {
35
+ console.error('上传图片失败:', error);
36
+ return replacement;
37
+ });
38
+ });
39
+
40
+ // 等待所有上传完成
41
+ return Promise.all(uploadPromises)
42
+ .then(results => {
43
+ // 第三步:替换所有 base64 为图片 URL
44
+ results.forEach((result) => {
45
+ if (result.url) {
46
+ content = content.replace(result.original, result.url);
47
+ }
48
+ });
49
+ return content;
50
+ });
51
+ }
52
+
53
+ return Promise.resolve(content);
54
+ }
@@ -1,13 +1,19 @@
1
- function formatJson(filterVal, jsonData) {
2
- return jsonData.map(v => filterVal.map(j => v[j]));
3
- }
4
- export default function downExcel(EHead, EBody, EList, ETitle = "") {
5
- require.ensure([], () => {
6
- const { export_json_to_excel } = require("./vendor/Export2Excel");
7
- const tHeader = EHead;
8
- const filterVal = EBody;
9
- const list = EList;
10
- const data = formatJson(filterVal, list);
11
- export_json_to_excel(tHeader, data, ETitle);
12
- });
1
+ import * as XLSX from 'xlsx';
2
+
3
+ /**
4
+ * 下载 Excel 文件
5
+ * @param {Array} data - 要导出的数据数组,格式为 [{key1: value1, key2: value2}, ...]
6
+ * @param {string} fileName - 下载的文件名称,例如 '列表'
7
+ * @param {string} sheetName - 工作表名称,例如 'Sheet1'
8
+ */
9
+ export default function downExcel(data, fileName = '列表', sheetName = 'Sheet1') {
10
+ // 将数据转换为工作表
11
+ const worksheet = XLSX.utils.json_to_sheet(data);
12
+
13
+ // 创建一个新的工作簿
14
+ const workbook = XLSX.utils.book_new();
15
+ XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
16
+
17
+ // 生成 Excel 文件并下载
18
+ XLSX.writeFile(workbook, fileName+'.xlsx');
13
19
  }
package/src/index.js CHANGED
@@ -27,6 +27,8 @@ import highLight from "./highLight";
27
27
  import flyToCart from "./flyToCart";
28
28
  // 下载excel
29
29
  import downExcel from "./downExcel";
30
+ // 处理base64的图片为链接
31
+ import base64Img from "./base64Img";
30
32
 
31
33
  export default {
32
34
  reg,
@@ -42,5 +44,6 @@ export default {
42
44
  emoji,
43
45
  highLight,
44
46
  flyToCart,
45
- downExcel
47
+ downExcel,
48
+ base64Img
46
49
  };
@@ -1,179 +0,0 @@
1
- /* eslint-disable */
2
- /* Blob.js
3
- * A Blob implementation.
4
- * 2014-05-27
5
- *
6
- * By Eli Grey, http://eligrey.com
7
- * By Devin Samarin, https://github.com/eboyjr
8
- * License: X11/MIT
9
- * See LICENSE.md
10
- */
11
-
12
- /*global self, unescape */
13
- /*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
14
- plusplus: true */
15
-
16
- /*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */
17
-
18
- (function (view) {
19
- "use strict";
20
-
21
- view.URL = view.URL || view.webkitURL;
22
-
23
- if (view.Blob && view.URL) {
24
- try {
25
- new Blob;
26
- return;
27
- } catch (e) {}
28
- }
29
-
30
- // Internally we use a BlobBuilder implementation to base Blob off of
31
- // in order to support older browsers that only have BlobBuilder
32
- var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || (function(view) {
33
- var
34
- get_class = function(object) {
35
- return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
36
- }
37
- , FakeBlobBuilder = function BlobBuilder() {
38
- this.data = [];
39
- }
40
- , FakeBlob = function Blob(data, type, encoding) {
41
- this.data = data;
42
- this.size = data.length;
43
- this.type = type;
44
- this.encoding = encoding;
45
- }
46
- , FBB_proto = FakeBlobBuilder.prototype
47
- , FB_proto = FakeBlob.prototype
48
- , FileReaderSync = view.FileReaderSync
49
- , FileException = function(type) {
50
- this.code = this[this.name = type];
51
- }
52
- , file_ex_codes = (
53
- "NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR "
54
- + "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR"
55
- ).split(" ")
56
- , file_ex_code = file_ex_codes.length
57
- , real_URL = view.URL || view.webkitURL || view
58
- , real_create_object_URL = real_URL.createObjectURL
59
- , real_revoke_object_URL = real_URL.revokeObjectURL
60
- , URL = real_URL
61
- , btoa = view.btoa
62
- , atob = view.atob
63
-
64
- , ArrayBuffer = view.ArrayBuffer
65
- , Uint8Array = view.Uint8Array
66
- ;
67
- FakeBlob.fake = FB_proto.fake = true;
68
- while (file_ex_code--) {
69
- FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1;
70
- }
71
- if (!real_URL.createObjectURL) {
72
- URL = view.URL = {};
73
- }
74
- URL.createObjectURL = function(blob) {
75
- var
76
- type = blob.type
77
- , data_URI_header
78
- ;
79
- if (type === null) {
80
- type = "application/octet-stream";
81
- }
82
- if (blob instanceof FakeBlob) {
83
- data_URI_header = "data:" + type;
84
- if (blob.encoding === "base64") {
85
- return data_URI_header + ";base64," + blob.data;
86
- } else if (blob.encoding === "URI") {
87
- return data_URI_header + "," + decodeURIComponent(blob.data);
88
- } if (btoa) {
89
- return data_URI_header + ";base64," + btoa(blob.data);
90
- } else {
91
- return data_URI_header + "," + encodeURIComponent(blob.data);
92
- }
93
- } else if (real_create_object_URL) {
94
- return real_create_object_URL.call(real_URL, blob);
95
- }
96
- };
97
- URL.revokeObjectURL = function(object_URL) {
98
- if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) {
99
- real_revoke_object_URL.call(real_URL, object_URL);
100
- }
101
- };
102
- FBB_proto.append = function(data/*, endings*/) {
103
- var bb = this.data;
104
- // decode data to a binary string
105
- if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) {
106
- var
107
- str = ""
108
- , buf = new Uint8Array(data)
109
- , i = 0
110
- , buf_len = buf.length
111
- ;
112
- for (; i < buf_len; i++) {
113
- str += String.fromCharCode(buf[i]);
114
- }
115
- bb.push(str);
116
- } else if (get_class(data) === "Blob" || get_class(data) === "File") {
117
- if (FileReaderSync) {
118
- var fr = new FileReaderSync;
119
- bb.push(fr.readAsBinaryString(data));
120
- } else {
121
- // async FileReader won't work as BlobBuilder is sync
122
- throw new FileException("NOT_READABLE_ERR");
123
- }
124
- } else if (data instanceof FakeBlob) {
125
- if (data.encoding === "base64" && atob) {
126
- bb.push(atob(data.data));
127
- } else if (data.encoding === "URI") {
128
- bb.push(decodeURIComponent(data.data));
129
- } else if (data.encoding === "raw") {
130
- bb.push(data.data);
131
- }
132
- } else {
133
- if (typeof data !== "string") {
134
- data += ""; // convert unsupported types to strings
135
- }
136
- // decode UTF-16 to binary string
137
- bb.push(unescape(encodeURIComponent(data)));
138
- }
139
- };
140
- FBB_proto.getBlob = function(type) {
141
- if (!arguments.length) {
142
- type = null;
143
- }
144
- return new FakeBlob(this.data.join(""), type, "raw");
145
- };
146
- FBB_proto.toString = function() {
147
- return "[object BlobBuilder]";
148
- };
149
- FB_proto.slice = function(start, end, type) {
150
- var args = arguments.length;
151
- if (args < 3) {
152
- type = null;
153
- }
154
- return new FakeBlob(
155
- this.data.slice(start, args > 1 ? end : this.data.length)
156
- , type
157
- , this.encoding
158
- );
159
- };
160
- FB_proto.toString = function() {
161
- return "[object Blob]";
162
- };
163
- FB_proto.close = function() {
164
- this.size = this.data.length = 0;
165
- };
166
- return FakeBlobBuilder;
167
- }(view));
168
-
169
- view.Blob = function Blob(blobParts, options) {
170
- var type = options ? (options.type || "") : "";
171
- var builder = new BlobBuilder();
172
- if (blobParts) {
173
- for (var i = 0, len = blobParts.length; i < len; i++) {
174
- builder.append(blobParts[i]);
175
- }
176
- }
177
- return builder.getBlob(type);
178
- };
179
- }(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this));
@@ -1,156 +0,0 @@
1
- /* eslint-disable */
2
- require("script-loader!file-saver");
3
- require("./Blob");
4
- require("script-loader!xlsx/dist/xlsx.core.min");
5
- function generateArray(table) {
6
- var out = [];
7
- var rows = table.querySelectorAll("tr");
8
- var ranges = [];
9
- for (var R = 0; R < rows.length; ++R) {
10
- var outRow = [];
11
- var row = rows[R];
12
- var columns = row.querySelectorAll("td");
13
- for (var C = 0; C < columns.length; ++C) {
14
- var cell = columns[C];
15
- var colspan = cell.getAttribute("colspan");
16
- var rowspan = cell.getAttribute("rowspan");
17
- var cellValue = cell.innerText;
18
- if (cellValue !== "" && cellValue == +cellValue) cellValue = +cellValue;
19
-
20
- //Skip ranges
21
- ranges.forEach(function(range) {
22
- if (
23
- R >= range.s.r &&
24
- R <= range.e.r &&
25
- outRow.length >= range.s.c &&
26
- outRow.length <= range.e.c
27
- ) {
28
- for (var i = 0; i <= range.e.c - range.s.c; ++i) outRow.push(null);
29
- }
30
- });
31
-
32
- //Handle Row Span
33
- if (rowspan || colspan) {
34
- rowspan = rowspan || 1;
35
- colspan = colspan || 1;
36
- ranges.push({
37
- s: { r: R, c: outRow.length },
38
- e: { r: R + rowspan - 1, c: outRow.length + colspan - 1 }
39
- });
40
- }
41
- //Handle Value
42
- outRow.push(cellValue !== "" ? cellValue : null);
43
-
44
- //Handle Colspan
45
- if (colspan) for (var k = 0; k < colspan - 1; ++k) outRow.push(null);
46
- }
47
- out.push(outRow);
48
- }
49
- return [out, ranges];
50
- }
51
-
52
- function datenum(v, date1904) {
53
- if (date1904) v += 1462;
54
- var epoch = Date.parse(v);
55
- return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
56
- }
57
-
58
- function sheet_from_array_of_arrays(data, opts) {
59
- var ws = {};
60
- var range = { s: { c: 10000000, r: 10000000 }, e: { c: 0, r: 0 } };
61
- for (var R = 0; R != data.length; ++R) {
62
- for (var C = 0; C != data[R].length; ++C) {
63
- if (range.s.r > R) range.s.r = R;
64
- if (range.s.c > C) range.s.c = C;
65
- if (range.e.r < R) range.e.r = R;
66
- if (range.e.c < C) range.e.c = C;
67
- var cell = { v: data[R][C] };
68
- if (cell.v == null) continue;
69
- var cell_ref = XLSX.utils.encode_cell({ c: C, r: R });
70
-
71
- if (typeof cell.v === "number") cell.t = "n";
72
- else if (typeof cell.v === "boolean") cell.t = "b";
73
- else if (cell.v instanceof Date) {
74
- cell.t = "n";
75
- cell.z = XLSX.SSF._table[14];
76
- cell.v = datenum(cell.v);
77
- } else cell.t = "s";
78
-
79
- ws[cell_ref] = cell;
80
- }
81
- }
82
- if (range.s.c < 10000000) ws["!ref"] = XLSX.utils.encode_range(range);
83
- return ws;
84
- }
85
-
86
- function Workbook() {
87
- if (!(this instanceof Workbook)) return new Workbook();
88
- this.SheetNames = [];
89
- this.Sheets = {};
90
- }
91
-
92
- function s2ab(s) {
93
- var buf = new ArrayBuffer(s.length);
94
- var view = new Uint8Array(buf);
95
- for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xff;
96
- return buf;
97
- }
98
-
99
- export function export_table_to_excel(id) {
100
- var theTable = document.getElementById(id);
101
- var oo = generateArray(theTable);
102
- var ranges = oo[1];
103
-
104
- /* original data */
105
- var data = oo[0];
106
- var ws_name = "SheetJS";
107
-
108
- var wb = new Workbook(),
109
- ws = sheet_from_array_of_arrays(data);
110
-
111
- /* add ranges to worksheet */
112
- // ws['!cols'] = ['apple', 'banan'];
113
- ws["!merges"] = ranges;
114
-
115
- /* add worksheet to workbook */
116
- wb.SheetNames.push(ws_name);
117
- wb.Sheets[ws_name] = ws;
118
-
119
- var wbout = XLSX.write(wb, {
120
- bookType: "xlsx",
121
- bookSST: false,
122
- type: "binary"
123
- });
124
-
125
- saveAs(
126
- new Blob([s2ab(wbout)], { type: "application/octet-stream" }),
127
- "test.xlsx"
128
- );
129
- }
130
-
131
- function formatJson(jsonData) {}
132
- export function export_json_to_excel(th, jsonData, defaultTitle) {
133
- /* original data */
134
-
135
- var data = jsonData;
136
- data.unshift(th);
137
- var ws_name = "SheetJS";
138
-
139
- var wb = new Workbook(),
140
- ws = sheet_from_array_of_arrays(data);
141
-
142
- /* add worksheet to workbook */
143
- wb.SheetNames.push(ws_name);
144
- wb.Sheets[ws_name] = ws;
145
-
146
- var wbout = XLSX.write(wb, {
147
- bookType: "xlsx",
148
- bookSST: false,
149
- type: "binary"
150
- });
151
- var title = defaultTitle || "列表";
152
- saveAs(
153
- new Blob([s2ab(wbout)], { type: "application/octet-stream" }),
154
- title + ".xlsx"
155
- );
156
- }