open-view-util.ts 3.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
import { IBizContext } from '@ibiz-template/core';
import { IPSAppView } from '@ibiz-template/model';
import {
  IModal,
  IModalData,
  IOpenViewUtil,
  ViewMode,
} from '@ibiz-template/runtime';
import { generateRoutePath } from '@ibiz-template/vue-util';
import router from '@/router';
import {
  getDrawerPlacement,
  openViewDrawer,
  openViewModal,
  openViewPopover,
} from '../overlay-view-util/overlay-view-util';

/**
 * 打开视图方式工具类
 *
 * @description 此实现类挂载在 ibiz.openViewUtil
 * @author chitanda
 * @date 2022-08-16 20:08:54
 * @export
 * @class OpenViewUtil
 * @implements {IOpenViewUtil}
 */
export class OpenViewUtil implements IOpenViewUtil {
  root(
    appView: IPSAppView,
    context?: IBizContext | undefined,
    params?: IParams | undefined,
  ): void {
    const path = generateRoutePath(
      appView,
      router.currentRoute,
      context,
      params,
    );

    router.push({ path });
  }

  /**
   * 模态打开视图
   *
   * @author lxm
   * @date 2022-09-12 01:09:06
   * @param {IPSAppView} appView
   * @param {(IBizContext | undefined)} [context]
   * @param {(IParams | undefined)} [params]
   * @returns {*}  {Promise<IModalData>}
   */
  async modal(
    appView: IPSAppView,
    context?: IBizContext | undefined,
    params?: IParams | undefined,
  ): Promise<IModalData> {
    // 获取视图path
    const modelPath = appView.modelPath!;

    // 设置默认的modal参数
    const opts = {
      width: appView.width || '80%',
      height: appView.height || '80%',
      footerHide: true,
    };

    const modal: IModal = { mode: ViewMode.MODAL };
    return openViewModal(
      {
        context,
        params,
        modelPath,
        modal,
      },
      opts,
    );
  }

  async popover(
    appView: IPSAppView,
    event: MouseEvent,
    context?: IBizContext | undefined,
    params?: IParams | undefined,
  ): Promise<IModalData> {
    // 获取视图path
    const modelPath = appView.modelPath!;

    const modal: IModal = { mode: ViewMode.POPOVER };
    return openViewPopover(
      event,
      {
        context,
        params,
        modelPath,
        modal,
      },
      { autoClose: true, placement: 'bottom' },
    );
  }

  /**
   * 抽屉打开视图
   *
   * @author lxm
   * @date 2022-09-15 15:09:50
   * @param {IPSAppView} appView
   * @param {(IBizContext | undefined)} [context]
   * @param {(IParams | undefined)} [params]
   * @returns {*}  {Promise<IModalData>}
   */
  async drawer(
    appView: IPSAppView,
    context?: IBizContext | undefined,
    params?: IParams | undefined,
  ): Promise<IModalData> {
    // 获取视图path
    const modelPath = appView.modelPath!;
    const placement = getDrawerPlacement(appView.openMode);

    // 设置默认的modal参数
    const opts = {
      width: appView.width || '800',
      height: appView.height || '600',
      placement,
    };

    const modal: IModal = { mode: ViewMode.DRAWER };
    return openViewDrawer(
      {
        context,
        params,
        modelPath,
        modal,
      },
      opts,
    );
  }

  async custom(
    appView: IPSAppView,
    context?: IBizContext | undefined,
    params?: IParams | undefined,
  ): Promise<IModalData> {
    ibiz.log.warn('openUserCustom', appView, context, params);
    throw new Error();
  }
}