ruoyi-plus-soybean/src/store/modules/app/index.ts

111 lines
3.0 KiB
TypeScript
Raw Normal View History

import { nextTick } from 'vue';
import { defineStore } from 'pinia';
2023-06-18 22:23:42 +08:00
import type { Socket } from 'socket.io-client';
import { LAYOUT_SCROLL_EL_ID } from '@soybeanjs/vue-materials';
interface AppState {
/** 滚动元素的id */
scrollElId: string;
/** 主体内容全屏 */
contentFull: boolean;
/** 禁用主体内容的水平方向的滚动 */
disableMainXScroll: boolean;
/** 重载页面(控制页面的显示) */
reloadFlag: boolean;
/** 项目配置的抽屉可见状态 */
settingDrawerVisible: boolean;
2022-01-08 20:49:21 +08:00
/** 侧边栏折叠状态 */
siderCollapse: boolean;
2022-01-08 20:49:21 +08:00
/** vertical-mix模式下 侧边栏的固定状态 */
mixSiderFixed: boolean;
2023-06-18 22:23:42 +08:00
/** socket.io 实例 */
socket: Socket | null;
}
export const useAppStore = defineStore('app-store', {
state: (): AppState => ({
scrollElId: LAYOUT_SCROLL_EL_ID,
contentFull: false,
disableMainXScroll: false,
reloadFlag: true,
settingDrawerVisible: false,
siderCollapse: false,
2023-06-18 22:23:42 +08:00
mixSiderFixed: false,
socket: null
}),
actions: {
/**
*
*/
getScrollConfig() {
const scrollEl = document.querySelector(`#${this.scrollElId}`);
const { scrollLeft = 0, scrollTop = 0 } = scrollEl || {};
return {
scrollEl,
scrollLeft,
scrollTop
};
},
/**
*
* @param duration - (ms)
*/
async reloadPage(duration = 0) {
this.reloadFlag = false;
await nextTick();
if (duration) {
setTimeout(() => {
this.reloadFlag = true;
}, duration);
} else {
this.reloadFlag = true;
}
setTimeout(() => {
document.documentElement.scrollTo({ left: 0, top: 0 });
}, 100);
},
/** 打开设置抽屉 */
openSettingDrawer() {
this.settingDrawerVisible = true;
},
/** 关闭设置抽屉 */
closeSettingDrawer() {
this.settingDrawerVisible = false;
},
/** 切换抽屉可见状态 */
2022-04-22 09:00:21 +08:00
toggleSettingDrawerVisible() {
this.settingDrawerVisible = !this.settingDrawerVisible;
},
/** 设置侧边栏折叠状态 */
setSiderCollapse(collapse: boolean) {
this.siderCollapse = collapse;
},
/** 折叠/展开 侧边栏折叠状态 */
toggleSiderCollapse() {
this.siderCollapse = !this.siderCollapse;
},
/** 设置 vertical-mix模式下 侧边栏的固定状态 */
setMixSiderIsFixed(isFixed: boolean) {
this.mixSiderFixed = isFixed;
},
/** 设置 vertical-mix模式下 侧边栏的固定状态 */
toggleMixSiderFixed() {
this.mixSiderFixed = !this.mixSiderFixed;
},
/** 设置主体是否禁用滚动 */
setDisableMainXScroll(disable: boolean) {
this.disableMainXScroll = disable;
},
/** 设置主体内容全屏 */
setContentFull(full: boolean) {
this.contentFull = full;
2023-06-18 22:23:42 +08:00
},
/** 设置socket实例 */
setSocket<T extends Socket = Socket>(socket: T) {
this.socket = socket;
}
}
});