zzz-pc-view 0.0.11 → 0.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zzz-pc-view",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "main": "src/index.umd.js",
5
5
  "module": "src/index.es.js",
6
6
  "types": "src/index.d.ts",
@@ -22,11 +22,20 @@ interface StoreType<T extends TypeWithPrototype = TypeWithPrototype> {
22
22
  [storeKey]: Store<T>;
23
23
  }
24
24
  /**
25
- * API 列表的接口,包含一个获取列表的方法
26
- * @template T 列表项的类型
25
+ * 定义一个接口 `ApiList`,用于描述一个包含 `getList` 方法的对象。
26
+ * `getList` 方法用于获取数据列表,它接受一个可选的 `query` 参数,
27
+ * 并返回一个 `HttpRequestPromise` 或 `Promise`,其解析值为 `CombineInstanceType<T>[]` 类型的数组。
28
+ *
29
+ * @template T 一个泛型类型,必须是一个类类型。
27
30
  */
28
31
  export interface ApiList<T extends TypeWithPrototype = TypeWithPrototype> {
29
- getList(query?: any): HttpRequestPromise<CombineInstanceType<T>[]>;
32
+ /**
33
+ * 获取数据列表的方法。
34
+ *
35
+ * @param {any} [query] - 可选的查询参数。
36
+ * @returns {HttpRequestPromise<CombineInstanceType<T>[]> | Promise<CombineInstanceType<T>[]>} 返回一个 `HttpRequestPromise` 或 `Promise`,其解析值为 `CombineInstanceType<T>[]` 类型的数组。
37
+ */
38
+ getList(query?: any): HttpRequestPromise<CombineInstanceType<T>[]> | Promise<CombineInstanceType<T>[]>;
30
39
  }
31
40
  /**
32
41
  * Loader 的参数接口,包含 API 列表、全局标志、子键和加载完成的回调函数
package/src/index.es.js CHANGED
@@ -691,6 +691,34 @@ const setDateByFormat = (date, dateStr, format, ...params) => {
691
691
  }
692
692
  return date.getTime();
693
693
  };
694
+ const timeConfigs = [
695
+ {
696
+ unit: "天",
697
+ step: 864e5,
698
+ pad: NaN,
699
+ max: Infinity
700
+ },
701
+ {
702
+ unit: "小时",
703
+ step: 36e5,
704
+ pad: 2,
705
+ max: 23
706
+ },
707
+ {
708
+ unit: "分",
709
+ step: 6e4,
710
+ pad: 2,
711
+ max: 59
712
+ },
713
+ {
714
+ unit: "秒",
715
+ step: 1e3,
716
+ pad: 2,
717
+ max: 59
718
+ }
719
+ ];
720
+ const timeConfigsLen = timeConfigs.length;
721
+ const lastTimeConfigsIndex = timeConfigsLen - 1;
694
722
  class ZDate extends Date {
695
723
  /**
696
724
  * 设置日期的季度。
@@ -922,6 +950,94 @@ class ZDate extends Date {
922
950
  setByFormat(...args) {
923
951
  return setDateByFormat(this, ...args);
924
952
  }
953
+ /**
954
+ * 获取两个时间之间的持续时间格式字符串。
955
+ *
956
+ * @param beginTime - 开始时间,可以是字符串、数字、Date 对象或 ZDate 对象。
957
+ * @param endTime - 结束时间,可以是字符串、数字、Date 对象或 ZDate 对象。
958
+ * @param lastEndIndex - 最后一个时间单位的索引,默认为 timeConfigs 数组的最后一个索引。
959
+ * @returns 持续时间的格式字符串。
960
+ *
961
+ * @example
962
+ const beginTime = new ZDate('2023/01/01 00:00:00')
963
+ const endTime = new ZDate('2023/01/01 00:00:05')
964
+ const durationStr = ZUtils.ZDate.getDurationFormatStr(beginTime, endTime)
965
+ console.log(durationStr)
966
+ *
967
+ * @example
968
+ const beginTime = new ZDate('2023/01/01 00:00:00')
969
+ const endTime = new ZDate('2023/01/01 00:05:00')
970
+ const durationStr = ZUtils.ZDate.getDurationFormatStr(beginTime, endTime, 2)
971
+ console.log(durationStr)
972
+
973
+ * @example
974
+ const beginTime = new ZDate('2023/01/01 00:00:00')
975
+ const endTime = new ZDate('2023/01/01 00:05:00')
976
+ const durationStr = ZUtils.ZDate.getDurationFormatStr(beginTime, endTime, -1)
977
+ console.log(durationStr)
978
+ */
979
+ static getDurationFormatStr(beginTime, endTime, lastEndIndex = lastTimeConfigsIndex) {
980
+ const results = [];
981
+ lastEndIndex = Math.max(
982
+ 0,
983
+ Math.min(
984
+ lastEndIndex + (lastEndIndex >> -1 & 1) * lastTimeConfigsIndex,
985
+ lastTimeConfigsIndex
986
+ )
987
+ );
988
+ const endIndex = lastEndIndex + 1;
989
+ const begin = new ZUtils.ZDate(beginTime).getTime();
990
+ const end = new ZUtils.ZDate(endTime).getTime();
991
+ let duration = end - begin;
992
+ if (duration === 0) {
993
+ results.push([0, timeConfigs[lastEndIndex]]);
994
+ } else {
995
+ for (let i = 0; i < endIndex; i++) {
996
+ const timeConfig = timeConfigs[i];
997
+ const { step } = timeConfig;
998
+ const result = duration / step;
999
+ results.push([result, timeConfig]);
1000
+ duration = duration % step;
1001
+ if (duration === 0) {
1002
+ break;
1003
+ }
1004
+ }
1005
+ }
1006
+ const lastResultsIndex = results.length - 1;
1007
+ const lastResult = results[lastResultsIndex];
1008
+ lastResult[0] = Math.ceil(lastResult[0]);
1009
+ if (lastResult[0] > lastResult[1].max) {
1010
+ lastResult[0] = 0;
1011
+ for (let i = lastResultsIndex - 1; i >= 0; i--) {
1012
+ const result = results[i];
1013
+ result[0] = Math.floor(result[0]) + 1;
1014
+ if (result[0] > result[1].max) {
1015
+ result[0] = 0;
1016
+ } else {
1017
+ break;
1018
+ }
1019
+ }
1020
+ }
1021
+ let firstNotZeroIndex = results.findIndex((result) => result[0] >= 1);
1022
+ if (firstNotZeroIndex === -1) {
1023
+ firstNotZeroIndex = lastResultsIndex;
1024
+ }
1025
+ let lastNotZeroIndex = lastResultsIndex;
1026
+ for (; lastNotZeroIndex > firstNotZeroIndex; lastNotZeroIndex--) {
1027
+ const result = results[lastNotZeroIndex];
1028
+ if (result[0] > 0) {
1029
+ break;
1030
+ }
1031
+ }
1032
+ let response2 = "";
1033
+ for (let i = firstNotZeroIndex; i <= lastNotZeroIndex; i++) {
1034
+ const result = results[i];
1035
+ const { unit, pad } = result[1];
1036
+ const value = Math.floor(result[0]);
1037
+ response2 += `${Number.isFinite(pad) ? value.toString().padStart(pad, "0") : value}${unit}`;
1038
+ }
1039
+ return response2;
1040
+ }
925
1041
  }
926
1042
  const completeByDate = (list2, dataTimeProp, dateRange, completeConfig, missDataFormatter = (data) => data) => {
927
1043
  const { interval } = completeConfig;
@@ -1625,7 +1741,7 @@ const index$c = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
1625
1741
  bindThenAjaxSource,
1626
1742
  create
1627
1743
  }, Symbol.toStringTag, { value: "Module" }));
1628
- const ZUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1744
+ const ZUtils$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1629
1745
  __proto__: null,
1630
1746
  WithNew,
1631
1747
  WithPrototype,
@@ -10112,7 +10228,7 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
10112
10228
  }, Symbol.toStringTag, { value: "Module" }));
10113
10229
  const indexPcViews = {
10114
10230
  install(app, param) {
10115
- app.config.globalProperties.$ZUtils = ZUtils;
10231
+ app.config.globalProperties.$ZUtils = ZUtils$1;
10116
10232
  app.config.globalProperties.$ZDecorators = ZDecorators;
10117
10233
  setApi(param.api);
10118
10234
  app.use(directiveInstaller);
@@ -10127,7 +10243,7 @@ const indexPcViews = {
10127
10243
  export {
10128
10244
  index as PcViews,
10129
10245
  ZDecorators,
10130
- ZUtils,
10246
+ ZUtils$1 as ZUtils,
10131
10247
  index$b as ZWebUtils,
10132
10248
  indexPcViews as default
10133
10249
  };