Files
UserhomeFront/src/api/BaseApi.ts
T

316 lines
11 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { PageData, PageParams } from "@/types/Basics";
import Abstract from "@/utils/axios/abstract";
import { BschResponse } from "axios";
const path = "/api";
class Base extends Abstract {
/**
*获取个人信息
* @memberof Basic
*/
getUserInfo() {
const url = path + "/user/GetUserInfo";
return this.getRequest({ url, isMsg: false });
}
/**
* 修改本人联系方式(手机号/邮箱,至少一项非空;后端经 UserBase 开放接口落库)。
* 成功返回更新后的最新用户信息(BoaUser,含新 phone/email),供调用方刷新 store 规避 CAS principal 旧值。
*/
updateContact(phone: string, email: string) {
const url = path + "/user/UpdateContact";
return this.postRequest<any>({ url, data: { phone, email } });
}
/**
*获取用户全部角色
* @memberof Basic
*/
getUserRole() {
const url = path + "/user/getUserRole";
return this.getRequest<Array<any>>({ url });
}
/**
*获取用户当前角色
* @memberof Basic
*/
findUserRole() {
const url = path + "/user/findUserRole";
return this.getRequest({ url });
}
/**
*获取用户所有应用
* @memberof Basic
*/
getUserApp(userId: number, schId: number) {
const url = path + "/user/GetUserApp";
return this.getRequest<any[]>({ url, params: { userId, schId } });
}
/**
*获取用户常用应用
* @memberof Basic
*/
getUsedApp(roleId: number, schId: number) {
const url = path + "/usedapp/getUsedApp";
return this.getRequest<any[]>({ url, params: { roleType: roleId, schId } });
}
/**
*获取应用详情
* @memberof Basic
*/
GetAppInfoById(appId: number) {
const url = path + "/user/GetAppInfoById";
return this.getRequest<any>({ url, params: { id: appId } });
}
/**
*获取用户消息
* @memberof Basic
*/
getMessageList() {
const url = path + "/getMessageByUserId";
return this.getRequest<PageData>({ url, params: { page: 1, count: 10 } });
}
/**
*获取用户消息
* @memberof Basic
*/
getMessagePageList(params: PageParams) {
const url = path + "/getMessageByUserId";
return this.getRequest<PageData>({ url, params });
}
/**
* 已读某一条消息
* @memberof Basic
*/
readMessage(id: number) {
const url = path + "/readMessage";
return this.postRequest({ url, params: { id } });
}
/**
* 已读全部消息
* @memberof Basic
*/
readMessageAll() {
const url = path + "/readMessageAll";
return this.postRequest({ url });
}
// ===== 消息中心代理(§3.5:经后端签名代理 UserMsg,前端不直连)=====
/**
* 消息中心分页列表({total, list[]};元素含改写后的绝对 jumpUrl、appId/appName)。
* 可选服务端筛选:msgType 0/1/2、appId(注册表应用 id)、isRead 0/1、keyword 标题/内容模糊。
* @memberof Basic
*/
getMsgCenterList(params: PageParams & { msgType?: number; appId?: string; isRead?: number; keyword?: string }) {
const url = path + "/msgCenter/list";
return this.getRequest<PageData>({ url, params });
}
/**
* 铃铛摘要:未读数 + 各应用待办角标 + 分类计数(sysUnread/bizUnread/approvalUnread 为未读口径,
* sysTotal/bizTotal/approvalTotal/total/readCount 为总数口径;旧版 UserMsg 无这些端点字段时缺省,前端按降级处理)
* @memberof Basic
*/
getMsgCenterSummary() {
const url = path + "/msgCenter/summary";
return this.getRequest<{
unreadCount: number;
todos: { count: number }[];
sysUnread?: number;
bizUnread?: number;
approvalUnread?: number;
sysTotal?: number;
bizTotal?: number;
approvalTotal?: number;
total?: number;
readCount?: number;
}>({ url });
}
/**
* 消息中心:按来源应用消息计数(「按应用」清单角标):[{appId, appName, total, unread}],
* total 含已读;无消息的应用不出现
* @memberof Basic
*/
getMsgCenterCountByApp() {
const url = path + "/msgCenter/countByApp";
return this.getRequest<{ appId: number | null; appName: string | null; total: number; unread: number }[]>({ url });
}
/**
* WS 实时推送握手地址(UserMsg 一次性票据;url=null 表示未配置/不可达,走手动刷新兜底)
* @memberof Basic
*/
getMsgCenterWsTicket() {
const url = path + "/msgCenter/wsTicket";
return this.getRequest<{ url: string | null }>({ url });
}
/**
* 消息中心:已读某一条(按登录人代理)
* @memberof Basic
*/
readMsgCenter(msgId: number) {
const url = path + "/msgCenter/read";
return this.postRequest({ url, params: { msgId } });
}
/**
* 消息中心:全部已读
* @memberof Basic
*/
readMsgCenterAll() {
const url = path + "/msgCenter/readAll";
return this.postRequest({ url });
}
/**
* 消息卡片直批(B3 §2):同意/拒绝消息对应的审批待办。
* 身份(operatorId/schId/operatorName)服务端取会话,前端只传消息定位与动作。
* 返回 {ok, message}——ok=false 时 message 为可直接展示的文案。
* @memberof Basic
*/
handleMsg(msgId: number, action: "approve" | "reject", opinion?: string) {
const url = path + "/msgCenter/handle";
return this.postRequest({ url, data: { msgId, action, opinion } });
}
/**
* 修改密码
* @memberof Basic
*/
updatePassword(oldPassword: string, password: string) {
const url = path + "/updateUserPassword";
return this.postRequest({ url, data: { oldPassword, password } });
}
/**
* 保存校级 LOGO(schId 后端按登录人推断:主学校→归属组→0 平台默认)
* @memberof Basic
*/
saveSchLogo(logoUrl: string) {
const url = path + "/saveSchLogo";
return this.postRequest({ url, params: { logoUrl } });
}
// ===== 学校默认主题档(主题设置 2026-09-30;后端契约见 SchSettingsController)=====
/**
* 读本校默认主题档(已登录可读):{themeState: "<ThemeState JSON>" | null}——
* null 表示未配置(前端"不写键、不报错"),登录后调一次写 localStorage["yh-theme-sch-default"]
*/
getSchTheme() {
const url = path + "/schTheme";
return this.getRequest<{ themeState: string | null; schId: number }>({ url });
}
/** 保存本校默认主题档(仅学校管理员):themeState 为整份 ThemeState JSON 字符串 */
saveSchThemeState(themeState: string) {
const url = path + "/saveSchThemeState";
return this.postRequest({ url, params: { themeState } });
}
/** 清空本校默认主题档(仅学校管理员;置空后读侧返回 null) */
clearSchTheme() {
const url = path + "/clearSchTheme";
return this.postRequest({ url });
}
// ===== LOGO 文字(平台/学校名称,2026-10-09 LOGO 文字轮;后端契约见 SchSettingsController#schLogoText)=====
/** 读 LOGO 文字(已登录可读):{logoText: string|null, schId=实际命中层}——本校空 → 平台层 → null */
getSchLogoText() {
const url = path + "/schLogoText";
return this.getRequest<{ logoText: string | null; schId: number }>({ url });
}
/** 保存 LOGO 文字(仅学校管理员/超管):trim 后落本级(超管=平台层 0,校管=本校),≤64;空串=清空本级 */
saveSchLogoText(logoText: string) {
const url = path + "/saveSchLogoText";
return this.postRequest({ url, params: { logoText } });
}
// ===== 默认壁纸(平台/学校两级,壁纸三级默认轮 2026-10-09;后端契约见 SchSettingsController#schWallpaper)=====
/** 读默认壁纸(已登录可读):{wallpaperUrl: string|null, schId=实际命中层}——本校空 → 平台层 → null */
getSchWallpaper() {
const url = path + "/schWallpaper";
return this.getRequest<{ wallpaperUrl: string | null; schId: number }>({ url });
}
/** 保存默认壁纸(仅学校管理员/超管):URL 取管理池返回的绝对地址原样存,≤255;空串=清空本级 */
saveSchWallpaper(wallpaperUrl: string) {
const url = path + "/saveSchWallpaper";
return this.postRequest({ url, params: { wallpaperUrl } });
}
// ===== 学校默认头像样式(默认头像轮 2026-09-30;后端契约见 SchSettingsController#schAvatarStyle)=====
/**
* 读本校默认头像样式(已登录可读):{avatarStyle: "text"|"silhouette"|null}——
* null 表示未配置(前端"不写键、不报错"),登录后调一次写 localStorage["yh-avatar-sch-default"]
*/
getSchAvatarStyle() {
const url = path + "/schAvatarStyle";
return this.getRequest<{ avatarStyle: string | null; schId: number }>({ url });
}
/** 保存本校默认头像样式(仅学校管理员):avatarStyle = "text" | "silhouette" */
saveSchAvatarStyle(avatarStyle: string) {
const url = path + "/saveSchAvatarStyle";
return this.postRequest({ url, params: { avatarStyle } });
}
/** 清空本校默认头像样式(仅学校管理员;置空后读侧返回 null) */
clearSchAvatarStyle() {
const url = path + "/clearSchAvatarStyle";
return this.postRequest({ url });
}
// ===== 用户外观偏好(外观偏好服务端化 2026-10-08;后端契约见 AppearanceController)=====
/**
* 读当前用户外观偏好聚合:{myTheme, schTheme, avatarMy, avatarSch, logoUrl}(紧凑编码/绝对 URL,查不到为 null)。
* 各子应用 yh-theme-init 异步补齐段的同源数据源;选择端预留(本轮设置页双写用不到)。
*/
getAppearance() {
const url = path + "/appearance";
return this.getRequest<{
myTheme: string | null;
schTheme: string | null;
avatarMy: string | null;
avatarSch: string | null;
logoUrl: string | null;
}>({ url });
}
/** 保存用户自选主题档(紧凑编码 theme|sideDeep01|gradOn01|sideFollow01);null=跟随学校默认。设置页 fire-and-forget 双写:成功不提示、失败不回滚本地 */
saveMyTheme(themeState: string | null) {
const url = path + "/saveMyTheme";
return this.postRequest({ url, data: { themeState } as any });
}
/** 保存用户自选头像样式("text"|"silhouette");null=跟随学校默认。双写语义同 saveMyTheme */
saveMyAvatarStyle(avatarStyle: string | null) {
const url = path + "/saveMyAvatarStyle";
return this.postRequest({ url, data: { avatarStyle } as any });
}
savUserRole(info: any) {
const url = path + "/user/savUserRole";
return this.postRequest({ url, data: info as any });
}
}
export default new Base();