@chaoswise/ui 3.0.21 → 3.0.23

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.
Files changed (32) hide show
  1. package/lib/Alert/index.js +48 -2
  2. package/lib/Alert/index.style.js +36 -0
  3. package/lib/Button/index.style.js +1 -3
  4. package/lib/CWMessage/MessageContent/TabList/index.js +14 -14
  5. package/lib/CWMessage/MessageContent/index.js +2 -2
  6. package/lib/CWMessage/index.js +6 -7
  7. package/lib/CWMessage/utils/generate/dayjs.js +12 -0
  8. package/lib/CWMessage/utils/generate/moment.js +2 -0
  9. package/lib/CWRangePicker/DropdownMenu/index.js +0 -1
  10. package/lib/CWRangePicker/utils/generate/dayjs.js +24 -12
  11. package/lib/ConfigProvider/customTheme.js +3 -2
  12. package/lib/Header/index.style.js +0 -1
  13. package/lib/IconSelect/components/SearchIcon/index.js +0 -1
  14. package/lib/LayoutWrapper/style/index.js +7 -2
  15. package/lib/QuickTransfer/index.js +16 -6
  16. package/lib/RangePicker/components/ExtraQuickSelect.js +1 -4
  17. package/lib/RangePicker/index.js +55 -43
  18. package/lib/RangePicker/utils/generate/dayjs.js +29 -15
  19. package/lib/RangePicker/utils/generate/moment.js +13 -11
  20. package/lib/ScrollLoad/index.js +0 -1
  21. package/lib/SiderMenu/index.js +7 -16
  22. package/lib/SiderMenu/index.style.js +19 -3
  23. package/lib/SingleSpa/import-html/process-tpl.js +5 -5
  24. package/lib/TimeRangeSlider/TimeRangeSliderCmp/hooks/useMouse.js +1 -1
  25. package/lib/TimeRangeSlider/TimeRangeSliderCmp/utils/generate/dayjs.js +20 -9
  26. package/lib/TimeRangeSlider/utils/generate/dayjs.js +42 -35
  27. package/lib/TimeRangeSlider/utils/generate/moment.js +25 -0
  28. package/lib/TimeZoneSelect/index.js +127 -0
  29. package/lib/utils/generate/dayjs.js +5 -0
  30. package/lib/utils/generate/moment.js +2 -1
  31. package/lib/utils/index.js +35 -0
  32. package/package.json +4 -1
@@ -1,4 +1,5 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _originalDayjs$tz;
2
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
5
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -10,13 +11,24 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
10
11
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
11
12
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
13
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
13
- import dayjs from "dayjs";
14
+ import originalDayjs from "dayjs";
14
15
  import duration from "dayjs/plugin/duration";
15
16
  import isSameOrAfter_dayjs from "dayjs/plugin/isSameOrAfter";
16
- dayjs.extend(isSameOrAfter_dayjs);
17
- dayjs.extend(duration);
17
+ import utc from "dayjs/plugin/utc";
18
+ import timezone from "dayjs/plugin/timezone";
19
+ originalDayjs.extend(isSameOrAfter_dayjs);
20
+ originalDayjs.extend(duration);
21
+ // 扩展 dayjs 支持时区
22
+ originalDayjs.extend(utc);
23
+ originalDayjs.extend(timezone);
18
24
  var _require = require("uuid"),
19
25
  uuidv4 = _require.v4;
26
+ var timeZone = ((_originalDayjs$tz = originalDayjs.tz()) === null || _originalDayjs$tz === void 0 || (_originalDayjs$tz = _originalDayjs$tz.$x) === null || _originalDayjs$tz === void 0 ? void 0 : _originalDayjs$tz.$timezone) || originalDayjs.tz.guess();
27
+ // 封装 dayjs 函数,使其每次调用时自动应用当前的全局时区
28
+ var dayjs = function dayjs() {
29
+ var instance = originalDayjs.apply(void 0, arguments);
30
+ return instance.tz();
31
+ };
20
32
  // 枚举时间单位
21
33
  var ENUM_TimeUnit = {
22
34
  s: ["Second", "Seconds", "秒", "seconds"],
@@ -26,13 +38,6 @@ var ENUM_TimeUnit = {
26
38
  mo: ["Month", "Months", "月", "mo"],
27
39
  y: ["Year", "Years", "年", "years"]
28
40
  };
29
- var EnumTimeType = {
30
- recently: "recentlyArray",
31
- relative: "relativeArray",
32
- absolute: "absoluteArray",
33
- unixTimestamp: "unixTimestampArray",
34
- other: "otherArray"
35
- };
36
41
 
37
42
  /**
38
43
  * 变换数据源格式
@@ -40,25 +45,27 @@ var EnumTimeType = {
40
45
  * @returns 重新编排组合的数据源
41
46
  */
42
47
  export var regroupDataSourceFn = function regroupDataSourceFn(dataSource) {
43
- var recentlyArray = [];
44
- var relativeArray = [];
45
- var absoluteArray = [];
46
- var unixTimestampArray = [];
47
- var otherArray = [];
48
+ var EnumTimeTypeData = {
49
+ recently: [],
50
+ relative: [],
51
+ absolute: [],
52
+ unixTimestamp: [],
53
+ other: []
54
+ };
48
55
  var regroupDataSource = [];
49
56
  dataSource.forEach(function (item) {
50
- if (EnumTimeType[item.type]) {
51
- eval(EnumTimeType[item.type]).push(item);
57
+ if (Object.keys(EnumTimeTypeData).includes(item.type)) {
58
+ EnumTimeTypeData[item.type].push(item);
52
59
  } else {
53
- eval(EnumTimeType["other"]).push(item);
60
+ EnumTimeTypeData["other"].push(item);
54
61
  }
55
62
  });
56
- Object.entries(EnumTimeType).map(function (item) {
57
- if (eval(item[1]).length) {
58
- var newObj = {};
59
- newObj.type = item[0];
60
- newObj.timeList = eval(item[1]);
61
- regroupDataSource.push(newObj);
63
+ Object.entries(EnumTimeTypeData).forEach(function (item) {
64
+ if (item[1].length) {
65
+ regroupDataSource.push({
66
+ type: item[0],
67
+ timeList: item[1]
68
+ });
62
69
  }
63
70
  });
64
71
  return regroupDataSource;
@@ -193,7 +200,7 @@ export var echoInputValue = function echoInputValue() {
193
200
  }
194
201
  };
195
202
 
196
- // 计算两个moment日期的时间差(时间戳)
203
+ // 计算两个dayjs日期的时间差(时间戳)
197
204
  export var computeTimeDiff = function computeTimeDiff(value) {
198
205
  var unit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "ms";
199
206
  return value[1].diff(value[0], unit);
@@ -210,7 +217,7 @@ export var computeTimeSpan = function computeTimeSpan(value, timeSpanBoundary) {
210
217
  if (timeDiff >= 60) {
211
218
  timeDiff = Number(timeDiff + 1);
212
219
  }
213
- var duration = dayjs.duration(timeDiff, "s");
220
+ var duration = originalDayjs.duration(timeDiff, "s");
214
221
  var _duration$$d = duration.$d,
215
222
  years = _duration$$d.years,
216
223
  months = _duration$$d.months,
@@ -298,7 +305,7 @@ export var cloneChangeDate = function cloneChangeDate(currentDate_0, currentDate
298
305
  if (_maxTimeDiff <= 0) {
299
306
  // 当前时间已经是极限了
300
307
  // 已经是极限直接当前时间向前推进timeSpanBoundary即可
301
- cloneCurrentDate_0 = dayjs().subtract(dayjs.duration(timeSpanBoundary, "s"));
308
+ cloneCurrentDate_0 = dayjs().subtract(originalDayjs.duration(timeSpanBoundary, "s"));
302
309
  cloneCurrentDate_1 = dayjs();
303
310
  switchInitial = true;
304
311
  } else {
@@ -307,27 +314,27 @@ export var cloneChangeDate = function cloneChangeDate(currentDate_0, currentDate
307
314
  var initialTimeDiff = computeTimeDiff([clone0, clone1], "s");
308
315
  if (timeSpanBoundary > initialTimeDiff) {
309
316
  var needChangeTimeDiff = Math.ceil(timeSpanBoundary - initialTimeDiff) / 2;
310
- cloneCurrentDate_0 = clone0.subtract(dayjs.duration(needChangeTimeDiff, "s"));
311
- cloneCurrentDate_1 = clone1.add(dayjs.duration(needChangeTimeDiff, "s"));
317
+ cloneCurrentDate_0 = clone0.subtract(originalDayjs.duration(needChangeTimeDiff, "s"));
318
+ cloneCurrentDate_1 = clone1.add(originalDayjs.duration(needChangeTimeDiff, "s"));
312
319
  // 计算最大值的时间差
313
320
  var _maxTimeDiff2 = computeTimeDiff([cloneCurrentDate_1, dayjs()]);
314
321
  if (_maxTimeDiff2 <= 0) {
315
322
  // 当前时间已经是极限了
316
323
  // 已经是极限直接当前时间向前推进timeSpanBoundary即可
317
- cloneCurrentDate_0 = dayjs().subtract(dayjs.duration(timeSpanBoundary, "s"));
324
+ cloneCurrentDate_0 = dayjs().subtract(originalDayjs.duration(timeSpanBoundary, "s"));
318
325
  cloneCurrentDate_1 = dayjs();
319
326
  switchInitial = true;
320
327
  }
321
328
  } else {
322
- cloneCurrentDate_1 = clone1.add(dayjs.duration(timeSpanBoundary, "s"));
329
+ cloneCurrentDate_1 = clone1.add(originalDayjs.duration(timeSpanBoundary, "s"));
323
330
  var clone = cloneCurrentDate_1.clone();
324
- cloneCurrentDate_0 = clone.subtract(dayjs.duration(timeSpanBoundary, "s"));
331
+ cloneCurrentDate_0 = clone.subtract(originalDayjs.duration(timeSpanBoundary, "s"));
325
332
  // 计算最大值的时间差
326
333
  var _maxTimeDiff3 = computeTimeDiff([cloneCurrentDate_1, dayjs()]);
327
334
  if (_maxTimeDiff3 <= 0) {
328
335
  // 当前时间已经是极限了
329
336
  // 已经是极限直接当前时间向前推进timeSpanBoundary即可
330
- cloneCurrentDate_0 = dayjs().subtract(dayjs.duration(timeSpanBoundary, "s"));
337
+ cloneCurrentDate_0 = dayjs().subtract(originalDayjs.duration(timeSpanBoundary, "s"));
331
338
  cloneCurrentDate_1 = dayjs();
332
339
  switchInitial = true;
333
340
  }
@@ -386,7 +393,7 @@ export var getChangeDate = function getChangeDate(recordDateValue, direction) {
386
393
  value = getChangeUnitDate(captureUnit[0], ENUM_TimeUnit[captureUnit[1]][3]);
387
394
  }
388
395
  var timeDiff = value[1].diff(value[0]);
389
- var duration = dayjs.duration(timeDiff);
396
+ var duration = originalDayjs.duration(timeDiff);
390
397
  var _cloneChangeDate = cloneChangeDate(value[0], value[1], direction, growSize, duration, timeSpanBoundary),
391
398
  _value = _cloneChangeDate.value,
392
399
  switchInitial = _cloneChangeDate.switchInitial;
@@ -616,7 +623,7 @@ var parseInputDate = function parseInputDate(text) {
616
623
  var finalFormat = "";
617
624
  for (var i = 0; i < FORMATS.length; i += 1) {
618
625
  var format = FORMATS[i];
619
- var date = dayjs(text, format, true);
626
+ var date = originalDayjs(text, format, true).tz(timeZone, true); // tz参数设置为undefined:使用设置后的全局时区, true:2023-01-01 02:02:02 切换到对应时区仍然是 2023-01-01 02:02:02
620
627
  if (date.isValid()) {
621
628
  finalDate = date;
622
629
  finalFormat = format;
@@ -704,4 +704,29 @@ export function getFinalDateOption(inputStr) {
704
704
  export var isExceedMaxTimeSpan = function isExceedMaxTimeSpan(value, timeSpanBoundary) {
705
705
  return computeTimeDiff(value, "s") > timeSpanBoundary;
706
706
  };
707
+
708
+ /**
709
+ * 是否小于最小的时间跨度
710
+ */
711
+ export var isLessThanMinTimeSpan = function isLessThanMinTimeSpan(value, timeSpanBoundary) {
712
+ return computeTimeDiff(value, "s") < timeSpanBoundary;
713
+ };
714
+
715
+ // 检查一个 moment 是否在另一个 moment 之后或与之相同。
716
+ export var isSameOrAfter = function isSameOrAfter(date1, date2) {
717
+ return moment(date1).isSameOrAfter(date2);
718
+ };
719
+
720
+ /**
721
+ * 判断选择的时间是否在要求的时间时间之内,默认为最近30天
722
+ */
723
+ export var isWithinTimeSpan = function isWithinTimeSpan(value, days) {
724
+ var startDate = moment().clone().subtract(days, "days");
725
+ var endDate = moment().clone();
726
+ if (isSameOrAfter(value[0], startDate) && isSameOrAfter(endDate, value[1])) {
727
+ return true;
728
+ } else {
729
+ return false;
730
+ }
731
+ };
707
732
  export default moment;
@@ -0,0 +1,127 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ import _Select from "@chaoswise/ui/lib/Select";
3
+ var _excluded = ["getSystemTimeZoneInfoApi", "onInitialChange", "getOptions", "renderLabel"],
4
+ _excluded2 = ["isSelected"];
5
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
6
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
7
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
8
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
9
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
10
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
13
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
14
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
15
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
16
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
17
+ // TimeZoneSelect.js
18
+ import React, { useState, useEffect } from "react";
19
+ import PropTypes from "prop-types";
20
+ var Option = _Select.Option;
21
+ var TimeZoneSelect = function TimeZoneSelect(_ref) {
22
+ var getSystemTimeZoneInfoApi = _ref.getSystemTimeZoneInfoApi,
23
+ onInitialChange = _ref.onInitialChange,
24
+ getOptions = _ref.getOptions,
25
+ renderLabel = _ref.renderLabel,
26
+ rest = _objectWithoutProperties(_ref, _excluded);
27
+ var _useState = useState([]),
28
+ _useState2 = _slicedToArray(_useState, 2),
29
+ timeZones = _useState2[0],
30
+ setTimeZones = _useState2[1];
31
+ var _useState3 = useState(false),
32
+ _useState4 = _slicedToArray(_useState3, 2),
33
+ loading = _useState4[0],
34
+ setLoading = _useState4[1];
35
+ useEffect(function () {
36
+ // 组件初始化时调用接口获取时区列表
37
+ var fetchTimeZones = /*#__PURE__*/function () {
38
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
39
+ var response, data, timeZoneData, _timeZoneData, initialTimeZone;
40
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
41
+ while (1) switch (_context.prev = _context.next) {
42
+ case 0:
43
+ setLoading(true);
44
+ _context.prev = 1;
45
+ _context.next = 4;
46
+ return getSystemTimeZoneInfoApi();
47
+ case 4:
48
+ response = _context.sent;
49
+ if (response.status === "success" && response.code == 100000) {
50
+ data = response.data;
51
+ timeZoneData = (data || []).map(function (item) {
52
+ return {
53
+ countryCity: item.countryCity,
54
+ countryCityCode: item.countryCityCode,
55
+ timeZone: item.timeZone,
56
+ label: "(".concat(item.timeZone, ") ").concat(item.countryCity),
57
+ isSelected: item.isSelected
58
+ };
59
+ });
60
+ _timeZoneData = timeZoneData.map(function (item) {
61
+ var isSelected = item.isSelected,
62
+ restTimeZoneData = _objectWithoutProperties(item, _excluded2);
63
+ return restTimeZoneData;
64
+ });
65
+ setTimeZones(_timeZoneData);
66
+
67
+ // 获取初始的时区值并传递给 onInitialChange
68
+ initialTimeZone = timeZoneData.find(function (item) {
69
+ return item.isSelected;
70
+ });
71
+ onInitialChange && onInitialChange(initialTimeZone ? initialTimeZone.countryCityCode : undefined);
72
+
73
+ // 提供选项数据给外部使用
74
+ if (getOptions) {
75
+ getOptions(_timeZoneData);
76
+ }
77
+ }
78
+ _context.next = 11;
79
+ break;
80
+ case 8:
81
+ _context.prev = 8;
82
+ _context.t0 = _context["catch"](1);
83
+ console.error("获取时区列表失败:", _context.t0);
84
+ case 11:
85
+ _context.prev = 11;
86
+ setLoading(false);
87
+ return _context.finish(11);
88
+ case 14:
89
+ case "end":
90
+ return _context.stop();
91
+ }
92
+ }, _callee, null, [[1, 8, 11, 14]]);
93
+ }));
94
+ return function fetchTimeZones() {
95
+ return _ref2.apply(this, arguments);
96
+ };
97
+ }();
98
+ fetchTimeZones();
99
+ }, []);
100
+ return /*#__PURE__*/React.createElement(_Select, _extends({
101
+ loading: loading,
102
+ showSearch: true,
103
+ optionFilterProp: "children",
104
+ virtual: false
105
+ }, rest), timeZones.map(function (tz) {
106
+ return /*#__PURE__*/React.createElement(Option, {
107
+ key: tz.countryCityCode,
108
+ value: tz.countryCityCode
109
+ }, renderLabel ? renderLabel(tz) : tz.label);
110
+ }));
111
+ };
112
+
113
+ // 为 props 添加类型检查
114
+ TimeZoneSelect.propTypes = {
115
+ getSystemTimeZoneInfoApi: PropTypes.func.isRequired,
116
+ // 获取时区列表的接口方法
117
+ value: PropTypes.string,
118
+ // 当前选择的时区值
119
+ onChange: PropTypes.func,
120
+ // 时区改变回调函数
121
+ onInitialChange: PropTypes.func,
122
+ // 接口初始值回调
123
+ getOptions: PropTypes.func,
124
+ // 获取选项数据
125
+ renderLabel: PropTypes.func // 自定义选项标签渲染函数,(当前选项标签)=>{}
126
+ };
127
+ export default TimeZoneSelect;
@@ -1,2 +1,7 @@
1
1
  import dayjs from "dayjs";
2
+ import utc from "dayjs/plugin/utc";
3
+ import timezone from "dayjs/plugin/timezone";
4
+ // 扩展 dayjs 支持时区
5
+ dayjs.extend(utc);
6
+ dayjs.extend(timezone);
2
7
  export default dayjs;
@@ -1,2 +1,3 @@
1
- import moment from "moment";
1
+ import moment from 'moment';
2
+ import "moment-timezone";
2
3
  export default moment;
@@ -1,3 +1,4 @@
1
+ import dayjs from './generate/dayjs';
1
2
  /**
2
3
  * 复制组件其它属性到目标组件
3
4
  */
@@ -87,4 +88,38 @@ export var formatMessage = function formatMessage(message) {
87
88
  } else {
88
89
  return "未找到对应的翻译信息";
89
90
  }
91
+ };
92
+
93
+ /**
94
+ * 根据特定时区将时间戳转换为固定时间偏移量的时间对象
95
+ * @param {*} time - 时间参数,可以是时间戳、日期字符串或 moment/dayjs 对象
96
+ * @param {*} defaultCountryCityCode - 默认时区代码,默认为本地时区(通过 moment/dayjs.tz.guess() 自动检测)
97
+ * @param {*} countryCityCode - 自定义时区代码,用于覆盖默认时区
98
+ * @returns 返回转换为指定时区的 moment/dayjs 对象 取决于webpack中useMomentWebpackPlugin配置,默认为true为moment对象,为false则为dayjs对象
99
+ */
100
+ export var setDateByTimeZone = function setDateByTimeZone(time) {
101
+ var defaultCountryCityCode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : dayjs.tz.guess();
102
+ var countryCityCode = arguments.length > 2 ? arguments[2] : undefined;
103
+ // 从 localStorage 获取时区信息
104
+ var timeZoneData = JSON.parse(localStorage.getItem('cw_timeZone'));
105
+ // 如果 localStorage 中没有找到时区信息,则使用默认时区(自动推测的本地时区)
106
+ var timezone = timeZoneData ? timeZoneData.countryCityCode : defaultCountryCityCode;
107
+ // 如果有传入的自定义时区代码,则使用自定义时区,否则使用从 localStorage 获取或推测的时区
108
+ var _timezone = countryCityCode ? countryCityCode : timezone;
109
+ // 返回转换为指定时区的 moment 对象
110
+ return dayjs.tz(time, _timezone);
111
+ };
112
+
113
+ /**
114
+ * 从localStorage获取format信息,直接获取字符串
115
+ * @param {*} format 默认的format配置
116
+ * @returns {format} 返回format信息
117
+ */
118
+ export var getFormatByLocalStorage = function getFormatByLocalStorage() {
119
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "YYYY-MM-DD HH:mm:ss";
120
+ // 从localStorage获取format信息,直接获取字符串
121
+ var formatData = localStorage.getItem('cw_timeFormat');
122
+
123
+ // 如果localStorage中存在formatData,则返回它,否则返回默认的format
124
+ return formatData ? formatData : format;
90
125
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chaoswise/ui",
3
3
  "packageName": "chaoswiseUI",
4
- "version": "3.0.21",
4
+ "version": "3.0.23",
5
5
  "description": "公共UI库",
6
6
  "keywords": [
7
7
  "ui",
@@ -27,6 +27,8 @@
27
27
  "@antv/g6": "^4.8.24",
28
28
  "@babel/runtime": "^7.18.3",
29
29
  "@chaoswise/ace": "^1.4.13",
30
+ "@chaoswise/cssinjs": "^1.0.5",
31
+ "@chaoswise/icons-svg": "^1.0.1",
30
32
  "@chaoswise/utils": "^0.0.35",
31
33
  "@ctrl/tinycolor": "^3.6.1",
32
34
  "@emotion/babel-plugin": "^11.11.0",
@@ -45,6 +47,7 @@
45
47
  "echarts": "^5.4.3",
46
48
  "echarts-for-react": "^3.0.2",
47
49
  "highlight.js": "^9.18.5",
50
+ "moment-timezone": "^0.5.46",
48
51
  "omit.js": "^2.0.2",
49
52
  "qrcode.react": "^3.1.0",
50
53
  "rc-cascader": "~3.27.0",