index16.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. import { g as j, m as M, d as p, r as O, u as A, _ as y, i as N, bo as U, dZ as $, f as B, bn as P, bq as _, o as L } from "./index2.js";
  2. import { createVNode as m, defineComponent as R, ref as D, onMounted as V, onUpdated as X, onBeforeUnmount as q } from "vue";
  3. import { S as Y } from "./index18.js";
  4. const z = (t) => {
  5. const {
  6. value: n,
  7. formatter: e,
  8. precision: a,
  9. decimalSeparator: s,
  10. groupSeparator: u = "",
  11. prefixCls: r
  12. } = t;
  13. let c;
  14. if (typeof e == "function")
  15. c = e({
  16. value: n
  17. });
  18. else {
  19. const i = String(n), f = i.match(/^(-?)(\d*)(\.(\d+))?$/);
  20. if (!f)
  21. c = i;
  22. else {
  23. const d = f[1];
  24. let o = f[2] || "0", l = f[4] || "";
  25. o = o.replace(/\B(?=(\d{3})+(?!\d))/g, u), typeof a == "number" && (l = l.padEnd(a, "0").slice(0, a > 0 ? a : 0)), l && (l = `${s}${l}`), c = [m("span", {
  26. key: "int",
  27. class: `${r}-content-value-int`
  28. }, [d, o]), l && m("span", {
  29. key: "decimal",
  30. class: `${r}-content-value-decimal`
  31. }, [l])];
  32. }
  33. }
  34. return m("span", {
  35. class: `${r}-content-value`
  36. }, [c]);
  37. };
  38. z.displayName = "StatisticNumber";
  39. const Z = (t) => {
  40. const {
  41. componentCls: n,
  42. marginXXS: e,
  43. padding: a,
  44. colorTextDescription: s,
  45. statisticTitleFontSize: u,
  46. colorTextHeading: r,
  47. statisticContentFontSize: c,
  48. statisticFontFamily: i
  49. } = t;
  50. return {
  51. [`${n}`]: p(p({}, O(t)), {
  52. [`${n}-title`]: {
  53. marginBottom: e,
  54. color: s,
  55. fontSize: u
  56. },
  57. [`${n}-skeleton`]: {
  58. paddingTop: a
  59. },
  60. [`${n}-content`]: {
  61. color: r,
  62. fontSize: c,
  63. fontFamily: i,
  64. [`${n}-content-value`]: {
  65. display: "inline-block",
  66. direction: "ltr"
  67. },
  68. [`${n}-content-prefix, ${n}-content-suffix`]: {
  69. display: "inline-block"
  70. },
  71. [`${n}-content-prefix`]: {
  72. marginInlineEnd: e
  73. },
  74. [`${n}-content-suffix`]: {
  75. marginInlineStart: e
  76. }
  77. }
  78. })
  79. };
  80. }, G = j("Statistic", (t) => {
  81. const {
  82. fontSizeHeading3: n,
  83. fontSize: e,
  84. fontFamily: a
  85. } = t, s = M(t, {
  86. statisticTitleFontSize: e,
  87. statisticContentFontSize: n,
  88. statisticFontFamily: a
  89. });
  90. return [Z(s)];
  91. }), E = () => ({
  92. prefixCls: String,
  93. decimalSeparator: String,
  94. groupSeparator: String,
  95. format: String,
  96. value: _([Number, String, Object]),
  97. valueStyle: {
  98. type: Object,
  99. default: void 0
  100. },
  101. valueRender: P(),
  102. formatter: B(),
  103. precision: Number,
  104. prefix: $(),
  105. suffix: $(),
  106. title: $(),
  107. loading: U()
  108. }), v = R({
  109. compatConfig: {
  110. MODE: 3
  111. },
  112. name: "AStatistic",
  113. inheritAttrs: !1,
  114. props: N(E(), {
  115. decimalSeparator: ".",
  116. groupSeparator: ",",
  117. loading: !1
  118. }),
  119. slots: Object,
  120. setup(t, n) {
  121. let {
  122. slots: e,
  123. attrs: a
  124. } = n;
  125. const {
  126. prefixCls: s,
  127. direction: u
  128. } = A("statistic", t), [r, c] = G(s);
  129. return () => {
  130. var i, f, d, o, l, g, S;
  131. const {
  132. value: H = 0,
  133. valueStyle: I,
  134. valueRender: T
  135. } = t, x = s.value, b = (i = t.title) !== null && i !== void 0 ? i : (f = e.title) === null || f === void 0 ? void 0 : f.call(e), h = (d = t.prefix) !== null && d !== void 0 ? d : (o = e.prefix) === null || o === void 0 ? void 0 : o.call(e), F = (l = t.suffix) !== null && l !== void 0 ? l : (g = e.suffix) === null || g === void 0 ? void 0 : g.call(e), k = (S = t.formatter) !== null && S !== void 0 ? S : e.formatter;
  136. let C = m(z, y({
  137. "data-for-update": Date.now()
  138. }, p(p({}, t), {
  139. prefixCls: x,
  140. value: H,
  141. formatter: k
  142. })), null);
  143. return T && (C = T(C)), r(m("div", y(y({}, a), {}, {
  144. class: [x, {
  145. [`${x}-rtl`]: u.value === "rtl"
  146. }, a.class, c.value]
  147. }), [b && m("div", {
  148. class: `${x}-title`
  149. }, [b]), m(Y, {
  150. paragraph: !1,
  151. loading: t.loading
  152. }, {
  153. default: () => [m("div", {
  154. style: I,
  155. class: `${x}-content`
  156. }, [h && m("span", {
  157. class: `${x}-content-prefix`
  158. }, [h]), C, F && m("span", {
  159. class: `${x}-content-suffix`
  160. }, [F])])]
  161. })]));
  162. };
  163. }
  164. }), J = [
  165. ["Y", 1e3 * 60 * 60 * 24 * 365],
  166. ["M", 1e3 * 60 * 60 * 24 * 30],
  167. ["D", 1e3 * 60 * 60 * 24],
  168. ["H", 1e3 * 60 * 60],
  169. ["m", 1e3 * 60],
  170. ["s", 1e3],
  171. ["S", 1]
  172. // million seconds
  173. ];
  174. function K(t, n) {
  175. let e = t;
  176. const a = /\[[^\]]*]/g, s = (n.match(a) || []).map((i) => i.slice(1, -1)), u = n.replace(a, "[]"), r = J.reduce((i, f) => {
  177. let [d, o] = f;
  178. if (i.includes(d)) {
  179. const l = Math.floor(e / o);
  180. return e -= l * o, i.replace(new RegExp(`${d}+`, "g"), (g) => {
  181. const S = g.length;
  182. return l.toString().padStart(S, "0");
  183. });
  184. }
  185. return i;
  186. }, u);
  187. let c = 0;
  188. return r.replace(a, () => {
  189. const i = s[c];
  190. return c += 1, i;
  191. });
  192. }
  193. function Q(t, n) {
  194. const {
  195. format: e = ""
  196. } = n, a = new Date(t).getTime(), s = Date.now(), u = Math.max(a - s, 0);
  197. return K(u, e);
  198. }
  199. const W = 1e3 / 30;
  200. function w(t) {
  201. return new Date(t).getTime();
  202. }
  203. const tt = () => p(p({}, E()), {
  204. value: _([Number, String, Object]),
  205. format: String,
  206. onFinish: Function,
  207. onChange: Function
  208. }), et = R({
  209. compatConfig: {
  210. MODE: 3
  211. },
  212. name: "AStatisticCountdown",
  213. props: N(tt(), {
  214. format: "HH:mm:ss"
  215. }),
  216. // emits: ['finish', 'change'],
  217. setup(t, n) {
  218. let {
  219. emit: e,
  220. slots: a
  221. } = n;
  222. const s = D(), u = D(), r = () => {
  223. const {
  224. value: o
  225. } = t;
  226. w(o) >= Date.now() ? c() : i();
  227. }, c = () => {
  228. if (s.value) return;
  229. const o = w(t.value);
  230. s.value = setInterval(() => {
  231. u.value.$forceUpdate(), o > Date.now() && e("change", o - Date.now()), r();
  232. }, W);
  233. }, i = () => {
  234. const {
  235. value: o
  236. } = t;
  237. s.value && (clearInterval(s.value), s.value = void 0, w(o) < Date.now() && e("finish"));
  238. }, f = (o) => {
  239. let {
  240. value: l,
  241. config: g
  242. } = o;
  243. const {
  244. format: S
  245. } = t;
  246. return Q(l, p(p({}, g), {
  247. format: S
  248. }));
  249. }, d = (o) => o;
  250. return V(() => {
  251. r();
  252. }), X(() => {
  253. r();
  254. }), q(() => {
  255. i();
  256. }), () => {
  257. const o = t.value;
  258. return m(v, y({
  259. ref: u
  260. }, p(p({}, L(t, ["onFinish", "onChange"])), {
  261. value: o,
  262. valueRender: d,
  263. formatter: f
  264. })), a);
  265. };
  266. }
  267. });
  268. v.Countdown = et;
  269. v.install = function(t) {
  270. return t.component(v.name, v), t.component(v.Countdown.name, v.Countdown), t;
  271. };
  272. const it = v.Countdown;
  273. export {
  274. it as S
  275. };