CustomModal.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <!-- 自定义提示组件 -->
  3. <!-- 根据title,配置提示的文字 -->
  4. <!-- 全局采用ref方式调用打开按钮-->
  5. <view class="custom-modal">
  6. <zwy-popup :ishide="isShow" width="660rpx" height="440rpx" radius="12rpx">
  7. <!-- 自定义展示内容 -->
  8. <view class="content">
  9. <view class="icon">
  10. <image style="width: 100%;height: 100%;" src="/static/images/components/modal/modal.svg" mode="scaleToFill"></image>
  11. </view>
  12. <view class="title">
  13. {{modalInfo.title}}
  14. </view>
  15. </view>
  16. <view class="footer">
  17. <button style="border-radius: 1998rpx;line-height: 60rpx;" type="default" @tap="handleCancel">取消</button>
  18. <button style="border-radius: 1998rpx;line-height: 60rpx;" type="primary" @tap="handleOk">确定</button>
  19. </view>
  20. </zwy-popup>
  21. </view>
  22. </template>
  23. <script setup>
  24. import {
  25. reactive,
  26. ref
  27. } from 'vue';
  28. const isShow = ref(false)
  29. const modalInfo = reactive({
  30. title: '',
  31. onOk: ()=>{},
  32. onCancel: ()=>{
  33. isShow.value = false
  34. }
  35. })
  36. /**
  37. * @description 打开弹窗
  38. * @param option 配置项,可以配置标题、确定\取消事件
  39. * @param option.title 标题
  40. * @param option.onOk 确定事件
  41. * @param option.onCancel 取消事件
  42. */
  43. const showModal = (option) => {
  44. modalInfo.title = option.title;
  45. modalInfo.onOk = option.onOk;
  46. option.onCancel && (modalInfo.onCancel = option.onCancel);
  47. isShow.value = true
  48. }
  49. const hideToast = () => {
  50. isShow.value = false
  51. }
  52. const handleCancel = () => {
  53. modalInfo.onCancel()
  54. isShow.value = false
  55. }
  56. const handleOk = () => {
  57. modalInfo.onOk()
  58. isShow.value = false
  59. }
  60. defineExpose({
  61. showModal
  62. })
  63. </script>
  64. <style lang="scss" scoped>
  65. .custom-modal{
  66. .content{
  67. position: relative;
  68. width: 100%;
  69. height: calc(100% - 76rpx);
  70. display: flex;
  71. justify-content: center;
  72. flex-direction: column;
  73. align-items: center;
  74. .icon{
  75. margin-left: -10rpx;
  76. width: 210rpx;
  77. height: 144rpx;
  78. }
  79. .title{
  80. margin-top: 8rpx;
  81. font-family: Source Han Sans;
  82. font-size: 50rpx;
  83. font-weight: 500;
  84. font-feature-settings: "kern" on;
  85. color: $uni-text-color;
  86. }
  87. }
  88. .footer{
  89. display: flex;
  90. justify-content: space-around;
  91. align-items: center;
  92. }
  93. }
  94. </style>