综合办公系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uv-overlay.vue 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <uv-transition
  3. :show="show"
  4. mode="fade"
  5. custom-class="uv-overlay"
  6. :duration="duration"
  7. :custom-style="overlayStyle"
  8. @click="clickHandler"
  9. @touchmove.stop.prevent="clear"
  10. >
  11. <slot />
  12. </uv-transition>
  13. </template>
  14. <script>
  15. import mpMixin from '@/uni_modules/uv-ui-tools/libs/mixin/mpMixin.js'
  16. import mixin from '@/uni_modules/uv-ui-tools/libs/mixin/mixin.js'
  17. import props from './props.js';
  18. /**
  19. * overlay 遮罩
  20. * @description 创建一个遮罩层,用于强调特定的页面元素,并阻止用户对遮罩下层的内容进行操作,一般用于弹窗场景
  21. * @tutorial https://www.uvui.cn/components/overlay.html
  22. * @property {Boolean} show 是否显示遮罩(默认 false )
  23. * @property {String | Number} zIndex zIndex 层级(默认 10070 )
  24. * @property {String | Number} duration 动画时长,单位毫秒(默认 300 )
  25. * @property {String | Number} opacity 不透明度值,当做rgba的第四个参数 (默认 0.5 )
  26. * @property {Object} customStyle 定义需要用到的外部样式
  27. * @event {Function} click 点击遮罩发送事件
  28. * @example <uv-overlay :show="show" @click="show = false"></uv-overlay>
  29. */
  30. export default {
  31. name: "uv-overlay",
  32. emits: ['click'],
  33. mixins: [mpMixin, mixin, props],
  34. watch: {
  35. show(newVal){
  36. // #ifdef H5
  37. if(newVal){
  38. document.querySelector('body').style.overflow = 'hidden';
  39. }else{
  40. document.querySelector('body').style.overflow = '';
  41. }
  42. // #endif
  43. }
  44. },
  45. computed: {
  46. overlayStyle() {
  47. const style = {
  48. position: 'fixed',
  49. top: 0,
  50. left: 0,
  51. right: 0,
  52. zIndex: this.zIndex,
  53. bottom: 0,
  54. 'background-color': `rgba(0, 0, 0, ${this.opacity})`
  55. }
  56. return this.$uv.deepMerge(style, this.$uv.addStyle(this.customStyle))
  57. }
  58. },
  59. methods: {
  60. clickHandler() {
  61. this.$emit('click')
  62. },
  63. clear() {}
  64. }
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. /* #ifndef APP-NVUE */
  69. $uv-overlay-top:0 !default;
  70. $uv-overlay-left:0 !default;
  71. $uv-overlay-width:100% !default;
  72. $uv-overlay-height:100% !default;
  73. $uv-overlay-background-color:rgba(0, 0, 0, .7) !default;
  74. .uv-overlay {
  75. position: fixed;
  76. top:$uv-overlay-top;
  77. left:$uv-overlay-left;
  78. width: $uv-overlay-width;
  79. height:$uv-overlay-height;
  80. background-color:$uv-overlay-background-color;
  81. }
  82. /* #endif */
  83. </style>