fix(layout): 🐛 处理退出账号bug|处理登录token有时未保存bug|其他优化

This commit is contained in:
ZOL4789
2024-12-08 21:00:28 +08:00
parent 3ce419d8cf
commit 470efded2e
11 changed files with 1780 additions and 6759 deletions
+1 -1
View File
@@ -26,7 +26,7 @@
"========= 启动vue(tauri项目会连带执行不需要单独执行) =========": "",
"dev": "vite",
"========= 打包vue(tauri项目会连带执行不需要单独执行) =========": "",
"build": "vue-tsc --noEmit && vite build",
"build": "tsc --noEmit && vite build",
"========= 启动tauri =========": "",
"tauri:dev": "tauri dev",
"========= 打包tauri =========": "",
+1742 -2726
View File
File diff suppressed because it is too large Load Diff
+16 -13
View File
@@ -2299,8 +2299,8 @@ dependencies = [
"tauri-plugin-os",
"tauri-plugin-process",
"tauri-plugin-shell",
"tauri-plugin-sql",
"tauri-plugin-single-instance",
"tauri-plugin-sql",
"tauri-plugin-updater",
"tauri-plugin-upload",
"tauri-plugin-websocket",
@@ -5661,6 +5661,21 @@ dependencies = [
"tokio",
]
[[package]]
name = "tauri-plugin-single-instance"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a25ac834491d089699a2bc9266a662faf373c9f779f05a2235bc6e4d9e61769a"
dependencies = [
"log",
"serde",
"serde_json",
"tauri",
"thiserror",
"windows-sys 0.59.0",
"zbus",
]
[[package]]
name = "tauri-plugin-sql"
version = "2.0.2"
@@ -5678,18 +5693,6 @@ dependencies = [
"thiserror",
"time",
"tokio",
name = "tauri-plugin-single-instance"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a25ac834491d089699a2bc9266a662faf373c9f779f05a2235bc6e4d9e61769a"
dependencies = [
"log",
"serde",
"serde_json",
"tauri",
"thiserror",
"windows-sys 0.59.0",
"zbus",
]
[[package]]
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
{"default":{"identifier":"default","description":"Capability for the main window","local":true,"windows":["*"],"permissions":["core:window:default","core:window:allow-create","core:window:allow-start-dragging","core:window:allow-close","core:window:allow-hide","core:window:allow-center","core:window:allow-show","core:window:allow-maximize","core:window:allow-minimize","core:window:allow-destroy","core:window:allow-is-focused","core:window:allow-is-fullscreen","core:window:allow-set-focus","core:window:allow-set-position","core:window:allow-scale-factor","core:window:allow-unminimize","core:window:allow-set-always-on-top","core:window:allow-set-size","core:window:allow-set-min-size","core:window:allow-unmaximize","core:window:allow-set-fullscreen","core:webview:allow-create-webview","core:webview:allow-create-webview-window","core:webview:allow-internal-toggle-devtools","core:webview:allow-set-webview-size","core:webview:allow-webview-size","core:event:default","core:event:allow-listen","os:default","os:allow-os-type","os:allow-arch","os:allow-version","os:allow-hostname","process:default","process:allow-exit","clipboard-manager:allow-clear","clipboard-manager:allow-write-image","http:allow-fetch","http:allow-fetch-cancel","http:allow-fetch-read-body","http:allow-fetch-send","core:tray:default","core:tray:allow-get-by-id","shell:default","shell:allow-open","autostart:allow-enable","autostart:allow-disable","autostart:allow-is-enabled","dialog:allow-confirm","core:resources:allow-close","sql:allow-load","sql:allow-execute","sql:allow-select","sql:allow-close",{"identifier":"http:default","allow":[{"url":"http://**"},{"url":"https://**"},{"url":"http://*:*"},{"url":"https://*:*"}]}]},"desktop-capability":{"identifier":"desktop-capability","description":"","local":true,"windows":["home"],"permissions":["updater:default","updater:allow-check","updater:allow-download","updater:allow-install"],"platforms":["macOS","windows","linux"]}}
+4 -1
View File
@@ -36,6 +36,8 @@ impl<R: Runtime> CustomInit for tauri::Builder<R> {
}
}
}))
.plugin(tauri_plugin_sql::Builder::new().build())
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
.plugin(tauri_plugin_updater::Builder::new().build())
}
@@ -86,7 +88,8 @@ impl<R: Runtime> CustomInit for tauri::Builder<R> {
}
WindowEvent::CloseRequested { api, .. } => {
if window.label().eq("home") {
match get_user_info().get_is_sign() {
let result = get_user_info().get_is_sign();
match result {
// 处理非正常关闭的情况, 并且还是在登录状态时才发送下线通知
Ok(is_sign) if is_sign => {
window.app_handle().emit("offline", ()).unwrap();
-4
View File
@@ -8,14 +8,10 @@ use user_cmd::{audio, default_window_icon, get_user_info, save_user_info, screen
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_sql::Builder::new().build())
.plugin(tauri_plugin_updater::Builder::new().build())
.init_plugin()
.init_webwindow_event()
.init_window_event()
.setup(move |app| {
app.handle()
.plugin(tauri_plugin_global_shortcut::Builder::new().build())?;
tray::create_tray(app.handle())?;
Ok(())
})
+3 -3
View File
@@ -246,9 +246,9 @@ useMitt.on('handleCloseWin', handleCloseWin)
onMounted(() => {
window.addEventListener('resize', handleResize)
osType.value = type()
unOffline = listen('offline', async () => {
await apis.offline().catch(() => {})
await exit(0)
unOffline = listen('offline', () => {
// 不一定成功
offline()
})
})
+4 -5
View File
@@ -76,9 +76,9 @@ export const useMsgInput = (messageInputDom: Ref) => {
{ label: '另存为', icon: 'Importing', disabled: true },
{ label: '全部选择', icon: 'check-one' }
])
const db = ref<Database>()
watchEffect(() => {
chatKey.value = chat.value.sendKey
if (!ait.value && personList.value.length > 0) {
@@ -94,8 +94,7 @@ export const useMsgInput = (messageInputDom: Ref) => {
chat.value.sendKey = v
})
onMounted(() => {
onMounted(async () => {
db.value = await Database.load('sqlite:sqlite.db')
await db.value.execute(`
CREATE TABLE IF NOT EXISTS message (
@@ -123,7 +122,7 @@ export const useMsgInput = (messageInputDom: Ref) => {
msgInput.value = event
})
})
/** 正在输入拼音时触发 */
messageInputDom.value.addEventListener('compositionstart', () => {
isChinese.value = true
+1 -1
View File
@@ -97,7 +97,7 @@ const moreList = ref<OPT.L.MoreList[]>([
click: async () => {
// rust保存用户信息
await invoke('save_user_info', {
userId: '',
userId: -1,
username: '',
token: '',
portrait: '',
+7 -6
View File
@@ -282,6 +282,7 @@ const normalLogin = async () => {
userStore.userInfo = account
loginHistoriesStore.addLoginHistory(account)
await setLoginState()
// rust保存用户信息
await invoke('save_user_info', {
userId: account.uid,
@@ -289,11 +290,10 @@ const normalLogin = async () => {
token: account.token,
portrait: '',
isSign: true
}).finally(() => {
// 打开主界面
openHomeWindow()
})
await setLoginState()
// 打开主界面
await openHomeWindow()
})
.catch(() => {
loading.value = false
@@ -316,6 +316,7 @@ const autoLogin = () => {
loginText.value = '登录成功, 正在跳转'
loading.value = false
const userDetail = await apis.getUserDetail()
await setLoginState()
// rust保存用户信息
await invoke('save_user_info', {
userId: userDetail.uid,
@@ -323,9 +324,9 @@ const autoLogin = () => {
token: '',
portrait: '',
isSign: true
}).finally(() => {
openHomeWindow()
})
await openHomeWindow()
await setLoginState()
})
.catch(() => {
localStorage.removeItem('TOKEN')