cu-dialog.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <!--
  2. * @Author: colpu ycg520520@qq.com
  3. * @Date: 2024-07-29 19:04:06
  4. * @LastEditors: colpu ycg520520@qq.com
  5. * @LastEditTime: 2024-07-30 12:40:44
  6. * @FilePath: /xj_project_app_2024_2_18/components/cu-dialog.vue
  7. * @Description:
  8. -->
  9. <template>
  10. <uni-popup
  11. ref="popupDialog"
  12. type="dialog"
  13. @change="onChange"
  14. @maskClick="onClose"
  15. >
  16. <view class="colpu__popup-body" @tap.stop="">
  17. <view class="colpu__popup-title" v-if="title"
  18. >{{ title }}
  19. <view class="colpu__popup-desc" v-if="desc">{{ desc }}</view>
  20. </view>
  21. <uni-icons
  22. type="closeempty"
  23. @click="popupDialog.close"
  24. class="colpu__popup-close"
  25. size="20"
  26. />
  27. <slot></slot>
  28. </view>
  29. </uni-popup>
  30. </template>
  31. <script lang="ts" setup>
  32. import { ref } from "vue";
  33. const popupDialog = ref();
  34. const props = defineProps({
  35. title: {
  36. type: String,
  37. default: "",
  38. },
  39. desc: {
  40. type: String,
  41. default: "",
  42. },
  43. });
  44. const $emit = defineEmits({
  45. close: null,
  46. confirm: null,
  47. });
  48. const onChange = (evt: any) => {
  49. const { show, type } = evt;
  50. console.log("=======>", show, type);
  51. if (show) {
  52. $emit("open", evt);
  53. } else {
  54. $emit("close", evt);
  55. }
  56. };
  57. const onClose = () => {
  58. $emit("close");
  59. };
  60. defineExpose({
  61. open: () => {
  62. console.log("------open");
  63. popupDialog.value.open();
  64. },
  65. close: () => {
  66. popupDialog.value.close();
  67. },
  68. });
  69. </script>
  70. <style lang="scss" scoped>
  71. .colpu__popup-body {
  72. min-width: 640rpx;
  73. width: 90%;
  74. margin: 0 auto;
  75. box-sizing: border-box;
  76. position: relative;
  77. padding: 30rpx 20rpx;
  78. border-radius: 12rpx;
  79. background-color: #fff;
  80. }
  81. .colpu__popup-close {
  82. position: absolute;
  83. width: 40rpx;
  84. height: 40rpx;
  85. top: 24rpx;
  86. right: 20rpx;
  87. }
  88. .colpu__popup-title {
  89. margin: 0 20rpx;
  90. font-size: 36rpx;
  91. line-height: 40rpx;
  92. margin-bottom: 20rpx;
  93. text-align: center;
  94. }
  95. .colpu__popup-desc {
  96. margin: 0 20rpx;
  97. font-size: 28rpx;
  98. line-height: 40rpx;
  99. text-align: center;
  100. color: #999;
  101. }
  102. </style>