TabsContent.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. default: () => stdin_default
  21. });
  22. module.exports = __toCommonJS(stdin_exports);
  23. var import_vue = require("vue");
  24. var import_vue2 = require("vue");
  25. var import_utils = require("../utils");
  26. var import_swipe = require("../swipe");
  27. var import_use_expose = require("../composables/use-expose");
  28. const [name, bem] = (0, import_utils.createNamespace)("tabs");
  29. var stdin_default = (0, import_vue2.defineComponent)({
  30. name,
  31. props: {
  32. count: (0, import_utils.makeRequiredProp)(Number),
  33. inited: Boolean,
  34. animated: Boolean,
  35. duration: (0, import_utils.makeRequiredProp)(import_utils.numericProp),
  36. swipeable: Boolean,
  37. lazyRender: Boolean,
  38. currentIndex: (0, import_utils.makeRequiredProp)(Number)
  39. },
  40. emits: ["change"],
  41. setup(props, {
  42. emit,
  43. slots
  44. }) {
  45. const swipeRef = (0, import_vue2.ref)();
  46. const onChange = (index) => emit("change", index);
  47. const renderChildren = () => {
  48. var _a;
  49. const Content = (_a = slots.default) == null ? void 0 : _a.call(slots);
  50. if (props.animated || props.swipeable) {
  51. return (0, import_vue.createVNode)(import_swipe.Swipe, {
  52. "ref": swipeRef,
  53. "loop": false,
  54. "class": bem("track"),
  55. "duration": +props.duration * 1e3,
  56. "touchable": props.swipeable,
  57. "lazyRender": props.lazyRender,
  58. "showIndicators": false,
  59. "onChange": onChange
  60. }, {
  61. default: () => [Content]
  62. });
  63. }
  64. return Content;
  65. };
  66. const swipeToCurrentTab = (index) => {
  67. const swipe = swipeRef.value;
  68. if (swipe && swipe.state.active !== index) {
  69. swipe.swipeTo(index, {
  70. immediate: !props.inited
  71. });
  72. }
  73. };
  74. (0, import_vue2.watch)(() => props.currentIndex, swipeToCurrentTab);
  75. (0, import_vue2.onMounted)(() => {
  76. swipeToCurrentTab(props.currentIndex);
  77. });
  78. (0, import_use_expose.useExpose)({
  79. swipeRef
  80. });
  81. return () => (0, import_vue.createVNode)("div", {
  82. "class": bem("content", {
  83. animated: props.animated || props.swipeable
  84. })
  85. }, [renderChildren()]);
  86. }
  87. });