popup.uvue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <demo-item :label="t('自定义')">
  5. <cl-button @tap="openPopup">{{ t("打开弹窗") }}</cl-button>
  6. <cl-list border class="mt-3">
  7. <view class="w-full p-2">
  8. <cl-tabs
  9. v-model="direction"
  10. :list="directionList"
  11. show-slider
  12. :height="66"
  13. ></cl-tabs>
  14. </view>
  15. <cl-list-item :label="t('设置宽度 80%')">
  16. <cl-switch v-model="isWidth"></cl-switch>
  17. </cl-list-item>
  18. <cl-list-item :label="t('无头')">
  19. <cl-switch v-model="unShowHeader"></cl-switch>
  20. </cl-list-item>
  21. <cl-list-item :label="t('自定义样式')">
  22. <cl-switch v-model="isCustom"></cl-switch>
  23. </cl-list-item>
  24. </cl-list>
  25. </demo-item>
  26. </view>
  27. <cl-popup
  28. v-model="visible"
  29. :title="t('标题')"
  30. :direction="direction"
  31. :size="size"
  32. :show-header="!unShowHeader"
  33. :pt="{
  34. className: parseClass([[isCustom, '!p-3']]),
  35. inner: {
  36. className: parseClass([[isCustom, '!rounded-2xl']])
  37. }
  38. }"
  39. >
  40. <view
  41. class="p-3"
  42. :class="{
  43. 'pt-0': !unShowHeader
  44. }"
  45. >
  46. <cl-image
  47. src="https://unix.cool-js.com/images/demo/bg1.png"
  48. class="mb-3"
  49. height="auto"
  50. width="100%"
  51. mode="widthFix"
  52. ></cl-image>
  53. <cl-text
  54. >春江花月夜, 花草复青青。 江水流不尽, 月光照无情。 夜来风雨急, 愁思满心头。
  55. 何时再相见, 共赏月明楼。
  56. </cl-text>
  57. </view>
  58. </cl-popup>
  59. </cl-page>
  60. </template>
  61. <script lang="ts" setup>
  62. import { t } from "@/locale";
  63. import DemoItem from "../components/item.uvue";
  64. import { computed, ref } from "vue";
  65. import type { ClPopupDirection, ClTabsItem } from "@/uni_modules/cool-ui";
  66. import { parseClass } from "@/cool";
  67. const visible = ref(false);
  68. const isWidth = ref(true);
  69. const unShowHeader = ref(false);
  70. const isCustom = ref(false);
  71. const direction = ref<ClPopupDirection>("bottom");
  72. const directionList = ref<ClTabsItem[]>([
  73. { label: t("底部"), value: "bottom" },
  74. { label: t("顶部"), value: "top" },
  75. { label: t("左侧"), value: "left" },
  76. { label: t("右侧"), value: "right" },
  77. { label: t("中间"), value: "center" }
  78. ]);
  79. const size = computed(() => {
  80. if (direction.value == "left" || direction.value == "right" || direction.value == "center") {
  81. return isWidth.value ? "80%" : "";
  82. }
  83. return "";
  84. });
  85. function openPopup() {
  86. visible.value = true;
  87. }
  88. </script>