From 9a74b31eaca58cd5903159f21b03503335775586 Mon Sep 17 00:00:00 2001
From: expdsn <18111002318@163.com>
Date: Wed, 13 Nov 2024 19:51:52 +0800
Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=87=E4=BB=BD1/2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/App.vue | 12 +++++--
src/GlobalModal.tsx | 31 ++++++++--------
src/config.ts | 2 +-
src/useRouterStore.ts | 2 +-
src/user/BackupRecovery.tsx | 49 +++++++++++++++++++++++++
src/user/UserPage.tsx | 9 ++---
src/user/useUserStore.ts | 71 +++++++++++++++++++++++++++++++------
7 files changed, 143 insertions(+), 33 deletions(-)
create mode 100644 src/user/BackupRecovery.tsx
diff --git a/src/App.vue b/src/App.vue
index 2e89d85..6b57a3d 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -16,6 +16,7 @@ import useLayoutStore from './layout/useLayoutStore'
import WelcomePage from './layout/grid/WelcomePage'
import TomatoPage from './layout/grid/TomatoPage'
import useRouterStore from './useRouterStore'
+import BackupRecovery from './user/BackupRecovery'
const Grid = asyncLoader(() => import('./layout/grid'))
const Fox = asyncLoader(() => import('./fox'))
const settings = useSettingsStore()
@@ -50,14 +51,21 @@ const layout = useLayoutStore()
(layout.state.simple && settings.state.simpleModeShowString.includes('showDock'))
"
/>
-
diff --git a/src/GlobalModal.tsx b/src/GlobalModal.tsx
index 3e8ea1c..42010f5 100644
--- a/src/GlobalModal.tsx
+++ b/src/GlobalModal.tsx
@@ -18,7 +18,7 @@ export default defineComponent(() => {
router.path.startsWith('widget-') ||
router.path === 'global-search' ||
router.path === 'global-adder' ||
- router.path === 'global-background'
+ router.path === 'global-background'
)
const full = ref(false)
watch(router, () => {
@@ -93,20 +93,21 @@ export default defineComponent(() => {
) : router.path === 'global-background' ? (
- ) : router.path.startsWith('widget-') ? (
- (() => {
- const name = router.path.split('-')[1]
- const selected = widgetList.find((el) => el.name === name)
- if (!selected)
- return (
-
- 组件维护中
-
- )
- const compo = selected.modal
- return
- })()
- ) : null}
+ ) :
+ router.path.startsWith('widget-') ? (
+ (() => {
+ const name = router.path.split('-')[1]
+ const selected = widgetList.find((el) => el.name === name)
+ if (!selected)
+ return (
+
+ 组件维护中
+
+ )
+ const compo = selected.modal
+ return
+ })()
+ ) : null}
diff --git a/src/config.ts b/src/config.ts
index fe9beda..ebb6f68 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -20,7 +20,7 @@ export const apiBase = import.meta.env.PROD
// 后端 cdn 加速地址
export const cdnBase = import.meta.env.PROD ? apiBase : apiBase
-
+// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NzJkYjg5OGUxMjY5NDc1ODYwMmYwMTgifQ.8fpdr_HPgxyU0yr-8f6nGdbHYjsFRlBa2lvjc0Zhe-A
// 图片后缀名
export const imgArr = [
'bmp',
diff --git a/src/useRouterStore.ts b/src/useRouterStore.ts
index 5d39ebc..52dd385 100644
--- a/src/useRouterStore.ts
+++ b/src/useRouterStore.ts
@@ -1,7 +1,7 @@
import { defineStore } from 'pinia'
import { computed, ref, watch } from 'vue'
-export type GlobalStr = 'search' | 'block' | 'adder' | 'login' | 'background'
+export type GlobalStr = 'search' | 'block' | 'adder' | 'login' | 'background' | 'backup'
export type SettingStr =
| 'user'
| 'background'
diff --git a/src/user/BackupRecovery.tsx b/src/user/BackupRecovery.tsx
new file mode 100644
index 0000000..56adeda
--- /dev/null
+++ b/src/user/BackupRecovery.tsx
@@ -0,0 +1,49 @@
+import { defineComponent, ref, Transition } from 'vue'
+import useRouterStore from '@/useRouterStore'
+import { Radio, RadioGroup } from 'ant-design-vue'
+import useUserStore from './useUserStore'
+
+
+export default defineComponent(() => {
+ const router = useRouterStore()
+ const userStore = useUserStore()
+ const select = ref(1)
+ return () => (
+
+
+
+
+
+
+
+
选择账号数据
+
+
检测到云端数据和本地数据不一致,请选择合并或者覆盖
+
{
+ select.value = e.target.value
+ }} class={"flex flex-col text-[#333] gap-y-3"}>
+ 合并数据
+ 覆盖数据
+
+
+
{
+ if (select.value === 1) {
+ userStore.comineData()
+ } else {
+ userStore.coverageData()
+ }
+ router.replace('')
+ }}
+ >
+
+
+
+
+
+
+ )
+})
diff --git a/src/user/UserPage.tsx b/src/user/UserPage.tsx
index f8afa8a..22122aa 100644
--- a/src/user/UserPage.tsx
+++ b/src/user/UserPage.tsx
@@ -39,12 +39,13 @@ export default defineComponent(() => {
性别:
-
- {user.profile.gender === 1 ? '男' : '女'}
+
+ {user.profile.gender === 1 ? '男' : user.profile.gender === 2 ? '女' : '未知'}
- )}
+ )
+ }
{user.isLogin ? (
@@ -90,6 +91,6 @@ export default defineComponent(() => {
)}
-
+
)
})
diff --git a/src/user/useUserStore.ts b/src/user/useUserStore.ts
index e632a43..9141eb6 100644
--- a/src/user/useUserStore.ts
+++ b/src/user/useUserStore.ts
@@ -1,8 +1,9 @@
import type { Block, Layout } from '@/layout/layout.types'
import useLayoutStore from '@/layout/useLayoutStore'
+import useRouterStore from '@/useRouterStore'
import request from '@/utils/request'
import { defineStore } from 'pinia'
-import { computed, reactive, ref, watch } from 'vue'
+import { computed, reactive, ref, toRefs, watch } from 'vue'
interface UserInfo {
id: string
@@ -41,21 +42,55 @@ function getLinkList(data: Layout) {
}
return list
}
+function areArraysEqualById(arr1: Block[], arr2: Block[]): boolean {
+ if (arr1.length !== arr2.length) {
+ return false;
+ }
+
+ // 将 arr2 转换为一个以 id 为键的映射
+ const arr2Map = new Map(arr2.map(item => [item.id, item]));
+
+ // 检查 arr1 中的每个 item 是否在 arr2 中存在,并且值是否相同
+ for (const item1 of arr1) {
+ const item2 = arr2Map.get(item1.id);
+ if (!item2 || JSON.stringify(item1) !== JSON.stringify(item2)) {
+ return false;
+ }
+ }
+
+ return true;
+}
export default defineStore('user', () => {
const token = ref(localStorage.getItem('token') || '')
- watch(token, (val) => {
- localStorage.setItem('token', val)
- })
+ const remoteData = ref(null)
+ const remoteAddList = ref([])
+
const profile = reactive({ ...defaultUserInfo })
const layout = useLayoutStore()
+
+ const isLogin = computed(() => !!token.value && !!profile.id)
+
+ watch(
+ token,
+ async (val) => {
+ localStorage.setItem('token', val)
+
+ if (!val) return
+ const res = await request('GET', '/api/profile')
+ Object.assign(profile, res)
+ },
+ { immediate: true }
+ )
+
watch(
token,
async (val) => {
if (!val) return
- const res = await request('GET', '/api/profile')
- Object.assign(profile, res)
+ console.log(val);
+
const data = await request('GET', '/api/backup')
+ if (!data) return
const remoteList = getLinkList(data)
const localList = getLinkList(layout.state)
const addList: Block[] = []
@@ -64,21 +99,37 @@ export default defineStore('user', () => {
addList.push(item)
}
}
- if (addList.length > 0) {
+ if (addList.length > 0 || areArraysEqualById(remoteList, localList) || (remoteList.length !== localList.length)) {
// TODO: 交给张阳
+ remoteAddList.value = addList
+ remoteData.value = data
+ useRouterStore().go('global-backup')
}
},
- { immediate: true }
)
- const isLogin = computed(() => !!token.value && !!profile.id)
const logout = () => {
token.value = ''
Object.assign(profile, { ...defaultUserInfo })
}
+ const comineData = () => {
+ if (!remoteData.value) return
+ Object.assign(layout.state.content[layout.state.currentPage].pages, remoteAddList.value)
+
+ }
+ const coverageData = () => {
+ if (!remoteData.value) return
+ console.log({ ...layout.state });
+ console.log({ ...remoteData.value });
+
+ Object.assign(layout.state, remoteData.value)
+
+ }
return {
token,
profile,
isLogin,
- logout
+ logout,
+ coverageData,
+ comineData
}
})