Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
yy-wow committed Nov 28, 2024
1 parent 14f17b7 commit 60dd530
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions packages/layout/src/DesignPlugins.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@
<script>
import { reactive, ref, watch } from 'vue'
import { Popover, Tooltip } from '@opentiny/vue'
import { useLayout, usePage, META_APP } from '@opentiny/tiny-engine-meta-register'
import { useLayout, usePage, useModal, META_APP } from '@opentiny/tiny-engine-meta-register'
import { PublicIcon } from '@opentiny/tiny-engine-common'
const STORAGE_KEY = 'tiny-engine-fixed-panels'
export default {
components: {
TinyPopover: Popover,
Expand All @@ -98,6 +100,7 @@ export default {
const iconComponents = {}
const pluginRef = ref(null)
const { isTemporaryPage } = usePage()
const { message } = useModal()
const pluginState = useLayout().getPluginState()
props.plugins.forEach(({ id, entry, icon }) => {
Expand Down Expand Up @@ -155,10 +158,28 @@ export default {
? pluginState.fixedPanels?.filter((item) => item !== pluginName)
: [...pluginState.fixedPanels, pluginName]
localStorage.setItem('fixedPanels', pluginState.fixedPanels)
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(pluginState.fixedPanels))
} catch (error) {
message({ message: `'Failed to persist fixed panels state:'${error}`, status: 'error' })
}
}
const restoreFixedPanels = () => {
try {
const storedPanels = localStorage.getItem(STORAGE_KEY)
pluginState.fixedPanels = storedPanels ? JSON.parse(storedPanels) : []
if (!Array.isArray(pluginState.fixedPanels)) {
pluginState.fixedPanels = []
}
} catch (error) {
message({ message: `'Failed to restore fixed panels state:'${error}`, status: 'error' })
pluginState.fixedPanels = []
}
}
pluginState.fixedPanels = localStorage.getItem('fixedPanels') || []
restoreFixedPanels()
return {
state,
Expand Down

0 comments on commit 60dd530

Please sign in to comment.