import Vue from 'vue'
import Vuex from 'vuex'

import user from './module/user'
import app from './module/app'
import createPersistedState from 'vuex-persistedstate'


Vue.use(Vuex)

export default new Vuex.Store({
  //vuex-persistedstate 配置，只持久化user和app相关属性
  plugins: [createPersistedState({
    reducer(val){
      return {
        user:val.user,
        app:val.app
      }
    }
    }
  )],
  state: {
    tableId: '',
    isTried: false,
    promoterDrawer: false,
    flowPermission1: {},
    approverDrawer: false,
    approverConfig1: {},
    copyerDrawer: false,
    copyerConfig1: {},
    conditionDrawer: false,
    conditionsConfig1: {
      conditionNodes: [],
    },
    process:{       //流程图
      nodeModal:{   //节点弹窗
        display:null,
        saveLoading:false,
        indexDisplay:null,
      },
      edgeModal:{   //连线弹窗
        display:null,
        saveLoading:false
      },
      currentNodeId:undefined,//当前点击工序id
      currentEdgeId:undefined,//当前点击连线id
    },
    print:{
      preview:{
        display:null,
      }
    }
  },
  mutations: {
    //关闭浏览器 清空token
    exit(state) {
      state.user.token = ''
    },
    setTableId(status, payload) {
      status.tableId = payload
    },
    setIsTried(status, payload) {
      status.isTried = payload
    },
    setPromoter(status, payload) {
      status.promoterDrawer = payload
    },
    setFlowPermission(status, payload) {
      status.flowPermission1 = payload
    },
    setApprover(status, payload) {
      status.approverDrawer = payload
    },
    setApproverConfig(status, payload) {
      status.approverConfig1 = payload
    },
    setCopyer(status, payload) {
      status.copyerDrawer = payload
    },
    setCopyerConfig(status, payload) {
      status.copyerConfig1 = payload
    },
    setCondition(status, payload) {
      status.conditionDrawer = payload
    },
    setConditionsConfig(status, payload) {
      status.conditionsConfig1 = payload
    },
    setProcessNodeModalDisplay(status, payload) {
      status.process.nodeModal.display = payload
    },
    setProcessNodeModalIndexDisplay(status, payload) {
      status.process.nodeModal.indexDisplay = payload
    },
    setProcessEdgeModalDisplay(status, payload) {
      status.process.edgeModal.display = payload
    },
    setCurrentNodeId(status, payload) {
      status.process.currentNodeId = payload
    },
    setCurrentEdgeId(status, payload) {
      status.process.currentEdgeId = payload
    },
    setPrintPreviewModalDisplay(status, payload) {
      status.print.preview.display = payload
    },
  },
  actions: {
    //
  },
  modules: {
    user,
    app,
  }
})
