c-confirm.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="mask" :class="maskState===0 ? 'none' : maskState===1 ? 'show' : ''" >
  3. <view class="mask-content" @click.stop.prevent="stopPrevent">
  4. <view class="icon-wrap" @click.stop="toggleMask('none')">
  5. <u-icon name="/static/app/close.png" size="45rpx"></u-icon>
  6. </view>
  7. <view class="title" v-if="defautlOptions.title" v-html="defautlOptions.title"></view>
  8. <view class="desc" v-if="defautlOptions.content" v-html="defautlOptions.content"></view>
  9. <view class="action-content">
  10. <u-button type="primary"
  11. style="margin-bottom: 30rpx;"
  12. shape="circle"
  13. class="c-button"
  14. :text="defautlOptions.confirmText"
  15. @click="confirm">
  16. </u-button>
  17. <u-button type="primary"
  18. style="margin-bottom: 30rpx;"
  19. v-if="defautlOptions.cancelText"
  20. shape="circle"
  21. class="c-button"
  22. plain
  23. :text="defautlOptions.cancelText"
  24. @click="cancel">
  25. </u-button>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. name:"c-confrim",
  33. data() {
  34. return {
  35. maskState: 0,
  36. defautlOptions: {
  37. title: '',
  38. content: '',
  39. confirmText: '确认',
  40. confirmClass: 'text-red',
  41. cancelText: '我在想想',
  42. cancelClass: 'text-black'
  43. }
  44. };
  45. },
  46. methods: {
  47. stopPrevent(){
  48. },
  49. toggleMask(type){
  50. let timer = type === 'show' ? 10 : 0;
  51. let state = type === 'show' ? 1 : 0;
  52. this.maskState = 2;
  53. setTimeout(()=>{
  54. this.maskState = state;
  55. }, timer)
  56. },
  57. /**
  58. * @description 确认
  59. * @param {Object} title: String desc: String
  60. */
  61. $confirm(options = {}){
  62. // 继承原来的
  63. this.defautlOptions = Object.assign(this.defautlOptions, options);
  64. return new Promise((resolve,reject)=> {
  65. this.toggleMask('show')
  66. this._confirm = () => {
  67. resolve(1)
  68. this._confirm = null;
  69. }
  70. this._cancel = () => {
  71. resolve(0)
  72. this._cancel = null;
  73. }
  74. })
  75. },
  76. confirm() {
  77. if(this._confirm){
  78. this._confirm()
  79. this.toggleMask();
  80. }
  81. },
  82. cancel() {
  83. if(this._cancel){
  84. this._cancel()
  85. this.toggleMask();
  86. }
  87. }
  88. },
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. .mask{
  93. display: flex;
  94. align-items: center;
  95. justify-content: center;
  96. position: fixed;
  97. left: 0;
  98. top: var(--window-top);
  99. bottom: 0;
  100. width: 100vw;
  101. background: rgba(0,0,0,0);
  102. z-index: 10001;
  103. transition: .6s;
  104. .mask-content{
  105. padding-top: 60rpx;
  106. display: flex;
  107. flex-direction: column;
  108. width: 590rpx;
  109. background: #fff;
  110. border-radius: 15px;
  111. transition: transform .1s opacity 0.1s;
  112. transform: scale(1.2);
  113. transition-timing-function: ease-out;
  114. opacity: 0.3;
  115. }
  116. &.none{
  117. display: none;
  118. }
  119. &.show{
  120. background: rgba(0,0,0,.4);
  121. .mask-content{
  122. transition: transform .3s;
  123. opacity: 1;
  124. transform: scale(1);
  125. }
  126. }
  127. .title{
  128. display: flex;
  129. justify-content: center;
  130. align-items: center;
  131. height: 128rpx;
  132. font-size: 31rpx;
  133. font-weight: 400;
  134. color: #000;
  135. }
  136. .desc {
  137. padding: 0 48rpx 40rpx;
  138. font-size: 26rpx;
  139. font-family: PingFang SC;
  140. font-weight: 400;
  141. color: #333333;
  142. line-height: 40rpx;
  143. text-indent: 2em;
  144. }
  145. .action-content{
  146. padding: 0 40rpx;
  147. }
  148. }
  149. .icon-wrap{
  150. position: absolute;
  151. top: -60rpx;
  152. right: -5rpx;
  153. }
  154. </style>