u-overlay.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. methods: {
  46. clickHandler() {
  47. this.$emit('click')
  48. }
  49. }
  50. }
  51. </script>
  52. <style lang="scss" scoped>
  53. @import "../../libs/css/components.scss";
  54. $u-overlay-top:0 !default;
  55. $u-overlay-left:0 !default;
  56. $u-overlay-width:100% !default;
  57. $u-overlay-height:100% !default;
  58. $u-overlay-background-color:rgba(0, 0, 0, .7) !default;
  59. .u-overlay {
  60. position: fixed;
  61. top:$u-overlay-top;
  62. left:$u-overlay-left;
  63. width: $u-overlay-width;
  64. height:$u-overlay-height;
  65. background-color:$u-overlay-background-color;
  66. }
  67. </style>