mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
✨ deviceInfo 保存到数据库
This commit is contained in:
23
src/App.vue
23
src/App.vue
@@ -23,6 +23,7 @@ import TGSqlite from "./plugins/Sqlite";
|
|||||||
import { useAppStore } from "./store/modules/app";
|
import { useAppStore } from "./store/modules/app";
|
||||||
import { useUserStore } from "./store/modules/user";
|
import { useUserStore } from "./store/modules/user";
|
||||||
import { getBuildTime } from "./utils/TGBuild";
|
import { getBuildTime } from "./utils/TGBuild";
|
||||||
|
import TGRequest from "./web/request/TGRequest";
|
||||||
|
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const isMain = ref<boolean>(false);
|
const isMain = ref<boolean>(false);
|
||||||
@@ -64,6 +65,7 @@ async function listenOnInit(): Promise<void> {
|
|||||||
await tauri.invoke("register_deep_link");
|
await tauri.invoke("register_deep_link");
|
||||||
await getDeepLink();
|
await getDeepLink();
|
||||||
await checkAppLoad();
|
await checkAppLoad();
|
||||||
|
await checkDeviceFp();
|
||||||
try {
|
try {
|
||||||
await checkUserLoad();
|
await checkUserLoad();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -94,6 +96,27 @@ async function checkAppLoad(): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检测 deviceFp
|
||||||
|
async function checkDeviceFp(): Promise<void> {
|
||||||
|
const appData = await TGSqlite.getAppData();
|
||||||
|
const deviceInfo = appData.find((item) => item.key === "deviceInfo")?.value;
|
||||||
|
const deviceLocal = appStore.deviceInfo;
|
||||||
|
if (deviceInfo === undefined) {
|
||||||
|
if (deviceLocal.device_fp === "0000000000000") {
|
||||||
|
// 获取 deviceFp
|
||||||
|
appStore.deviceInfo = await TGRequest.Device.getFp(appStore.deviceInfo);
|
||||||
|
console.info("deviceInfo 已重新获取!");
|
||||||
|
}
|
||||||
|
await TGSqlite.saveAppData("deviceInfo", JSON.stringify(deviceLocal));
|
||||||
|
console.info("deviceInfo 数据已插入!");
|
||||||
|
} else if (JSON.parse(deviceInfo) !== deviceLocal) {
|
||||||
|
appStore.deviceInfo = JSON.parse(deviceInfo);
|
||||||
|
console.info("deviceInfo 数据已加载!");
|
||||||
|
} else {
|
||||||
|
console.info("deviceInfo 数据已同步!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 检测 ck,info 数据
|
// 检测 ck,info 数据
|
||||||
async function checkUserLoad(): Promise<void> {
|
async function checkUserLoad(): Promise<void> {
|
||||||
const ckDB = await TGSqlite.getCookie();
|
const ckDB = await TGSqlite.getCookie();
|
||||||
|
|||||||
@@ -490,6 +490,7 @@ async function confirmUpdateDevice(): Promise<void> {
|
|||||||
showSnackbar({
|
showSnackbar({
|
||||||
text: "设备信息已更新! DeviceFp: " + appStore.deviceInfo.device_fp,
|
text: "设备信息已更新! DeviceFp: " + appStore.deviceInfo.device_fp,
|
||||||
});
|
});
|
||||||
|
await TGSqlite.saveAppData("deviceInfo", JSON.stringify(appStore.deviceInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清除用户缓存
|
// 清除用户缓存
|
||||||
|
|||||||
8
src/types/Sqlite/AppData.d.ts
vendored
8
src/types/Sqlite/AppData.d.ts
vendored
@@ -1,18 +1,19 @@
|
|||||||
/**
|
/**
|
||||||
* @file types Sqlite AppData.d.ts
|
* @file types/Sqlite/AppData.d.ts
|
||||||
* @description Sqlite AppData 类型定义文件
|
* @description Sqlite AppData 类型定义文件
|
||||||
* @since Beta v0.3.3
|
* @since Beta v0.3.8
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare namespace TGApp.Sqlite.AppData {
|
declare namespace TGApp.Sqlite.AppData {
|
||||||
/**
|
/**
|
||||||
* @description AppData 数据库 - key 枚举
|
* @description AppData 数据库 - key 枚举
|
||||||
* @since Beta v0.3.3
|
* @since Beta v0.3.8
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
* @property {string} APP_VERSION - App 版本
|
* @property {string} APP_VERSION - App 版本
|
||||||
* @property {string} DATA_UPDATED - 数据库更新时间
|
* @property {string} DATA_UPDATED - 数据库更新时间
|
||||||
* @property {string} COOKIE - Cookie
|
* @property {string} COOKIE - Cookie
|
||||||
* @property {string} USER_INFO - 用户信息
|
* @property {string} USER_INFO - 用户信息
|
||||||
|
* @property {string} DEVICE_INFO - 设备信息
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
enum DBKey {
|
enum DBKey {
|
||||||
@@ -20,6 +21,7 @@ declare namespace TGApp.Sqlite.AppData {
|
|||||||
DATA_UPDATED = "dataUpdated",
|
DATA_UPDATED = "dataUpdated",
|
||||||
COOKIE = "cookie",
|
COOKIE = "cookie",
|
||||||
USER_INFO = "userInfo",
|
USER_INFO = "userInfo",
|
||||||
|
DEVICE_INFO = "deviceInfo",
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user