@whitesev/utils 2.5.2 → 2.5.4

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.
@@ -273,24 +273,24 @@ var Utils = (function () {
273
273
  }
274
274
  /**
275
275
  * 获取多组Cookie
276
- * @param paramDetails 配置
276
+ * @param option 配置
277
277
  * @param callback 获取操作后的回调
278
278
  * + cookies object[]
279
279
  * + error string|undefined
280
280
  **/
281
- list(paramDetails, callback) {
282
- if (paramDetails == null) {
281
+ list(option, callback) {
282
+ if (option == null) {
283
283
  throw new Error("Utils.GMCookie.list 参数不能为空");
284
284
  }
285
285
  let resultData = [];
286
286
  try {
287
- let details = {
287
+ let defaultOption = {
288
288
  url: this.windowApi.window.location.href,
289
289
  domain: this.windowApi.window.location.hostname,
290
290
  name: "",
291
291
  path: "/",
292
292
  };
293
- details = utils.assign(details, paramDetails);
293
+ defaultOption = utils.assign(defaultOption, option);
294
294
  let cookies = this.windowApi.document.cookie.split(";");
295
295
  cookies.forEach((item) => {
296
296
  item = item.trim();
@@ -298,9 +298,9 @@ var Utils = (function () {
298
298
  let itemName = itemSplit[0];
299
299
  itemSplit.splice(0, 1);
300
300
  let itemValue = decodeURIComponent(itemSplit.join(""));
301
- let nameRegexp = details.name instanceof RegExp
302
- ? details.name
303
- : new RegExp("^" + details.name, "g");
301
+ let nameRegexp = defaultOption.name instanceof RegExp
302
+ ? defaultOption.name
303
+ : new RegExp("^" + defaultOption.name, "g");
304
304
  if (itemName.match(nameRegexp)) {
305
305
  resultData.push({
306
306
  domain: this.windowApi.window.location.hostname,
@@ -328,20 +328,20 @@ var Utils = (function () {
328
328
  }
329
329
  /**
330
330
  * 获取多组Cookie
331
- * @param paramDetails 配置
331
+ * @param option 配置
332
332
  **/
333
- getList(paramDetails) {
334
- if (paramDetails == null) {
333
+ getList(option) {
334
+ if (option == null) {
335
335
  throw new Error("Utils.GMCookie.list 参数不能为空");
336
336
  }
337
337
  let resultData = [];
338
- let details = {
338
+ let defaultOption = {
339
339
  url: this.windowApi.window.location.href,
340
340
  domain: this.windowApi.window.location.hostname,
341
341
  name: "",
342
342
  path: "/",
343
343
  };
344
- details = utils.assign(details, paramDetails);
344
+ defaultOption = utils.assign(defaultOption, option);
345
345
  let cookies = this.windowApi.document.cookie.split(";");
346
346
  cookies.forEach((item) => {
347
347
  item = item.trim();
@@ -349,9 +349,9 @@ var Utils = (function () {
349
349
  let itemName = itemSplit[0];
350
350
  itemSplit.splice(0, 1);
351
351
  let itemValue = decodeURIComponent(itemSplit.join(""));
352
- let nameRegexp = details.name instanceof RegExp
353
- ? details.name
354
- : new RegExp("^" + details.name, "g");
352
+ let nameRegexp = defaultOption.name instanceof RegExp
353
+ ? defaultOption.name
354
+ : new RegExp("^" + defaultOption.name, "g");
355
355
  if (itemName.match(nameRegexp)) {
356
356
  resultData.push({
357
357
  domain: this.windowApi.window.location.hostname,
@@ -371,12 +371,13 @@ var Utils = (function () {
371
371
  }
372
372
  /**
373
373
  * 设置Cookie
374
- * @param paramDetails 配置
374
+ * @param option 配置
375
375
  * @param callback 设置操作后的回调(成功/失败)
376
376
  */
377
- set(paramDetails, callback = (error) => { }) {
377
+ set(option, callback) {
378
+ let errorInfo;
378
379
  try {
379
- let details = {
380
+ let defaultOption = {
380
381
  url: this.windowApi.window.location.href,
381
382
  name: "",
382
383
  value: "",
@@ -389,43 +390,52 @@ var Utils = (function () {
389
390
  */
390
391
  expirationDate: Math.floor(Date.now()) + 60 * 60 * 24 * 30,
391
392
  };
392
- details = utils.assign(details, paramDetails);
393
- let life = details.expirationDate
394
- ? details.expirationDate
393
+ defaultOption = utils.assign(defaultOption, option);
394
+ let life = defaultOption.expirationDate
395
+ ? defaultOption.expirationDate
395
396
  : Math.floor(Date.now()) + 60 * 60 * 24 * 30;
396
- let cookieStr = details.name +
397
+ let cookieStr = defaultOption.name +
397
398
  "=" +
398
- decodeURIComponent(details.value) +
399
+ decodeURIComponent(defaultOption.value) +
399
400
  ";expires=" +
400
401
  new Date(life).toGMTString() +
401
402
  "; path=/";
402
403
  this.windowApi.document.cookie = cookieStr;
403
- callback();
404
404
  }
405
405
  catch (error) {
406
- callback(error);
406
+ errorInfo = error;
407
+ }
408
+ finally {
409
+ if (typeof callback === "function") {
410
+ callback(errorInfo);
411
+ }
407
412
  }
408
413
  }
409
414
  /**
410
415
  * 删除Cookie
411
- * @param paramDetails 配置
416
+ * @param option 配置
412
417
  * @param callback 删除操作后的回调(成功/失败)
413
418
  */
414
- delete(paramDetails, callback = (error) => { }) {
419
+ delete(option, callback) {
420
+ let errorInfo;
415
421
  try {
416
- let details = {
422
+ let defaultOption = {
417
423
  url: this.windowApi.window.location.href,
418
424
  name: "",
419
- // @ts-ignore
420
- firstPartyDomain: "",
425
+ path: "/",
426
+ firstPartyDomain: this.windowApi.window.location.hostname,
421
427
  };
422
- details = utils.assign(details, paramDetails);
423
- let cookieStr = details.name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
428
+ defaultOption = utils.assign(defaultOption, option);
429
+ let cookieStr = `${defaultOption.name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${defaultOption.path}; domain=${defaultOption.firstPartyDomain};`;
424
430
  this.windowApi.document.cookie = cookieStr;
425
- callback();
426
431
  }
427
432
  catch (error) {
428
- callback(error);
433
+ errorInfo = error;
434
+ }
435
+ finally {
436
+ if (typeof callback === "function") {
437
+ callback(errorInfo);
438
+ }
429
439
  }
430
440
  }
431
441
  }
@@ -4111,7 +4121,7 @@ var Utils = (function () {
4111
4121
  this.windowApi = new WindowApi(option);
4112
4122
  }
4113
4123
  /** 版本号 */
4114
- version = "2024.11.16";
4124
+ version = "2024.12.3";
4115
4125
  addStyle(cssText) {
4116
4126
  if (typeof cssText !== "string") {
4117
4127
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -4829,9 +4839,7 @@ var Utils = (function () {
4829
4839
  getMaxZIndexNodeInfo(deviation = 1, target = this.windowApi.document, ignoreCallBack) {
4830
4840
  deviation = Number.isNaN(deviation) ? 1 : deviation;
4831
4841
  const UtilsContext = this;
4832
- // 最大值2147483647
4833
- const maxZIndex = Math.pow(2, 31) - 1;
4834
- // 比较值2000000000
4842
+ // 比较值 2000000000
4835
4843
  const maxZIndexCompare = 2 * Math.pow(10, 9);
4836
4844
  // 当前页面最大的z-index
4837
4845
  let zIndex = 0;
@@ -4883,7 +4891,7 @@ var Utils = (function () {
4883
4891
  zIndex += deviation;
4884
4892
  if (zIndex >= maxZIndexCompare) {
4885
4893
  // 最好不要超过最大值
4886
- zIndex = maxZIndex;
4894
+ zIndex = maxZIndexCompare;
4887
4895
  }
4888
4896
  return {
4889
4897
  node: maxZIndexNode,