layout.js 2.99 KB
Newer Older
wangdanlei's avatar
wangdanlei committed
1
import { getLayouts } from '@/api/config.js'
wangdanlei's avatar
wangdanlei committed
2 3
import { searchApi } from '@/api/index.js'
import _cloneDeep from 'lodash.clonedeep'
wangdanlei's avatar
wangdanlei committed
4
const state = {
wangdanlei's avatar
wangdanlei committed
5 6
  layout: {},
  pageInfo: {}
wangdanlei's avatar
wangdanlei committed
7 8 9 10 11 12
}
const mutations = {
  UPDATE_LAYOUT: (state, configs) => {
    state.layout = {}
    state.layout = configs
  },
wangdanlei's avatar
wangdanlei committed
13 14 15
  UPDATE_PAGE_INFO: (state, config) => {
    state.pageInfo[config.pageKey] = config.data
  },
wangdanlei's avatar
wangdanlei committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  SET_LAYOUT: (state, config) => {
    for (const a in config) {
      if (state.layout[a]) {
        state.layout[a] = Object.assign(state.layout[a], config[a])
      } else {
        state.layout[a] = config[a]
      }
    }
  }
}

const actions = {
  setLayouts({ commit, state }, config) {
    commit('SET_LAYOUT', config)
  },
wangdanlei's avatar
wangdanlei committed
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
  getPageInfo({ commit, state }, pageKey) {
    return new Promise((resolve, reject) => {
      if (state.pageInfo[pageKey]) {
        resolve(_cloneDeep(state.pageInfo[pageKey]))
      } else {
        const serverParams = {
          pageFrom: 1,
          pageSize: 1,
          openProps: [
            {
              name: 'targetDxModelChooseLink',
              openProps: [{
                name: 'source'
              }]
            },
            {
              name: 'sourceDxPageComponentLink',
              openProps: [{
                name: 'target',
                openProps: [{
                  name: 'targetDxModelComponentLink'
                }]
              }
              ]
            }
          ],
          searchItems: {
            items: [
              { fieldName: 'pageKey', operator: 'EQ', value: pageKey }
            ]
          },
          sortItem: [{ fieldName: 'modifyTime', sortOrder: 'asc' }]
        }
        searchApi('DxApplicationPage', serverParams).then(res => {
          if (res.items && res.items.content[0]) {
            resolve(res.items.content[0])
            commit('UPDATE_PAGE_INFO', { pageKey, data: res.items.content[0] })
          } else {
            resolve(null)
          }
        })
      }
    })
  },
wangdanlei's avatar
wangdanlei committed
75 76
  getLayouts({ commit, state }, { modelName, layoutKey, isRest }) {
    return new Promise(async(resolve, reject) => {
wangdanlei's avatar
wangdanlei committed
77 78 79 80
      // if (!isRest && state.layout[modelName] && state.layout[modelName][layoutKey]) {
      //   resolve(JSON.parse(JSON.stringify(state.layout[modelName][layoutKey])))
      // } else {
      getLayouts(modelName, layoutKey).then(res => {
wangdanlei's avatar
wangdanlei committed
81 82 83
        if (res.items) {
          if (isRest) {
            resolve(res)
wangdanlei's avatar
wangdanlei committed
84 85 86 87 88 89 90 91 92 93
          } else {
            const detail = res.items.slice(-1)[0]
            if (typeof detail.configDetails === 'string') {
              detail.configDetails = JSON.parse(detail.configDetails)
            }
            // const config = {}
            // config[modelName] = {}
            // config[modelName][layoutKey] = detail
            // commit('SET_LAYOUT', config)
            resolve(JSON.parse(JSON.stringify(detail)))
wangdanlei's avatar
wangdanlei committed
94 95 96 97 98 99
          }
        }
        resolve(null)
      }).catch(() => {
        resolve()
      })
wangdanlei's avatar
wangdanlei committed
100
      // }
wangdanlei's avatar
wangdanlei committed
101 102 103 104 105 106 107 108 109 110
    })
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}