modal.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <gui-modal :customClass="['gui-bg-white', 'gui-dark-bg-level-3', 'gui-border-radius']" ref="modalForm" :title="modalTitle">
  3. <template v-slot:content>
  4. <view class="gui-padding gui-bg-gray gui-dark-bg-level-2">
  5. <text class="gui-block gui-text-center gui-text gui-color-gray"
  6. style="line-height:100rpx; padding:10rpx;">
  7. {{ modalContent }}
  8. </text>
  9. </view>
  10. </template>
  11. <!-- 利用 flex 布局 可以放置多个自定义按钮哦 -->
  12. <template v-slot:btns>
  13. <view class="gui-flex gui-row gui-space-between operation-flex">
  14. <view hover-class="gui-tap" class="modal-btns gui-flex1" @tap="handleLoginOutCancel">
  15. <text class="modal-btns gui-color-gray">取消</text>
  16. </view>
  17. <view class="line"></view>
  18. <view hover-class="gui-tap" class="modal-btns gui-flex1" @tap="handleLoginOutConfirm">
  19. <text class="modal-btns gui-primary-color">确认</text>
  20. </view>
  21. </view>
  22. </template>
  23. </gui-modal>
  24. </template>
  25. <script>
  26. import {
  27. ref,
  28. defineComponent,
  29. watch,
  30. computed
  31. } from "vue"
  32. export default defineComponent({
  33. name: "modal-component",
  34. props: {
  35. // 模态框状态
  36. modalState: {
  37. type: Boolean,
  38. default: false
  39. },
  40. title: {
  41. type: String,
  42. default: "提示"
  43. },
  44. content: {
  45. type: String,
  46. default: "确定要这么做吗?"
  47. },
  48. // 在列表中的列表索引
  49. clickIndex: {
  50. type: Number,
  51. default: undefined
  52. }
  53. },
  54. setup(props, context) {
  55. const modalForm = ref();
  56. const modalTitle = computed(() => props.title ?? "提示");
  57. const modalContent = computed(() => props.content ?? "确定要这么做吗");
  58. watch(() => props.modalState, (state) => {
  59. if (state) {
  60. modalForm.value.open();
  61. } else {
  62. modalForm.value.close();
  63. }
  64. }, {
  65. deep: true
  66. })
  67. const handleLoginOutCancel = function() {
  68. context.emit("update:modalState", !props.modalState);
  69. context.emit("update:clickIndex", undefined);
  70. modalForm.value.close();
  71. }
  72. const handleLoginOutConfirm = function() {
  73. context.emit("update:modalState", !props.modalState);
  74. context.emit("update:clickIndex", props.clickIndex);
  75. context.emit("complate");
  76. modalForm.value.close();
  77. }
  78. return {
  79. modalForm,
  80. modalTitle,
  81. modalContent,
  82. handleLoginOutConfirm,
  83. handleLoginOutCancel
  84. }
  85. }
  86. })
  87. </script>
  88. <style scoped>
  89. .ucenter-face {
  90. width: 100rpx;
  91. height: 100rpx;
  92. }
  93. .ucenter-face-image {
  94. width: 100rpx;
  95. height: 100rpx;
  96. }
  97. .ucenter-line {
  98. height: 20rpx;
  99. margin: 16rpx 0;
  100. }
  101. .logoff {
  102. line-height: 88rpx;
  103. font-size: 28rpx;
  104. }
  105. .gui-list-title-text {
  106. line-height: 60rpx;
  107. }
  108. .modal-btns {
  109. height: 100rpx;
  110. line-height: 100rpx;
  111. display: flex;
  112. justify-content: center;
  113. align-items: center;
  114. }
  115. .operation-flex {
  116. display: flex;
  117. flex-direction: row;
  118. align-items: center;
  119. }
  120. .line {
  121. height: 80rpx;
  122. width: 1rpx;
  123. background-color: #dcdcdc;
  124. }
  125. </style>