@duxweb/dvha-core 1.1.11 → 1.1.13
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("json-2-csv"),c=require("vue"),u=require("./export.cjs");function l(t){const a=c.computed(()=>{const{filename:e,headers:r,csvOptions:n,...s}=t;return s}),i=c.computed(()=>{const e=t.csvOptions||{},r=e.quote;return{prependHeader:t.headers!==!1,keys:Array.isArray(t.headers)?t.headers:void 0,delimiter:{field:e.delimiter||",",wrap:typeof r=="string"?r:'"',eol:e.eol||`
|
|
2
|
-
`},excelBOM:e.writeBOM
|
|
2
|
+
`},excelBOM:e.writeBOM!==!1}});return u.useExport({...a.value,onSuccess:async e=>{if(!e?.data||!e?.data?.length){t.onError?.({message:"No data to export",status:400});return}try{const r=await d.json2csv(e.data,i.value),n=new Blob([r],{type:"text/csv;charset=utf-8;"}),s=URL.createObjectURL(n),o=document.createElement("a");o.href=s,o.download=t.filename||"export.csv",o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(s),t.onSuccess?.(e)}catch(r){t.onError?.({message:`CSV Export Error: ${r}`,status:500})}}})}exports.useExportCsv=l;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`},excelBOM:e.excelBOM||!1,headerFields:e.headerFields,keys:e.keys,trimHeaderFields:e.trimHeaderFields||!1,trimFieldValues:e.trimFieldValues||!1}}),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("@vueuse/core"),x=require("json-2-csv"),g=require("vue"),A=require("./import.cjs");function S(o){const h=g.computed(()=>{const{csvOptions:e,...n}=o;return n}),v=g.computed(()=>{const e=o.csvOptions||{};return{delimiter:{field:e.delimiter||",",wrap:e.wrap||'"',eol:e.eol||`
|
|
2
|
+
`},excelBOM:e.excelBOM||!1,headerFields:e.headerFields,keys:e.keys,trimHeaderFields:e.trimHeaderFields||!1,trimFieldValues:e.trimFieldValues||!1}}),f=A.useImport({...h.value}),y=async e=>{const n=await e.arrayBuffer(),t=new Uint8Array(n),M=t.length>=3&&t[0]===239&&t[1]===187&&t[2]===191,b=t.length>=2&&t[0]===255&&t[1]===254,w=t.length>=2&&t[0]===254&&t[1]===255,p=o.encoding||"auto",c=(r,s)=>{try{return new TextDecoder(r,{fatal:!1}).decode(s||t)}catch{return""}},B=r=>{if(!r)return{rep:Number.MAX_SAFE_INTEGER,ctrl:Number.MAX_SAFE_INTEGER};let s=0,i=0;for(let l=0;l<r.length;l++){const u=r.charCodeAt(l);u===65533&&s++,u<32&&u!==9&&u!==10&&u!==13&&i++}return{rep:s,ctrl:i}},a=r=>r.replace(/^\ufeff/,"");if(M)return a(c("utf-8"));if(b)return a(c("utf-16le"));if(w)return a(c("utf-16be"));if(p!=="auto")return a(c(p));const m=["utf-8","gb18030","gbk"].map(r=>{const s=c(r),i=B(s);return{enc:r,text:s,sc:i}});return m.sort((r,s)=>r.sc.rep-s.sc.rep||r.sc.ctrl-s.sc.ctrl),a(m[0].text)},d=async e=>{try{const n=await y(e),t=await x.csv2json(n,v.value);t&&t.length>0?await f.trigger(t):o.onError?.({message:"CSV 文件为空或格式不正确",status:400})}catch(n){o.onError?.({message:`CSV 解析错误: ${n}`,status:500})}},{open:E,reset:O,onChange:F}=C.useFileDialog({accept:".csv",multiple:!1});return F(e=>{e&&e.length>0&&d(e[0])}),{...f,open:()=>{O(),E()},readFile:d}}exports.useImportCsv=S;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { useFileDialog as
|
|
2
|
-
import { csv2json as
|
|
3
|
-
import { computed as
|
|
4
|
-
import { useImport as
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
const { csvOptions: e, ...
|
|
8
|
-
return
|
|
9
|
-
}),
|
|
10
|
-
const e =
|
|
1
|
+
import { useFileDialog as b } from "@vueuse/core";
|
|
2
|
+
import { csv2json as A } from "json-2-csv";
|
|
3
|
+
import { computed as g } from "vue";
|
|
4
|
+
import { useImport as C } from "./import.js";
|
|
5
|
+
function V(n) {
|
|
6
|
+
const h = g(() => {
|
|
7
|
+
const { csvOptions: e, ...o } = n;
|
|
8
|
+
return o;
|
|
9
|
+
}), E = g(() => {
|
|
10
|
+
const e = n.csvOptions || {};
|
|
11
11
|
return {
|
|
12
12
|
delimiter: {
|
|
13
13
|
field: e.delimiter || ",",
|
|
@@ -21,35 +21,64 @@ function w(s) {
|
|
|
21
21
|
trimHeaderFields: e.trimHeaderFields || !1,
|
|
22
22
|
trimFieldValues: e.trimFieldValues || !1
|
|
23
23
|
};
|
|
24
|
-
}),
|
|
25
|
-
...
|
|
26
|
-
}),
|
|
24
|
+
}), u = C({
|
|
25
|
+
...h.value
|
|
26
|
+
}), y = async (e) => {
|
|
27
|
+
const o = await e.arrayBuffer(), t = new Uint8Array(o), w = t.length >= 3 && t[0] === 239 && t[1] === 187 && t[2] === 191, B = t.length >= 2 && t[0] === 255 && t[1] === 254, M = t.length >= 2 && t[0] === 254 && t[1] === 255, m = n.encoding || "auto", c = (r, s) => {
|
|
28
|
+
try {
|
|
29
|
+
return new TextDecoder(r, { fatal: !1 }).decode(s || t);
|
|
30
|
+
} catch {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
}, x = (r) => {
|
|
34
|
+
if (!r) return { rep: Number.MAX_SAFE_INTEGER, ctrl: Number.MAX_SAFE_INTEGER };
|
|
35
|
+
let s = 0, i = 0;
|
|
36
|
+
for (let f = 0; f < r.length; f++) {
|
|
37
|
+
const l = r.charCodeAt(f);
|
|
38
|
+
l === 65533 && s++, l < 32 && l !== 9 && l !== 10 && l !== 13 && i++;
|
|
39
|
+
}
|
|
40
|
+
return { rep: s, ctrl: i };
|
|
41
|
+
}, a = (r) => r.replace(/^\ufeff/, "");
|
|
42
|
+
if (w)
|
|
43
|
+
return a(c("utf-8"));
|
|
44
|
+
if (B)
|
|
45
|
+
return a(c("utf-16le"));
|
|
46
|
+
if (M)
|
|
47
|
+
return a(c("utf-16be"));
|
|
48
|
+
if (m !== "auto")
|
|
49
|
+
return a(c(m));
|
|
50
|
+
const p = ["utf-8", "gb18030", "gbk"].map((r) => {
|
|
51
|
+
const s = c(r), i = x(s);
|
|
52
|
+
return { enc: r, text: s, sc: i };
|
|
53
|
+
});
|
|
54
|
+
return p.sort((r, s) => r.sc.rep - s.sc.rep || r.sc.ctrl - s.sc.ctrl), a(p[0].text);
|
|
55
|
+
}, d = async (e) => {
|
|
27
56
|
try {
|
|
28
|
-
const
|
|
29
|
-
|
|
57
|
+
const o = await y(e), t = await A(o, E.value);
|
|
58
|
+
t && t.length > 0 ? await u.trigger(t) : n.onError?.({
|
|
30
59
|
message: "CSV 文件为空或格式不正确",
|
|
31
60
|
status: 400
|
|
32
61
|
});
|
|
33
|
-
} catch (
|
|
34
|
-
|
|
35
|
-
message: `CSV 解析错误: ${
|
|
62
|
+
} catch (o) {
|
|
63
|
+
n.onError?.({
|
|
64
|
+
message: `CSV 解析错误: ${o}`,
|
|
36
65
|
status: 500
|
|
37
66
|
});
|
|
38
67
|
}
|
|
39
|
-
}, { open:
|
|
68
|
+
}, { open: O, reset: v, onChange: F } = b({
|
|
40
69
|
accept: ".csv",
|
|
41
70
|
multiple: !1
|
|
42
71
|
});
|
|
43
|
-
return
|
|
44
|
-
e && e.length > 0 &&
|
|
72
|
+
return F((e) => {
|
|
73
|
+
e && e.length > 0 && d(e[0]);
|
|
45
74
|
}), {
|
|
46
|
-
...
|
|
75
|
+
...u,
|
|
47
76
|
open: () => {
|
|
48
|
-
|
|
77
|
+
v(), O();
|
|
49
78
|
},
|
|
50
|
-
readFile:
|
|
79
|
+
readFile: d
|
|
51
80
|
};
|
|
52
81
|
}
|
|
53
82
|
export {
|
|
54
|
-
|
|
83
|
+
V as useImportCsv
|
|
55
84
|
};
|