c-confirm-success.vue 2.8 KB

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