popup.uvue 2.3 KB

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