change
This commit is contained in:
parent
3a07dae8b3
commit
35be5445b6
|
@ -1,6 +1,7 @@
|
||||||
import type { Block, Layout } from '@/layout/layout.types'
|
import type { Block, Layout } from '@/layout/layout.types'
|
||||||
import useLayoutStore from '@/layout/useLayoutStore'
|
import useLayoutStore from '@/layout/useLayoutStore'
|
||||||
import useRouterStore from '@/useRouterStore'
|
import useRouterStore from '@/useRouterStore'
|
||||||
|
import { sendParent } from '@/utils/parent'
|
||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { computed, reactive, ref, watch } from 'vue'
|
import { computed, reactive, ref, watch } from 'vue'
|
||||||
|
@ -22,27 +23,24 @@ const defaultUserInfo: UserInfo = {
|
||||||
openId: ''
|
openId: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function areArraysEqualById(arr1: Block[], arr2: Block[]): boolean {
|
function areArraysEqualById(arr1: Block[], arr2: Block[]): boolean {
|
||||||
if (arr1.length !== arr2.length) {
|
if (arr1.length !== arr2.length) {
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将 arr2 转换为一个以 id 为键的映射
|
// 将 arr2 转换为一个以 id 为键的映射
|
||||||
|
|
||||||
|
|
||||||
// 检查 arr1 中的每个 item 是否在 arr2 中存在,并且值是否相同
|
// 检查 arr1 中的每个 item 是否在 arr2 中存在,并且值是否相同
|
||||||
for (let i = 0; i < arr1.length; i++) {
|
for (let i = 0; i < arr1.length; i++) {
|
||||||
console.log(arr1[i].id);
|
console.log(arr1[i].id)
|
||||||
console.log(arr2[i].id);
|
console.log(arr2[i].id)
|
||||||
|
|
||||||
if (arr1[i].id !== arr2[i].id) {
|
if (arr1[i].id !== arr2[i].id) {
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineStore('user', () => {
|
export default defineStore('user', () => {
|
||||||
|
@ -77,19 +75,20 @@ export default defineStore('user', () => {
|
||||||
token,
|
token,
|
||||||
async (val) => {
|
async (val) => {
|
||||||
localStorage.setItem('token', val)
|
localStorage.setItem('token', val)
|
||||||
|
if (!val) {
|
||||||
if (!val) return
|
sendParent(['logout'])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sendParent(['login', val])
|
||||||
const res = await request<UserInfo>('GET', '/api/profile')
|
const res = await request<UserInfo>('GET', '/api/profile')
|
||||||
Object.assign(profile, res)
|
Object.assign(profile, res)
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
watch(
|
watch(token, async (val) => {
|
||||||
token,
|
|
||||||
async (val) => {
|
|
||||||
if (!val) return
|
if (!val) return
|
||||||
console.log(val);
|
console.log(val)
|
||||||
|
|
||||||
const data = await request<Layout>('GET', '/api/backup')
|
const data = await request<Layout>('GET', '/api/backup')
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
@ -106,13 +105,11 @@ export default defineStore('user', () => {
|
||||||
// // addList.push(item)
|
// // addList.push(item)
|
||||||
// remoteAddList.value.push(item)
|
// remoteAddList.value.push(item)
|
||||||
// }
|
// }
|
||||||
if (localList.findIndex(val => val.id === item.id) === -1) {
|
if (localList.findIndex((val) => val.id === item.id) === -1) {
|
||||||
|
|
||||||
remoteAddList.value.push({ ...item })
|
remoteAddList.value.push({ ...item })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (remoteAddList.value.length > 0 || !areArraysEqualById(remoteList, localList)) {
|
if (remoteAddList.value.length > 0 || !areArraysEqualById(remoteList, localList)) {
|
||||||
// TODO: 交给张阳
|
// TODO: 交给张阳
|
||||||
// remoteAddList.value = addList
|
// remoteAddList.value = addList
|
||||||
|
@ -120,16 +117,15 @@ export default defineStore('user', () => {
|
||||||
|
|
||||||
useRouterStore().go('global-backup')
|
useRouterStore().go('global-backup')
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
)
|
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
token.value = ''
|
token.value = ''
|
||||||
Object.assign(profile, { ...defaultUserInfo })
|
Object.assign(profile, { ...defaultUserInfo })
|
||||||
}
|
}
|
||||||
const comineData = () => {
|
const comineData = () => {
|
||||||
if (!remoteAddList.value) return
|
if (!remoteAddList.value) return
|
||||||
console.log({ ...remoteAddList.value });
|
console.log({ ...remoteAddList.value })
|
||||||
remoteAddList.value.map(item => {
|
remoteAddList.value.map((item) => {
|
||||||
layout.state.content[layout.state.current].pages[layout.state.currentPage].list.push(item)
|
layout.state.content[layout.state.current].pages[layout.state.currentPage].list.push(item)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -138,7 +134,6 @@ export default defineStore('user', () => {
|
||||||
Object.assign(layout.state.content, remoteData.value.content)
|
Object.assign(layout.state.content, remoteData.value.content)
|
||||||
Object.assign(layout.state.dock, remoteData.value.dock)
|
Object.assign(layout.state.dock, remoteData.value.dock)
|
||||||
Object.assign(layout.state.dir, remoteData.value.dir)
|
Object.assign(layout.state.dir, remoteData.value.dir)
|
||||||
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
token,
|
token,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// 发送消息
|
// 发送消息
|
||||||
export function sendParent(data: ['openSide']) {
|
export function sendParent(data: ['openSide'] | ['login', string] | ['logout']) {
|
||||||
parent.window.postMessage(
|
parent.window.postMessage(
|
||||||
{
|
{
|
||||||
type: data[0],
|
type: data[0],
|
||||||
|
|
Loading…
Reference in New Issue