@das-fed/utils 1.0.0
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/api-services/index.js +19846 -0
- package/api-services/modules/app-manage.js +6 -0
- package/api-services/modules/authentication.js +6 -0
- package/api-services/modules/bems.js +11 -0
- package/api-services/modules/contract.js +6 -0
- package/api-services/modules/duty-manage.js +15 -0
- package/api-services/modules/enterpriseright.js +6 -0
- package/api-services/modules/file.js +409 -0
- package/api-services/modules/gateway-edge.js +6 -0
- package/api-services/modules/index.js +494 -0
- package/api-services/modules/iot.js +19 -0
- package/api-services/modules/justauth.js +7 -0
- package/api-services/modules/knowledge.js +6 -0
- package/api-services/modules/link.js +6 -0
- package/api-services/modules/permission.js +6 -0
- package/api-services/modules/platformManage.js +14 -0
- package/api-services/modules/portal.js +6 -0
- package/api-services/modules/space-manage.js +6 -0
- package/api-services/modules/super-admin.js +9 -0
- package/api-services/modules/supplier.js +8 -0
- package/api-services/modules/supplychain-manage.js +6 -0
- package/api-services/modules/systemConfiguration.js +6 -0
- package/api-services/modules/tool.js +6 -0
- package/api-services/src/create-service.js +19846 -0
- package/api-services/src/sso.js +200 -0
- package/api-services/src/util.js +23 -0
- package/atob/index.js +12 -0
- package/common-info/getIframeUrl.js +13 -0
- package/common-info/index.js +311 -0
- package/common-info/setInfoFromUrl.js +156 -0
- package/common-tools/arr-tools.js +15 -0
- package/common-tools/date-format.js +22 -0
- package/common-tools/get-url-params.js +92 -0
- package/common-tools/handle-data.js +5 -0
- package/common-tools/index.js +213 -0
- package/common-tools/nest-tree-format.js +53 -0
- package/common-tools/obj-tools.js +21 -0
- package/common-tools/setHtmlMinWH.js +11 -0
- package/common-tools/throttled.js +19 -0
- package/config/index.js +26 -0
- package/curring-http/index.js +17310 -0
- package/directive/auth.js +114 -0
- package/directive/clickOutside.js +53 -0
- package/directive/hoverInside.js +40 -0
- package/directive/index.js +183 -0
- package/directive/utils.js +12 -0
- package/dom-check-in/index.js +16 -0
- package/dom-watcher/index.js +10 -0
- package/hooks/popup-manager/use-zindex.js +41 -0
- package/index.js +215 -0
- package/load-js/index.js +23 -0
- package/oss/index.js +16 -0
- package/package.json +44 -0
- package/pinyin-first-character/index.js +12223 -0
- package/process-engine-info/index.js +12 -0
- package/pure-image-src/index.js +30 -0
- package/set-personal-info/index.js +24 -0
- package/size-watcher/index.js +27 -0
- package/style/index.js +115 -0
- package/style/math.js +32 -0
- package/style/style.js +84 -0
- package/token-tools/index.js +179 -0
- package/vue/hooks/use-model-value.js +11 -0
- package/vue/index.js +11 -0
- package/webSocket-service/index.js +170 -0
- package/with-install/index.js +8 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createService } from '@das-fed/utils/api-services';
|
|
2
|
+
|
|
3
|
+
const version = "v1";
|
|
4
|
+
const bemsBase = `/api/bems/data-manage/${version}`;
|
|
5
|
+
const bemsModules = {
|
|
6
|
+
energyType: createService(`${bemsBase}/energy-type`),
|
|
7
|
+
energyObject: createService(`${bemsBase}/energy-object`),
|
|
8
|
+
energyDimension: createService(`${bemsBase}/energy-dimension`)
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { bemsModules };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createService } from '@das-fed/utils/api-services';
|
|
2
|
+
|
|
3
|
+
const version = "v1";
|
|
4
|
+
const dutyModules = {
|
|
5
|
+
classes: createService(`/api/duty-manage/classes/${version}`),
|
|
6
|
+
// 班次管理
|
|
7
|
+
group: createService(`/api/duty-manage/group/${version}`),
|
|
8
|
+
// 分组管理
|
|
9
|
+
scheduling: createService(`/api/duty-manage/scheduling/${version}`),
|
|
10
|
+
// 排班管理
|
|
11
|
+
shift: createService(`/api/duty-manage/shift/${version}`)
|
|
12
|
+
// 交接班管理
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { dutyModules };
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { createService } from '@das-fed/utils/api-services';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
import { ref } from 'vue';
|
|
4
|
+
|
|
5
|
+
const version = "v1";
|
|
6
|
+
createService(`/api/iot/${version}`);
|
|
7
|
+
({
|
|
8
|
+
thingmodel: createService(`/api/iot-device/thingmodel/${version}`),
|
|
9
|
+
deviceManage: createService(`/api/iot-device/devicemanage/${version}`),
|
|
10
|
+
product: createService(`/api/iot-device/product/${version}`),
|
|
11
|
+
productStorage: createService(`/api/iot-device/product-storage/${version}`)
|
|
12
|
+
});
|
|
13
|
+
({
|
|
14
|
+
projectDevice: createService(`/api/device-relation/deviceproject/${version}`),
|
|
15
|
+
deviceRules: createService(`/api/device-relation/devicerule/${version}`),
|
|
16
|
+
project: createService(`/api/device-relation/project/${version}`)
|
|
17
|
+
});
|
|
18
|
+
const iotMinio = createService(`/api/oss/minio/${version}`);
|
|
19
|
+
const iotProgress = createService(`/api/progress/accessor/${version}`);
|
|
20
|
+
|
|
21
|
+
let urlAlphabet =
|
|
22
|
+
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
|
|
23
|
+
|
|
24
|
+
const POOL_SIZE_MULTIPLIER = 128;
|
|
25
|
+
let pool, poolOffset;
|
|
26
|
+
let fillPool = bytes => {
|
|
27
|
+
if (!pool || pool.length < bytes) {
|
|
28
|
+
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
29
|
+
crypto.randomFillSync(pool);
|
|
30
|
+
poolOffset = 0;
|
|
31
|
+
} else if (poolOffset + bytes > pool.length) {
|
|
32
|
+
crypto.randomFillSync(pool);
|
|
33
|
+
poolOffset = 0;
|
|
34
|
+
}
|
|
35
|
+
poolOffset += bytes;
|
|
36
|
+
};
|
|
37
|
+
let nanoid = (size = 21) => {
|
|
38
|
+
fillPool((size -= 0));
|
|
39
|
+
let id = '';
|
|
40
|
+
for (let i = poolOffset - size; i < poolOffset; i++) {
|
|
41
|
+
id += urlAlphabet[pool[i] & 63];
|
|
42
|
+
}
|
|
43
|
+
return id
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
47
|
+
|
|
48
|
+
function getDefaultExportFromCjs (x) {
|
|
49
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var dayjs_min = {exports: {}};
|
|
53
|
+
|
|
54
|
+
(function (module, exports) {
|
|
55
|
+
!function(t,e){module.exports=e();}(commonjsGlobal,(function(){var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",c="month",f="quarter",h="year",d="date",l="Invalid Date",$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return "["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},m=function(t,e,n){var r=String(t);return !r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return (e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return -t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,c),s=n-i<0,u=e.clone().add(r+(s?-1:1),c);return +(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return {M:c,y:h,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:f}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",D={};D[g]=M;var p="$isDayjsObject",S=function(t){return t instanceof _||!(!t||!t[p])},w=function t(e,n,r){var i;if(!e)return g;if("string"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split("-");if(!i&&u.length>1)return t(u[0])}else {var a=e.name;D[a]=e,i=a;}return !r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[p]=!0;}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match($);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init();},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds();},m.$utils=function(){return b},m.isValid=function(){return !(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<O(t)},m.$g=function(t,e,n){return b.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!b.u(e)||e,f=b.p(t),l=function(t,e){var i=b.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},$=function(t,e){return b.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,v="set"+(this.$u?"UTC":"");switch(f){case h:return r?l(1,0):l(31,11);case c:return r?l(1,M):l(0,M+1);case o:var g=this.$locale().weekStart||0,D=(y<g?y+7:y)-g;return l(r?m-D:m+(6-D),M);case a:case d:return $(v+"Hours",0);case u:return $(v+"Minutes",1);case s:return $(v+"Seconds",2);case i:return $(v+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=b.p(t),f="set"+(this.$u?"UTC":""),l=(n={},n[a]=f+"Date",n[d]=f+"Date",n[c]=f+"Month",n[h]=f+"FullYear",n[u]=f+"Hours",n[s]=f+"Minutes",n[i]=f+"Seconds",n[r]=f+"Milliseconds",n)[o],$=o===a?this.$D+(e-this.$W):e;if(o===c||o===h){var y=this.clone().set(d,1);y.$d[l]($),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d;}else l&&this.$d[l]($);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[b.p(t)]()},m.add=function(r,f){var d,l=this;r=Number(r);var $=b.p(f),y=function(t){var e=O(l);return b.w(e.date(e.date()+Math.round(t*r)),l)};if($===c)return this.set(c,this.$M+r);if($===h)return this.set(h,this.$y+r);if($===a)return y(1);if($===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[$]||1,m=this.$d.getTime()+r*M;return b.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||l;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=b.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,c=n.months,f=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},d=function(t){return b.s(s%12||12,t,"0")},$=f||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(y,(function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return b.s(e.$y,4,"0");case"M":return a+1;case"MM":return b.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,c,3);case"MMMM":return h(c,a);case"D":return e.$D;case"DD":return b.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return h(n.weekdaysMin,e.$W,o,2);case"ddd":return h(n.weekdaysShort,e.$W,o,3);case"dddd":return o[e.$W];case"H":return String(s);case"HH":return b.s(s,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return $(s,u,!0);case"A":return $(s,u,!1);case"m":return String(u);case"mm":return b.s(u,2,"0");case"s":return String(e.$s);case"ss":return b.s(e.$s,2,"0");case"SSS":return b.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,l){var $,y=this,M=b.p(d),m=O(r),v=(m.utcOffset()-this.utcOffset())*e,g=this-m,D=function(){return b.m(y,m)};switch(M){case h:$=D()/12;break;case c:$=D();break;case f:$=D()/3;break;case o:$=(g-v)/6048e5;break;case a:$=(g-v)/864e5;break;case u:$=g/n;break;case s:$=g/e;break;case i:$=g/t;break;default:$=g;}return l?$:b.a($)},m.daysInMonth=function(){return this.endOf(c).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=w(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return b.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),k=_.prototype;return O.prototype=k,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",c],["$y",h],["$D",d]].forEach((function(t){k[t[1]]=function(e){return this.$g(e,t[0],t[1])};})),O.extend=function(t,e){return t.$i||(t(e,_,O),t.$i=!0),O},O.locale=w,O.isDayjs=S,O.unix=function(t){return O(1e3*t)},O.en=D[g],O.Ls=D,O.p={},O}));
|
|
56
|
+
} (dayjs_min));
|
|
57
|
+
|
|
58
|
+
var dayjs_minExports = dayjs_min.exports;
|
|
59
|
+
var dayjs = /*@__PURE__*/getDefaultExportFromCjs(dayjs_minExports);
|
|
60
|
+
|
|
61
|
+
const getConfig = () => {
|
|
62
|
+
let windowConfig = window?.config || {};
|
|
63
|
+
let config = { ...windowConfig };
|
|
64
|
+
if (!config.rootContainer)
|
|
65
|
+
config.rootContainer = "#app";
|
|
66
|
+
if (!config.baseURL)
|
|
67
|
+
config.baseURL = location.origin;
|
|
68
|
+
if (!config.ossBaseURL)
|
|
69
|
+
config.ossBaseURL = "/oss";
|
|
70
|
+
if (config.ossBaseURL.startsWith("/"))
|
|
71
|
+
config.ossBaseURL = `${config.baseURL}/oss`;
|
|
72
|
+
if (!config.ssoBaseURL)
|
|
73
|
+
config.ssoBaseURL = config.baseURL;
|
|
74
|
+
let { microAppName, publicPath, mainAppName } = config;
|
|
75
|
+
const isPro = import.meta.env.PROD;
|
|
76
|
+
if (microAppName && isPro && !publicPath)
|
|
77
|
+
publicPath = `/${microAppName}/`.replace(/\/\//g, "/");
|
|
78
|
+
if (!publicPath)
|
|
79
|
+
publicPath = "/";
|
|
80
|
+
config.publicPath = publicPath;
|
|
81
|
+
if (!config.autoOssBucket)
|
|
82
|
+
config.autoOssBucket = mainAppName || microAppName;
|
|
83
|
+
return config;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const getMinioToken = iotMinio.get(`token`);
|
|
87
|
+
const importMinio = iotMinio.post(`putObject`, (config) => {
|
|
88
|
+
if (!config.headers)
|
|
89
|
+
config.headers = {};
|
|
90
|
+
config.headers["Content-Type"] = "multipart/form-data";
|
|
91
|
+
config.responseType = "blob";
|
|
92
|
+
return config;
|
|
93
|
+
});
|
|
94
|
+
const importMultiMinio = iotMinio.post(`upload-objects`, (config) => {
|
|
95
|
+
if (!config.headers)
|
|
96
|
+
config.headers = {};
|
|
97
|
+
config.headers["Content-Type"] = "multipart/form-data";
|
|
98
|
+
config.responseType = "blob";
|
|
99
|
+
return config;
|
|
100
|
+
});
|
|
101
|
+
const getTaskProgress = iotProgress.get(`progress`);
|
|
102
|
+
const useFile = () => {
|
|
103
|
+
let showProgressDialog = ref(false);
|
|
104
|
+
let progressTitle = ref("");
|
|
105
|
+
let percent = ref(0);
|
|
106
|
+
let progressStatus = ref("normal");
|
|
107
|
+
let progressLoading = ref(false);
|
|
108
|
+
let progressTimer;
|
|
109
|
+
let progressResult = ref("");
|
|
110
|
+
let errorFileName = ref("");
|
|
111
|
+
let errorFileSize = ref("");
|
|
112
|
+
let errorMessage = ref("");
|
|
113
|
+
let errorImport = ref(false);
|
|
114
|
+
let errorFilePath = ref("");
|
|
115
|
+
let tempErrPathName = "";
|
|
116
|
+
let fileInfo;
|
|
117
|
+
const resetStataus = () => {
|
|
118
|
+
errorFileName.value = "";
|
|
119
|
+
errorFileSize.value = "";
|
|
120
|
+
errorMessage.value = "";
|
|
121
|
+
errorImport.value = false;
|
|
122
|
+
errorFilePath.value = "";
|
|
123
|
+
};
|
|
124
|
+
const getMinioConfig = async () => {
|
|
125
|
+
const [error, data] = await getMinioToken().run();
|
|
126
|
+
if (error) {
|
|
127
|
+
return { stauts: false };
|
|
128
|
+
}
|
|
129
|
+
return { status: true, data };
|
|
130
|
+
};
|
|
131
|
+
const readFileAndAddToMap = (file) => {
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
const chunkSize = 1024 * 1024;
|
|
134
|
+
const chunks = [];
|
|
135
|
+
let offset = 0;
|
|
136
|
+
while (offset < file.size) {
|
|
137
|
+
const chunk = file.slice(offset, offset + chunkSize);
|
|
138
|
+
chunks.push(chunk);
|
|
139
|
+
offset += chunkSize;
|
|
140
|
+
}
|
|
141
|
+
const mergedBlob = new Blob(chunks, { type: file.type });
|
|
142
|
+
resolve(mergedBlob);
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
const fileImport = async (importFunc, file, options, needProgress = true, errPathName = "", isBatch = false) => {
|
|
146
|
+
tempErrPathName = errPathName;
|
|
147
|
+
if (needProgress) {
|
|
148
|
+
progressStatus.value = "normal";
|
|
149
|
+
percent.value = 0;
|
|
150
|
+
progressTitle.value = "\u5BFC\u5165\u8FDB\u5EA6";
|
|
151
|
+
showProgressDialog.value = true;
|
|
152
|
+
progressResult.value = "";
|
|
153
|
+
}
|
|
154
|
+
fileInfo = file;
|
|
155
|
+
const tokenResult = await getMinioConfig();
|
|
156
|
+
if (!tokenResult.status)
|
|
157
|
+
return;
|
|
158
|
+
let minioConfig = tokenResult.data;
|
|
159
|
+
let params = null;
|
|
160
|
+
let { autoContentType, bucketName, importFileName } = options;
|
|
161
|
+
const fn = isBatch ? importMultiMinio : importMinio;
|
|
162
|
+
if (isBatch) {
|
|
163
|
+
let blobList = [];
|
|
164
|
+
await file.forEach(async (ele) => {
|
|
165
|
+
let blob = await readFileAndAddToMap(ele);
|
|
166
|
+
blobList.push(blob);
|
|
167
|
+
});
|
|
168
|
+
params = new FormData();
|
|
169
|
+
params.append("accessKeyId", minioConfig.accessKeyId);
|
|
170
|
+
params.append("secretAccessKey", minioConfig.secretAccessKey);
|
|
171
|
+
params.append("sessionToken", minioConfig.sessionToken);
|
|
172
|
+
params.append("bucketName", bucketName);
|
|
173
|
+
file.forEach((v, i) => {
|
|
174
|
+
params.append("file", blobList[i]);
|
|
175
|
+
});
|
|
176
|
+
importFileName.forEach((v) => {
|
|
177
|
+
params.append("filePaths", v);
|
|
178
|
+
});
|
|
179
|
+
} else {
|
|
180
|
+
const blob = await readFileAndAddToMap(file);
|
|
181
|
+
params = {
|
|
182
|
+
accessKeyId: minioConfig.accessKeyId,
|
|
183
|
+
secretAccessKey: minioConfig.secretAccessKey,
|
|
184
|
+
sessionToken: minioConfig.sessionToken,
|
|
185
|
+
file: blob,
|
|
186
|
+
bucketName,
|
|
187
|
+
filePath: importFileName,
|
|
188
|
+
autoContentType
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const [error, data] = await fn(params).run();
|
|
192
|
+
if (error)
|
|
193
|
+
return;
|
|
194
|
+
const toStringData = await toStringObject(data.data);
|
|
195
|
+
const importResult = await importFunc?.(toStringData);
|
|
196
|
+
if (needProgress) {
|
|
197
|
+
if (!importResult.status) {
|
|
198
|
+
showProgressDialog.value = false;
|
|
199
|
+
progressStatus.value = "error";
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
progressTitle.value = "\u5BFC\u5165\u8FDB\u5EA6";
|
|
203
|
+
showProgressDialog.value = true;
|
|
204
|
+
checkProgress(importResult.taskId, "import", "");
|
|
205
|
+
} else {
|
|
206
|
+
if (!importResult.status)
|
|
207
|
+
return;
|
|
208
|
+
progressStatus.value = "success";
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
const fileAction = async (exportFunc, fileName = "", actionTitle = "") => {
|
|
212
|
+
progressStatus.value = "normal";
|
|
213
|
+
percent.value = 0;
|
|
214
|
+
progressTitle.value = actionTitle || "\u5BFC\u51FA\u8FDB\u5EA6";
|
|
215
|
+
showProgressDialog.value = true;
|
|
216
|
+
const importResult = await exportFunc?.();
|
|
217
|
+
if (!importResult.status) {
|
|
218
|
+
showProgressDialog.value = false;
|
|
219
|
+
progressStatus.value = "error";
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
checkProgress(importResult.taskId, "action", "");
|
|
223
|
+
};
|
|
224
|
+
const fileExport = async (exportFunc, fileName = "", fileSuffix = "") => {
|
|
225
|
+
progressStatus.value = "normal";
|
|
226
|
+
percent.value = 0;
|
|
227
|
+
progressTitle.value = "\u5BFC\u51FA\u8FDB\u5EA6";
|
|
228
|
+
showProgressDialog.value = true;
|
|
229
|
+
const importResult = await exportFunc?.();
|
|
230
|
+
if (!importResult.status) {
|
|
231
|
+
showProgressDialog.value = false;
|
|
232
|
+
progressStatus.value = "error";
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
dayjs().format("YYYYMMDDHHmmss") + ".xlsx";
|
|
236
|
+
checkProgress(importResult.taskId, "export", fileName ? fileName : "", fileSuffix);
|
|
237
|
+
};
|
|
238
|
+
const checkProgress = async (taskId, type, fileName, fileSuffix = "") => {
|
|
239
|
+
progressLoading.value = true;
|
|
240
|
+
getProgress(taskId, type, fileName, fileSuffix);
|
|
241
|
+
progressTimer = setTimeout(() => {
|
|
242
|
+
}, 50);
|
|
243
|
+
};
|
|
244
|
+
const clearTimer = () => {
|
|
245
|
+
clearTimeout(progressTimer);
|
|
246
|
+
progressTimer = null;
|
|
247
|
+
showProgressDialog.value = false;
|
|
248
|
+
};
|
|
249
|
+
const getProgress = async (taskId, type = "export", fileName, fileSuffix = "") => {
|
|
250
|
+
const [error, data] = await getTaskProgress("", {
|
|
251
|
+
url: `progress/${taskId}`
|
|
252
|
+
}).run();
|
|
253
|
+
if (error) {
|
|
254
|
+
progressLoading.value = false;
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
percent.value = data.percentage;
|
|
258
|
+
const tip = type == "export" ? "\u5BFC\u51FA" : "\u5BFC\u5165";
|
|
259
|
+
if (percent.value == 100) {
|
|
260
|
+
progressResult.value = data;
|
|
261
|
+
progressLoading.value = false;
|
|
262
|
+
clearTimer();
|
|
263
|
+
if (type == "export") {
|
|
264
|
+
if (data.status == 1) {
|
|
265
|
+
progressStatus.value = "success";
|
|
266
|
+
downloadFile(`${getConfig().baseURL}/oss${data.filePath}`, fileName, fileSuffix);
|
|
267
|
+
progressLoading.value = false;
|
|
268
|
+
} else if (data.status == 2) {
|
|
269
|
+
errorMessage.value = data.message || `${tip}\u5931\u8D25`;
|
|
270
|
+
}
|
|
271
|
+
} else if (type == "import") {
|
|
272
|
+
if (!!data.filePath) {
|
|
273
|
+
progressStatus.value = "error";
|
|
274
|
+
const matchName = fileInfo.name?.match(/(.*?)(\.[^.]*$|$)/);
|
|
275
|
+
const suffix = matchName.length ? matchName[2] : "";
|
|
276
|
+
errorImport.value = true;
|
|
277
|
+
const pathName = data.filePath?.replace(/(.*\/)*([^.]+).*/gi, "$2");
|
|
278
|
+
errorFileName.value = tempErrPathName ? tempErrPathName : `${pathName}${suffix}`;
|
|
279
|
+
errorFileSize.value = fileInfo.sizeText;
|
|
280
|
+
errorMessage.value = "\u90E8\u5206\u6570\u636E\u6821\u9A8C\u4E0D\u901A\u8FC7\uFF0C\u8BF7\u4E0B\u8F7D\u9644\u4EF6\u5E76\u4FEE\u6539\uFF0C\u91CD\u65B0\u5BFC\u5165\uFF01";
|
|
281
|
+
errorFilePath.value = `${getConfig().baseURL}/oss${data.filePath}`;
|
|
282
|
+
}
|
|
283
|
+
tipHandle(data.status, tip, data.message);
|
|
284
|
+
} else if (type == "action") {
|
|
285
|
+
progressStatus.value = "success";
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
if (progressTimer && data.status != 2) {
|
|
289
|
+
progressTimer = setTimeout(() => {
|
|
290
|
+
getProgress(taskId, type, fileName, fileSuffix);
|
|
291
|
+
}, 50);
|
|
292
|
+
} else {
|
|
293
|
+
progressResult.value = data;
|
|
294
|
+
progressLoading.value = false;
|
|
295
|
+
tipHandle(data.status, tip, data.message);
|
|
296
|
+
clearTimer();
|
|
297
|
+
errorImport.value = true;
|
|
298
|
+
errorMessage.value = data?.message || "";
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
const tipHandle = (status, tip, message) => {
|
|
303
|
+
if (status == 1) {
|
|
304
|
+
progressStatus.value = "success";
|
|
305
|
+
errorFileName.value = "";
|
|
306
|
+
errorFileSize.value = "";
|
|
307
|
+
errorMessage.value = "";
|
|
308
|
+
} else if (status == 2) {
|
|
309
|
+
progressStatus.value = "error";
|
|
310
|
+
errorMessage.value = message ? message : "\u90E8\u5206\u6570\u636E\u6821\u9A8C\u4E0D\u901A\u8FC7\uFF0C\u8BF7\u4E0B\u8F7D\u9644\u4EF6\u5E76\u4FEE\u6539\uFF0C\u91CD\u65B0\u5BFC\u5165\uFF01";
|
|
311
|
+
} else if (status == 3) {
|
|
312
|
+
progressStatus.value = "error";
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
const generateUniqueName = (fileName) => {
|
|
316
|
+
const matchName = fileName?.match(/(.*?)(\.[^.]*$|$)/);
|
|
317
|
+
const suffix = matchName.length ? matchName[2] : "";
|
|
318
|
+
const name = matchName.length ? matchName[1] : fileName;
|
|
319
|
+
return `${name}${nanoid()}${suffix}`;
|
|
320
|
+
};
|
|
321
|
+
return {
|
|
322
|
+
showProgressDialog,
|
|
323
|
+
progressTitle,
|
|
324
|
+
percent,
|
|
325
|
+
progressStatus,
|
|
326
|
+
progressLoading,
|
|
327
|
+
progressResult,
|
|
328
|
+
errorFileName,
|
|
329
|
+
errorFileSize,
|
|
330
|
+
errorMessage,
|
|
331
|
+
errorImport,
|
|
332
|
+
errorFilePath,
|
|
333
|
+
fileImport,
|
|
334
|
+
fileExport,
|
|
335
|
+
fileAction,
|
|
336
|
+
generateUniqueName,
|
|
337
|
+
downloadFile,
|
|
338
|
+
resetStataus,
|
|
339
|
+
checkProgress
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
const fileBobType = (type) => {
|
|
343
|
+
let tempType = type?.toLocaleLowerCase();
|
|
344
|
+
let typeList = {
|
|
345
|
+
excel: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
346
|
+
pdf: "application/pdf",
|
|
347
|
+
doc: "application/msword",
|
|
348
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
349
|
+
xls: "application/vnd.ms-excel",
|
|
350
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
351
|
+
zip: "application/zip",
|
|
352
|
+
txt: "text/plain",
|
|
353
|
+
html: "text/html",
|
|
354
|
+
xml: "application/xml",
|
|
355
|
+
json: "application/json",
|
|
356
|
+
css: "text/css",
|
|
357
|
+
js: "application/javascript",
|
|
358
|
+
svg: "image/svg+xml",
|
|
359
|
+
jpg: "image/jpeg",
|
|
360
|
+
jpeg: "image/jpeg",
|
|
361
|
+
gif: "image/gif",
|
|
362
|
+
bmp: "image/bmp",
|
|
363
|
+
ico: "image/x-icon",
|
|
364
|
+
mp3: "audio/mpeg",
|
|
365
|
+
mp4: "video/mp4",
|
|
366
|
+
pem: "application/x-pem-file",
|
|
367
|
+
crt: "application/x-x509-ca-cert",
|
|
368
|
+
der: "application/x-x509-ca-cert",
|
|
369
|
+
cer: "application/pkix-cert"
|
|
370
|
+
};
|
|
371
|
+
return typeList[tempType];
|
|
372
|
+
};
|
|
373
|
+
const downloadFile = (path, filename, fileSuffix = "excel") => {
|
|
374
|
+
const xhr = new XMLHttpRequest();
|
|
375
|
+
xhr.open("get", path);
|
|
376
|
+
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
|
|
377
|
+
xhr.responseType = "blob";
|
|
378
|
+
xhr.onload = function(e) {
|
|
379
|
+
const blob = new Blob([this.response], {
|
|
380
|
+
type: fileBobType(fileSuffix)
|
|
381
|
+
});
|
|
382
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
383
|
+
if (window.navigator.msSaveOrOpenBlob) {
|
|
384
|
+
navigator.msSaveBlob(blob, filename);
|
|
385
|
+
} else {
|
|
386
|
+
const element = document.createElement("a");
|
|
387
|
+
element.href = objectUrl;
|
|
388
|
+
element.download = filename;
|
|
389
|
+
element.click();
|
|
390
|
+
window.URL.revokeObjectURL(objectUrl);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
xhr.send();
|
|
394
|
+
};
|
|
395
|
+
const toStringObject = (blob) => {
|
|
396
|
+
return new Promise((resolve, reject) => {
|
|
397
|
+
var reader = new FileReader();
|
|
398
|
+
reader.onload = function(event) {
|
|
399
|
+
let data = "";
|
|
400
|
+
if (typeof reader.result == "string") {
|
|
401
|
+
data = JSON.parse(reader.result);
|
|
402
|
+
}
|
|
403
|
+
resolve(data);
|
|
404
|
+
};
|
|
405
|
+
reader.readAsText(blob);
|
|
406
|
+
});
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
export { downloadFile, useFile };
|