feat(short-drama-agent-front): 新增全局主题和左右布局切换
This commit is contained in:
1 parent
db9aea1694
commit
27ee9fd4ff
10 files changed
+709
-41
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
/** 全局工作台主导航所在的一侧。 */
|
||||
export type WorkspaceLayout = 'left' | 'right'
|
||||
|
||||
const storageKey = 'drama-studio-workspace-layout'
|
||||
|
||||
/**
|
||||
* 读取工作台布局,缺少偏好或无法访问存储时使用左侧导航。
|
||||
* @returns 已保存的主导航位置
|
||||
*/
|
||||
function readLayout(): WorkspaceLayout {
|
||||
try {
|
||||
if (localStorage.getItem(storageKey) === 'right') return 'right'
|
||||
} catch {
|
||||
/* 存储不可用时使用默认布局。 */
|
||||
}
|
||||
return 'left'
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存工作台布局偏好,存储不可用时仍允许在当前页面切换。
|
||||
* @returns 当前主导航位置
|
||||
*/
|
||||
export function useWorkspaceLayout() {
|
||||
/** 侧栏和外观工具栏共用的布局偏好。 */
|
||||
const layout = ref<WorkspaceLayout>(readLayout())
|
||||
watch(layout, value => {
|
||||
try {
|
||||
localStorage.setItem(storageKey, value)
|
||||
} catch {
|
||||
/* 存储不可用时保留当前会话的选择。 */
|
||||
}
|
||||
})
|
||||
return layout
|
||||
}
|
||||
Reference in new issue
Block a user