u-overlay.vue 2.0 KB

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