CountDown.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name2 in all)
  7. __defProp(target, name2, { get: all[name2], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. countDownProps: () => countDownProps,
  21. default: () => stdin_default
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_vue2 = require("vue");
  26. var import_utils = require("../utils");
  27. var import_utils2 = require("./utils");
  28. var import_use = require("@vant/use");
  29. var import_use_expose = require("../composables/use-expose");
  30. const [name, bem] = (0, import_utils.createNamespace)("count-down");
  31. const countDownProps = {
  32. time: (0, import_utils.makeNumericProp)(0),
  33. format: (0, import_utils.makeStringProp)("HH:mm:ss"),
  34. autoStart: import_utils.truthProp,
  35. millisecond: Boolean
  36. };
  37. var stdin_default = (0, import_vue2.defineComponent)({
  38. name,
  39. props: countDownProps,
  40. emits: ["change", "finish"],
  41. setup(props, {
  42. emit,
  43. slots
  44. }) {
  45. const {
  46. start,
  47. pause,
  48. reset,
  49. current
  50. } = (0, import_use.useCountDown)({
  51. time: +props.time,
  52. millisecond: props.millisecond,
  53. onChange: (current2) => emit("change", current2),
  54. onFinish: () => emit("finish")
  55. });
  56. const timeText = (0, import_vue2.computed)(() => (0, import_utils2.parseFormat)(props.format, current.value));
  57. const resetTime = () => {
  58. reset(+props.time);
  59. if (props.autoStart) {
  60. start();
  61. }
  62. };
  63. (0, import_vue2.watch)(() => props.time, resetTime, {
  64. immediate: true
  65. });
  66. (0, import_use_expose.useExpose)({
  67. start,
  68. pause,
  69. reset: resetTime
  70. });
  71. return () => (0, import_vue.createVNode)("div", {
  72. "role": "timer",
  73. "class": bem()
  74. }, [slots.default ? slots.default(current.value) : timeText.value]);
  75. }
  76. });