CountDown.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_utils = require("../utils");
  26. var import_utils2 = require("./utils");
  27. var import_use = require("@vant/use");
  28. var import_use_expose = require("../composables/use-expose");
  29. const [name, bem] = (0, import_utils.createNamespace)("count-down");
  30. const countDownProps = {
  31. time: (0, import_utils.makeNumericProp)(0),
  32. format: (0, import_utils.makeStringProp)("HH:mm:ss"),
  33. autoStart: import_utils.truthProp,
  34. millisecond: Boolean
  35. };
  36. var stdin_default = (0, import_vue.defineComponent)({
  37. name,
  38. props: countDownProps,
  39. emits: ["change", "finish"],
  40. setup(props, {
  41. emit,
  42. slots
  43. }) {
  44. const {
  45. start,
  46. pause,
  47. reset,
  48. current
  49. } = (0, import_use.useCountDown)({
  50. time: +props.time,
  51. millisecond: props.millisecond,
  52. onChange: (current2) => emit("change", current2),
  53. onFinish: () => emit("finish")
  54. });
  55. const timeText = (0, import_vue.computed)(() => (0, import_utils2.parseFormat)(props.format, current.value));
  56. const resetTime = () => {
  57. reset(+props.time);
  58. if (props.autoStart) {
  59. start();
  60. }
  61. };
  62. (0, import_vue.watch)(() => props.time, resetTime, {
  63. immediate: true
  64. });
  65. (0, import_use_expose.useExpose)({
  66. start,
  67. pause,
  68. reset: resetTime
  69. });
  70. return () => (0, import_vue.createVNode)("div", {
  71. "role": "timer",
  72. "class": bem()
  73. }, [slots.default ? slots.default(current.value) : timeText.value]);
  74. }
  75. });