1
This commit is contained in:
@@ -33,7 +33,11 @@ const widgetState = computed(() => {
|
|||||||
|
|
||||||
const position = computed(() => {
|
const position = computed(() => {
|
||||||
if (isMobile.value || !isMounted.value) return { x: 0, y: 0 }
|
if (isMobile.value || !isMounted.value) return { x: 0, y: 0 }
|
||||||
return widgetState.value?.position ?? getDefaultPosition()
|
const storedPos = widgetState.value?.position
|
||||||
|
if (storedPos && storedPos.x >= 0 && storedPos.y >= 0) {
|
||||||
|
return storedPos
|
||||||
|
}
|
||||||
|
return getDefaultPosition()
|
||||||
})
|
})
|
||||||
|
|
||||||
const order = computed(() => {
|
const order = computed(() => {
|
||||||
@@ -59,11 +63,8 @@ function getDefaultPosition() {
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await nextTick()
|
await nextTick()
|
||||||
|
|
||||||
const storedData = localStorage.getItem('wufangzhen-settings')
|
const storedPos = widgetState.value?.position
|
||||||
const parsed = storedData ? JSON.parse(storedData) : null
|
if (!storedPos || storedPos.x < 0 || storedPos.y < 0) {
|
||||||
const storedWidget = parsed?.widgets?.find((w: { id: string }) => w.id === props.id)
|
|
||||||
|
|
||||||
if (!storedWidget) {
|
|
||||||
const defaultPos = getDefaultPosition()
|
const defaultPos = getDefaultPosition()
|
||||||
settingsStore.updateWidgetPosition(props.id, defaultPos)
|
settingsStore.updateWidgetPosition(props.id, defaultPos)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ export const useSettingsStore = defineStore('settings', () => {
|
|||||||
if (!existingIds.includes(id)) {
|
if (!existingIds.includes(id)) {
|
||||||
widgets.value.push({
|
widgets.value.push({
|
||||||
id,
|
id,
|
||||||
position: { x: 20, y: 20 + index * 120 },
|
position: { x: -1, y: -1 },
|
||||||
order: index
|
order: index
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user