tn-landscape.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="tn-landscape-class tn-landscape">
  3. <view v-if="showValue" class="tn-landscape__container" :style="[containerStyle]">
  4. <slot></slot>
  5. <view
  6. v-if="closeBtn"
  7. class="tn-landscape__icon tn-icon-close-fill"
  8. :class="[{
  9. 'tn-landscape__icon--left-top': closePosition === 'leftTop',
  10. 'tn-landscape__icon--right-top': closePosition === 'rightTop',
  11. 'tn-landscape__icon--bottom': closePosition === 'bottom'
  12. }]"
  13. :style="[closeBtnStyle]"
  14. @tap="close"
  15. ></view>
  16. </view>
  17. <view
  18. v-if="mask"
  19. class="tn-landscape__mask"
  20. :class="[{'tn-landscape__mask--show': showValue}]"
  21. :style="[maskStyle]"
  22. @tap="closeMask"
  23. ></view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. name: 'tn-landscape',
  29. props: {
  30. // 显示
  31. show: {
  32. type: Boolean,
  33. default: false
  34. },
  35. // 显示关闭图标
  36. closeBtn: {
  37. type: Boolean,
  38. default: true
  39. },
  40. // 关闭图标颜色
  41. closeColor: {
  42. type: String,
  43. default: ''
  44. },
  45. // 关闭图标大小,单位rpx
  46. closeSize: {
  47. type: Number,
  48. default: 0
  49. },
  50. // 关闭图标位置
  51. // leftTop -> 左上角 rightTop -> 右上角 bottom -> 底部
  52. closePosition: {
  53. type: String,
  54. default: 'rightTop'
  55. },
  56. // 关闭图标top值,单位rpx
  57. // 当关闭图标在leftTop或者rightTop时生效
  58. closeTop: {
  59. type: Number,
  60. default: 0
  61. },
  62. // 关闭图标right值,单位rpx
  63. // 当关闭图标在RightTop时生效
  64. closeRight: {
  65. type: Number,
  66. default: 0
  67. },
  68. // 关闭图标bottom值,单位rpx
  69. // 当关闭图标在bottom时生效
  70. closeBottom: {
  71. type: Number,
  72. default: 0
  73. },
  74. // 关闭图标left值,单位rpx
  75. // 当关闭图标在leftTop时生效
  76. closeLeft: {
  77. type: Number,
  78. default: 0
  79. },
  80. // 显示遮罩
  81. mask: {
  82. type: Boolean,
  83. default: true
  84. },
  85. // 点击遮罩可以关闭
  86. maskCloseable: {
  87. type: Boolean,
  88. default: true
  89. },
  90. // zIndex
  91. zIndex: {
  92. type: Number,
  93. default: 0
  94. }
  95. },
  96. computed: {
  97. containerStyle() {
  98. let style = {}
  99. style.zIndex = this.zIndex ? this.zIndex : this.$t.zIndex.landsacpe
  100. return style
  101. },
  102. closeBtnStyle() {
  103. let style = {}
  104. if (this.closePosition === 'leftTop') {
  105. if (this.closeTop) {
  106. style.top = this.closeTop + 'rpx'
  107. }
  108. if (this.closeLeft) {
  109. style.left = this.closeLeft + 'rpx'
  110. }
  111. } else if (this.closePosition === 'rightTop') {
  112. if (this.closeTop) {
  113. style.top = this.closeTop + 'rpx'
  114. }
  115. if (this.closeRight) {
  116. style.right = this.closeRight + 'rpx'
  117. }
  118. } else if (this.closePosition === 'bottom') {
  119. if (this.closeBottom) {
  120. style.bottom = this.closeBottom + 'rpx'
  121. }
  122. }
  123. if (this.closeSize) {
  124. style.fontSize = this.closeSize + 'rpx'
  125. }
  126. if (this.closeColor) {
  127. style.color = this.closeColor
  128. }
  129. return style
  130. },
  131. maskStyle() {
  132. let style = {}
  133. style.zIndex = this.zIndex ? this.zIndex - 1 : this.$t.zIndex.landsacpe - 1
  134. return style
  135. }
  136. },
  137. watch: {
  138. show: {
  139. handler(val) {
  140. this.showValue = val
  141. },
  142. immediate: true
  143. }
  144. },
  145. data() {
  146. return {
  147. showValue: false
  148. }
  149. },
  150. methods: {
  151. // 关闭压屏窗
  152. close() {
  153. this.showValue = false
  154. this.$emit('close')
  155. },
  156. // 点击遮罩关闭
  157. closeMask() {
  158. if (!this.maskCloseable) return
  159. this.close()
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang="scss" scoped>
  165. .tn-landscape {
  166. width: 100%;
  167. overflow: hidden;
  168. &__container {
  169. max-width: 100%;
  170. position: fixed;
  171. display: inline-flex;
  172. flex-direction: column;
  173. align-items: center;
  174. justify-content: center;
  175. left: 50%;
  176. top: 50%;
  177. transform: translate(-50%, -50%);
  178. }
  179. &__icon {
  180. position: absolute;
  181. text-align: center;
  182. font-size: 50rpx;
  183. color: #FFFFFF;
  184. &--left-top {
  185. top: -40rpx;
  186. left: 20rpx;
  187. }
  188. &--right-top {
  189. top: -40rpx;
  190. right: 40rpx;
  191. }
  192. &--bottom {
  193. left: 50%;
  194. bottom: -40rpx;
  195. transform: translateX(-50%);
  196. }
  197. }
  198. &__mask {
  199. position: fixed;
  200. width: 100%;
  201. height: 100%;
  202. background-color: $tn-mask-bg-color;
  203. top: 0;
  204. right: 0;
  205. bottom: 0;
  206. left: 0;
  207. opacity: 0;
  208. transform: scale3d(1, 1, 0);
  209. transition: all 0.25s ease-in;
  210. &--show {
  211. opacity: 1 !important;
  212. transform: scale3d(1, 1, 1);
  213. }
  214. }
  215. }
  216. </style>