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.

71 lines
2.1 KiB

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