use-mask.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <view class="use-mask pos-f pos-full overflow-hidden" :class="[show ? 'use-mask-show' : '']" :style="[maskStyle]" @touchmove.stop.prevent @tap="click">
  3. <slot />
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. // 是否显示遮罩
  10. show: {
  11. type: Boolean,
  12. default: false
  13. },
  14. // 层级z-index
  15. zIndex: {
  16. type: [Number, String],
  17. default: '10000'
  18. },
  19. // 遮罩的动画样式, 是否使用使用zoom进行scale进行缩放
  20. zoom: {
  21. type: Boolean,
  22. default: true
  23. },
  24. // 遮罩的过渡时间,单位为ms
  25. duration: {
  26. type: [Number, String],
  27. default: 300
  28. },
  29. // 是否可以通过点击遮罩进行关闭
  30. maskClickAble: {
  31. type: Boolean,
  32. default: true
  33. }
  34. },
  35. computed: {
  36. maskStyle() {
  37. let style = {
  38. transition: `all ${this.duration / 1000}s ease-in-out`,
  39. zIndex: this.zIndex,
  40. };
  41. if (this.show) {
  42. style.zIndex = this.zIndex;
  43. } else {
  44. style.zIndex = -1;
  45. }
  46. // 缩放
  47. if (this.zoom) {
  48. style.transform = 'scale(1.2, 1.2)';
  49. }
  50. return style;
  51. }
  52. },
  53. methods: {
  54. click() {
  55. if (this.maskClickAble) {
  56. this.$emit('click');
  57. }
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang="scss">
  63. .use-mask {
  64. opacity: 0;
  65. background-color: rgba(0, 0, 0, 0.6);
  66. }
  67. .use-mask-show {
  68. opacity: 1;
  69. visibility: visible;
  70. transform: scale(1);
  71. }
  72. </style>