1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-10 20:39:48 +08:00

improves: Add state restart for modules that manage and store data. (#397)

This commit is contained in:
Edwin Betancourt 2020-03-11 21:38:41 -04:00 committed by GitHub
parent 902832ee79
commit d03de8b2a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 207 additions and 144 deletions

View File

@ -5,7 +5,13 @@ const {{name}} = {
},
{{/if}}
{{#if mutations}}
mutations: {},
mutations: {
{{#if state}}
resetState{{name}}(state) {
state = {}
}
{{/if}}
},
{{/if}}
{{#if actions}}
actions: {},

View File

@ -1,17 +1,26 @@
import { requestListRecordsLogs, requestListWorkflowsLogs, requestListWorkflows, requestListRecordChats, requestListChatEntries, requestCreateChatEntry } from '@/api/ADempiere/data'
import {
requestListRecordsLogs,
requestListWorkflowsLogs,
requestListWorkflows,
requestListRecordChats,
requestListChatEntries,
requestCreateChatEntry
} from '@/api/ADempiere/data'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
const initStateContainerInfo = {
listworkflowLog: [],
listRecordLogs: [],
listRecordChats: [],
listChatEntries: [],
listWorkflows: [],
chat: [],
note: [],
isNote: false
}
const containerInfo = {
state: {
listworkflowLog: [],
listRecordLogs: [],
listRecordChats: [],
listChatEntries: [],
listWorkflows: [],
chat: [],
note: [],
isNote: false
},
state: initStateContainerInfo,
mutations: {
addListWorkflow(state, payload) {
state.listworkflowLog = payload
@ -36,6 +45,9 @@ const containerInfo = {
},
isNote(state, payload) {
state.isNote = payload
},
resetStateContainerInfo(state) {
state = initStateContainerInfo
}
},
actions: {
@ -66,17 +78,17 @@ const containerInfo = {
const pageToken = 0
return requestListRecordChats({ tableName, recordId, pageSize, pageToken })
.then(response => {
var chatList = response.recordChatsList
var listRecord = {
const chatList = response.recordChatsList
const listRecord = {
recordChatsList: response.recordChatsList,
recordCount: response.recordCount,
nextPageToken: response.nextPageToken
}
chatList.forEach(chat => {
var uuid = chat.chatUuid
const uuid = chat.chatUuid
requestListChatEntries({ uuid, pageSize, pageToken })
.then(response => {
var listlogsChat = state.chat
const listlogsChat = state.chat
let chatUpgrade = []
let chatAll
if (recordId === chat.recordId) {
@ -102,24 +114,25 @@ const containerInfo = {
console.warn(`Error getting List Chat: ${error.message}. Code: ${error.code}.`)
})
},
listRecordLogs({ commit, state }, params) {
listRecordLogs({ commit }, params) {
const tableName = params.tableName
const recordId = params.recordId
const pageSize = 0
const pageToken = 0
return requestListRecordsLogs({ tableName, recordId, pageSize, pageToken })
.then(response => {
var listRecord = {
const listRecord = {
recordCount: response.recordCount,
recorLogs: response.recordLogsList
}
commit('addListRecordLogs', listRecord)
return listRecord
})
.catch(error => {
console.warn(`Error getting List Record Logs: ${error.message}. Code: ${error.code}.`)
})
},
listWorkflowLogs({ commit, state, dispatch }, params) {
listWorkflowLogs({ commit, dispatch }, params) {
const tableName = params.tableName
const recordId = params.recordId
const pageSize = 0
@ -127,28 +140,30 @@ const containerInfo = {
dispatch('listWorkflows', tableName)
return requestListWorkflowsLogs({ tableName, recordId, pageSize, pageToken })
.then(response => {
var workflowLog = {
const workflowLog = {
recordCount: response.recordCount,
workflowLogsList: response.workflowLogsList,
nextPageToken: response.nextPageToken
}
commit('addListWorkflow', workflowLog)
return workflowLog
})
.catch(error => {
console.warn(`Error getting List workflow: ${error.message}. Code: ${error.code}.`)
})
},
listWorkflows({ commit, state }, tableName) {
listWorkflows({ commit }, tableName) {
const pageSize = 0
const pageToken = 0
return requestListWorkflows({ tableName, pageSize, pageToken })
.then(response => {
var nodeWorflow = {
const nodeWorflow = {
nextPageToken: response.nextPageToken,
recordCount: response.recordCount,
workflowsList: response.workflowsList
}
commit('addListWorkflows', nodeWorflow)
return nodeWorflow
})
.catch(error => {
console.warn(`Error getting List workflow: ${error.message}. Code: ${error.code}.`)

View File

@ -4,7 +4,7 @@ import { requestListDocumentActions, requestListDocumentStatuses } from '@/api/A
// Store used for set all related to context menu
// for Window, Process, Smart Browser andother customized component
// See structure:
// menu: [
// contextMenu: [
// {
// containerUuid: '',
// relations: [],
@ -14,22 +14,24 @@ import { requestListDocumentActions, requestListDocumentStatuses } from '@/api/A
// lastAction: {}
// }
// ]
const contextMenu = {
state: {
contextMenu: [],
listDocumentStatus: {
defaultDocumentAction: undefined,
documentActionsList: [],
recordId: undefined,
recordUuid: undefined
},
listDocumentAction: {
defaultDocumentAction: undefined,
documentActionsList: [],
recordId: undefined,
recordUuid: undefined
}
const initStateContextMenu = {
contextMenu: [],
listDocumentStatus: {
defaultDocumentAction: undefined,
documentActionsList: [],
recordId: undefined,
recordUuid: undefined
},
listDocumentAction: {
defaultDocumentAction: undefined,
documentActionsList: [],
recordId: undefined,
recordUuid: undefined
}
}
const contextMenu = {
state: initStateContextMenu,
mutations: {
setContextMenu(state, payload) {
state.contextMenu.push(payload)
@ -42,6 +44,9 @@ const contextMenu = {
},
addlistDocumentStatus(state, payload) {
state.listDocumentStatus = payload
},
resetContextMenu(state) {
state = initStateContextMenu
}
},
actions: {

View File

@ -13,13 +13,15 @@ import { parseContext } from '@/utils/ADempiere/contextUtils'
import { showMessage } from '@/utils/ADempiere/notification'
import language from '@/lang'
const initStateBusinessData = {
recordSelection: [], // record data and selection
inGetting: [],
contextInfoField: [],
recordPrivateAccess: {}
}
const data = {
state: {
recordSelection: [], // record data and selection
inGetting: [],
contextInfoField: [],
recordPrivateAccess: {}
},
state: initStateBusinessData,
mutations: {
addInGetting(state, payload) {
state.inGetting.push(payload)
@ -81,6 +83,9 @@ const data = {
},
setPrivateAccess(state, payload) {
state.recordPrivateAccess = payload
},
resetStateBusinessData(state) {
state = initStateBusinessData
}
},
actions: {
@ -900,6 +905,18 @@ const data = {
})
console.warn(`Error unlock private access: ${error.message}. Code: ${error.code}.`)
})
},
resetStateBusinessData({ commit }) {
commit('resetStateContainerInfo')
commit('setInitialContext', {})
commit('resetStateTranslations')
commit('resetStateBusinessData')
commit('resetContextMenu')
commit('resetStateTranslations')
commit('resetStateLookup')
commit('resetStateProcessControl')
commit('resetStateUtils')
commit('resetStateWindowControl')
}
},
getters: {

View File

@ -4,6 +4,7 @@ import {
updateEntity
} from '@/api/ADempiere/data'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
const languageControl = {
state: {
languagesList: [],
@ -25,6 +26,9 @@ const languageControl = {
},
addTranslationChangeRecord(state, payload) {
payload.currentTranslation = payload.newTranlation
},
resetStateTranslations(state) {
state.translationsList = []
}
},
actions: {

View File

@ -3,11 +3,13 @@ import { getCurrentRole } from '@/utils/ADempiere/auth'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
import { parseContext } from '@/utils/ADempiere/contextUtils'
const initStateLookup = {
lookupItem: [],
lookupList: []
}
const lookup = {
state: {
lookupItem: [],
lookupList: []
},
state: initStateLookup,
mutations: {
addLoockupItem(state, payload) {
state.lookupItem.push(payload)
@ -18,6 +20,9 @@ const lookup = {
deleteLookupList(state, payload) {
state.lookupItem = payload.lookupItem
state.lookupList = payload.lookupList
},
resetStateLookup(state) {
state = initStateLookup
}
},
actions: {

View File

@ -7,24 +7,26 @@ import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
import language from '@/lang'
import router from '@/router'
const initStateProcessControl = {
inExecution: [], // process not response from server
isVisibleDialog: false,
reportObject: {},
reportList: [],
metadata: {},
process: [], // process to run finish
sessionProcess: [],
notificationProcess: [],
inRequestMetadata: [],
reportViewList: [],
totalResponse: 0,
totalRequest: 0,
totalSelection: 0,
errorSelection: 0,
successSelection: 0
}
const processControl = {
state: {
inExecution: [], // process not response from server
isVisibleDialog: false,
reportObject: {},
reportList: [],
metadata: {},
process: [], // process to run finish
sessionProcess: [],
notificationProcess: [],
inRequestMetadata: [],
reportViewList: [],
totalResponse: 0,
totalRequest: 0,
totalSelection: 0,
errorSelection: 0,
successSelection: 0
},
state: initStateProcessControl,
mutations: {
// Add process in execution
addInExecution(state, payload) {
@ -49,8 +51,8 @@ const processControl = {
addStartedProcess(state, payload) {
state.process.push(payload)
},
dataResetCacheProcess(state, payload) {
state.process = payload
resetStateProcessControl(state) {
state = initStateProcessControl
},
/**
*
@ -78,16 +80,6 @@ const processControl = {
changeFormatReport(state, payload) {
state.reportFormat = payload
},
clearProcessControl(state) {
state.inExecution = [] // process not response from server
state.reportObject = {}
state.reportList = []
state.metadata = {}
state.process = [] // process to run finish
state.sessionProcess = []
state.notificationProcess = []
state.inRequestMetadata = []
},
setReportViewsList(state, payload) {
state.reportViewList.push(payload)
},
@ -913,9 +905,6 @@ const processControl = {
if (reportFormat !== undefined) {
commit('changeFormatReport', reportFormat)
}
},
clearProcessControl({ commit }) {
commit('clearProcessControl')
}
},
getters: {

View File

@ -1,12 +1,20 @@
import { requestReportViews, requestPrintFormats, requestDrillTables, getReportOutput } from '@/api/ADempiere'
import { isEmptyValue } from '@/utils/ADempiere'
const contextMenu = {
state: {
reportFormatsList: [],
reportViewsList: [],
drillTablesList: [],
reportOutput: {}
},
import {
requestReportViews,
requestPrintFormats,
requestDrillTables,
getReportOutput
} from '@/api/ADempiere/data'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
const initStateReportControl = {
reportFormatsList: [],
reportViewsList: [],
drillTablesList: [],
reportOutput: {}
}
const reportControl = {
state: initStateReportControl,
mutations: {
setReportFormatsList(state, payload) {
state.reportFormatsList.push(payload)
@ -19,6 +27,9 @@ const contextMenu = {
},
setNewReportOutput(state, payload) {
state.reportOutput = payload
},
resetReportControl(state) {
state = initStateReportControl
}
},
actions: {
@ -181,7 +192,7 @@ const contextMenu = {
},
getters: {
getPrintFormatList: (state) => (containerUuid) => {
var printFormatList = state.reportFormatsList.find(list => list.containerUuid === containerUuid)
const printFormatList = state.reportFormatsList.find(list => list.containerUuid === containerUuid)
if (printFormatList) {
return printFormatList.printFormatList
}
@ -191,14 +202,14 @@ const contextMenu = {
return getters.getPrintFormatList(containerUuid).find(printFormat => printFormat.isDefault)
},
getReportViewList: (state) => (containerUuid) => {
var reportViewList = state.reportViewsList.find(list => list.containerUuid === containerUuid)
const reportViewList = state.reportViewsList.find(list => list.containerUuid === containerUuid)
if (reportViewList) {
return reportViewList.viewList
}
return []
},
getDrillTablesList: (state) => (containerUuid) => {
var drillTablesList = state.drillTablesList.find(list => list.containerUuid === containerUuid)
const drillTablesList = state.drillTablesList.find(list => list.containerUuid === containerUuid)
if (drillTablesList) {
return drillTablesList.viewList
}
@ -207,4 +218,4 @@ const contextMenu = {
}
}
export default contextMenu
export default reportControl

View File

@ -1,36 +1,38 @@
import Vue from 'vue'
const utils = {
state: {
width: 0,
height: 0,
splitHeight: 50,
splitHeightTop: 0,
widthLayout: 0,
tempShareLink: '',
oldAction: undefined,
reportType: '',
isShowedTable: false,
recordUuidTable: 0,
isShowedTabChildren: false,
recordTable: 0,
selectionProcess: [],
isContainerInfo: false,
documentAction: [],
chatText: '',
markDown: false,
openRoute: {
path: '',
name: '',
route: {},
params: {},
definedParameters: {},
query: {},
isReaded: false,
isLoaded: false
},
panelRight: ''
const initStateUtils = {
width: 0,
height: 0,
splitHeight: 50,
splitHeightTop: 0,
widthLayout: 0,
tempShareLink: '',
oldAction: undefined,
reportType: '',
isShowedTable: false,
recordUuidTable: 0,
isShowedTabChildren: false,
recordTable: 0,
selectionProcess: [],
isContainerInfo: false,
documentAction: [],
chatText: '',
markDown: false,
openRoute: {
path: '',
name: '',
route: {},
params: {},
definedParameters: {},
query: {},
isReaded: false,
isLoaded: false
},
panelRight: ''
}
const utils = {
state: initStateUtils,
mutations: {
setWidth(state, width) {
state.width = width
@ -92,6 +94,9 @@ const utils = {
},
setPanelRight(state, payload) {
state.panelRight = payload
},
resetStateUtils(state) {
state = initStateUtils
}
},
actions: {

View File

@ -8,19 +8,20 @@ import language from '@/lang'
import router from '@/router'
import { generateField, getFieldTemplate } from '@/utils/ADempiere/dictionaryUtils'
const initStateWindow = {
window: [],
windowIndex: 0
}
const window = {
state: {
window: [],
windowIndex: 0
},
state: initStateWindow,
mutations: {
addWindow(state, payload) {
state.window.push(payload)
state.windowIndex++
},
dictionaryResetCacheWindow(state) {
state.window = []
state.windowIndex = 0
state = initStateWindow
},
changeWindow(state, payload) {
payload.window = payload.newWindow

View File

@ -5,20 +5,22 @@ import { showMessage } from '@/utils/ADempiere/notification'
import language from '@/lang'
import router from '@/router'
const windowControl = {
state: {
inCreate: [],
references: [],
windowOldRoute: {
path: '',
fullPath: '',
query: {}
},
dataLog: {}, // { containerUuid, recordId, tableName, eventType }
tabSequenceRecord: [],
totalResponse: 0,
totalRequest: 0
const initStateWindowControl = {
inCreate: [],
references: [],
windowOldRoute: {
path: '',
fullPath: '',
query: {}
},
dataLog: {}, // { containerUuid, recordId, tableName, eventType }
tabSequenceRecord: [],
totalResponse: 0,
totalRequest: 0
}
const windowControl = {
state: initStateWindowControl,
mutations: {
addInCreate(state, payload) {
state.inCreate.push(payload)
@ -43,6 +45,9 @@ const windowControl = {
},
setTotalRequest(state, payload) {
state.totalRequest = payload
},
resetStateWindowControl(state) {
state = initStateWindowControl
}
},
actions: {

View File

@ -162,7 +162,7 @@ const actions = {
commit('SET_TOKEN', '')
commit('SET_ROLES', [])
commit('setIsSession', false)
dispatch('clearProcessControl', null, {
dispatch('resetStateBusinessData', null, {
root: true
})
dispatch('dictionaryResetCache', null, {
@ -227,7 +227,7 @@ const actions = {
// Update user info and context associated with session
dispatch('getInfo', changeRoleResponse.uuid)
dispatch('clearProcessControl', null, {
dispatch('resetStateBusinessData', null, {
root: true
})
dispatch('dictionaryResetCache', null, {