@qxs-bns/utils 0.0.44 → 0.0.46
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/es/index.mjs +833 -1
- package/es/index.mjs.map +1 -1
- package/lib/index.cjs +31 -1
- package/lib/index.cjs.map +1 -1
- package/package.json +2 -2
- package/types/src/api-client/axios-client.d.ts +2 -2
- package/types/src/api-client/axios-client.d.ts.map +1 -1
- package/types/src/api-client/fetch-client.d.ts +0 -1
- package/types/src/api-client/fetch-client.d.ts.map +1 -1
- package/types/src/argo-log.d.ts +9 -2
- package/types/src/argo-log.d.ts.map +1 -1
- package/types/tsconfig.tsbuildinfo +1 -1
- package/README.md +0 -65
- package/es/src/api-client/axios-client.mjs +0 -2
- package/es/src/api-client/axios-client.mjs.map +0 -1
- package/es/src/api-client/fetch-client.mjs +0 -2
- package/es/src/api-client/fetch-client.mjs.map +0 -1
- package/es/src/argo-log.mjs +0 -2
- package/es/src/argo-log.mjs.map +0 -1
- package/es/src/date-transfer.mjs +0 -2
- package/es/src/date-transfer.mjs.map +0 -1
- package/es/src/device.mjs +0 -2
- package/es/src/device.mjs.map +0 -1
- package/es/src/file-operations.mjs +0 -2
- package/es/src/file-operations.mjs.map +0 -1
- package/es/src/json.mjs +0 -2
- package/es/src/json.mjs.map +0 -1
- package/es/src/oss-uploader.mjs +0 -2
- package/es/src/oss-uploader.mjs.map +0 -1
- package/es/src/storage.mjs +0 -2
- package/es/src/storage.mjs.map +0 -1
- package/es/src/types.mjs +0 -2
- package/es/src/types.mjs.map +0 -1
- package/es/src/watermark.mjs +0 -2
- package/es/src/watermark.mjs.map +0 -1
- package/lib/src/api-client/axios-client.cjs +0 -2
- package/lib/src/api-client/axios-client.cjs.map +0 -1
- package/lib/src/api-client/fetch-client.cjs +0 -2
- package/lib/src/api-client/fetch-client.cjs.map +0 -1
- package/lib/src/argo-log.cjs +0 -2
- package/lib/src/argo-log.cjs.map +0 -1
- package/lib/src/date-transfer.cjs +0 -2
- package/lib/src/date-transfer.cjs.map +0 -1
- package/lib/src/device.cjs +0 -2
- package/lib/src/device.cjs.map +0 -1
- package/lib/src/file-operations.cjs +0 -2
- package/lib/src/file-operations.cjs.map +0 -1
- package/lib/src/json.cjs +0 -2
- package/lib/src/json.cjs.map +0 -1
- package/lib/src/oss-uploader.cjs +0 -2
- package/lib/src/oss-uploader.cjs.map +0 -1
- package/lib/src/storage.cjs +0 -2
- package/lib/src/storage.cjs.map +0 -1
- package/lib/src/types.cjs +0 -2
- package/lib/src/types.cjs.map +0 -1
- package/lib/src/watermark.cjs +0 -2
- package/lib/src/watermark.cjs.map +0 -1
package/es/index.mjs
CHANGED
|
@@ -1,2 +1,834 @@
|
|
|
1
|
-
|
|
1
|
+
import { utils as O, writeFile as M, read as _ } from "xlsx";
|
|
2
|
+
import D from "ali-oss";
|
|
3
|
+
const J = (s) => s === void 0, L = (s) => typeof s == "boolean", H = (s) => typeof s == "number";
|
|
4
|
+
function V(s) {
|
|
5
|
+
return typeof Element > "u" ? !1 : s instanceof Element;
|
|
6
|
+
}
|
|
7
|
+
function G(s) {
|
|
8
|
+
return s === window;
|
|
9
|
+
}
|
|
10
|
+
function X(s) {
|
|
11
|
+
return /^[\],:{}\s]*$/.test(s.replace(/\\["\\/bfnrtu]/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, "")) && j(s);
|
|
12
|
+
}
|
|
13
|
+
function j(s) {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(s), !0;
|
|
16
|
+
} catch {
|
|
17
|
+
return !1;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function Y(s) {
|
|
21
|
+
return s.type.startsWith("image/");
|
|
22
|
+
}
|
|
23
|
+
function T(s) {
|
|
24
|
+
if (s === null || typeof s != "object")
|
|
25
|
+
return !1;
|
|
26
|
+
const e = Object.getPrototypeOf(s);
|
|
27
|
+
return e === null || e === Object.prototype;
|
|
28
|
+
}
|
|
29
|
+
class Z {
|
|
30
|
+
/**
|
|
31
|
+
* 构造函数,实现单例模式
|
|
32
|
+
* @param apiInstance - Axios 实例
|
|
33
|
+
* @param isWholeResponse - 是否返回完整响应
|
|
34
|
+
*/
|
|
35
|
+
constructor(e, t) {
|
|
36
|
+
this.apiInstance = e, this.isWholeResponse = t;
|
|
37
|
+
}
|
|
38
|
+
toSuccessEnvelope(e) {
|
|
39
|
+
return e;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 判断是否为业务错误
|
|
43
|
+
* @param obj - 待判断的对象
|
|
44
|
+
*/
|
|
45
|
+
isBusinessError(e) {
|
|
46
|
+
return T(e) && typeof e.message == "string" && (typeof e.code == "number" || typeof e.code == "string") && String(e.code) !== "0";
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 判断是否为 Axios 响应对象
|
|
50
|
+
* @param value - 待判断的值
|
|
51
|
+
*/
|
|
52
|
+
isAxiosResponse(e) {
|
|
53
|
+
return T(e) && e.data !== void 0 && this.isBusinessError(e.data) && e.status !== void 0 && e.statusText !== void 0 && e.headers !== void 0 && e.config !== void 0 && e.request !== void 0;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 判断是否为错误响应
|
|
57
|
+
* @param value - 待判断的值
|
|
58
|
+
*/
|
|
59
|
+
isErrorResponse(e) {
|
|
60
|
+
return T(e) && "code" in e && "message" in e && String(e.code) !== "0";
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 发起 API 请求,返回统一的响应格式 { res, error }
|
|
64
|
+
* @template K - URL 配置对象类型
|
|
65
|
+
* @template W - 是否返回完整响应,true 返回 SuccessResponse,false 只返回 data
|
|
66
|
+
* @param axiosConfig - Axios 请求配置
|
|
67
|
+
* @param params - 请求参数(GET 请求会自动转为 params,其他方法转为 data)
|
|
68
|
+
* @param isWholeResponse - 是否返回完整响应,默认使用实例配置
|
|
69
|
+
* @returns Promise<UseApiResponse<W, T, S, E>> - 包含 res 和 error 的统一响应对象
|
|
70
|
+
*/
|
|
71
|
+
useApi = async (e, t, i = this.isWholeResponse) => {
|
|
72
|
+
let o = null, n = null;
|
|
73
|
+
try {
|
|
74
|
+
const r = {
|
|
75
|
+
...e,
|
|
76
|
+
...t ? e.method && ["GET"].includes(e.method.toUpperCase()) ? { params: t } : { data: t } : {}
|
|
77
|
+
};
|
|
78
|
+
r.url = (r.proxyPrefix || "") + e.url, delete r.proxyPrefix;
|
|
79
|
+
const c = await this.apiInstance(r), d = this.toSuccessEnvelope(c.data);
|
|
80
|
+
o = i ? d : d.data;
|
|
81
|
+
} catch (r) {
|
|
82
|
+
const c = r?.response?.data;
|
|
83
|
+
this.isErrorResponse(c) ? n = c : this.isAxiosResponse(r) ? n = r.data : this.isErrorResponse(r) && (n = r);
|
|
84
|
+
}
|
|
85
|
+
return { res: o, error: n };
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* 发起 API 请求
|
|
89
|
+
* @template K - URL 配置对象类型
|
|
90
|
+
* @template W - 是否返回完整响应
|
|
91
|
+
* @param axiosConfig - Axios 请求配置
|
|
92
|
+
* @param params - 请求参数
|
|
93
|
+
* @param isWholeResponse - 是否返回完整响应,默认使用实例配置
|
|
94
|
+
* @returns 根据 isWholeResponse 返回完整响应或解包后的数据
|
|
95
|
+
*/
|
|
96
|
+
apiClient = async (e, t, i) => {
|
|
97
|
+
const o = i ?? this.isWholeResponse, n = {
|
|
98
|
+
...e,
|
|
99
|
+
...t ? e.method && ["GET"].includes(e.method.toUpperCase()) ? { params: t } : { data: t } : {}
|
|
100
|
+
};
|
|
101
|
+
return n.proxyPrefix && (n.url = (n.proxyPrefix || "") + e.url, delete n.proxyPrefix), o ? await this.apiInstance(n) : await this.apiInstance(n);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
class q extends Error {
|
|
105
|
+
code;
|
|
106
|
+
details;
|
|
107
|
+
status;
|
|
108
|
+
constructor(e, t, i, o) {
|
|
109
|
+
super(t), this.name = "ApiError", this.code = e, this.status = i, this.details = o;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
class ee {
|
|
113
|
+
constructor(e) {
|
|
114
|
+
this.client = e;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 发起 API 请求,返回统一的响应格式 { res, error }
|
|
118
|
+
* @template K - URL 配置对象类型
|
|
119
|
+
* @param config - 请求配置(单参数时使用 ky 原生参数如 searchParams/json)
|
|
120
|
+
* @param requestData - 请求数据(双参数时自动根据 method 处理)
|
|
121
|
+
* @returns Promise<{ res, error }> - 统一响应格式
|
|
122
|
+
*/
|
|
123
|
+
useApi = async (e, t) => {
|
|
124
|
+
let i = null, o = null;
|
|
125
|
+
try {
|
|
126
|
+
const { url: n, proxyPrefix: r, signal: c, ...d } = e, a = (r || "") + n, u = {
|
|
127
|
+
...d,
|
|
128
|
+
signal: c
|
|
129
|
+
// 传递 signal 给 ky
|
|
130
|
+
};
|
|
131
|
+
t && (e.method.toUpperCase() === "GET" ? u.searchParams = t : u.json = t);
|
|
132
|
+
const l = await this.client(a, u);
|
|
133
|
+
(l.headers.get("content-type") ?? "").toLowerCase().includes("text/event-stream") ? i = l.body : i = await l.json();
|
|
134
|
+
} catch (n) {
|
|
135
|
+
o = n;
|
|
136
|
+
}
|
|
137
|
+
return { res: i, error: o };
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* 发起 API 请求,直接返回数据或抛出错误
|
|
141
|
+
* @template K - URL 配置对象类型
|
|
142
|
+
* @param config - 请求配置(单参数时使用 ky 原生参数如 searchParams/json)
|
|
143
|
+
* @param requestData - 请求数据(双参数时自动根据 method 处理)
|
|
144
|
+
* @returns Promise<Response> - 直接返回响应数据
|
|
145
|
+
*/
|
|
146
|
+
apiClient = async (e, t) => {
|
|
147
|
+
const { url: i, method: o, proxyPrefix: n, signal: r, ...c } = e, d = (n || "") + i, a = {
|
|
148
|
+
...c,
|
|
149
|
+
method: o.toLowerCase(),
|
|
150
|
+
signal: r,
|
|
151
|
+
// 传递 signal 给 ky
|
|
152
|
+
throwOnError: !0
|
|
153
|
+
};
|
|
154
|
+
t && (o.toUpperCase() === "GET" ? a.searchParams = t : a.json = t);
|
|
155
|
+
const u = await this.client(d, a);
|
|
156
|
+
return (u.headers.get("content-type") ?? "").toLowerCase().includes("text/event-stream") ? u.body : await u.json();
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function v(s) {
|
|
160
|
+
if (Array.isArray(s))
|
|
161
|
+
return `[${s.map((e) => v(e)).join(",")}]`;
|
|
162
|
+
if (s && typeof s == "object") {
|
|
163
|
+
const e = s;
|
|
164
|
+
return `{${Object.keys(e).sort().map((i) => `${JSON.stringify(i)}:${v(e[i])}`).join(",")}}`;
|
|
165
|
+
}
|
|
166
|
+
return JSON.stringify(s);
|
|
167
|
+
}
|
|
168
|
+
class S {
|
|
169
|
+
static instance;
|
|
170
|
+
sdkPromise = null;
|
|
171
|
+
sdk = null;
|
|
172
|
+
usingMock = !1;
|
|
173
|
+
constructor() {
|
|
174
|
+
}
|
|
175
|
+
static getInstance() {
|
|
176
|
+
return S.instance || (S.instance = new S()), S.instance;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* 加载 SDK
|
|
180
|
+
*/
|
|
181
|
+
async loadSDK(e = !1) {
|
|
182
|
+
if (this.sdk)
|
|
183
|
+
return this.sdk;
|
|
184
|
+
if (this.sdkPromise)
|
|
185
|
+
return this.sdkPromise;
|
|
186
|
+
if (typeof window > "u")
|
|
187
|
+
return null;
|
|
188
|
+
const t = window;
|
|
189
|
+
return t.__argoLogSDKPromise ? (this.sdkPromise = t.__argoLogSDKPromise, this.sdk = await this.sdkPromise, this.sdk || (this.sdkPromise = null, delete t.__argoLogSDKPromise), this.sdk) : (this.sdkPromise = this.createSDKPromise(e), t.__argoLogSDKPromise = this.sdkPromise, this.sdk = await this.sdkPromise, this.sdk || (this.sdkPromise = null, delete t.__argoLogSDKPromise), this.sdk);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* 创建 SDK 加载 Promise
|
|
193
|
+
*/
|
|
194
|
+
async createSDKPromise(e) {
|
|
195
|
+
try {
|
|
196
|
+
const t = await import("ans-javascript-sdk");
|
|
197
|
+
return this.usingMock = !1, t.default;
|
|
198
|
+
} catch {
|
|
199
|
+
return e ? (this.usingMock = !0, this.createMockSDK()) : (this.usingMock = !1, null);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* 创建 Mock SDK - 用于开发和文档环境
|
|
204
|
+
*/
|
|
205
|
+
createMockSDK() {
|
|
206
|
+
return {
|
|
207
|
+
init: (e) => {
|
|
208
|
+
},
|
|
209
|
+
track: (e, t) => {
|
|
210
|
+
},
|
|
211
|
+
profileSet: (e) => {
|
|
212
|
+
},
|
|
213
|
+
alias: (e) => {
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* 获取已加载的 SDK
|
|
219
|
+
*/
|
|
220
|
+
getSDK() {
|
|
221
|
+
return this.sdk;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* 检查 SDK 是否已加载
|
|
225
|
+
*/
|
|
226
|
+
isLoaded() {
|
|
227
|
+
return this.sdk !== null;
|
|
228
|
+
}
|
|
229
|
+
isUsingMock() {
|
|
230
|
+
return this.usingMock;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const K = S.getInstance();
|
|
234
|
+
class b {
|
|
235
|
+
static instances = /* @__PURE__ */ new Map();
|
|
236
|
+
AnalysysAgent = null;
|
|
237
|
+
pendingQueue = [];
|
|
238
|
+
isInitialized = !1;
|
|
239
|
+
isInitializing = !1;
|
|
240
|
+
initSettled = !1;
|
|
241
|
+
initializationPromise = null;
|
|
242
|
+
constructor(e) {
|
|
243
|
+
try {
|
|
244
|
+
if (typeof window > "u")
|
|
245
|
+
return this.initSettled = !0, this;
|
|
246
|
+
if (!e)
|
|
247
|
+
return this.initSettled = !0, this;
|
|
248
|
+
const t = v(e), i = b.instances.get(t);
|
|
249
|
+
if (i)
|
|
250
|
+
return i;
|
|
251
|
+
b.instances.set(t, this), this.initializationPromise = this.initializeSDK(e, t);
|
|
252
|
+
} catch {
|
|
253
|
+
this.initSettled = !0;
|
|
254
|
+
}
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
async initializeSDK(e, t) {
|
|
258
|
+
if (this.isInitializing || this.isInitialized)
|
|
259
|
+
return this.isInitialized;
|
|
260
|
+
this.isInitializing = !0;
|
|
261
|
+
try {
|
|
262
|
+
const i = await K.loadSDK(!!e.allowMock);
|
|
263
|
+
if (i) {
|
|
264
|
+
this.AnalysysAgent = i;
|
|
265
|
+
const { allowMock: o, ...n } = e;
|
|
266
|
+
return i.init(n), this.isInitialized = !0, this.processPendingQueue(), !0;
|
|
267
|
+
}
|
|
268
|
+
return b.instances.delete(t), this.pendingQueue = [], !1;
|
|
269
|
+
} catch {
|
|
270
|
+
return b.instances.delete(t), this.pendingQueue = [], !1;
|
|
271
|
+
} finally {
|
|
272
|
+
this.isInitializing = !1, this.initSettled = !0;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
processPendingQueue() {
|
|
276
|
+
this.pendingQueue.forEach((e) => e()), this.pendingQueue = [];
|
|
277
|
+
}
|
|
278
|
+
track = (e, t) => {
|
|
279
|
+
const i = () => {
|
|
280
|
+
e && this.AnalysysAgent && this.AnalysysAgent.track(e, t);
|
|
281
|
+
};
|
|
282
|
+
if (!this.isInitialized && !this.initSettled) {
|
|
283
|
+
this.pendingQueue.push(i);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (this.isInitialized)
|
|
287
|
+
try {
|
|
288
|
+
i();
|
|
289
|
+
} catch {
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
setProfile = (e) => {
|
|
293
|
+
const t = () => {
|
|
294
|
+
e && this.AnalysysAgent && this.AnalysysAgent.profileSet(e);
|
|
295
|
+
};
|
|
296
|
+
if (!this.isInitialized && !this.initSettled) {
|
|
297
|
+
this.pendingQueue.push(t);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (this.isInitialized)
|
|
301
|
+
try {
|
|
302
|
+
t();
|
|
303
|
+
} catch {
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
setAlias = (e) => {
|
|
307
|
+
const t = () => {
|
|
308
|
+
e && this.AnalysysAgent && this.AnalysysAgent.alias(e);
|
|
309
|
+
};
|
|
310
|
+
if (!this.isInitialized && !this.initSettled) {
|
|
311
|
+
this.pendingQueue.push(t);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (this.isInitialized)
|
|
315
|
+
try {
|
|
316
|
+
t();
|
|
317
|
+
} catch {
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* 获取 SDK 初始化状态
|
|
322
|
+
*/
|
|
323
|
+
get initialized() {
|
|
324
|
+
return this.isInitialized;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* 当前是否使用 mock SDK
|
|
328
|
+
*/
|
|
329
|
+
get usingMock() {
|
|
330
|
+
return this.isInitialized && K.isUsingMock();
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* 等待 SDK 初始化完成
|
|
334
|
+
*/
|
|
335
|
+
async waitForInitialization() {
|
|
336
|
+
return this.isInitialized ? !0 : this.initializationPromise ?? !1;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function te(s) {
|
|
340
|
+
const e = Math.floor(s / 1e3), t = Math.floor(e / 60), i = Math.floor(t / 60), o = Math.floor(i / 24), n = (a) => a.toString().padStart(2, "0");
|
|
341
|
+
if (i < 1) {
|
|
342
|
+
const a = n(t % 60), u = n(e % 60);
|
|
343
|
+
return `${a}:${u}`;
|
|
344
|
+
}
|
|
345
|
+
if (o < 1) {
|
|
346
|
+
const a = n(i), u = n(t % 60), l = n(e % 60);
|
|
347
|
+
return `${a}:${u}:${l}`;
|
|
348
|
+
}
|
|
349
|
+
const r = i % 24, c = t % 60, d = [];
|
|
350
|
+
return o > 0 && d.push(`${o}天`), r > 0 && d.push(`${r}小时`), c > 0 && d.push(`${c}分钟`), d.join("");
|
|
351
|
+
}
|
|
352
|
+
function R() {
|
|
353
|
+
const s = navigator.userAgent;
|
|
354
|
+
return /iPhone|iPad|iPod|iOS/i.test(s) ? "iOS" : /Android/i.test(s) ? "Android" : "desktop";
|
|
355
|
+
}
|
|
356
|
+
function se() {
|
|
357
|
+
const s = R();
|
|
358
|
+
return s === "iOS" || s === "Android";
|
|
359
|
+
}
|
|
360
|
+
function ie() {
|
|
361
|
+
return /iPhone|iPad|iPod|iOS/i.test(navigator.userAgent);
|
|
362
|
+
}
|
|
363
|
+
function ne() {
|
|
364
|
+
return /Android/i.test(navigator.userAgent);
|
|
365
|
+
}
|
|
366
|
+
async function U(s) {
|
|
367
|
+
return new Promise((e, t) => {
|
|
368
|
+
try {
|
|
369
|
+
const i = document.createElement("script");
|
|
370
|
+
i.src = s, i.onload = () => {
|
|
371
|
+
e();
|
|
372
|
+
}, i.onerror = () => {
|
|
373
|
+
t(new Error(`Failed to load script from ${s}`));
|
|
374
|
+
}, document.head.appendChild(i);
|
|
375
|
+
} catch (i) {
|
|
376
|
+
t(i);
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
async function B() {
|
|
381
|
+
try {
|
|
382
|
+
if (await U("https://gosspublic.alicdn.com/aliyun-oss-sdk.min.js"), await U("https://cdnfile.yaomaitong.cn/cdn/js/aliyun-upload-sdk1.3.1.min.js"), !window.AliyunUpload)
|
|
383
|
+
throw new Error("SDK 加载成功但未找到 AliyunUpload 对象");
|
|
384
|
+
} catch (s) {
|
|
385
|
+
throw s;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
async function re(s) {
|
|
389
|
+
if (typeof window > "u")
|
|
390
|
+
throw new TypeError("VideoUploader 只能在浏览器环境中使用");
|
|
391
|
+
window.AliyunUpload || await B();
|
|
392
|
+
let e = null, t = null;
|
|
393
|
+
const i = new window.AliyunUpload.Vod({
|
|
394
|
+
// 上传进度回调
|
|
395
|
+
onUploadProgress: s.onUploadProgress,
|
|
396
|
+
// 上传凭证过期回调
|
|
397
|
+
onUploadTokenExpired: s.onUploadTokenExpired || (() => {
|
|
398
|
+
}),
|
|
399
|
+
// 开始上传回调,用于设置上传凭证和地址
|
|
400
|
+
onUploadstarted: async (n) => {
|
|
401
|
+
try {
|
|
402
|
+
const { uploadAuth: r, uploadAddress: c, videoId: d } = await s.onUploadstarted?.(n) || {};
|
|
403
|
+
r && c && d && i.setUploadAuthAndAddress(n, r, c, d);
|
|
404
|
+
} catch (r) {
|
|
405
|
+
throw r;
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
// 上传成功回调
|
|
409
|
+
onUploadSucceed: (n) => {
|
|
410
|
+
e?.(n);
|
|
411
|
+
},
|
|
412
|
+
// 上传失败回调
|
|
413
|
+
onUploadFailed: (n, r, c) => {
|
|
414
|
+
t?.(new Error(`${c} ${r}`));
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
return {
|
|
418
|
+
uploader: i,
|
|
419
|
+
upload: async (n) => new Promise((r, c) => {
|
|
420
|
+
e = r, t = c;
|
|
421
|
+
const d = JSON.stringify({
|
|
422
|
+
Vod: {
|
|
423
|
+
UserData: {
|
|
424
|
+
IsShowWaterMark: "false",
|
|
425
|
+
// 不显示水印
|
|
426
|
+
Priority: "7"
|
|
427
|
+
// 上传优先级
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
i.addFile(n, null, null, null, d), i.startUpload();
|
|
432
|
+
})
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
function oe(s, e) {
|
|
436
|
+
const t = document.createElement("a");
|
|
437
|
+
t.download = e, t.style.display = "none", t.href = s, document.body.appendChild(t), t.click(), document.body.removeChild(t);
|
|
438
|
+
}
|
|
439
|
+
function ae(s = "", e = [], t) {
|
|
440
|
+
try {
|
|
441
|
+
if (!e.length)
|
|
442
|
+
return;
|
|
443
|
+
const i = O.aoa_to_sheet(e);
|
|
444
|
+
t && (i["!merges"] = t);
|
|
445
|
+
const o = O.book_new();
|
|
446
|
+
O.book_append_sheet(o, i, ""), M(o, `${s}.xlsx`);
|
|
447
|
+
} catch {
|
|
448
|
+
return new Error("数据导出失败");
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function ce(s, e, t) {
|
|
452
|
+
return new Promise((i, o) => {
|
|
453
|
+
const n = new FileReader();
|
|
454
|
+
n.readAsArrayBuffer(s), n.onload = (r) => {
|
|
455
|
+
const c = r.target?.result, d = _(c, { type: "binary" }), a = [];
|
|
456
|
+
for (const u in d.Sheets)
|
|
457
|
+
if (Object.prototype.hasOwnProperty.call(d.Sheets, u)) {
|
|
458
|
+
let l = [];
|
|
459
|
+
const h = d.Sheets[u]["!ref"] || "", m = h.split(":"), p = t + m[1].toString();
|
|
460
|
+
l = l.concat(O.sheet_to_json(d.Sheets[u], { header: 1, range: t ? p : h }));
|
|
461
|
+
const g = l[0];
|
|
462
|
+
l.shift();
|
|
463
|
+
const y = l.map((w) => {
|
|
464
|
+
const $ = {};
|
|
465
|
+
return g.forEach((E, A) => {
|
|
466
|
+
$[E] = w[A];
|
|
467
|
+
}), $;
|
|
468
|
+
});
|
|
469
|
+
a.push(...y);
|
|
470
|
+
}
|
|
471
|
+
e && e(a), i(a);
|
|
472
|
+
}, n.onerror = (r) => {
|
|
473
|
+
o(r);
|
|
474
|
+
};
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
class C extends Error {
|
|
478
|
+
constructor(e) {
|
|
479
|
+
super(e), this.name = "OssError";
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
const x = {
|
|
483
|
+
accessKeyId: "",
|
|
484
|
+
accessKeySecret: "",
|
|
485
|
+
stsToken: "",
|
|
486
|
+
secure: !0,
|
|
487
|
+
bucket: "yao-file-daily",
|
|
488
|
+
region: "oss-cn-hangzhou",
|
|
489
|
+
timeout: 6e4
|
|
490
|
+
};
|
|
491
|
+
class k {
|
|
492
|
+
// 使用 Map 缓存不同配置的 client
|
|
493
|
+
static clients = /* @__PURE__ */ new Map();
|
|
494
|
+
static expireTime = 900 * 1e3;
|
|
495
|
+
// 获取凭证配置
|
|
496
|
+
static async getOssCredentials(e) {
|
|
497
|
+
const t = await e();
|
|
498
|
+
if (!t)
|
|
499
|
+
throw new C("获取凭证失败");
|
|
500
|
+
return t;
|
|
501
|
+
}
|
|
502
|
+
// 生成 client 缓存 key
|
|
503
|
+
static getClientKey(e) {
|
|
504
|
+
const t = e.endpoint || "", i = e.region || x.region, o = e.bucket || x.bucket;
|
|
505
|
+
return `${t}-${i}-${o}`;
|
|
506
|
+
}
|
|
507
|
+
// 初始化 OSS Client
|
|
508
|
+
static async initOssClient(e, t) {
|
|
509
|
+
const i = this.getClientKey(e), o = this.clients.get(i), n = Date.now();
|
|
510
|
+
if (o && n - o.createTime < this.expireTime)
|
|
511
|
+
return o.client;
|
|
512
|
+
try {
|
|
513
|
+
const { accessKeyId: r, accessKeySecret: c, securityToken: d, bucket: a, region: u, endpoint: l, cname: h, secure: m, timeout: p } = e, g = {
|
|
514
|
+
...x,
|
|
515
|
+
accessKeyId: r,
|
|
516
|
+
accessKeySecret: c,
|
|
517
|
+
stsToken: d,
|
|
518
|
+
bucket: a || x.bucket,
|
|
519
|
+
region: u || x.region,
|
|
520
|
+
endpoint: l,
|
|
521
|
+
cname: h,
|
|
522
|
+
secure: m !== void 0 ? m : x.secure,
|
|
523
|
+
timeout: p || x.timeout,
|
|
524
|
+
refreshSTSToken: async () => {
|
|
525
|
+
const w = await this.getOssCredentials(t);
|
|
526
|
+
return {
|
|
527
|
+
accessKeyId: w.accessKeyId,
|
|
528
|
+
accessKeySecret: w.accessKeySecret,
|
|
529
|
+
stsToken: w.securityToken
|
|
530
|
+
};
|
|
531
|
+
},
|
|
532
|
+
refreshSTSTokenInterval: 3e5
|
|
533
|
+
}, y = new D(g);
|
|
534
|
+
return this.clients.set(i, {
|
|
535
|
+
client: y,
|
|
536
|
+
createTime: n,
|
|
537
|
+
credentials: e
|
|
538
|
+
}), y;
|
|
539
|
+
} catch (r) {
|
|
540
|
+
throw new C(r instanceof Error ? r.message : String(r));
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
// 获取 OSS Client(用于手动控制上传流程)
|
|
544
|
+
static async getClient(e) {
|
|
545
|
+
const { getCredentials: t } = e, i = await this.getOssCredentials(t);
|
|
546
|
+
return await this.initOssClient(i, t);
|
|
547
|
+
}
|
|
548
|
+
// 上传文件方法
|
|
549
|
+
static async uploadFile(e) {
|
|
550
|
+
const { file: t, onProgress: i = () => {
|
|
551
|
+
}, path: o, headers: n, getCredentials: r } = e, c = await this.getOssCredentials(r), d = await this.initOssClient(c, r);
|
|
552
|
+
try {
|
|
553
|
+
const a = o || c.path || "ksh/pdf", u = a && /\.\w+$/.test(a) ? a : `${a}/${t.name}`, l = n || c.headers, h = {
|
|
554
|
+
progress(p) {
|
|
555
|
+
const g = Math.round(p * 100);
|
|
556
|
+
i({ percent: g });
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
return l && (h.headers = l), await d.multipartUpload(u, t, h);
|
|
560
|
+
} catch (a) {
|
|
561
|
+
throw new C(a instanceof Error ? a.message : String(a));
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
// 生成签名URL方法
|
|
565
|
+
static async generateSignedUrl(e) {
|
|
566
|
+
const { objectKey: t, getCredentials: i, expires: o = 3600 } = e, n = await this.getOssCredentials(i), r = await this.initOssClient(n, i);
|
|
567
|
+
try {
|
|
568
|
+
return await r.signatureUrl(t, { expires: o });
|
|
569
|
+
} catch (c) {
|
|
570
|
+
throw new C(c instanceof Error ? c.message : String(c));
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
// 清理过期的 client 缓存
|
|
574
|
+
static clearExpiredClients() {
|
|
575
|
+
const e = Date.now();
|
|
576
|
+
for (const [t, i] of this.clients.entries())
|
|
577
|
+
e - i.createTime >= this.expireTime && this.clients.delete(t);
|
|
578
|
+
}
|
|
579
|
+
// 清理所有缓存
|
|
580
|
+
static clearAllClients() {
|
|
581
|
+
this.clients.clear();
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
const le = k.getClient.bind(k), de = k.uploadFile.bind(k), ue = k.generateSignedUrl.bind(k);
|
|
585
|
+
class he {
|
|
586
|
+
prefix;
|
|
587
|
+
constructor(e = "qxs_") {
|
|
588
|
+
this.prefix = e;
|
|
589
|
+
}
|
|
590
|
+
local = {
|
|
591
|
+
has: (e, t = !0) => {
|
|
592
|
+
const i = t ? `${this.prefix}${e}` : e;
|
|
593
|
+
return Object.prototype.hasOwnProperty.call(localStorage, i);
|
|
594
|
+
},
|
|
595
|
+
get: (e, t = !0) => {
|
|
596
|
+
const i = t ? `${this.prefix}${e}` : e;
|
|
597
|
+
return localStorage.getItem(i);
|
|
598
|
+
},
|
|
599
|
+
set: (e, t, i = !0) => {
|
|
600
|
+
const o = i ? `${this.prefix}${e}` : e;
|
|
601
|
+
localStorage.setItem(o, t);
|
|
602
|
+
},
|
|
603
|
+
remove: (e, t = !0) => {
|
|
604
|
+
const i = t ? `${this.prefix}${e}` : e;
|
|
605
|
+
localStorage.removeItem(i);
|
|
606
|
+
},
|
|
607
|
+
clear: () => {
|
|
608
|
+
localStorage.clear();
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
session = {
|
|
612
|
+
has: (e, t = !0) => {
|
|
613
|
+
const i = t ? `${this.prefix}${e}` : e;
|
|
614
|
+
return Object.prototype.hasOwnProperty.call(sessionStorage, i);
|
|
615
|
+
},
|
|
616
|
+
get: (e, t = !0) => {
|
|
617
|
+
const i = t ? `${this.prefix}${e}` : e;
|
|
618
|
+
return sessionStorage.getItem(i);
|
|
619
|
+
},
|
|
620
|
+
set: (e, t, i = !0) => {
|
|
621
|
+
const o = i ? `${this.prefix}${e}` : e;
|
|
622
|
+
sessionStorage.setItem(o, t);
|
|
623
|
+
},
|
|
624
|
+
remove: (e, t = !0) => {
|
|
625
|
+
const i = t ? `${this.prefix}${e}` : e;
|
|
626
|
+
sessionStorage.removeItem(i);
|
|
627
|
+
},
|
|
628
|
+
clear: () => {
|
|
629
|
+
sessionStorage.clear();
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
cookie = {
|
|
633
|
+
has: (e, t = !0) => {
|
|
634
|
+
const i = t ? `${this.prefix}${e}` : e;
|
|
635
|
+
return new RegExp(`(^|;)\\s*${i}=`).test(document.cookie);
|
|
636
|
+
},
|
|
637
|
+
get: (e, t = !0) => {
|
|
638
|
+
const i = t ? `${this.prefix}${e}` : e, o = document.cookie.match(new RegExp(`(^|;)\\s*${i}=([^;]*)`));
|
|
639
|
+
return o ? decodeURIComponent(o[2]) : null;
|
|
640
|
+
},
|
|
641
|
+
set: (e, t, i = 1, o = "/", n = window.location.hostname, r = !0) => {
|
|
642
|
+
const c = r ? `${this.prefix}${e}` : e, d = /* @__PURE__ */ new Date();
|
|
643
|
+
d.setTime(d.getTime() + i * 24 * 60 * 60 * 1e3);
|
|
644
|
+
const a = `;expires=${d.toUTCString()}`, u = `;path=${o}`, l = n ? `;domain=${n}` : "";
|
|
645
|
+
document.cookie = `${c}=${encodeURIComponent(t)}${a}${u}${l}`;
|
|
646
|
+
},
|
|
647
|
+
remove: (e, t = "/", i = window.location.hostname, o = !0) => {
|
|
648
|
+
const n = o ? `${this.prefix}${e}` : e, r = `;expires=${(/* @__PURE__ */ new Date(0)).toUTCString()}`, c = `;path=${t}`, d = i ? `;domain=${i}` : "";
|
|
649
|
+
document.cookie = `${n}=;${r}${c}${d}`;
|
|
650
|
+
},
|
|
651
|
+
clear: () => {
|
|
652
|
+
const e = document.cookie.match(/[^ =;]+(?==)/g);
|
|
653
|
+
e && e.forEach((t) => {
|
|
654
|
+
document.cookie = `${t}=;expires=${(/* @__PURE__ */ new Date(0)).toUTCString()};path=/`;
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
const W = {
|
|
660
|
+
id: "wm_div_id",
|
|
661
|
+
prefix: "mask_div_id",
|
|
662
|
+
text: "测试水印",
|
|
663
|
+
x: 0,
|
|
664
|
+
y: 0,
|
|
665
|
+
rows: 0,
|
|
666
|
+
cols: 0,
|
|
667
|
+
width: 0,
|
|
668
|
+
height: 0,
|
|
669
|
+
x_space: 100,
|
|
670
|
+
y_space: 40,
|
|
671
|
+
font: "微软雅黑",
|
|
672
|
+
color: "black",
|
|
673
|
+
fontsize: "18px",
|
|
674
|
+
alpha: 0.15,
|
|
675
|
+
zIndex: 9999999,
|
|
676
|
+
angle: 15,
|
|
677
|
+
parent_width: 0,
|
|
678
|
+
parent_height: 0,
|
|
679
|
+
parent_node: null,
|
|
680
|
+
monitor: !0
|
|
681
|
+
};
|
|
682
|
+
function F(s, e, t) {
|
|
683
|
+
const o = document.createElement("canvas").getContext("2d");
|
|
684
|
+
if (!o)
|
|
685
|
+
return { width: 100, height: 100 };
|
|
686
|
+
o.font = `${t} ${e}`;
|
|
687
|
+
const n = o.measureText(s.trim()), r = Number.parseFloat(t), c = n.actualBoundingBoxAscent !== void 0 && n.actualBoundingBoxDescent !== void 0 ? n.actualBoundingBoxAscent + n.actualBoundingBoxDescent : r;
|
|
688
|
+
return {
|
|
689
|
+
width: Math.ceil(n.width),
|
|
690
|
+
height: Math.ceil(c)
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
function pe() {
|
|
694
|
+
const s = { ...W };
|
|
695
|
+
let e = !1;
|
|
696
|
+
const t = new MutationObserver(d), i = new ResizeObserver(() => {
|
|
697
|
+
e || r(s);
|
|
698
|
+
});
|
|
699
|
+
function o(a, u) {
|
|
700
|
+
const l = a - s.x, h = u - s.y, m = s.x_space || 20, p = s.y_space || 20, g = Math.ceil(l / (s.width + m)), y = Math.ceil(h / (s.height + p));
|
|
701
|
+
return {
|
|
702
|
+
cols: g,
|
|
703
|
+
rows: y,
|
|
704
|
+
x_space: m,
|
|
705
|
+
y_space: p
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
function n(a, u, l) {
|
|
709
|
+
const h = document.createElement("div");
|
|
710
|
+
return h.textContent = s.text, h.id = `${s.prefix}${l}`, h.style.cssText = `
|
|
711
|
+
transform: rotate(-${s.angle}deg);
|
|
712
|
+
position: absolute;
|
|
713
|
+
left: ${a}px;
|
|
714
|
+
top: ${u}px;
|
|
715
|
+
overflow: hidden;
|
|
716
|
+
z-index: 999999;
|
|
717
|
+
opacity: ${s.alpha};
|
|
718
|
+
font-size: ${s.fontsize};
|
|
719
|
+
font-family: ${s.font};
|
|
720
|
+
color: ${s.color};
|
|
721
|
+
text-align: center;
|
|
722
|
+
width: ${s.width}px;
|
|
723
|
+
height: ${s.height}px;
|
|
724
|
+
line-height: ${s.height}px;
|
|
725
|
+
display: flex;
|
|
726
|
+
align-items: center;
|
|
727
|
+
justify-content: center;
|
|
728
|
+
user-select: none;
|
|
729
|
+
visibility: visible;
|
|
730
|
+
`.replace(/\s+/g, " ").trim(), h;
|
|
731
|
+
}
|
|
732
|
+
function r(a) {
|
|
733
|
+
if (document.querySelectorAll(`#${s.id}`).forEach((f) => {
|
|
734
|
+
f.parentNode?.removeChild(f);
|
|
735
|
+
}), Object.assign(s, a), s.width === 0 && s.height === 0 || s.width === 0 || s.height === 0) {
|
|
736
|
+
const f = F(
|
|
737
|
+
s.text,
|
|
738
|
+
s.font,
|
|
739
|
+
s.fontsize
|
|
740
|
+
), P = 10;
|
|
741
|
+
s.width === 0 && (s.width = f.width + P), s.height === 0 && (s.height = f.height + P);
|
|
742
|
+
}
|
|
743
|
+
const l = s.parent_node || document.body, h = Math.max(l.scrollWidth, l.clientWidth), m = Math.max(l.scrollHeight, l.clientHeight), p = document.createElement("div");
|
|
744
|
+
p.id = s.id, l.closest("body") && getComputedStyle(l).position === "static" && (l.style.position = "relative"), p.style.cssText = `
|
|
745
|
+
pointer-events: none;
|
|
746
|
+
display: block;
|
|
747
|
+
position: absolute;
|
|
748
|
+
top: 0;
|
|
749
|
+
left: 0;
|
|
750
|
+
width: 100%;
|
|
751
|
+
height: 100%;
|
|
752
|
+
z-index: ${s.zIndex};
|
|
753
|
+
overflow: hidden;
|
|
754
|
+
`.replace(/\s+/g, " ").trim();
|
|
755
|
+
const g = p.attachShadow ? p.attachShadow({ mode: "open" }) : p;
|
|
756
|
+
l.appendChild(p);
|
|
757
|
+
const { cols: y, rows: w, x_space: $, y_space: E } = o(h, m);
|
|
758
|
+
s.cols = y, s.rows = w, s.x_space = $, s.y_space = E;
|
|
759
|
+
const A = document.createDocumentFragment();
|
|
760
|
+
for (let f = 0; f < w; f++) {
|
|
761
|
+
const P = s.y + (s.height + E) * f;
|
|
762
|
+
for (let I = 0; I < y; I++) {
|
|
763
|
+
const z = s.x + (s.width + $) * I;
|
|
764
|
+
A.appendChild(n(z, P, f * y + I));
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if (g.appendChild(A), s.monitor) {
|
|
768
|
+
i.observe(l);
|
|
769
|
+
const f = {
|
|
770
|
+
attributes: !0,
|
|
771
|
+
// 监听属性变化
|
|
772
|
+
childList: !0,
|
|
773
|
+
// 监听子元素变化
|
|
774
|
+
subtree: !0,
|
|
775
|
+
// 监听子树变化
|
|
776
|
+
characterData: !0
|
|
777
|
+
// 监听文本内容变化
|
|
778
|
+
};
|
|
779
|
+
t.observe(p, f), g !== p && t.observe(g, f);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function c() {
|
|
783
|
+
const a = document.getElementById(s.id);
|
|
784
|
+
t.disconnect(), a && a.parentNode?.removeChild(a);
|
|
785
|
+
}
|
|
786
|
+
function d(a) {
|
|
787
|
+
if (e) {
|
|
788
|
+
e = !1;
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
if (!document.getElementById(s.id)) {
|
|
792
|
+
r(s);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
a.some((h) => h.type === "childList" || h.type === "attributes" || h.type === "characterData") && r(s);
|
|
796
|
+
}
|
|
797
|
+
return {
|
|
798
|
+
addMark: r,
|
|
799
|
+
removeMark: () => {
|
|
800
|
+
e = !0, c();
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
export {
|
|
805
|
+
q as ApiError,
|
|
806
|
+
Z as ApiService,
|
|
807
|
+
b as ArgoLog,
|
|
808
|
+
ee as FetchApiService,
|
|
809
|
+
ae as JsonToExcel,
|
|
810
|
+
C as OssError,
|
|
811
|
+
k as OssUploader,
|
|
812
|
+
he as Storage,
|
|
813
|
+
re as createVideoUploader,
|
|
814
|
+
oe as downloadFile,
|
|
815
|
+
ce as excelToJson,
|
|
816
|
+
te as formatDuration,
|
|
817
|
+
ue as generateSignedUrl,
|
|
818
|
+
le as getClient,
|
|
819
|
+
R as getDeviceType,
|
|
820
|
+
ne as isAndroid,
|
|
821
|
+
L as isBoolean,
|
|
822
|
+
V as isElement,
|
|
823
|
+
ie as isIOS,
|
|
824
|
+
Y as isImageByMimeType,
|
|
825
|
+
X as isJSONString,
|
|
826
|
+
se as isMobile,
|
|
827
|
+
H as isNumber,
|
|
828
|
+
T as isPlainObject,
|
|
829
|
+
J as isUndefined,
|
|
830
|
+
G as isWindow,
|
|
831
|
+
de as uploadFile,
|
|
832
|
+
pe as watermark
|
|
833
|
+
};
|
|
2
834
|
//# sourceMappingURL=index.mjs.map
|