popup.uvue 2.4 KB

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