import Vue from "vue";

class ApprovalStore {
  private static readonly DATA = "approval_data";
  private static readonly TASK_INFO = "approval_taskInfo";

  private static readonly VERSION = "approval_version";
  private static readonly EXPIRE = 1000 * 60 * 60 * 24;
  public get version(): string {
    return Vue.ls.get(ApprovalStore.VERSION);
  }

  public set version(version: string) {
    Vue.ls.set(ApprovalStore.VERSION, version);
  }

  /**
   * @Description: 设置缓存数据 以instId为区分  跳转到详情时传入
   * @author guoxuhui
   * @date 2021-03-17
   * @time 14:40
   */
  public setFlowParameters(data: any) {
    const instId = data.instId || "";
    Vue.ls.set(ApprovalStore.DATA + ":" + instId, data, ApprovalStore.EXPIRE);
  }

  /**
   * @Description: 获取缓存数据 以instId 为区分 在审批列表中展示
   * @author guoxuhui
   * @date 2021-03-17
   * @time 14:40
   */
  public getFlowParameters(instId: string): any {
    return Vue.ls.get(ApprovalStore.DATA + ":" + instId);
  }

  /**
   * @Description: 缓存查出的流程数据，以流程实例id为区分 每个流程实例存在一条数据
   * @author guoxuhui
   * @date 2021-03-17
   * @time 14:42
   */
  public setTaskInfoByInstId(data: any) {
    const instId = data.instId || "";
    Vue.ls.set(ApprovalStore.TASK_INFO + ":" + instId, data, ApprovalStore.EXPIRE);
  }
  public removeTaskInfoByInstId(instId: string) {
    Vue.ls.remove(ApprovalStore.TASK_INFO + ":" + instId);
  }
  public removeFlowParameters(instId: string) {
    Vue.ls.remove(ApprovalStore.DATA + ":" + instId);
  }
  /**
   * @Description: 获取查出的流程数据，以流程实例id为区分 每个流程实例存在一条数据
   * @author guoxuhui
   * @date 2021-03-17
   * @time 14:42
   */
  public getTaskInfoByInstId(instId: string): any {
    Vue.ls.get(ApprovalStore.TASK_INFO + ":" + instId);
  }
}

const approvalStore = new ApprovalStore();

export { approvalStore, ApprovalStore };
