登录
文档目录
图片名称

弹窗型组件混入

2025-04-15 00:00:35(最后一次修改:2025-04-15 00:01:49)

何时使用

  1. 弹窗型组件指的是有容器(如modal,drawer)包裹的,由属性栏上渲染的弹窗触发器触发的组件。

  2. 弹窗触发器为平铺组件,框架内置了默认的弹窗触发器,用户可参考默认触发器开发新的弹窗触发器

弹窗组件示例

源码展示

import { Component, Vue, Prop } from 'vue-property-decorator';
import { cloneDeep } from 'lodash';
import { ComponentNeedShow } from 'cloudpivot/common';
import { mixins } from 'vue-class-component';
@Component
export class PropertyModalBase extends mixins(ComponentNeedShow) {
  modalData: any = null;

  afterSHow(initData) {
    this.modalData = cloneDeep(initData);
  }

  backData(value: any) {
    this.$emit('backData', value);
  }

  otherValueChange(key, value) {
    this.$emit('otherValueChange', key, value);
  }
}
// 需要外部组件通过ref调用show方法才能显示的组件,需要混入此mixin
import { Component, Vue, Prop } from 'vue-property-decorator';
import { observeModal } from 'cloudpivot/common/src/utils/dom';
@Component
export class ComponentNeedShow extends Vue {
  //核心组件类型
  componentType: 'modal' | 'drawer' | 'popover' | 'big-dialog' = 'modal';

  componentVisible = false;

  //核心组件的包装class
  wrapClassName = '';

  noFooter = false;

  /**
   * 组件的显示只有一个入口,就是本方法
   * @param initData 初始化数据,某些数据需要在显示时传入
   */
  show(initData?: any) {
    let modalWrapClass = this.wrapClassName;
    if (this.wrapClassName.includes(' ')) {
      modalWrapClass = this.wrapClassName.split(' ')[0];
    }
    this.beforeShow(initData);
    this.componentVisible = true;
    this.afterShow(initData);
    if (this.componentType === 'modal' && modalWrapClass) {
      this.$nextTick(() => {
        observeModal(modalWrapClass, {
          noFooter: this.noFooter,
        });
      });
    }
  }

  /**
   * 组件的隐藏应该只有一个入口,就是本方法
   */
  hidden() {
    this.componentVisible = false;
    this.afterHidden();
  }

  beforeShow(initData?: any) {}

  afterShow(initData?: any) {}

  afterHidden() {}
}

属性说明

属性名
说明
类型
modalData
弹窗数据,在外部调用show方法时会当作参数传入
any
componentType
包装组件类型
'modal' | 'drawer' | 'popover' | 'big-dialog'
componentVisible
控制包装组件显隐
boolean
wrapClassName
包装组件类名
string
noFooter
modal类型下是否使用组件footer

函数说明
函数名
说明
参数
show
触发器点击时执行本方法可展示弹窗组件
弹窗数据
hidden
隐藏包装器,弹窗内部调用

beforeShow
展示前调用
弹窗数据
afterShow
展示后调用
弹窗数据
afterHidden
隐藏后调用

backData
属性值回传
新的属性值
otherValueChange
非controller直接绑定的属性值改变,不会触发subscribtion
属性key,属性value


  • 没有用(0

本文链接:https://open.hetusaas.com/?id=28

图片名称

网友评论

图片名称