ShaerPopup.vue 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <div v-if="showSelf" class="dialog" :style="{'z-index': zIndex}">
  3. <div class="dialog-mark" @click="closeMyself" :style="{'z-index': zIndex + 1}">
  4. <div v-show="myShareShow" class="sharetiptxt" style>
  5. <img style=" height:100%; z-index:46" src="../assets/buttonImg/shareText.png" alt />
  6. </div>
  7. <transition name="dialog">
  8. <div class="dialog-sprite">
  9. <div class="dialog-body">
  10. <div class="bd2 flex-col">
  11. <img class="pic1" :src="currentMonth.shareImg" alt />
  12. </div>
  13. <div class="bd1 flex-col">
  14. <span class="btn" :style="`background-image: url(${popuSave});`"></span>
  15. </div>
  16. </div>
  17. <!-- 右侧 -->
  18. </div>
  19. </transition>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'ShaerPopup',
  26. props: {
  27. show: {
  28. type: Boolean,
  29. default: false,
  30. required: true
  31. },
  32. cancelText: {
  33. type: String,
  34. default: '取消',
  35. required: false
  36. },
  37. currentMonth: {
  38. type: Object
  39. }
  40. },
  41. data() {
  42. return {
  43. name: 'dialog',
  44. showSelf: false,
  45. zIndex: this.getZIndex(),
  46. bodyOverflow: '',
  47. popuSave: require('../assets/buttonImg/pressSave.png'),
  48. myShareShow: true
  49. }
  50. },
  51. watch: {
  52. show(val) {
  53. console.log('🚀 ~ file: Popup.vue ~ line 78 ~ show ~ val', val)
  54. this.showSelf = val
  55. }
  56. },
  57. created() {
  58. this.showSelf = this.show
  59. },
  60. mounted() {
  61. this.forbidScroll()
  62. },
  63. methods: {
  64. /** 禁止页面滚动 */
  65. forbidScroll() {
  66. this.bodyOverflow = document.body.style.overflow
  67. document.body.style.overflow = 'hidden'
  68. },
  69. /** 每次获取之后 zindex 自动增加 */
  70. getZIndex() {
  71. let zIndexInit = 2022112
  72. return zIndexInit++
  73. },
  74. /** 取消按钮操作 */
  75. cancel() {
  76. // this.$emit('cancel', true)
  77. },
  78. /** 确认按钮操作 */
  79. confirm() {
  80. this.$emit('confirm', true)
  81. },
  82. /** 点击遮罩关闭弹窗 */
  83. closeMyself(event) {
  84. // this.sloveBodyOverflow()
  85. this.$emit('closeMyself', true)
  86. },
  87. /** 恢复页面的滚动 */
  88. sloveBodyOverflow() {
  89. this.showSelf = false
  90. document.body.style.overflow = this.bodyOverflow
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="less" scoped>
  96. // 弹窗动画
  97. // 最外层 设置position定位
  98. // 遮罩 设置背景层,z-index值要足够大确保能覆盖,高度 宽度设置满 做到全屏遮罩
  99. .flex-col {
  100. display: flex;
  101. flex-direction: column;
  102. }
  103. .dialog {
  104. position: fixed;
  105. top: 0;
  106. right: 0;
  107. width: 100%;
  108. height: 100%;
  109. transition: opacity 1s;
  110. // 内容层 z-index要比遮罩大,否则会被遮盖
  111. .dialog-mark {
  112. position: absolute;
  113. top: 0;
  114. height: 0;
  115. width: 100%;
  116. height: 100%;
  117. background: rgba(0, 0, 0, 0.9);
  118. left: 0;
  119. top: 0;
  120. z-index: 99;
  121. display: flex;
  122. align-items: center;
  123. justify-content: center;
  124. .sharetiptxt {
  125. background-size: 100% auto;
  126. background-repeat: no-repeat;
  127. z-index: 55;
  128. width: 20px;
  129. height: 320px;
  130. display: block;
  131. position: absolute;
  132. right: 1rem;
  133. top: 0.5em;
  134. animation: tipup 1s ease infinite;
  135. }
  136. }
  137. .dialog-sprite {
  138. width: 100vw;
  139. display: flex;
  140. justify-content: center;
  141. position: relative;
  142. .dialog-body {
  143. flex: 1;
  144. overflow-x: hidden;
  145. overflow-y: scroll;
  146. padding: 0 15px 20px 15px;
  147. //中间卡片
  148. .bd2 {
  149. z-index: 33;
  150. width: 100%;
  151. justify-content: flex-start;
  152. align-items: center;
  153. margin-top: 20px;
  154. .pic1 {
  155. z-index: 45;
  156. width: 280px;
  157. height: 464px;
  158. }
  159. }
  160. //底部按钮
  161. .bd1 {
  162. width: 100%;
  163. background-size: 100% auto;
  164. margin: 10px auto 0;
  165. .btn {
  166. z-index: 42;
  167. width: 162px;
  168. height: 46.8px;
  169. display: block;
  170. text-align: center;
  171. align-self: center;
  172. margin-top: 12px;
  173. background-size: 100% auto;
  174. background-repeat: no-repeat;
  175. }
  176. }
  177. }
  178. }
  179. }
  180. @keyframes tipup {
  181. 0% {
  182. transform: translateY(0%);
  183. }
  184. 50% {
  185. transform: translateY(5%);
  186. }
  187. 100% {
  188. transform: translateY(0%);
  189. }
  190. }
  191. </style>