ly-modal.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view class="modal-box">
  3. <uv-modal
  4. ref="modelBox"
  5. :align="pd.align"
  6. :asyncClose="pd.asyncClose"
  7. :buttonReverse="pd.buttonReverse"
  8. :cancelColor="pd.cancelColor"
  9. :cancelText="pd.cancelText"
  10. :closeOnClickOverlay="pd.closeOnClickOverlay"
  11. :confirmColor="pd.confirmColor"
  12. :confirmText="pd.confirmText"
  13. :content="pd.content"
  14. :negativeTop="pd.negativeTop"
  15. :showCancelButton="pd.showCancelButton"
  16. :showConfirmButton="pd.showConfirmButton"
  17. :textStyle="pd.textStyle"
  18. :title="pd.title"
  19. :width="pd.width"
  20. :zIndex="pd.zIndex"
  21. :zoom="pd.zoom"
  22. @cancel="cancel"
  23. @close="closeHandle"
  24. @confirm="confirm">
  25. <view v-if='pd.slotData && pd.slotData.open == true'>
  26. <uv-input v-if="pd.slotData.type == 'input'"
  27. v-model="commitData.input"
  28. :customStyle="{height:pd.slotData.height || '40rpx',width:pd.slotData.width || '200rpx'}"
  29. :inputAlign="pd.slotData.textAlign || 'left'"
  30. :type="pd.slotData.inputType || 'text'"
  31. >
  32. <template v-if="pd.slotData.openend" slot="suffix">
  33. <text>{{ pd.slotData.endTxt }}</text>
  34. </template>
  35. </uv-input>
  36. <view v-if="pd.slotData.type == 'text'">{{ pd.content }}</view>
  37. <slot v-if="pd.slotData.type == 'slot'"></slot>
  38. </view>
  39. <slot/>
  40. </uv-modal>
  41. </view>
  42. </template>
  43. <script setup>
  44. import {reactive, ref} from "vue";
  45. import {sleep} from "@/utils/util";
  46. const defaultData = {
  47. title: '',
  48. content: '',
  49. confirmText: '确认',
  50. cancelText: '取消',
  51. showConfirmButton: true,
  52. showCancelButton: false,
  53. confirmColor: '#2979ff',
  54. cancelColor: '#606266',
  55. buttonReverse: false,
  56. zoom: true,
  57. asyncClose: false,
  58. closeOnClickOverlay: true,
  59. negativeTop: 0,
  60. width: '650rpx',
  61. zIndex: 10075,
  62. align: 'left',
  63. textStyle: {},
  64. cancel: null,
  65. close: null,
  66. confirm: null,
  67. /**
  68. * slotData:{
  69. * open Boolean 是否打开插槽
  70. * type String 插槽属性 { input , text , slot}
  71. * type:input {
  72. * openend Boolean 打开input的后插槽
  73. * endTxt String 后插槽文字
  74. * width String input宽度
  75. * height String input高度
  76. * textAlign String 输入框文字排版 center left right
  77. * }
  78. * }
  79. * **/
  80. slotData: {},
  81. }
  82. const show = ref(false)
  83. const modelBox = ref()
  84. let pd = reactive({...defaultData})
  85. const open = async (row) => {
  86. if (show.value) {
  87. close()
  88. await sleep(100)
  89. }
  90. for (const key in pd) {
  91. if (defaultData.hasOwnProperty(key)) {
  92. pd[key] = defaultData[key];
  93. } else {
  94. delete pd[key];
  95. }
  96. }
  97. // 应用新的row值到pd
  98. for (const key in row) {
  99. pd[key] = row[key];
  100. }
  101. modelBox.value.open()
  102. show.value = true
  103. }
  104. const closeHandle = () => {
  105. console.log('closeHandle')
  106. }
  107. const close = () => {
  108. console.log('close')
  109. // modelBox.value.close()
  110. show.value = false
  111. }
  112. const cancel = () => {
  113. console.log('cancel')
  114. if (pd.cancel) pd.cancel()
  115. }
  116. const confirm = () => {
  117. console.log('confirm')
  118. if (pd.confirm) pd.confirm()
  119. }
  120. defineExpose({
  121. open,
  122. close,
  123. cancel,
  124. confirm,
  125. })
  126. </script>
  127. <style lang="less" scoped>
  128. </style>