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