1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-13 07:04:21 +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}}
{{#if mutations}} {{#if mutations}}
mutations: {}, mutations: {
{{#if state}}
resetState{{name}}(state) {
state = {}
}
{{/if}}
},
{{/if}} {{/if}}
{{#if actions}} {{#if actions}}
actions: {}, actions: {},

View File

@ -1,8 +1,14 @@
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' import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
const containerInfo = { const initStateContainerInfo = {
state: {
listworkflowLog: [], listworkflowLog: [],
listRecordLogs: [], listRecordLogs: [],
listRecordChats: [], listRecordChats: [],
@ -11,7 +17,10 @@ const containerInfo = {
chat: [], chat: [],
note: [], note: [],
isNote: false isNote: false
}, }
const containerInfo = {
state: initStateContainerInfo,
mutations: { mutations: {
addListWorkflow(state, payload) { addListWorkflow(state, payload) {
state.listworkflowLog = payload state.listworkflowLog = payload
@ -36,6 +45,9 @@ const containerInfo = {
}, },
isNote(state, payload) { isNote(state, payload) {
state.isNote = payload state.isNote = payload
},
resetStateContainerInfo(state) {
state = initStateContainerInfo
} }
}, },
actions: { actions: {
@ -66,17 +78,17 @@ const containerInfo = {
const pageToken = 0 const pageToken = 0
return requestListRecordChats({ tableName, recordId, pageSize, pageToken }) return requestListRecordChats({ tableName, recordId, pageSize, pageToken })
.then(response => { .then(response => {
var chatList = response.recordChatsList const chatList = response.recordChatsList
var listRecord = { const listRecord = {
recordChatsList: response.recordChatsList, recordChatsList: response.recordChatsList,
recordCount: response.recordCount, recordCount: response.recordCount,
nextPageToken: response.nextPageToken nextPageToken: response.nextPageToken
} }
chatList.forEach(chat => { chatList.forEach(chat => {
var uuid = chat.chatUuid const uuid = chat.chatUuid
requestListChatEntries({ uuid, pageSize, pageToken }) requestListChatEntries({ uuid, pageSize, pageToken })
.then(response => { .then(response => {
var listlogsChat = state.chat const listlogsChat = state.chat
let chatUpgrade = [] let chatUpgrade = []
let chatAll let chatAll
if (recordId === chat.recordId) { if (recordId === chat.recordId) {
@ -102,24 +114,25 @@ const containerInfo = {
console.warn(`Error getting List Chat: ${error.message}. Code: ${error.code}.`) console.warn(`Error getting List Chat: ${error.message}. Code: ${error.code}.`)
}) })
}, },
listRecordLogs({ commit, state }, params) { listRecordLogs({ commit }, params) {
const tableName = params.tableName const tableName = params.tableName
const recordId = params.recordId const recordId = params.recordId
const pageSize = 0 const pageSize = 0
const pageToken = 0 const pageToken = 0
return requestListRecordsLogs({ tableName, recordId, pageSize, pageToken }) return requestListRecordsLogs({ tableName, recordId, pageSize, pageToken })
.then(response => { .then(response => {
var listRecord = { const listRecord = {
recordCount: response.recordCount, recordCount: response.recordCount,
recorLogs: response.recordLogsList recorLogs: response.recordLogsList
} }
commit('addListRecordLogs', listRecord) commit('addListRecordLogs', listRecord)
return listRecord
}) })
.catch(error => { .catch(error => {
console.warn(`Error getting List Record Logs: ${error.message}. Code: ${error.code}.`) 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 tableName = params.tableName
const recordId = params.recordId const recordId = params.recordId
const pageSize = 0 const pageSize = 0
@ -127,28 +140,30 @@ const containerInfo = {
dispatch('listWorkflows', tableName) dispatch('listWorkflows', tableName)
return requestListWorkflowsLogs({ tableName, recordId, pageSize, pageToken }) return requestListWorkflowsLogs({ tableName, recordId, pageSize, pageToken })
.then(response => { .then(response => {
var workflowLog = { const workflowLog = {
recordCount: response.recordCount, recordCount: response.recordCount,
workflowLogsList: response.workflowLogsList, workflowLogsList: response.workflowLogsList,
nextPageToken: response.nextPageToken nextPageToken: response.nextPageToken
} }
commit('addListWorkflow', workflowLog) commit('addListWorkflow', workflowLog)
return workflowLog
}) })
.catch(error => { .catch(error => {
console.warn(`Error getting List workflow: ${error.message}. Code: ${error.code}.`) console.warn(`Error getting List workflow: ${error.message}. Code: ${error.code}.`)
}) })
}, },
listWorkflows({ commit, state }, tableName) { listWorkflows({ commit }, tableName) {
const pageSize = 0 const pageSize = 0
const pageToken = 0 const pageToken = 0
return requestListWorkflows({ tableName, pageSize, pageToken }) return requestListWorkflows({ tableName, pageSize, pageToken })
.then(response => { .then(response => {
var nodeWorflow = { const nodeWorflow = {
nextPageToken: response.nextPageToken, nextPageToken: response.nextPageToken,
recordCount: response.recordCount, recordCount: response.recordCount,
workflowsList: response.workflowsList workflowsList: response.workflowsList
} }
commit('addListWorkflows', nodeWorflow) commit('addListWorkflows', nodeWorflow)
return nodeWorflow
}) })
.catch(error => { .catch(error => {
console.warn(`Error getting List workflow: ${error.message}. Code: ${error.code}.`) 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 // Store used for set all related to context menu
// for Window, Process, Smart Browser andother customized component // for Window, Process, Smart Browser andother customized component
// See structure: // See structure:
// menu: [ // contextMenu: [
// { // {
// containerUuid: '', // containerUuid: '',
// relations: [], // relations: [],
@ -14,8 +14,7 @@ import { requestListDocumentActions, requestListDocumentStatuses } from '@/api/A
// lastAction: {} // lastAction: {}
// } // }
// ] // ]
const contextMenu = { const initStateContextMenu = {
state: {
contextMenu: [], contextMenu: [],
listDocumentStatus: { listDocumentStatus: {
defaultDocumentAction: undefined, defaultDocumentAction: undefined,
@ -29,7 +28,10 @@ const contextMenu = {
recordId: undefined, recordId: undefined,
recordUuid: undefined recordUuid: undefined
} }
}, }
const contextMenu = {
state: initStateContextMenu,
mutations: { mutations: {
setContextMenu(state, payload) { setContextMenu(state, payload) {
state.contextMenu.push(payload) state.contextMenu.push(payload)
@ -42,6 +44,9 @@ const contextMenu = {
}, },
addlistDocumentStatus(state, payload) { addlistDocumentStatus(state, payload) {
state.listDocumentStatus = payload state.listDocumentStatus = payload
},
resetContextMenu(state) {
state = initStateContextMenu
} }
}, },
actions: { actions: {

View File

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

View File

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

View File

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

View File

@ -7,8 +7,7 @@ import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
import language from '@/lang' import language from '@/lang'
import router from '@/router' import router from '@/router'
const processControl = { const initStateProcessControl = {
state: {
inExecution: [], // process not response from server inExecution: [], // process not response from server
isVisibleDialog: false, isVisibleDialog: false,
reportObject: {}, reportObject: {},
@ -24,7 +23,10 @@ const processControl = {
totalSelection: 0, totalSelection: 0,
errorSelection: 0, errorSelection: 0,
successSelection: 0 successSelection: 0
}, }
const processControl = {
state: initStateProcessControl,
mutations: { mutations: {
// Add process in execution // Add process in execution
addInExecution(state, payload) { addInExecution(state, payload) {
@ -49,8 +51,8 @@ const processControl = {
addStartedProcess(state, payload) { addStartedProcess(state, payload) {
state.process.push(payload) state.process.push(payload)
}, },
dataResetCacheProcess(state, payload) { resetStateProcessControl(state) {
state.process = payload state = initStateProcessControl
}, },
/** /**
* *
@ -78,16 +80,6 @@ const processControl = {
changeFormatReport(state, payload) { changeFormatReport(state, payload) {
state.reportFormat = 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) { setReportViewsList(state, payload) {
state.reportViewList.push(payload) state.reportViewList.push(payload)
}, },
@ -913,9 +905,6 @@ const processControl = {
if (reportFormat !== undefined) { if (reportFormat !== undefined) {
commit('changeFormatReport', reportFormat) commit('changeFormatReport', reportFormat)
} }
},
clearProcessControl({ commit }) {
commit('clearProcessControl')
} }
}, },
getters: { getters: {

View File

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

View File

@ -1,7 +1,6 @@
import Vue from 'vue' import Vue from 'vue'
const utils = { const initStateUtils = {
state: {
width: 0, width: 0,
height: 0, height: 0,
splitHeight: 50, splitHeight: 50,
@ -30,7 +29,10 @@ const utils = {
isLoaded: false isLoaded: false
}, },
panelRight: '' panelRight: ''
}, }
const utils = {
state: initStateUtils,
mutations: { mutations: {
setWidth(state, width) { setWidth(state, width) {
state.width = width state.width = width
@ -92,6 +94,9 @@ const utils = {
}, },
setPanelRight(state, payload) { setPanelRight(state, payload) {
state.panelRight = payload state.panelRight = payload
},
resetStateUtils(state) {
state = initStateUtils
} }
}, },
actions: { actions: {

View File

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

View File

@ -5,8 +5,7 @@ import { showMessage } from '@/utils/ADempiere/notification'
import language from '@/lang' import language from '@/lang'
import router from '@/router' import router from '@/router'
const windowControl = { const initStateWindowControl = {
state: {
inCreate: [], inCreate: [],
references: [], references: [],
windowOldRoute: { windowOldRoute: {
@ -18,7 +17,10 @@ const windowControl = {
tabSequenceRecord: [], tabSequenceRecord: [],
totalResponse: 0, totalResponse: 0,
totalRequest: 0 totalRequest: 0
}, }
const windowControl = {
state: initStateWindowControl,
mutations: { mutations: {
addInCreate(state, payload) { addInCreate(state, payload) {
state.inCreate.push(payload) state.inCreate.push(payload)
@ -43,6 +45,9 @@ const windowControl = {
}, },
setTotalRequest(state, payload) { setTotalRequest(state, payload) {
state.totalRequest = payload state.totalRequest = payload
},
resetStateWindowControl(state) {
state = initStateWindowControl
} }
}, },
actions: { actions: {

View File

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