CustomModal.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. defineExpose
  28. } from 'vue';
  29. const isShow = ref(false)
  30. const modalInfo = reactive({
  31. title: '',
  32. onOk: ()=>{},
  33. onCancel: ()=>{}
  34. })
  35. /**
  36. * @description 打开弹窗
  37. * @param option 配置项,可以配置标题、确定\取消事件
  38. * @param option.title 标题
  39. * @param option.onOk 确定事件
  40. * @param option.onCancel 取消事件
  41. */
  42. const showModal = (option) => {
  43. modalInfo.title = option.title;
  44. modalInfo.onOk = option.onOk;
  45. modalInfo.onCancel = option.onCancel;
  46. isShow.value = true
  47. }
  48. const hideToast = () => {
  49. isShow.value = false
  50. }
  51. const handleCancel = () => {
  52. modalInfo.onCancel()
  53. isShow.value = false
  54. }
  55. const handleOk = () => {
  56. modalInfo.onOk()
  57. isShow.value = false
  58. }
  59. defineExpose({
  60. showModal
  61. })
  62. </script>
  63. <style lang="scss" scoped>
  64. .custom-modal{
  65. .content{
  66. position: relative;
  67. width: 100%;
  68. height: 100%;
  69. display: flex;
  70. justify-content: center;
  71. flex-direction: column;
  72. align-items: center;
  73. .icon{
  74. margin-left: -10rpx;
  75. width: 210rpx;
  76. height: 144rpx;
  77. }
  78. .title{
  79. margin-top: 8rpx;
  80. font-family: Source Han Sans;
  81. font-size: 50rpx;
  82. font-weight: 500;
  83. font-feature-settings: "kern" on;
  84. color: $uni-text-color;
  85. }
  86. }
  87. .footer{
  88. display: flex;
  89. justify-content: space-around;
  90. align-items: center;
  91. }
  92. }
  93. </style>