@pisell/utils 2.0.1 → 2.0.3
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/constants/index.d.ts +4 -1
- package/es/constants/index.js +6 -1
- package/es/document.js +2 -2
- package/es/escPosPrinter/index.js +2 -2
- package/es/firebase/index.js +34 -13
- package/es/index.js +17 -1
- package/es/jsBridge/index.js +44 -2
- package/es/jsBridge/regDeviceApi.js +6 -10
- package/es/jsBridge/types.js +1 -0
- package/es/locales.js +5 -6
- package/es/log.js +23 -14
- package/es/miniRedux.js +14 -10
- package/es/otherUtils.js +2 -2
- package/es/walletValidity.js +499 -0
- package/lib/constants/index.d.ts +4 -1
- package/lib/constants/index.js +6 -1
- package/lib/escPosPrinter/EscPosPrinter.js +43 -86
- package/lib/escPosPrinter/index.js +2 -2
- package/lib/firebase/index.js +22 -0
- package/lib/image.js +1 -2
- package/lib/index.js +24 -1
- package/lib/jsBridge/index.js +33 -1
- package/lib/jsBridge/regDeviceApi.js +5 -13
- package/lib/jsBridge/types.js +17 -0
- package/lib/locales.js +0 -1
- package/lib/log.js +10 -1
- package/lib/miniRedux.js +5 -7
- package/lib/walletValidity.js +349 -0
- package/package.json +1 -1
- package/es/format.d.ts +0 -28
- package/es/index.d.ts +0 -13
- package/es/jsBridge/index.d.ts +0 -106
- package/es/locales.d.ts +0 -12
- package/es/miniRedux.d.ts +0 -16
- package/lib/format.d.ts +0 -28
- package/lib/index.d.ts +0 -13
- package/lib/jsBridge/index.d.ts +0 -106
- package/lib/locales.d.ts +0 -12
- package/lib/miniRedux.d.ts +0 -16
package/es/miniRedux.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
function _typeof(
|
|
2
|
-
function ownKeys(
|
|
3
|
-
function _objectSpread(
|
|
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
|
+
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
|
+
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
4
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
-
function _toPropertyKey(
|
|
6
|
-
function _toPrimitive(
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
8
|
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."); }
|
|
9
9
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
10
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
-
function _iterableToArrayLimit(
|
|
11
|
+
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
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
import React, { createContext, useCallback, useReducer, forwardRef, useRef } from 'react';
|
|
13
|
+
import React, { createContext, useCallback, useMemo, useReducer, forwardRef, useRef } from 'react';
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
export var miniRedux = function miniRedux(_ref2) {
|
|
16
16
|
var _ref2$namespace = _ref2.namespace,
|
|
@@ -23,7 +23,6 @@ export var miniRedux = function miniRedux(_ref2) {
|
|
|
23
23
|
var Context = /*#__PURE__*/createContext({});
|
|
24
24
|
var Provider = function Provider(ComponentUi) {
|
|
25
25
|
var Components = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
26
|
-
var _objectSpread2, _ref5;
|
|
27
26
|
var stateRef = useRef();
|
|
28
27
|
var _useReducer = useReducer(function (state, _ref3) {
|
|
29
28
|
var type = _ref3.type,
|
|
@@ -50,14 +49,19 @@ export var miniRedux = function miniRedux(_ref2) {
|
|
|
50
49
|
});
|
|
51
50
|
}
|
|
52
51
|
}, []);
|
|
53
|
-
|
|
52
|
+
|
|
53
|
+
// 缓存Context value,避免不必要的重新渲染
|
|
54
|
+
var contextValue = useMemo(function () {
|
|
55
|
+
return _defineProperty(_defineProperty({}, namespace, providerState), "dispatch", _dispatch);
|
|
56
|
+
}, [providerState, _dispatch]);
|
|
57
|
+
var _props = _objectSpread(_objectSpread({}, props), {}, _defineProperty(_defineProperty({}, namespace, providerState), "dispatch", _dispatch));
|
|
54
58
|
var _ref = null;
|
|
55
59
|
if (_props.forwardedRef) {
|
|
56
60
|
_ref = _props.forwardedRef;
|
|
57
61
|
delete _props.forwardedRef;
|
|
58
62
|
}
|
|
59
63
|
return /*#__PURE__*/_jsx(Context.Provider, {
|
|
60
|
-
value:
|
|
64
|
+
value: contextValue,
|
|
61
65
|
children: /*#__PURE__*/_jsx(ComponentUi, _objectSpread(_objectSpread({}, _props), {}, {
|
|
62
66
|
ref: ref
|
|
63
67
|
}))
|
package/es/otherUtils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function _typeof(
|
|
2
|
-
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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
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
|
+
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 new 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 new 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 new 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; }
|
|
3
3
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
4
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
5
|
// @ts-ignore
|
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
|
|
3
|
+
// 文案配置类型定义
|
|
4
|
+
|
|
5
|
+
// 常量定义
|
|
6
|
+
var CONSTANTS = {
|
|
7
|
+
ALL_DAY_START: '00:00',
|
|
8
|
+
ALL_DAY_END: '23:59',
|
|
9
|
+
DEFAULT_FUTURE_YEARS: 10,
|
|
10
|
+
SECONDS_SUFFIX: ':59'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// 日程项接口定义
|
|
14
|
+
|
|
15
|
+
// 多语言文案配置
|
|
16
|
+
var textConfig = {
|
|
17
|
+
'zh-HK': {
|
|
18
|
+
weekdays: ['日', '一', '二', '三', '四', '五', '六'],
|
|
19
|
+
separator: '、',
|
|
20
|
+
timeSeparator: '–',
|
|
21
|
+
rangeSeparator: ' 至 ',
|
|
22
|
+
periodSeparator: ';',
|
|
23
|
+
timeSlotSeparator: ',',
|
|
24
|
+
every: '每',
|
|
25
|
+
day: '天',
|
|
26
|
+
week: '周',
|
|
27
|
+
month: '月',
|
|
28
|
+
year: '年',
|
|
29
|
+
available: '可用',
|
|
30
|
+
unlimited: '无限期',
|
|
31
|
+
multipleRules: '多規則,點詳情',
|
|
32
|
+
multipleSlots: ',多時段',
|
|
33
|
+
until: '至',
|
|
34
|
+
daily: '每天',
|
|
35
|
+
days: '天',
|
|
36
|
+
weeks: '周',
|
|
37
|
+
everyPrefix: '每',
|
|
38
|
+
weekPrefix: '周',
|
|
39
|
+
dateFormat: 'YYYY-MM-DD',
|
|
40
|
+
dateTimeFormat: 'YYYY-MM-DD HH:mm',
|
|
41
|
+
longTermValidFrom: '自',
|
|
42
|
+
noExpiry: '起長期有效',
|
|
43
|
+
on: ''
|
|
44
|
+
},
|
|
45
|
+
'zh-CN': {
|
|
46
|
+
weekdays: ['日', '一', '二', '三', '四', '五', '六'],
|
|
47
|
+
separator: '、',
|
|
48
|
+
timeSeparator: '–',
|
|
49
|
+
rangeSeparator: ' 至 ',
|
|
50
|
+
periodSeparator: ';',
|
|
51
|
+
timeSlotSeparator: ',',
|
|
52
|
+
every: '每',
|
|
53
|
+
day: '天',
|
|
54
|
+
week: '周',
|
|
55
|
+
month: '月',
|
|
56
|
+
year: '年',
|
|
57
|
+
available: '可用',
|
|
58
|
+
unlimited: '无限期',
|
|
59
|
+
multipleRules: '多规则,点详情',
|
|
60
|
+
multipleSlots: ',多时段',
|
|
61
|
+
until: '至',
|
|
62
|
+
daily: '每天',
|
|
63
|
+
days: '天',
|
|
64
|
+
weeks: '周',
|
|
65
|
+
everyPrefix: '每',
|
|
66
|
+
weekPrefix: '周',
|
|
67
|
+
dateFormat: 'YYYY-MM-DD',
|
|
68
|
+
dateTimeFormat: 'YYYY-MM-DD HH:mm',
|
|
69
|
+
longTermValidFrom: '自',
|
|
70
|
+
noExpiry: '起长期有效',
|
|
71
|
+
on: ''
|
|
72
|
+
},
|
|
73
|
+
'en': {
|
|
74
|
+
weekdays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
|
75
|
+
separator: ', ',
|
|
76
|
+
timeSeparator: '–',
|
|
77
|
+
rangeSeparator: ' - ',
|
|
78
|
+
periodSeparator: '; ',
|
|
79
|
+
timeSlotSeparator: ', ',
|
|
80
|
+
every: 'every ',
|
|
81
|
+
day: 'day',
|
|
82
|
+
week: 'week',
|
|
83
|
+
month: 'month',
|
|
84
|
+
year: 'year',
|
|
85
|
+
available: 'available',
|
|
86
|
+
unlimited: 'unlimited',
|
|
87
|
+
multipleRules: 'Multiple rules, see details',
|
|
88
|
+
multipleSlots: ', multiple slots',
|
|
89
|
+
until: 'Until ',
|
|
90
|
+
daily: 'daily',
|
|
91
|
+
days: 'days',
|
|
92
|
+
weeks: 'weeks',
|
|
93
|
+
everyPrefix: 'every ',
|
|
94
|
+
weekPrefix: '',
|
|
95
|
+
dateFormat: 'DD MMM YYYY',
|
|
96
|
+
dateTimeFormat: 'DD MMM YYYY h:mm A',
|
|
97
|
+
longTermValidFrom: 'from ',
|
|
98
|
+
noExpiry: ', no expiry',
|
|
99
|
+
on: 'on '
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 获取星期几的表示
|
|
105
|
+
* @param dayNumbers 星期几的数字数组 (0-6, 0代表周日)
|
|
106
|
+
* @param locale 语言设置
|
|
107
|
+
* @param separator 分隔符,可选,默认使用locale配置的分隔符
|
|
108
|
+
* @returns 格式化的星期几文案
|
|
109
|
+
*/
|
|
110
|
+
function getWeekdayText(dayNumbers, locale, separator) {
|
|
111
|
+
var config = textConfig[locale];
|
|
112
|
+
return dayNumbers.map(function (day) {
|
|
113
|
+
return config.weekdays[day];
|
|
114
|
+
}).join(separator || config.separator);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 获取指定语言的文案配置
|
|
119
|
+
* @param locale 语言设置
|
|
120
|
+
* @param key 配置项key
|
|
121
|
+
* @returns 对应语言的文案
|
|
122
|
+
*/
|
|
123
|
+
function getText(locale, key) {
|
|
124
|
+
return textConfig[locale][key];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 获取指定语言的配置对象(缓存优化)
|
|
129
|
+
* @param locale 语言设置
|
|
130
|
+
* @returns 对应语言的完整配置对象
|
|
131
|
+
*/
|
|
132
|
+
function getConfig(locale) {
|
|
133
|
+
return textConfig[locale];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 获取每日频率文案
|
|
138
|
+
* @param frequency 频率数字
|
|
139
|
+
* @param locale 语言设置
|
|
140
|
+
* @returns 格式化的每日频率文案
|
|
141
|
+
*/
|
|
142
|
+
function getDailyFrequencyText(frequency, locale) {
|
|
143
|
+
if (frequency === 1) {
|
|
144
|
+
return getText(locale, 'daily');
|
|
145
|
+
}
|
|
146
|
+
var config = textConfig[locale];
|
|
147
|
+
if (locale === 'en') {
|
|
148
|
+
return "".concat(config.everyPrefix).concat(frequency, " ").concat(config.days);
|
|
149
|
+
} else {
|
|
150
|
+
return "".concat(config.everyPrefix).concat(frequency).concat(config.days);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 获取每周频率前缀文案
|
|
156
|
+
* @param frequency 频率数字
|
|
157
|
+
* @param locale 语言设置
|
|
158
|
+
* @returns 格式化的每周频率前缀文案
|
|
159
|
+
*/
|
|
160
|
+
function getWeeklyFrequencyPrefix(frequency, locale) {
|
|
161
|
+
if (frequency === 1) {
|
|
162
|
+
return '';
|
|
163
|
+
}
|
|
164
|
+
var config = textConfig[locale];
|
|
165
|
+
if (locale === 'en') {
|
|
166
|
+
return "".concat(config.everyPrefix).concat(frequency, " ").concat(config.weeks, ", ");
|
|
167
|
+
} else {
|
|
168
|
+
return "".concat(config.everyPrefix).concat(frequency).concat(config.weeks, " ");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 格式化日期时间函数
|
|
174
|
+
* @param dateTime 日期时间字符串
|
|
175
|
+
* @param isAll 是否为全天
|
|
176
|
+
* @param locale 语言设置
|
|
177
|
+
* @returns 格式化后的日期时间字符串
|
|
178
|
+
*/
|
|
179
|
+
function formatDateTime(dateTime) {
|
|
180
|
+
var isAll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
181
|
+
var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'zh-CN';
|
|
182
|
+
var date = dayjs(dateTime);
|
|
183
|
+
var config = getConfig(locale);
|
|
184
|
+
if (isAll) {
|
|
185
|
+
// 全天情况下的日期格式
|
|
186
|
+
return date.format(config.dateFormat);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// 非全天情况下的日期时间格式
|
|
190
|
+
return date.format(config.dateTimeFormat);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* 判断是否为全天日程
|
|
195
|
+
* @param startTime 开始时间 (HH:mm格式)
|
|
196
|
+
* @param endTime 结束时间 (HH:mm格式)
|
|
197
|
+
* @returns 是否为全天日程
|
|
198
|
+
*/
|
|
199
|
+
function isAllDaySchedule(startTime, endTime) {
|
|
200
|
+
return startTime === CONSTANTS.ALL_DAY_START && endTime === CONSTANTS.ALL_DAY_END;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 生成日期范围文案
|
|
205
|
+
* @param startDate 开始日期
|
|
206
|
+
* @param endDate 结束日期
|
|
207
|
+
* @param isStarted 是否已开始
|
|
208
|
+
* @param locale 语言设置
|
|
209
|
+
* @param isAllDay 是否为全天
|
|
210
|
+
* @returns 格式化的日期范围文案
|
|
211
|
+
*/
|
|
212
|
+
function formatDateRange(startDate, endDate, isStarted, locale) {
|
|
213
|
+
var isAllDay = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
214
|
+
var config = getConfig(locale);
|
|
215
|
+
if (isStarted) {
|
|
216
|
+
var endDateStr = formatDateTime(endDate, isAllDay, locale);
|
|
217
|
+
return "".concat(config.until).concat(endDateStr);
|
|
218
|
+
} else {
|
|
219
|
+
var startDateStr = formatDateTime(startDate, isAllDay, locale);
|
|
220
|
+
var _endDateStr = formatDateTime(endDate, isAllDay, locale);
|
|
221
|
+
return "".concat(startDateStr).concat(config.rangeSeparator).concat(_endDateStr);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 获取schedule摘要信息
|
|
227
|
+
* @param scheduleList 日程列表
|
|
228
|
+
* @param locale 语言设置
|
|
229
|
+
* @returns 摘要文本
|
|
230
|
+
*/
|
|
231
|
+
export function getScheduleSummary(scheduleList) {
|
|
232
|
+
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'zh-CN';
|
|
233
|
+
try {
|
|
234
|
+
// 输入验证
|
|
235
|
+
if (!scheduleList || !Array.isArray(scheduleList)) {
|
|
236
|
+
return '';
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// 如果是多个日程,直接返回多规则提示
|
|
240
|
+
if (scheduleList.length > 1) {
|
|
241
|
+
return getText(locale, 'multipleRules');
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// 如果没有日程,返回空字符串
|
|
245
|
+
if (scheduleList.length === 0) {
|
|
246
|
+
return '';
|
|
247
|
+
}
|
|
248
|
+
var schedule = scheduleList[0];
|
|
249
|
+
if (!schedule) {
|
|
250
|
+
return '';
|
|
251
|
+
}
|
|
252
|
+
var now = dayjs();
|
|
253
|
+
|
|
254
|
+
// 获取日程开始时间
|
|
255
|
+
var startTime = null;
|
|
256
|
+
if (schedule.start_time) {
|
|
257
|
+
startTime = dayjs(schedule.start_time);
|
|
258
|
+
} else if (schedule.designation && schedule.designation.length > 0) {
|
|
259
|
+
// designation类型,取第一个日期作为开始时间
|
|
260
|
+
var firstDesignation = schedule.designation[0];
|
|
261
|
+
if (firstDesignation && firstDesignation.start_date && firstDesignation.start_time) {
|
|
262
|
+
startTime = dayjs("".concat(firstDesignation.start_date, " ").concat(firstDesignation.start_time));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// 判断开始时间是否在当前时间之后
|
|
267
|
+
var isStarted = startTime ? isTimeStarted(now, startTime) : false;
|
|
268
|
+
|
|
269
|
+
// 根据不同类型和状态返回摘要
|
|
270
|
+
return generateSummaryText(schedule, isStarted, locale);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
console.warn('Error in getScheduleSummary:', error);
|
|
273
|
+
return '';
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* 判断开始时间是否在当前时间之后
|
|
279
|
+
* @param now 当前时间
|
|
280
|
+
* @param startTime 开始时间
|
|
281
|
+
* @returns 是否已开始
|
|
282
|
+
*/
|
|
283
|
+
function isTimeStarted(now, startTime) {
|
|
284
|
+
return startTime.isBefore(now);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 生成摘要文本
|
|
289
|
+
* @param schedule 日程对象
|
|
290
|
+
* @param isStarted 是否已开始
|
|
291
|
+
* @param locale 语言设置
|
|
292
|
+
* @returns 生成的摘要文本
|
|
293
|
+
*/
|
|
294
|
+
function generateSummaryText(schedule, isStarted, locale) {
|
|
295
|
+
// 1. 多天多段 (designation类型且有多个日期段)
|
|
296
|
+
if (schedule.type === 'designation' && schedule.designation && schedule.designation.length > 1) {
|
|
297
|
+
return getText(locale, 'multipleRules');
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// 2. 单日多段 (time-slots类型)
|
|
301
|
+
if (schedule.type === 'time-slots') {
|
|
302
|
+
var endDate = getScheduleEndDate(schedule);
|
|
303
|
+
if (!endDate) return '';
|
|
304
|
+
var endDateStr = formatDateTime(endDate, true, locale);
|
|
305
|
+
var prefix = '';
|
|
306
|
+
var suffix = getText(locale, 'multipleSlots');
|
|
307
|
+
return "".concat(prefix).concat(endDateStr).concat(suffix);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// 3. 循环日程
|
|
311
|
+
if (schedule.repeat_type !== 'none' && schedule.repeat_rule) {
|
|
312
|
+
return generateRecurringSummary(schedule, isStarted, locale);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// 4. 单个日程(包括designation类型的单个日期段)
|
|
316
|
+
return generateSingleScheduleSummary(schedule, isStarted, locale);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 生成循环日程摘要
|
|
321
|
+
* @param schedule 日程对象
|
|
322
|
+
* @param isStarted 是否已开始
|
|
323
|
+
* @param locale 语言设置
|
|
324
|
+
* @returns 循环日程摘要文本
|
|
325
|
+
*/
|
|
326
|
+
function generateRecurringSummary(schedule, isStarted, locale) {
|
|
327
|
+
var repeat_type = schedule.repeat_type,
|
|
328
|
+
repeat_rule = schedule.repeat_rule;
|
|
329
|
+
if (!repeat_rule) return '';
|
|
330
|
+
var frequency = repeat_rule.frequency,
|
|
331
|
+
frequency_date = repeat_rule.frequency_date,
|
|
332
|
+
end = repeat_rule.end;
|
|
333
|
+
|
|
334
|
+
// 特殊处理:当 end.type === 'never' 时的格式
|
|
335
|
+
if (end.type === 'never') {
|
|
336
|
+
return generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeat_type, frequency, frequency_date);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// 原有逻辑:有结束时间的循环日程
|
|
340
|
+
var endDate = getScheduleEndDate(schedule);
|
|
341
|
+
if (!endDate) return '';
|
|
342
|
+
var endDateStr = formatDateTime(endDate, true, locale);
|
|
343
|
+
|
|
344
|
+
// 按天循环
|
|
345
|
+
if (repeat_type === 'daily') {
|
|
346
|
+
var frequencyText = getDailyFrequencyText(frequency, locale);
|
|
347
|
+
var dateRange = formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
|
|
348
|
+
return "".concat(dateRange, "\uFF0C").concat(frequencyText);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// 按周循环
|
|
352
|
+
if (repeat_type === 'weekly') {
|
|
353
|
+
var weekdaysText = getWeekdayText(frequency_date, locale, '/');
|
|
354
|
+
var frequencyPrefix = getWeeklyFrequencyPrefix(frequency, locale);
|
|
355
|
+
var config = getConfig(locale);
|
|
356
|
+
var _dateRange = formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
|
|
357
|
+
return "".concat(_dateRange, "\uFF0C").concat(frequencyPrefix).concat(config.weekPrefix).concat(weekdaysText);
|
|
358
|
+
}
|
|
359
|
+
return '';
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* 生成永不结束的循环日程摘要
|
|
364
|
+
* @param schedule 日程对象
|
|
365
|
+
* @param isStarted 是否已开始
|
|
366
|
+
* @param locale 语言设置
|
|
367
|
+
* @param repeatType 循环类型
|
|
368
|
+
* @param frequency 频率
|
|
369
|
+
* @param frequencyDate 频率日期数组(用于周循环)
|
|
370
|
+
* @returns 永不结束的循环日程摘要文本
|
|
371
|
+
*/
|
|
372
|
+
function generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeatType, frequency, frequencyDate) {
|
|
373
|
+
var config = getConfig(locale);
|
|
374
|
+
|
|
375
|
+
// 按天循环
|
|
376
|
+
if (repeatType === 'daily') {
|
|
377
|
+
if (frequency === 1) {
|
|
378
|
+
// 频率=1:中文"自 YYYY-MM-DD 起长期有效",英文"Valid from DD MMM YYYY, no expiry"
|
|
379
|
+
if (schedule.start_time) {
|
|
380
|
+
var startDateStr = formatDateTime(schedule.start_time, true, locale);
|
|
381
|
+
return "".concat(config.longTermValidFrom).concat(startDateStr).concat(config.noExpiry);
|
|
382
|
+
}
|
|
383
|
+
return '';
|
|
384
|
+
} else {
|
|
385
|
+
// 频率>1:中文"每2天可用",英文"Every 2 days"
|
|
386
|
+
var frequencyText = getDailyFrequencyText(frequency, locale);
|
|
387
|
+
if (locale === 'en') {
|
|
388
|
+
return "".concat(frequencyText);
|
|
389
|
+
} else {
|
|
390
|
+
return "".concat(frequencyText).concat(config.available);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// 按周循环
|
|
396
|
+
if (repeatType === 'weekly') {
|
|
397
|
+
var weekdaysText = getWeekdayText(frequencyDate, locale, locale === 'en' ? ' & ' : '/');
|
|
398
|
+
if (frequency === 1) {
|
|
399
|
+
// 频率=1:中文"每周三/五可用",英文"on Wed & Fri"
|
|
400
|
+
if (locale === 'en') {
|
|
401
|
+
return "".concat(config.on).concat(weekdaysText);
|
|
402
|
+
} else {
|
|
403
|
+
return "".concat(config.everyPrefix).concat(config.weekPrefix).concat(weekdaysText).concat(config.available);
|
|
404
|
+
}
|
|
405
|
+
} else {
|
|
406
|
+
// 频率>1:中文"每2周 周三/五",英文"Every 2 weeks, on Wed & Fri"
|
|
407
|
+
var frequencyPrefix = getWeeklyFrequencyPrefix(frequency, locale);
|
|
408
|
+
if (locale === 'en') {
|
|
409
|
+
return "".concat(frequencyPrefix).concat(config.on).concat(weekdaysText);
|
|
410
|
+
} else {
|
|
411
|
+
return "".concat(frequencyPrefix).concat(config.weekPrefix).concat(weekdaysText);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return '';
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* 生成单个日程摘要
|
|
420
|
+
* @param schedule 日程对象
|
|
421
|
+
* @param isStarted 是否已开始
|
|
422
|
+
* @param locale 语言设置
|
|
423
|
+
* @returns 单个日程摘要文本
|
|
424
|
+
*/
|
|
425
|
+
function generateSingleScheduleSummary(schedule, isStarted, locale) {
|
|
426
|
+
var isAllDay = schedule.is_all === 1;
|
|
427
|
+
|
|
428
|
+
// 处理designation类型的单个日期段
|
|
429
|
+
if (schedule.type === 'designation' && schedule.designation && schedule.designation.length === 1) {
|
|
430
|
+
var designation = schedule.designation[0];
|
|
431
|
+
var startDate = designation.start_date;
|
|
432
|
+
var endDate = designation.end_date;
|
|
433
|
+
var startTime = designation.start_time;
|
|
434
|
+
var endTime = designation.end_time;
|
|
435
|
+
|
|
436
|
+
// 判断是否为全天
|
|
437
|
+
var isDesignationAllDay = isAllDaySchedule(startTime, endTime);
|
|
438
|
+
if (isDesignationAllDay || isAllDay) {
|
|
439
|
+
// 全天日程
|
|
440
|
+
return formatDateRange(startDate, endDate, isStarted, locale, true);
|
|
441
|
+
} else {
|
|
442
|
+
// 非全天日程
|
|
443
|
+
var startDateTime = "".concat(startDate, " ").concat(startTime).concat(CONSTANTS.SECONDS_SUFFIX);
|
|
444
|
+
var endDateTime = "".concat(endDate, " ").concat(endTime).concat(CONSTANTS.SECONDS_SUFFIX);
|
|
445
|
+
return formatDateRange(startDateTime, endDateTime, isStarted, locale, false);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// 标准日程处理
|
|
450
|
+
if (isAllDay) {
|
|
451
|
+
// 全天日程
|
|
452
|
+
var _endDate = getScheduleEndDate(schedule);
|
|
453
|
+
if (!_endDate) return '';
|
|
454
|
+
return formatDateRange(schedule.start_time, _endDate, isStarted, locale, true);
|
|
455
|
+
} else {
|
|
456
|
+
// 非全天日程
|
|
457
|
+
return formatDateRange(schedule.start_time, schedule.end_time, isStarted, locale, false);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* 获取日程结束日期
|
|
463
|
+
* @param schedule 日程对象
|
|
464
|
+
* @returns 结束日期字符串,如果无法确定则返回null
|
|
465
|
+
*/
|
|
466
|
+
function getScheduleEndDate(schedule) {
|
|
467
|
+
try {
|
|
468
|
+
// 循环日程
|
|
469
|
+
if (schedule.repeat_rule) {
|
|
470
|
+
if (schedule.repeat_rule.end.type === 'never') {
|
|
471
|
+
// 无限期的情况,返回一个合理的未来日期作为显示
|
|
472
|
+
var futureDate = dayjs().add(CONSTANTS.DEFAULT_FUTURE_YEARS, 'year');
|
|
473
|
+
return "".concat(futureDate.format('YYYY-MM-DD'), " ").concat(CONSTANTS.ALL_DAY_END).concat(CONSTANTS.SECONDS_SUFFIX);
|
|
474
|
+
} else if (schedule.repeat_rule.end.end_date) {
|
|
475
|
+
return "".concat(schedule.repeat_rule.end.end_date, " ").concat(CONSTANTS.ALL_DAY_END).concat(CONSTANTS.SECONDS_SUFFIX);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// designation类型
|
|
480
|
+
if (schedule.designation && schedule.designation.length > 0) {
|
|
481
|
+
var lastDesignation = schedule.designation[schedule.designation.length - 1];
|
|
482
|
+
return "".concat(lastDesignation.end_date, " ").concat(lastDesignation.end_time).concat(CONSTANTS.SECONDS_SUFFIX);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// 标准日程
|
|
486
|
+
if (schedule.end_time) {
|
|
487
|
+
return schedule.end_time;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// time-slots类型
|
|
491
|
+
if (schedule.start_time) {
|
|
492
|
+
return schedule.start_time;
|
|
493
|
+
}
|
|
494
|
+
return null;
|
|
495
|
+
} catch (error) {
|
|
496
|
+
console.warn('Error in getScheduleEndDate:', error);
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
}
|
package/lib/constants/index.d.ts
CHANGED
package/lib/constants/index.js
CHANGED
|
@@ -23,7 +23,12 @@ __export(constants_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(constants_exports);
|
|
25
25
|
var webHookApi = {
|
|
26
|
-
warning_log:
|
|
26
|
+
warning_log: {
|
|
27
|
+
// 非生产环境共用一个url
|
|
28
|
+
test: "https://open.feishu.cn/open-apis/bot/v2/hook/985186a7-d939-4daf-9f30-3a3cc9c47d97",
|
|
29
|
+
// 生产环境
|
|
30
|
+
prod: "https://open.feishu.cn/open-apis/bot/v2/hook/887dfff9-2ccc-4513-87ff-a05d8cef953e"
|
|
31
|
+
}
|
|
27
32
|
};
|
|
28
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
34
|
0 && (module.exports = {
|