@fast-china/utils 1.0.3 → 1.0.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.
@@ -13480,127 +13480,13 @@ var FastUtils = function(exports, vue) {
13480
13480
  }
13481
13481
  consoleWarn("document", "binding value must be a string or number");
13482
13482
  };
13483
- const objectUtil = {
13484
- /**
13485
- * 对象URL参数化
13486
- */
13487
- objectToQueryString(obj) {
13488
- let params = "";
13489
- for (const key in obj) {
13490
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
13491
- if (params !== "") {
13492
- params += "&";
13493
- }
13494
- params += `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;
13495
- }
13496
- }
13497
- return params;
13498
- },
13499
- /**
13500
- * 是否存在重复值
13501
- */
13502
- hasDuplicateProperty(arr, prop) {
13503
- const values2 = arr.map((obj) => obj[prop]);
13504
- const uniqueValues = new Set(values2);
13505
- return values2.length !== uniqueValues.size;
13506
- },
13507
- /**
13508
- * 是否存在非重复值
13509
- */
13510
- hasDifferentProperty(arr, prop) {
13511
- const valueSet = /* @__PURE__ */ new Set();
13512
- for (const obj of arr) {
13513
- valueSet.add(obj[prop]);
13514
- if (valueSet.size > 1) {
13515
- return true;
13516
- }
13517
- }
13518
- return false;
13519
- },
13520
- /**
13521
- * 时间处理翻译
13522
- */
13523
- dateTimeFix(date2) {
13524
- if (date2 !== null && date2 !== void 0 && date2) {
13525
- if (typeof date2 === "string") {
13526
- date2 = new Date(date2);
13527
- }
13528
- let timestamp = date2.getTime();
13529
- if (timestamp.toString().length < 13) {
13530
- const arrTimestamp = timestamp.toString().split("");
13531
- for (let start = 0; start < 13; start++) {
13532
- if (!arrTimestamp[start]) {
13533
- arrTimestamp[start] = "0";
13534
- }
13535
- }
13536
- timestamp = parseInt(arrTimestamp.join(""));
13537
- }
13538
- const minute = 1e3 * 60;
13539
- const hour = minute * 60;
13540
- const day = hour * 24;
13541
- const month = day * 30;
13542
- const curTime = (/* @__PURE__ */ new Date()).getTime();
13543
- const diffValue = curTime - timestamp;
13544
- const monthC = diffValue / month;
13545
- const weekC = diffValue / (7 * day);
13546
- const dayC = diffValue / day;
13547
- const hourC = diffValue / hour;
13548
- const minC = diffValue / minute;
13549
- if (diffValue < 0) {
13550
- const monthC1 = Math.abs(monthC);
13551
- const weekC1 = Math.abs(weekC);
13552
- const dayC1 = Math.abs(dayC);
13553
- const hourC1 = Math.abs(hourC);
13554
- const minC1 = Math.abs(minC);
13555
- if (monthC1 > 12) {
13556
- return `${parseInt(`${monthC1 / 12}`)}年后`;
13557
- } else if (monthC1 >= 6) {
13558
- return "半年后";
13559
- } else if (monthC1 >= 1) {
13560
- return `${parseInt(`${monthC1}`)}月后`;
13561
- } else if (weekC1 > 2) {
13562
- return "半月后";
13563
- } else if (weekC1 >= 1) {
13564
- return `${parseInt(`${weekC1}`)}周后`;
13565
- } else if (dayC1 >= 1) {
13566
- return `${parseInt(`${dayC1}`)}天后`;
13567
- } else if (hourC1 >= 1) {
13568
- return `${parseInt(`${hourC1}`)}小时后`;
13569
- } else if (minC1 >= 1) {
13570
- return `${parseInt(`${minC1}`)}分钟后`;
13571
- }
13572
- return "刚刚";
13573
- }
13574
- if (monthC > 12) {
13575
- return `${parseInt(`${monthC / 12}`)}年前`;
13576
- } else if (monthC >= 6) {
13577
- return "半年前";
13578
- } else if (monthC >= 1) {
13579
- return `${parseInt(`${monthC}`)}月前`;
13580
- } else if (weekC > 2) {
13581
- return "半月前";
13582
- } else if (weekC >= 1) {
13583
- return `${parseInt(`${weekC}`)}周前`;
13584
- } else if (dayC >= 1) {
13585
- return `${parseInt(`${dayC}`)}天前`;
13586
- } else if (hourC >= 1) {
13587
- return `${parseInt(`${hourC}`)}小时前`;
13588
- } else if (minC >= 1) {
13589
- return `${parseInt(`${minC}`)}分钟前`;
13590
- }
13591
- return "刚刚";
13592
- } else {
13593
- return "";
13594
- }
13595
- }
13596
- };
13597
- const state = vue.reactive({
13483
+ const state$1 = vue.reactive({
13598
13484
  prefix: "fast__",
13599
13485
  expireSuffix: "__Expire",
13600
13486
  crypto: false
13601
13487
  });
13602
- const CACHE_PREFIX = vue.computed(() => state.prefix);
13603
- const CACHE_EXPIRE_SUFFIX = vue.computed(() => state.expireSuffix);
13488
+ const CACHE_PREFIX = vue.computed(() => state$1.prefix);
13489
+ const CACHE_EXPIRE_SUFFIX = vue.computed(() => state$1.expireSuffix);
13604
13490
  const useStorage = () => {
13605
13491
  return {
13606
13492
  /**
@@ -13608,21 +13494,21 @@ var FastUtils = function(exports, vue) {
13608
13494
  * @param key
13609
13495
  */
13610
13496
  prefix(key) {
13611
- state.prefix = key;
13497
+ state$1.prefix = key;
13612
13498
  },
13613
13499
  /**
13614
13500
  * 缓存过期值后缀 Key
13615
13501
  * @param key
13616
13502
  */
13617
13503
  expireSuffix(key) {
13618
- state.expireSuffix = key;
13504
+ state$1.expireSuffix = key;
13619
13505
  },
13620
13506
  /**
13621
13507
  * 设置缓存是否加密
13622
13508
  * @param crypto
13623
13509
  */
13624
13510
  crypto(crypto) {
13625
- state.crypto = crypto;
13511
+ state$1.crypto = crypto;
13626
13512
  }
13627
13513
  };
13628
13514
  };
@@ -13673,7 +13559,7 @@ var FastUtils = function(exports, vue) {
13673
13559
  */
13674
13560
  set(key, val, expire, encrypt) {
13675
13561
  try {
13676
- encrypt ?? (encrypt = state.crypto);
13562
+ encrypt ?? (encrypt = state$1.crypto);
13677
13563
  if (expire) {
13678
13564
  if (isNaN(expire) || expire < 1) {
13679
13565
  throw new Error("有效期应为一个有效数值");
@@ -13683,13 +13569,13 @@ var FastUtils = function(exports, vue) {
13683
13569
  expire
13684
13570
  };
13685
13571
  const expireJson = JSON.stringify(expireData);
13686
- storage.set(`${state.prefix}${key}${state.expireSuffix}`, expireJson);
13572
+ storage.set(`${state$1.prefix}${key}${state$1.expireSuffix}`, expireJson);
13687
13573
  }
13688
13574
  let valJson = JSON.stringify(val);
13689
13575
  if (encrypt) {
13690
13576
  valJson = base64Util.toBase64(valJson);
13691
13577
  }
13692
- storage.set(`${state.prefix}${key}`, valJson);
13578
+ storage.set(`${state$1.prefix}${key}`, valJson);
13693
13579
  } catch (error) {
13694
13580
  consoleError("Local", error);
13695
13581
  }
@@ -13702,18 +13588,18 @@ var FastUtils = function(exports, vue) {
13702
13588
  */
13703
13589
  get(key, decrypt) {
13704
13590
  try {
13705
- decrypt ?? (decrypt = state.crypto);
13706
- let valJson = storage.get(`${state.prefix}${key}`);
13591
+ decrypt ?? (decrypt = state$1.crypto);
13592
+ let valJson = storage.get(`${state$1.prefix}${key}`);
13707
13593
  if (valJson) {
13708
13594
  if (decrypt) {
13709
13595
  valJson = base64Util.base64ToStr(valJson);
13710
13596
  }
13711
- const expireJson = storage.get(`${state.prefix}${key}${state.expireSuffix}`);
13597
+ const expireJson = storage.get(`${state$1.prefix}${key}${state$1.expireSuffix}`);
13712
13598
  if (expireJson) {
13713
13599
  const expireData = JSON.parse(expireJson);
13714
13600
  if (Date.now() > expireData.time + expireData.expire * 60 * 1e3) {
13715
- storage.remove(`${state.prefix}${key}`);
13716
- storage.remove(`${state.prefix}${key}${state.expireSuffix}`);
13601
+ storage.remove(`${state$1.prefix}${key}`);
13602
+ storage.remove(`${state$1.prefix}${key}${state$1.expireSuffix}`);
13717
13603
  return null;
13718
13604
  }
13719
13605
  }
@@ -13734,8 +13620,8 @@ var FastUtils = function(exports, vue) {
13734
13620
  */
13735
13621
  remove(key) {
13736
13622
  try {
13737
- storage.remove(`${state.prefix}${key}`);
13738
- storage.remove(`${state.prefix}${key}${state.expireSuffix}`);
13623
+ storage.remove(`${state$1.prefix}${key}`);
13624
+ storage.remove(`${state$1.prefix}${key}${state$1.expireSuffix}`);
13739
13625
  } catch (error) {
13740
13626
  consoleError("Local", error);
13741
13627
  }
@@ -13747,7 +13633,7 @@ var FastUtils = function(exports, vue) {
13747
13633
  removeByPrefix(key) {
13748
13634
  try {
13749
13635
  for (const itemKey in storage.keys) {
13750
- if (itemKey.indexOf(`${state.prefix}${key}`) !== -1) {
13636
+ if (itemKey.indexOf(`${state$1.prefix}${key}`) !== -1) {
13751
13637
  storage.remove(itemKey);
13752
13638
  }
13753
13639
  }
@@ -13780,7 +13666,7 @@ var FastUtils = function(exports, vue) {
13780
13666
  return;
13781
13667
  }
13782
13668
  try {
13783
- encrypt ?? (encrypt = state.crypto);
13669
+ encrypt ?? (encrypt = state$1.crypto);
13784
13670
  if (expire) {
13785
13671
  if (isNaN(expire) || expire < 1) {
13786
13672
  throw new Error("有效期应为一个有效数值");
@@ -13790,13 +13676,13 @@ var FastUtils = function(exports, vue) {
13790
13676
  expire
13791
13677
  };
13792
13678
  const expireJson = JSON.stringify(expireData);
13793
- window.sessionStorage.setItem(`${state.prefix}${key}${state.expireSuffix}`, expireJson);
13679
+ window.sessionStorage.setItem(`${state$1.prefix}${key}${state$1.expireSuffix}`, expireJson);
13794
13680
  }
13795
13681
  let valJson = JSON.stringify(val);
13796
13682
  if (encrypt) {
13797
13683
  valJson = base64Util.toBase64(valJson);
13798
13684
  }
13799
- window.sessionStorage.setItem(`${state.prefix}${key}`, valJson);
13685
+ window.sessionStorage.setItem(`${state$1.prefix}${key}`, valJson);
13800
13686
  } catch (error) {
13801
13687
  consoleError("Session", error);
13802
13688
  }
@@ -13813,18 +13699,18 @@ var FastUtils = function(exports, vue) {
13813
13699
  return;
13814
13700
  }
13815
13701
  try {
13816
- decrypt ?? (decrypt = state.crypto);
13817
- let valJson = window.sessionStorage.getItem(`${state.prefix}${key}`);
13702
+ decrypt ?? (decrypt = state$1.crypto);
13703
+ let valJson = window.sessionStorage.getItem(`${state$1.prefix}${key}`);
13818
13704
  if (valJson) {
13819
13705
  if (decrypt) {
13820
13706
  valJson = base64Util.base64ToStr(valJson);
13821
13707
  }
13822
- const expireJson = window.sessionStorage.getItem(`${state.prefix}${key}${state.expireSuffix}`);
13708
+ const expireJson = window.sessionStorage.getItem(`${state$1.prefix}${key}${state$1.expireSuffix}`);
13823
13709
  if (expireJson) {
13824
13710
  const expireData = JSON.parse(expireJson);
13825
13711
  if (Date.now() > expireData.time + expireData.expire * 60 * 1e3) {
13826
- window.sessionStorage.removeItem(`${state.prefix}${key}`);
13827
- window.sessionStorage.removeItem(`${state.prefix}${key}${state.expireSuffix}`);
13712
+ window.sessionStorage.removeItem(`${state$1.prefix}${key}`);
13713
+ window.sessionStorage.removeItem(`${state$1.prefix}${key}${state$1.expireSuffix}`);
13828
13714
  return null;
13829
13715
  }
13830
13716
  }
@@ -13849,8 +13735,8 @@ var FastUtils = function(exports, vue) {
13849
13735
  return;
13850
13736
  }
13851
13737
  try {
13852
- window.sessionStorage.removeItem(`${state.prefix}${key}`);
13853
- window.sessionStorage.removeItem(`${state.prefix}${key}${state.expireSuffix}`);
13738
+ window.sessionStorage.removeItem(`${state$1.prefix}${key}`);
13739
+ window.sessionStorage.removeItem(`${state$1.prefix}${key}${state$1.expireSuffix}`);
13854
13740
  } catch (error) {
13855
13741
  consoleError("Session", error);
13856
13742
  }
@@ -13866,7 +13752,7 @@ var FastUtils = function(exports, vue) {
13866
13752
  }
13867
13753
  try {
13868
13754
  for (const itemKey in window.sessionStorage) {
13869
- if (itemKey.indexOf(`${state.prefix}${key}`) !== -1) {
13755
+ if (itemKey.indexOf(`${state$1.prefix}${key}`) !== -1) {
13870
13756
  window.sessionStorage.removeItem(itemKey);
13871
13757
  }
13872
13758
  }
@@ -13978,6 +13864,146 @@ var FastUtils = function(exports, vue) {
13978
13864
  }
13979
13865
  }
13980
13866
  };
13867
+ const state = vue.reactive({
13868
+ cacheKey: "__DEVICE_ID",
13869
+ deviceId: ""
13870
+ });
13871
+ const uuidRegExp = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
13872
+ const makeIdentity = () => {
13873
+ if (state.deviceId && uuidRegExp.test(state.deviceId)) {
13874
+ Local.set(state.cacheKey, state.deviceId);
13875
+ return state.deviceId;
13876
+ }
13877
+ let deviceID = Local.get(state.cacheKey);
13878
+ if (deviceID && uuidRegExp.test(deviceID)) {
13879
+ state.deviceId = deviceID;
13880
+ return deviceID;
13881
+ }
13882
+ deviceID = stringUtil.generateUUID();
13883
+ Local.set(state.cacheKey, deviceID);
13884
+ state.deviceId = deviceID;
13885
+ return deviceID;
13886
+ };
13887
+ const useIdentity = () => {
13888
+ return {
13889
+ ...state,
13890
+ makeIdentity
13891
+ };
13892
+ };
13893
+ const objectUtil = {
13894
+ /**
13895
+ * 对象URL参数化
13896
+ */
13897
+ objectToQueryString(obj) {
13898
+ let params = "";
13899
+ for (const key in obj) {
13900
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
13901
+ if (params !== "") {
13902
+ params += "&";
13903
+ }
13904
+ params += `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;
13905
+ }
13906
+ }
13907
+ return params;
13908
+ },
13909
+ /**
13910
+ * 是否存在重复值
13911
+ */
13912
+ hasDuplicateProperty(arr, prop) {
13913
+ const values2 = arr.map((obj) => obj[prop]);
13914
+ const uniqueValues = new Set(values2);
13915
+ return values2.length !== uniqueValues.size;
13916
+ },
13917
+ /**
13918
+ * 是否存在非重复值
13919
+ */
13920
+ hasDifferentProperty(arr, prop) {
13921
+ const valueSet = /* @__PURE__ */ new Set();
13922
+ for (const obj of arr) {
13923
+ valueSet.add(obj[prop]);
13924
+ if (valueSet.size > 1) {
13925
+ return true;
13926
+ }
13927
+ }
13928
+ return false;
13929
+ },
13930
+ /**
13931
+ * 时间处理翻译
13932
+ */
13933
+ dateTimeFix(date2) {
13934
+ if (date2 !== null && date2 !== void 0 && date2) {
13935
+ if (typeof date2 === "string") {
13936
+ date2 = new Date(date2);
13937
+ }
13938
+ let timestamp = date2.getTime();
13939
+ if (timestamp.toString().length < 13) {
13940
+ const arrTimestamp = timestamp.toString().split("");
13941
+ for (let start = 0; start < 13; start++) {
13942
+ if (!arrTimestamp[start]) {
13943
+ arrTimestamp[start] = "0";
13944
+ }
13945
+ }
13946
+ timestamp = parseInt(arrTimestamp.join(""));
13947
+ }
13948
+ const minute = 1e3 * 60;
13949
+ const hour = minute * 60;
13950
+ const day = hour * 24;
13951
+ const month = day * 30;
13952
+ const curTime = (/* @__PURE__ */ new Date()).getTime();
13953
+ const diffValue = curTime - timestamp;
13954
+ const monthC = diffValue / month;
13955
+ const weekC = diffValue / (7 * day);
13956
+ const dayC = diffValue / day;
13957
+ const hourC = diffValue / hour;
13958
+ const minC = diffValue / minute;
13959
+ if (diffValue < 0) {
13960
+ const monthC1 = Math.abs(monthC);
13961
+ const weekC1 = Math.abs(weekC);
13962
+ const dayC1 = Math.abs(dayC);
13963
+ const hourC1 = Math.abs(hourC);
13964
+ const minC1 = Math.abs(minC);
13965
+ if (monthC1 > 12) {
13966
+ return `${parseInt(`${monthC1 / 12}`)}年后`;
13967
+ } else if (monthC1 >= 6) {
13968
+ return "半年后";
13969
+ } else if (monthC1 >= 1) {
13970
+ return `${parseInt(`${monthC1}`)}月后`;
13971
+ } else if (weekC1 > 2) {
13972
+ return "半月后";
13973
+ } else if (weekC1 >= 1) {
13974
+ return `${parseInt(`${weekC1}`)}周后`;
13975
+ } else if (dayC1 >= 1) {
13976
+ return `${parseInt(`${dayC1}`)}天后`;
13977
+ } else if (hourC1 >= 1) {
13978
+ return `${parseInt(`${hourC1}`)}小时后`;
13979
+ } else if (minC1 >= 1) {
13980
+ return `${parseInt(`${minC1}`)}分钟后`;
13981
+ }
13982
+ return "刚刚";
13983
+ }
13984
+ if (monthC > 12) {
13985
+ return `${parseInt(`${monthC / 12}`)}年前`;
13986
+ } else if (monthC >= 6) {
13987
+ return "半年前";
13988
+ } else if (monthC >= 1) {
13989
+ return `${parseInt(`${monthC}`)}月前`;
13990
+ } else if (weekC > 2) {
13991
+ return "半月前";
13992
+ } else if (weekC >= 1) {
13993
+ return `${parseInt(`${weekC}`)}周前`;
13994
+ } else if (dayC >= 1) {
13995
+ return `${parseInt(`${dayC}`)}天前`;
13996
+ } else if (hourC >= 1) {
13997
+ return `${parseInt(`${hourC}`)}小时前`;
13998
+ } else if (minC >= 1) {
13999
+ return `${parseInt(`${minC}`)}分钟前`;
14000
+ }
14001
+ return "刚刚";
14002
+ } else {
14003
+ return "";
14004
+ }
14005
+ }
14006
+ };
13981
14007
  const useExpose = (expose, exposed) => {
13982
14008
  expose(exposed);
13983
14009
  return exposed;
@@ -14071,6 +14097,7 @@ var FastUtils = function(exports, vue) {
14071
14097
  exports.stringUtil = stringUtil;
14072
14098
  exports.throwError = throwError;
14073
14099
  exports.useExpose = useExpose;
14100
+ exports.useIdentity = useIdentity;
14074
14101
  exports.useProps = useProps;
14075
14102
  exports.useRender = useRender;
14076
14103
  exports.useStorage = useStorage;