From ce816d6c2dc275d9119750cb2c6c94be8e71498a Mon Sep 17 00:00:00 2001 From: sunhao Date: Thu, 26 Jun 2025 18:04:27 +0800 Subject: [PATCH] * [bug #63677] fix doc app reload not work as expected. --- lib/zin/wg/docapp/js/v1.js | 92 ++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/lib/zin/wg/docapp/js/v1.js b/lib/zin/wg/docapp/js/v1.js index af98395867..7494b4aab0 100644 --- a/lib/zin/wg/docapp/js/v1.js +++ b/lib/zin/wg/docapp/js/v1.js @@ -1,13 +1,16 @@ -let lastAppUrl = ''; -let originalDocumentTitle = document.title; -let documentTitleSuffix = ' - ' + originalDocumentTitle.split(' - ').pop(); -let currentDocApp = null; -let currentUser = null; -let currentSpaceType = ''; -let userPrivs = {}; -let docLangData = null; -let docBasicModal = {}; -const savingDocData = {}; +if(!window.docAppData) window.docAppData = { + lastAppUrl: '', + originalDocumentTitle: document.title, + documentTitleSuffix: ' - ' + document.title.split(' - ').pop(), + currentDocApp: null, + currentUser: null, + currentSpaceType: '', + userPrivs: {}, + docLangData: null, + docBasicModal: {}, + savingDocData: {}, +}; +const docAppData = window.docAppData; window.setZentaoSlashMenu = function(menus, title, vision, position) { @@ -121,12 +124,12 @@ window.reloadZentaoList = function(blockID) */ window.getDocApp = function() { - if(!currentDocApp) + if(!docAppData.currentDocApp) { const docApp = $('#docApp').data('zui.DocApp'); - currentDocApp = docApp ? docApp.$ : null; + docAppData.currentDocApp = docApp ? docApp.$ : null; } - return currentDocApp; + return docAppData.currentDocApp; } /** @@ -138,13 +141,13 @@ window.getDocApp = function() */ window.getLang = function(key, args) { - if(!docLangData) + if(!docAppData.docLangData) { const docApp = getDocApp(); - docLangData = docApp ? docApp.props.langData : {}; + docAppData.docLangData = docApp ? docApp.props.langData : {}; } - if(typeof key !== 'string') return docLangData; - const value = docLangData[key]; + if(typeof key !== 'string') return docAppData.docLangData; + const value = docAppData.docLangData[key]; if(value === undefined) return; if(args) { @@ -162,7 +165,7 @@ window.getLang = function(key, args) */ window.hasPriv = function(priv, value) { - const setting = userPrivs[priv]; + const setting = docAppData.userPrivs[priv]; return value !== undefined ? setting === value : !!setting; } @@ -341,13 +344,13 @@ function handleSwitchView(mode, location, info) { url = zui.formatString(formatUrl, formatOptions).replace('&libID=0&moduleID=0&docID=0&mode=home&orderBy=id_desc&recTotal=0&recPerPage=0&pageID=1&filterType=&search=&noSpace=false', '').replace('&libID=0&moduleID=0&browseType=all¶m=&orderBy=&recTotal=0&recPerPage=20&pageID=1&mode=home&docID=0&search=', ''); } - if(url === lastAppUrl) return; - if(lastAppUrl && !$.apps.getAppUrl().endsWith(url)) $.apps.updateAppUrl(url, info.title ? (info.title + documentTitleSuffix) : originalDocumentTitle); - lastAppUrl = url; - if(docBasicModal.current) + if(url === docAppData.lastAppUrl) return; + if(docAppData.lastAppUrl && !$.apps.getAppUrl().endsWith(url)) $.apps.updateAppUrl(url, info.title ? (info.title + docAppData.documentTitleSuffix) : docAppData.originalDocumentTitle); + docAppData.lastAppUrl = url; + if(docAppData.docBasicModal.current) { - docBasicModal.current.destroy(); - docBasicModal = {}; + docAppData.docBasicModal.current.destroy(); + docAppData.docBasicModal = {}; } } @@ -359,6 +362,7 @@ function showDocBasicModal(parentID, docID, isDraft, modalType = 'doc') const libID = docApp.libID; const moduleID = docApp.moduleID; const url = $.createLink('doc', 'setDocBasic', `objectType=${spaceType}&objectID=${spaceID}&libID=${libID}&moduleID=${moduleID}&parentID=${parentID || 0}&docID=${docID || 0}&isDraft=${isDraft ? 'yes' : 'no'}&modalType=${modalType}`); + const docBasicModal = docAppData.docBasicModal; if(docBasicModal.doc === docID && docBasicModal.current) { @@ -384,7 +388,7 @@ function showDocBasicModal(parentID, docID, isDraft, modalType = 'doc') if(!docBasicModal.keepOnHide && docBasicModal.current) docBasicModal.current.destroy(); }, $onDestroy: () => { - if(docBasicModal.current) docBasicModal = {}; + if(docBasicModal.current) docAppData.docBasicModal = {}; } }); } @@ -393,7 +397,7 @@ function showDocBasicModal(parentID, docID, isDraft, modalType = 'doc') window.beforeSetDocBasicInfo = function(_, form) { - docBasicModal.keepOnHide = true; + docAppData.docBasicModal.keepOnHide = true; if (window.docBasicModalResolver) window.docBasicModalResolver(new FormData(form)); zui.Modal.query('#setDocBasicForm').hide(); return false; @@ -599,10 +603,10 @@ function handleSaveDoc(doc) }; if(doc.fromVersion) docData.fromVersion = doc.fromVersion; - if(savingDocData[doc.id]) + if(docAppData.savingDocData[doc.id]) { - mergeDocFormData(docData, savingDocData[doc.id]); - delete savingDocData[doc.id]; + mergeDocFormData(docData, docAppData.savingDocData[doc.id]); + delete docAppData.savingDocData[doc.id]; } return new Promise((resolve) => { @@ -653,7 +657,7 @@ function handleSaveDoc(doc) docApp.isSavingDoc = false; $(docApp.element).find('[zui-command^="saveDoc"],[zui-command^="saveNewDoc"]').removeAttr('disabled'); const {id, acl, users, addedBy} = doc; - if(acl == 'private' && !users.includes(currentUser) && addedBy !== currentUser) + if(acl == 'private' && !users.includes(docAppData.currentUser) && addedBy !== docAppData.currentUser) { if(docApp.hasEditingDoc) { @@ -1422,10 +1426,10 @@ const commands = const doc = {type: 'chapter', status: 'normal', parent: args[0]}; return submitNewDoc(doc, spaceID, libID, moduleID, formData).then(() => { docApp.load(null, null, null, {noLoading: false, picks: 'doc'}); - if(docBasicModal.current) + if(docAppData.docBasicModal.current) { - docBasicModal.current.destroy(); - docBasicModal = {}; + docAppData.docBasicModal.current.destroy(); + docAppData.docBasicModal = {}; } }); }); @@ -1548,7 +1552,7 @@ const commands = const docType = args[1] || doc.contentType; const saveEdited = args[2] || 0; showDocBasicModal(0, docID).then(formData => { - savingDocData[docID] = formData; + docAppData.savingDocData[docID] = formData; if(saveEdited == 1) { const docData = { @@ -1947,8 +1951,8 @@ function getFilterTypes(mode) { if(mode === 'home') { - if(currentSpaceType === 'project') return getLang('projectFilterTypes'); - if(currentSpaceType === 'product') return getLang('productFilterTypes'); + if(docAppData.currentSpaceType === 'project') return getLang('projectFilterTypes'); + if(docAppData.currentSpaceType === 'product') return getLang('productFilterTypes'); return getLang('spaceFilterTypes'); } if(mode === 'list') @@ -1970,8 +1974,8 @@ function isMatchFilter(type, filterType, item) { if(type === 'doc') { - if(filterType === 'createdByMe') return item.addedBy === currentUser; - if(filterType === 'editedByMe') return item.editedBy === currentUser; + if(filterType === 'createdByMe') return item.addedBy === docAppData.currentUser; + if(filterType === 'editedByMe') return item.editedBy === docAppData.currentUser; if(filterType === 'draft') return item.status === 'draft'; if(filterType === 'collect') return item.isCollector; if(filterType === 'released') return item.status === 'normal'; @@ -2162,10 +2166,10 @@ function initOfficePreview(options) */ window.setDocAppOptions = function(_, options) { - currentUser = options.currentUser; - currentSpaceType = options.spaceType; - userPrivs = options.privs; - docLangData = options.langData; + docAppData.currentUser = options.currentUser; + docAppData.currentSpaceType = options.spaceType; + docAppData.userPrivs = options.privs; + docAppData.docLangData = options.langData; if(options.canPreviewOffice && options.fileInfoUrl) initOfficePreview(options); @@ -2174,8 +2178,8 @@ window.setDocAppOptions = function(_, options) defaultState : {listType: '', libReleaseMap: {}}, commands : commands, customRenders : customRenders, - onCreateDoc : userPrivs.create ? handleCreateDoc : null, - onSaveDoc : userPrivs.edit ? handleSaveDoc : null, + onCreateDoc : docAppData.userPrivs.create ? handleCreateDoc : null, + onSaveDoc : docAppData.userPrivs.edit ? handleSaveDoc : null, canMoveDoc : canMoveDoc, onSwitchView : handleSwitchView, getActions : getActions,