From 8e9baff321bf3661279c5290963fd1df9d894d7c Mon Sep 17 00:00:00 2001 From: liumengyi Date: Mon, 3 Mar 2025 09:13:06 +0800 Subject: [PATCH] * [misc,done,0.5h] move to js. --- lib/zin/wg/docapp/js/v1.js | 26 ++++++++++++++++++++++ lib/zin/wg/docapp/v1.php | 39 +++++++-------------------------- lib/zin/wg/history/js/v1.js | 26 ++++++++++++++++++++++ lib/zin/wg/history/v1.php | 43 +++++++++++-------------------------- 4 files changed, 73 insertions(+), 61 deletions(-) create mode 100644 lib/zin/wg/history/js/v1.js diff --git a/lib/zin/wg/docapp/js/v1.js b/lib/zin/wg/docapp/js/v1.js index 3dacb2e6af..6f74739019 100644 --- a/lib/zin/wg/docapp/js/v1.js +++ b/lib/zin/wg/docapp/js/v1.js @@ -1948,3 +1948,29 @@ window.docAppCustomRenders = customRenders; window.getDocApp = getDocApp; window.getDocAppLang = getLang; window.docAppHasPriv = hasPriv; + +window.getFileActions = function(file) +{ + let fileActions = []; + + let canPreview = false; + let officeTypes = 'doc|docx|xls|xlsx|ppt|pptx|pdf'; + let isOfficeFile = officeTypes.includes(file.extension); + let previewExtension = 'txt|jpg|jpeg|gif|png|bmp|mp4'; + if(previewExtension.includes(file.extension)) canPreview = true; + if(libreOfficeTurnon && isOfficeFile) canPreview = true; + if(canPreview) + { + let previewAction = {icon: 'eye', title: previewLang, url: previewLink.replace('{id}', file.id).replace('\\', ''), className: 'text-primary', target: '_blank'}; + if(!isOfficeFile) + { + previewAction['data-toggle'] = 'modal'; + previewAction['data-size'] = 'lg'; + delete previewAction.target; + } + fileActions.push(previewAction); + } + + fileActions.push({icon: 'download', title: downloadLang, url: downloadLink.replace('{id}', file.id).replace('\\', ''), className: 'text-primary', target: '_blank'}); + return fileActions; +} diff --git a/lib/zin/wg/docapp/v1.php b/lib/zin/wg/docapp/v1.php index f14ddd8ecf..e7fe59f9ea 100644 --- a/lib/zin/wg/docapp/v1.php +++ b/lib/zin/wg/docapp/v1.php @@ -244,41 +244,18 @@ class docApp extends wg $fileListProps = array(); if($canDownload) { - $previewLink = helper::createLink('file', 'download', "fileID={id}&mouse=left"); + $previewLink = helper::createLink('file', 'download', "fileID={id}&mouse=left"); + jsVar('previewLang', $lang->file->preview); + jsVar('downloadLang', $lang->file->download); + jsVar('previewLink', $previewLink); + jsVar('downloadLink', $fileUrl); + jsVar('libreOfficeTurnon', isset($config->file->libreOfficeTurnon) && $config->file->libreOfficeTurnon == 1); + $fileListProps['fileUrl'] = $fileUrl; $fileListProps['target'] = '_blank'; $fileListProps['hoverItemActions'] = true; $fileListProps['itemProps'] = array('target' => '_blank'); - if($canDownload) $fileListProps['fileActions'] = jsCallback('file') - ->const('previewLang', $lang->file->preview) - ->const('downloadLang', $lang->file->download) - ->const('previewLink', $previewLink) - ->const('downloadLink', $fileUrl) - ->const('libreOfficeTurnon', isset($config->file->libreOfficeTurnon) && $config->file->libreOfficeTurnon == 1) - ->do(" - let fileActions = []; - - let canPreview = false; - let officeTypes = 'doc|docx|xls|xlsx|ppt|pptx|pdf'; - let isOfficeFile = officeTypes.includes(file.extension); - let previewExtension = 'txt|jpg|jpeg|gif|png|bmp|mp4'; - if(previewExtension.includes(file.extension)) canPreview = true; - if(libreOfficeTurnon && isOfficeFile) canPreview = true; - if(canPreview) - { - let previewAction = {icon: 'eye', title: previewLang, url: previewLink.replace('{id}', file.id).replace('\\', ''), className: 'text-primary', target: '_blank'}; - if(!isOfficeFile) - { - previewAction['data-toggle'] = 'modal'; - previewAction['data-size'] = 'lg'; - delete previewAction.target; - } - fileActions.push(previewAction); - } - - fileActions.push({icon: 'download', title: downloadLang, url: downloadLink.replace('{id}', file.id).replace('\\', ''), className: 'text-primary', target: '_blank'}); - return fileActions; - "); + $fileListProps['fileActions'] = jsCallback('file')->do('return getFileActions(file)'); } else { diff --git a/lib/zin/wg/history/js/v1.js b/lib/zin/wg/history/js/v1.js new file mode 100644 index 0000000000..2cc8fe4a57 --- /dev/null +++ b/lib/zin/wg/history/js/v1.js @@ -0,0 +1,26 @@ + +window.getFileActions = function(file) +{ + let fileActions = []; + + let canPreview = false; + let officeTypes = 'doc|docx|xls|xlsx|ppt|pptx|pdf'; + let isOfficeFile = officeTypes.includes(file.extension); + let previewExtension = 'txt|jpg|jpeg|gif|png|bmp|mp4'; + if(previewExtension.includes(file.extension)) canPreview = true; + if(libreOfficeTurnon && isOfficeFile) canPreview = true; + if(canPreview) + { + let previewAction = {icon: 'eye', title: previewLang, url: previewLink.replace('{id}', file.id).replace('\\', ''), className: 'text-primary', target: '_blank'}; + if(!isOfficeFile) + { + previewAction['data-toggle'] = 'modal'; + previewAction['data-size'] = 'lg'; + delete previewAction.target; + } + fileActions.push(previewAction); + } + + fileActions.push({icon: 'download', title: downloadLang, url: downloadLink.replace('{id}', file.id).replace('\\', ''), className: 'text-primary', target: '_blank'}); + return fileActions; +} diff --git a/lib/zin/wg/history/v1.php b/lib/zin/wg/history/v1.php index 9478b405b4..6f0a61e7f6 100644 --- a/lib/zin/wg/history/v1.php +++ b/lib/zin/wg/history/v1.php @@ -25,6 +25,11 @@ class history extends wg 'commentBtn?: string|array' // 是否允许添加备注。 ); + public static function getPageJS(): ?string + { + return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js'); + } + protected function onCheckErrors(): array | null { if(empty($this->prop('objectID'))) return array('The property "objectID" of widget "history" is undefined.'); @@ -105,39 +110,17 @@ class history extends wg $downloadLink = helper::createLink('file', 'download', "fileID={id}"); $downloadLink .= strpos($downloadLink, '?') === false ? '?' : '&'; $downloadLink .= session_name() . '=' . session_id(); + + jsVar('previewLang', $lang->file->preview); + jsVar('downloadLang', $lang->file->download); + jsVar('previewLink', $previewLink); + jsVar('downloadLink', $downloadLink); + jsVar('libreOfficeTurnon', isset($config->file->libreOfficeTurnon) && $config->file->libreOfficeTurnon == 1); + $fileListProps['fileUrl'] = $downloadLink; $fileListProps['hoverItemActions'] = true; $fileListProps['itemProps'] = array('target' => '_blank'); - $fileListProps['fileActions'] = jsCallback('file') - ->const('previewLang', $lang->file->preview) - ->const('downloadLang', $lang->file->download) - ->const('previewLink', $previewLink) - ->const('downloadLink', $downloadLink) - ->const('libreOfficeTurnon', isset($config->file->libreOfficeTurnon) && $config->file->libreOfficeTurnon == 1) - ->do(" - let fileActions = []; - - let canPreview = false; - let officeTypes = 'doc|docx|xls|xlsx|ppt|pptx|pdf'; - let isOfficeFile = officeTypes.includes(file.extension); - let previewExtension = 'txt|jpg|jpeg|gif|png|bmp|mp4'; - if(previewExtension.includes(file.extension)) canPreview = true; - if(libreOfficeTurnon && isOfficeFile) canPreview = true; - if(canPreview) - { - let previewAction = {icon: 'eye', title: previewLang, url: previewLink.replace('{id}', file.id).replace('\\', ''), className: 'text-primary', target: '_blank'}; - if(!isOfficeFile) - { - previewAction['data-toggle'] = 'modal'; - previewAction['data-size'] = 'lg'; - delete previewAction.target; - } - fileActions.push(previewAction); - } - - fileActions.push({icon: 'download', title: downloadLang, url: downloadLink.replace('{id}', file.id).replace('\\', ''), className: 'text-primary', target: '_blank'}); - return fileActions; - "); + $fileListProps['fileActions'] = jsCallback('file')->do('return getFileActions(file)'); } return zui::historyPanel