|
|
|
|
@ -8,6 +8,7 @@ import { useTabsStore } from '@renderer/store/tabs'
|
|
|
|
|
import { NIcon } from 'naive-ui'
|
|
|
|
|
import { CloseCircleOutline } from '@vicons/ionicons5'
|
|
|
|
|
import eventBus from '@renderer/utils/eventBus'
|
|
|
|
|
import type { WebviewTag } from 'electron'
|
|
|
|
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
const tabsStore = useTabsStore()
|
|
|
|
|
@ -43,52 +44,42 @@ onBeforeUnmount(() => {
|
|
|
|
|
const navigateToLogout = async () => {
|
|
|
|
|
// 定义登出脚本
|
|
|
|
|
const logoutScript = `
|
|
|
|
|
// 尝试找到登出按钮并点击
|
|
|
|
|
const logoutSelectors = [
|
|
|
|
|
'#logout',
|
|
|
|
|
'[href*="logout"]',
|
|
|
|
|
'button[onclick*="logout"]',
|
|
|
|
|
'.logout-btn'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
let foundLogout = false
|
|
|
|
|
|
|
|
|
|
for (const selector of logoutSelectors) {
|
|
|
|
|
const btn = document.querySelector(selector)
|
|
|
|
|
if (btn) {
|
|
|
|
|
btn.click()
|
|
|
|
|
foundLogout = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 清除本地存储
|
|
|
|
|
localStorage.clear()
|
|
|
|
|
sessionStorage.clear()
|
|
|
|
|
|
|
|
|
|
// 清除cookies
|
|
|
|
|
document.cookie.split(";").forEach(c => {
|
|
|
|
|
document.cookie = c.replace(/^ +/, "")
|
|
|
|
|
.replace(/=.*/, "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
foundLogout
|
|
|
|
|
(function() {
|
|
|
|
|
const exitButtons = Array.from(document.querySelectorAll('*')).filter(el =>
|
|
|
|
|
/退出\s*(登录)?/.test(el.textContent?.trim())
|
|
|
|
|
);
|
|
|
|
|
console.log(exitButtons)
|
|
|
|
|
if (exitButtons.length > 0) {
|
|
|
|
|
exitButtons.forEach(el => {
|
|
|
|
|
el.click()
|
|
|
|
|
})
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
})();
|
|
|
|
|
`
|
|
|
|
|
const webviews = document.querySelectorAll('webview')
|
|
|
|
|
const webviews = document.querySelectorAll('webview') as NodeListOf<WebviewTag>
|
|
|
|
|
console.log(webviews)
|
|
|
|
|
// 遍历所有 webview 执行登出
|
|
|
|
|
webviews.forEach(webview => {
|
|
|
|
|
webview.addEventListener('close', () => {
|
|
|
|
|
console.log('webview被关闭')
|
|
|
|
|
// webview.src = 'about:blank'
|
|
|
|
|
// webview.executeJavaScript(logoutScript)
|
|
|
|
|
console.log('webview被关闭')
|
|
|
|
|
webview.executeJavaScript(logoutScript).then(success => {
|
|
|
|
|
if (!success) {
|
|
|
|
|
console.warn('未在webview中找到退出按钮');
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
webview.loadURL('https://12366.chinatax.gov.cn/usercenter/login/out')
|
|
|
|
|
// webview.addEventListener('close', () => {
|
|
|
|
|
// console.log('webview被关闭')
|
|
|
|
|
// // webview.src = 'about:blank'
|
|
|
|
|
// webview.executeJavaScript(logoutScript)
|
|
|
|
|
// })
|
|
|
|
|
// ✅ 正确调用 Electron 的 webview API
|
|
|
|
|
// webview.executeJavaScript(logoutScript)
|
|
|
|
|
// .then(success => {
|
|
|
|
|
// if (success) {
|
|
|
|
|
// console.log('登出脚本执行成功')
|
|
|
|
|
// webview.reload(); // 刷新页面
|
|
|
|
|
// webview.reload() // 刷新页面
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// .catch(err => console.error('脚本执行失败:', err))
|
|
|
|
|
@ -109,8 +100,17 @@ const navigateToLogout = async () => {
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="web-content">
|
|
|
|
|
<webview v-for="tab in tabsStore.tabs" v-show="tab.id === tabsStore.currentTabId" :key="tab.id" :src="tab.url"
|
|
|
|
|
sandbox="allow-same-origin allow-scripts" frameborder="0" class="webview" :data-tab-id="tab.id"></webview>
|
|
|
|
|
<webview
|
|
|
|
|
v-for="tab in tabsStore.tabs"
|
|
|
|
|
v-show="tab.id === tabsStore.currentTabId"
|
|
|
|
|
:key="tab.id"
|
|
|
|
|
:src="tab.url"
|
|
|
|
|
sandbox="allow-same-origin allow-scripts"
|
|
|
|
|
frameborder="0"
|
|
|
|
|
class="webview"
|
|
|
|
|
:data-tab-id="tab.id"
|
|
|
|
|
allowpopups>
|
|
|
|
|
</webview>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|