feat: 接入 UserHome 前端业务代码(含真实 src/依赖,保留 projman 标准 CI)
deploy-userbase-front / build-and-deploy (push) Failing after 1m54s
build / build (push) Successful in 3m36s

This commit is contained in:
chenxing
2026-09-09 22:37:59 +08:00
parent a53ce07228
commit 4279f99be1
270 changed files with 12479 additions and 25715 deletions
+114 -95
View File
@@ -1,125 +1,144 @@
import { defineStore } from "pinia";
import Utils from "@/utils";
import { SchLenLevel, SchoolStageDict, Subject, UserRoleEnum } from "@/types";
import { get } from "lodash";
import { RoleInfo, UserSettingInfo, WidgetInfo, WidgetPosition } from "@/types";
import { flatten, indexOf, isNull, orderBy, pick, set } from "lodash";
import { BaseDict } from "@/types/Basics";
import Apis from "@/api/index";
import { alovaInstance } from "@/utils/alova/alova-iview";
import { getMenuList } from "@/assets/config/menu";
export interface IModule {
id: number;
modId: number;
name: string;
page: string;
url?: string;
icon?: string;
childState?: boolean;
children?: IModule[];
[key: string]: any;
}
export interface IdefaultStore {
curStatsDate: Date;
userRole: UserRoleEnum;
/** 管理端访问范围(GetUserScope 返回,后端单点判定):BUREAU 区域组 / SCHOOL 可管理学校组 */
userScope: { bureauGroupId?: number | null; schoolGroupIds?: number[] | null };
lenLevel: Array<SchLenLevel>;
subjects: Array<Subject>;
/** 系统字典(GetSysDict 接口返回) */
sysDict: Record<string, any>;
/** 模块列表(当前写死,后续接入接口) */
modules: Array<IModule>;
/** 角色是否已落定(App.vue GetUserScope/降级判定完成后置 true,路由守卫依赖) */
roleLoaded: boolean;
menuVisible: boolean;
userInfo: any;
curRoleInfo: RoleInfo;
userRoleList: Array<RoleInfo>;
curUserSettingInfo: UserSettingInfo;
curUserMenuList: Array<any>; //当前角色菜单
curUserAppList: Array<any>; //当前角色所有应用
curRoleUid: string | null; //当前角色uid
// curUsedAppList: Array<any>; //当前角色常用应用
}
const defaultRoleInfo = () => ({
roleId: 0,
roleName: "",
schId: 0,
schName: "",
childId: 0,
childName: "",
});
const defaultUserSettingInfo = () => ({
wallpaperUrl: "",
isWidgetShow: true,
widgetAppIds: "",
widgetAppList: [],
desktopAppList: [],
width: 380,
height: 300,
xaxis: 0,
yaxis: 0,
});
// currentYear: 0,
// currentSemester: null,
export const useDefaultStore = defineStore("defaultStore", {
state: (): IdefaultStore => {
return {
curStatsDate: new Date(),
userRole: UserRoleEnum.School,
userScope: { bureauGroupId: null, schoolGroupIds: null },
lenLevel: [],
subjects: [],
sysDict: {},
modules: [],
roleLoaded: false,
menuVisible: true,
userInfo: {},
curRoleInfo: defaultRoleInfo(),
curUserSettingInfo: defaultUserSettingInfo(),
userRoleList: [],
curUserAppList: [],
curUserMenuList: [],
curRoleUid: null,
};
},
actions: {
setCurStatsDate(dt: Date) {
this.curStatsDate = dt;
setCurRoleInfo(info: RoleInfo) {
this.curRoleInfo = info;
},
setUserRole(role: UserRoleEnum) {
this.userRole = role;
setCurUserSettingsInfo(info: UserSettingInfo) {
this.curUserSettingInfo = info;
},
setUserScope(scope: { bureauGroupId?: number | null; schoolGroupIds?: number[] | null }) {
this.userScope = scope || { bureauGroupId: null, schoolGroupIds: null };
setCurUserAppList(apps: any[]) {
this.curUserAppList = apps;
},
setRoleLoaded(loaded: boolean) {
this.roleLoaded = loaded;
setCurUserMenuList(menus: any[]) {
this.curUserMenuList = menus;
},
setSchLenLevel(len: Array<SchLenLevel>) {
this.lenLevel = len;
},
/** 获取系统字典 */
async fetchSysDict() {
try {
const data = await alovaInstance.Request(Apis.Base.getSysDict());
this.sysDict = (data as Record<string, any>) || {};
} catch (e) {
console.error("获取系统字典失败", e);
this.sysDict = {};
}
},
/** 获取模块列表(数据源 src/assets/config/menu.ts,按当前级别过滤菜单权限矩阵) */
async fetchModules() {
this.modules = await getMenuList(this.userRole);
updateWidgetInfo(info: WidgetPosition) {
Object.assign(this.curUserSettingInfo, info);
},
},
getters: {
getCurrentStatsDateObj() {
let dt = Utils.dateFormat(this.curStatsDate!, "yyyy-MM-dd");
return {
startDate: dt + " 00:00:00",
endDate: dt + " 00:00:00",
};
getCurSchId(): number {
return this.curRoleInfo?.schId || -1;
},
getSchLenLevel(): Array<SchLenLevel> {
return this.lenLevel;
getCurRoleId(): number {
return this.curRoleInfo?.roleId || -1;
},
/**获取学校学段 */
getSchLenStage(): Array<BaseDict> {
let arr: SchLenLevel[] = this.lenLevel;
let obj = arr.sort((a, b) => a.stage - b.stage).map(item => ({ k: item.stage, v: item.name }));
return obj || [];
getCurUserId(): number {
if (this.getCurRoleId == 3) {
if (!!this.curRoleInfo.childId) return this.curRoleInfo.childId;
}
return this.userInfo.id;
},
/**获取学校年级 */
getSchLenGrade(): SchLenLevel["grades"] {
let arr: SchLenLevel[] = this.lenLevel;
let obj = arr.map(item => item.grades);
let result = obj.flat().sort((a, b) => a.gradeId - b.gradeId);
return result || [];
getCurWallPaperUrl(): any {
return this.curUserSettingInfo.wallpaperUrl;
},
getStageSubjects(): Array<BaseDict> {
let arr: BaseDict[] = [];
this.subjects.forEach(element => {
const stageName = SchoolStageDict.find(x => x.k == element.stage)?.v;
arr.push({
k: element.id,
v: stageName + (element.alias || element.name),
name: element.alias || element.name,
stage: element.stage,
code: element.code,
});
getFlattenAppList(): any[] {
return flatten(this.curUserAppList.map(x => x.apps));
},
getIsAdmin() {
// const user: any = this.userInfo;
// if (user.type == 1) return true;
// if (typeof user.roleIds == "undefined" || user.roleIds == null) return false;
// let adminRoleList = user.roleList.filter((x: any) => [2, 5, 7].includes(x.roleId));
// return adminRoleList.findIndex((x: any) => x.schId == this.getCurSchId) > -1;
const user: any = this.userInfo;
if (user.type == 1) return true;
let roleId: number = this.getCurRoleId;
return [2, 5, 7].includes(roleId);
},
getWidgetSel(): BaseDict[] {
const { widgetAppList } = this.curUserSettingInfo;
let arr = widgetAppList.map(x => {
return { k: x.id, v: x.name, checked: this.getWidgetAppIds.includes(x.id) } as BaseDict;
});
arr.sort((a, b) => a.stage - b.stage);
return arr;
},
/**获取系统字典 */
getSysDict(): Record<string, any> {
return this.sysDict;
getWidgetAppIds() {
const { widgetAppIds: appIds, widgetAppList: appList } = this.curUserSettingInfo;
let checkIds: number[] = [];
if (appIds == null) checkIds = appList.map(x => x.id);
else if (appIds.length == 0) checkIds = [];
else checkIds = appIds.split(",").map(x => parseInt(x));
return checkIds;
},
getWidgetAppList() {
const { widgetAppList: appList } = this.curUserSettingInfo;
const appIds: number[] = this.getWidgetAppIds;
let arr: any[] = appList
.filter(x => appIds.includes(x.id))
.sort((a: any, b: any) => {
return appIds.indexOf(b.id) - appIds.indexOf(a.id);
});
return arr;
},
getWidgetDragObj() {
let keys: Array<keyof WidgetInfo> = ["isWidgetShow", "xaxis", "yaxis", "width", "height"];
let dragObj: WidgetInfo = pick(this.curUserSettingInfo, keys);
let defaultObj = defaultUserSettingInfo();
if (dragObj.isWidgetShow == null) {
dragObj = pick(defaultObj, keys);
dragObj.isWidgetShow = true;
}
if (dragObj.xaxis === null || dragObj.yaxis == null) {
dragObj.xaxis = defaultObj.xaxis;
dragObj.yaxis = defaultObj.yaxis;
dragObj.width = defaultObj.width;
dragObj.height = defaultObj.height;
}
return dragObj;
},
},
});