fix: 修复客户端无法打开工作报告

This commit is contained in:
kuaifan 2025-06-02 08:22:04 +08:00
parent 991f050dbb
commit 678868153a
8 changed files with 64 additions and 33 deletions

1
electron/build.js vendored
View File

@ -559,7 +559,6 @@ async function startBuild(data) {
origin: "./",
homeUrl: utils.formatUrl(data.url),
apiUrl: utils.formatUrl(data.url) + "api/",
routeMode: "hash",
}
// information
if (data.id === 'app') {

View File

@ -59,7 +59,7 @@ const electronMenu = {
async saveImageAs(url, params) {
let extension = '';
if (utils.isLocalAssetPath(url)) {
if (utils.isLocalHost(url)) {
extension = utils.localAssetRestoreRealPath(url).split('.').pop().toLowerCase();
} else {
const urlExtension = url.split('.').pop().split(/[#?]/)[0].toLowerCase();
@ -89,7 +89,7 @@ const electronMenu = {
try {
if (electronMenu.isBlobOrDataUrl(url)) {
await electronMenu.writeNativeImage(filePath, nativeImage.createFromDataURL(url));
} else if (utils.isLocalAssetPath(url)) {
} else if (utils.isLocalHost(url)) {
await fs.promises.copyFile(utils.localAssetRestoreRealPath(url), filePath);
} else {
const writeStream = fs.createWriteStream(filePath)
@ -127,7 +127,7 @@ const electronMenu = {
if (params.linkURL || params.srcURL) {
const url = params.linkURL || params.srcURL;
if (!electronMenu.isBlobOrDataUrl(url) && !utils.isLocalAssetPath(url)) {
if (!electronMenu.isBlobOrDataUrl(url) && !utils.isLocalHost(url)) {
popupMenu.append(new MenuItem({
label: electronMenu.language.openInBrowser,
click: async function () {
@ -161,7 +161,7 @@ const electronMenu = {
clipboard.writeText(url.substring(MAILTO_PREFIX.length));
},
}));
} else if (!utils.isLocalAssetPath(url)) {
} else if (!utils.isLocalHost(url)) {
popupMenu.append(new MenuItem({
label: params.hasImageContents ? electronMenu.language.copyImageAddress : electronMenu.language.copyLinkAddress,
click: async function () {

View File

@ -129,7 +129,7 @@
return this.activeItem ? this.activeItem.title : 'Untitled'
},
canBrowser() {
return !(this.activeItem && /^file:/.test(this.activeItem.url))
return !(this.activeItem && this.isLocalHost(this.activeItem.url))
}
},
watch: {
@ -181,6 +181,23 @@
sendMessage(event, args) {
electron?.sendMessage(event, args)
},
/**
* 判断是否是本地URL
* @param url
* @returns {boolean}
*/
isLocalHost(url) {
if (!url) {
return false
}
try {
const uri = new URL(url)
return uri.hostname == "localhost"
} catch (e) {
return false
}
}
},
}

20
electron/utils.js vendored
View File

@ -623,12 +623,20 @@ const utils = {
},
/**
* 是否本地资源路径
* @param {string} url
* 判断是否是本地URL
* @param url
* @returns {boolean}
*/
isLocalAssetPath(url) {
return url.startsWith('local-asset://')
isLocalHost(url) {
if (!url) {
return false
}
try {
const uri = new URL(url)
return uri.hostname == "localhost"
} catch (e) {
return false
}
},
/**
@ -637,7 +645,7 @@ const utils = {
* @returns {string}
*/
localAssetRestoreRealPath(url) {
if (!utils.isLocalAssetPath(url)) {
if (!utils.isLocalHost(url)) {
return url
}
@ -664,7 +672,7 @@ const utils = {
loadUrl(browser, serverUrl, hash = null) {
if (serverUrl) {
if (hash) {
serverUrl = `${serverUrl}#${hash}`.replace(/\/*#\/*/g, '/')
serverUrl = `${serverUrl}#${hash}`
}
browser.loadURL(serverUrl).then(_ => { }).catch(_ => { })
} else {

View File

@ -3,6 +3,7 @@ const isEEUIApp = window && window.navigator && /eeui/i.test(window.navigator.us
const isSoftware = isElectron || isEEUIApp;
import {languageName, switchLanguage as $L} from "./language";
import {isLocalHost} from "./components/Replace/utils";
import './functions/common'
import './functions/eeui'
@ -77,7 +78,7 @@ VueRouter.prototype.push = function push(location) {
}
// 路由方式
const routeMode = (window && window.systemInfo && window.systemInfo.routeMode === 'hash') ? 'hash' : 'history';
const routeMode = isLocalHost(window.location) ? 'hash' : 'history';
const router = new VueRouter({mode: routeMode, routes});
// 进度条配置
@ -337,24 +338,24 @@ const $preload = async () => {
}
await store.dispatch("preload");
const hash = (window.location[routeMode === 'history' ? 'pathname' : 'hash']).replace(/^[#\/\s]+/, '');
const hash = (window.location[routeMode === 'hash' ? 'hash' : 'pathname']).replace(/^[#\/\s]+/, '');
if (hash !== 'preload') {
await $init()
return
}
window.__initializeApp = async (route) => {
if (/^https?:\/\//.test(route)) {
if ($A.getDomain(route) !== $A.getDomain($A.mainUrl())) {
window.__initializeApp = async (loadHash) => {
if (/^https?:\/\//.test(loadHash)) {
if ($A.getDomain(loadHash) !== $A.getDomain($A.mainUrl())) {
window.location.href = url;
return;
}
route = route.replace(/^https?:\/\/[^\/]+/, '');
loadHash = loadHash.replace(/^https?:\/\/[^\/]+/, '');
}
if (routeMode === 'hash') {
route = `#/${route.replace(/^[#\/\s]+/, '')}`;
loadHash = `#/${loadHash.replace(/^[#\/\s]+/, '')}`;
}
window.history.replaceState(null, '', route)
window.history.replaceState(null, '', loadHash)
await $init()
}
}

View File

@ -67,15 +67,20 @@ const convertLocalResourcePath = (() => {
})()
/**
* 是否是本地资源路径
* 是否是本地URL
* @param url
* @returns {*}
*/
const isLocalResourcePath = (url) => {
return url && (
url.startsWith('file://') ||
url.startsWith('local-asset://')
)
const isLocalHost = (url) => {
if (!url) {
return false
}
try {
const uri = new URL(url)
return uri.hostname == "localhost"
} catch (e) {
return false
}
}
export {convertLocalResourcePath, isLocalResourcePath}
export {convertLocalResourcePath, isLocalHost}

View File

@ -672,7 +672,7 @@ import longpress from "../../../directives/longpress";
import TransferDom from "../../../directives/transfer-dom";
import resizeObserver from "../../../directives/resize-observer";
import {languageList} from "../../../language";
import {isLocalResourcePath} from "../../../components/Replace/utils";
import {isLocalHost} from "../../../components/Replace/utils";
import emitter from "../../../store/events";
import Forwarder from "./Forwarder/index.vue";
import {throttle} from "lodash";
@ -3086,7 +3086,7 @@ export default {
value: $A.thumbRestore(event.target.currentSrc),
})
}
if (data.type !== 'file' && !isLocalResourcePath(event.target.currentSrc)) {
if (data.type !== 'file' && !isLocalHost(event.target.currentSrc)) {
this.operateCopys.push({
type: 'imagedown',
icon: '',

View File

@ -1,6 +1,7 @@
import * as openpgp from 'openpgp_hi/lightweight';
import {initLanguage, languageList, languageName} from "../language";
import {$callData, $urlSafe, SSEClient} from '../utils'
import {isLocalHost} from "../components/Replace/utils";
import emitter from "./events";
import axios from "axios";
@ -1224,7 +1225,7 @@ export default {
userUrl({state}, url) {
return new Promise(resolve => {
// 如果是访问:服务器域名 且 当前是本地文件,则将服务器域名替换成本地路径
if ($A.getDomain(url) == $A.getDomain($A.mainUrl()) && window.location.protocol == "file:") {
if ($A.getDomain(url) == $A.getDomain($A.mainUrl()) && isLocalHost(window.location)) {
try {
const remoteURL = new URL(url)
if (/^\/(single|meeting)\//.test(remoteURL.pathname)) {
@ -1245,7 +1246,7 @@ export default {
userid: state.userId,
}
// 如果是访问:服务器域名 或 本地文件,则添加 token 参数
if ($A.getDomain(url) == $A.getDomain($A.mainUrl()) || $A.getProtocol(url) == "file:") {
if ($A.getDomain(url) == $A.getDomain($A.mainUrl()) || isLocalHost(window.location)) {
params.token = state.userToken
}
resolve($A.urlAddParams(url, params))
@ -1305,11 +1306,11 @@ export default {
if (typeof objects.params.allowAccess === "undefined") {
// 如果是本地文件,则允许跨域
objects.params.allowAccess = $A.getProtocol(objects.params.url) == "file:"
objects.params.allowAccess = isLocalHost(objects.params.url)
}
if (typeof objects.params.showProgress === "undefined") {
// 如果不是本地文件,则显示进度条
objects.params.showProgress = $A.getProtocol(objects.params.url) != "file:"
objects.params.showProgress = !isLocalHost(objects.params.url)
}
$A.eeuiAppOpenPage(objects)