merge code pull
This commit is contained in:
143
src/api/admin/usertable.ts
Normal file
143
src/api/admin/usertable.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
import request from '/@/utils/request';
|
||||
|
||||
/**
|
||||
* 用户表格配置管理API
|
||||
*/
|
||||
|
||||
// 固定的 key,用于存储所有表格配置
|
||||
const USER_TABLE_CONFIG_KEY = 'user-table-configs'
|
||||
|
||||
/**
|
||||
* 获取用户表格列配置(获取所有配置)
|
||||
* @returns 返回所有列配置数据
|
||||
*/
|
||||
export function getUserTableConfig() {
|
||||
return request({
|
||||
url: '/admin/sysUserTable/currentInfo',
|
||||
method: 'get',
|
||||
params: { tableKey: USER_TABLE_CONFIG_KEY }
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有用户表格配置(从本地缓存)
|
||||
* @returns 所有配置对象
|
||||
*/
|
||||
export function getAllTableConfigsFromLocal(): Record<string, any> {
|
||||
const localKey = 'user-table-configs-all'
|
||||
const localData = localStorage.getItem(localKey)
|
||||
if (localData) {
|
||||
try {
|
||||
return JSON.parse(localData)
|
||||
} catch (error) {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存所有用户表格配置到本地缓存
|
||||
* @param configs 所有配置对象
|
||||
*/
|
||||
export function saveAllTableConfigsToLocal(configs: Record<string, any>) {
|
||||
const localKey = 'user-table-configs-all'
|
||||
localStorage.setItem(localKey, JSON.stringify(configs))
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定 tableKey 的配置(从本地统一存储)
|
||||
* @param tableKey 表格标识
|
||||
* @returns 配置对象 { visibleColumns: string[], columnOrder: string[] } 或 null
|
||||
*/
|
||||
export function getTableConfigFromLocal(tableKey: string): { visibleColumns: string[], columnOrder: string[] } | null {
|
||||
const allConfigs = getAllTableConfigsFromLocal()
|
||||
return allConfigs[tableKey] || null
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存指定 tableKey 的配置到本地统一存储
|
||||
* @param tableKey 表格标识
|
||||
* @param config 配置对象 { visibleColumns?: string[], columnOrder?: string[] }
|
||||
*/
|
||||
export function saveTableConfigToLocal(tableKey: string, config: { visibleColumns?: string[], columnOrder?: string[] }) {
|
||||
const allConfigs = getAllTableConfigsFromLocal()
|
||||
if (!allConfigs[tableKey]) {
|
||||
allConfigs[tableKey] = {}
|
||||
}
|
||||
if (config.visibleColumns !== undefined) {
|
||||
allConfigs[tableKey].visibleColumns = config.visibleColumns
|
||||
}
|
||||
if (config.columnOrder !== undefined) {
|
||||
allConfigs[tableKey].columnOrder = config.columnOrder
|
||||
}
|
||||
saveAllTableConfigsToLocal(allConfigs)
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户表格列配置(从本地读取所有配置,更新当前配置后一起保存)
|
||||
* @param tableKey 表格标识(通常是路由路径)
|
||||
* @param config 配置数据 { visibleColumns: string[], columnOrder: string[] }
|
||||
* @returns
|
||||
*/
|
||||
export async function updateUserTableConfig(tableKey: string, config: {
|
||||
visibleColumns?: string[];
|
||||
columnOrder?: string[];
|
||||
}) {
|
||||
// 从本地获取所有配置
|
||||
let allConfigs = getAllTableConfigsFromLocal()
|
||||
|
||||
// 更新当前 tableKey 的配置
|
||||
allConfigs[tableKey] = {
|
||||
visibleColumns: config.visibleColumns || [],
|
||||
columnOrder: config.columnOrder || []
|
||||
}
|
||||
|
||||
// 更新本地缓存
|
||||
saveAllTableConfigsToLocal(allConfigs)
|
||||
|
||||
// 保存所有配置到后端,使用固定的 key
|
||||
return request({
|
||||
url: '/admin/sysUserTable/save',
|
||||
method: 'post',
|
||||
data: {
|
||||
value: {
|
||||
[USER_TABLE_CONFIG_KEY]: allConfigs
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化用户表格配置(登录后调用,获取所有配置并保存到本地)
|
||||
* @returns Promise
|
||||
*/
|
||||
export async function initUserTableConfigs() {
|
||||
try {
|
||||
const res = await getUserTableConfig()
|
||||
if (res.data && res.data.value && res.data.value[USER_TABLE_CONFIG_KEY]) {
|
||||
// 从固定的 key 中获取所有配置
|
||||
const allConfigs = res.data.value[USER_TABLE_CONFIG_KEY]
|
||||
// 保存到本地
|
||||
saveAllTableConfigsToLocal(allConfigs)
|
||||
return allConfigs
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('初始化用户表格配置失败:', error)
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户表格列配置
|
||||
* @param tableKey 表格标识(通常是路由路径)
|
||||
* @returns
|
||||
*/
|
||||
export function deleteUserTableConfig(tableKey: string) {
|
||||
return request({
|
||||
url: '/admin/sysUserTable/delete',
|
||||
method: 'delete',
|
||||
params: { tableKey }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -30,8 +30,9 @@ export const addObj = (data: any) => {
|
||||
*/
|
||||
export const getDetail = (id: string) => {
|
||||
return request({
|
||||
url: `/stuwork/activityinfo/${id}`,
|
||||
method: 'get'
|
||||
url: '/stuwork/activityinfo/detail',
|
||||
method: 'get',
|
||||
params: { id }
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ export const exportData = (query?: any) => {
|
||||
*/
|
||||
export const syncClassroomArrangement = () => {
|
||||
return request({
|
||||
url: '/stuwork/classroombase/sync',
|
||||
url: '/stuwork/teachclassroom/initData',
|
||||
method: 'post'
|
||||
});
|
||||
};
|
||||
|
||||
@@ -72,11 +72,11 @@ export const delObj = (ids: string[]) => {
|
||||
|
||||
/**
|
||||
* 批量设置(批量更新选中教室的学院)
|
||||
* @param data 包含ids(教室ID数组)和deptCode(学院代码)
|
||||
* @param data 数组格式,每个元素包含 id(教室ID)和 deptCode(学院代码)
|
||||
*/
|
||||
export const batchSet = (data: any) => {
|
||||
export const batchSet = (data: any[]) => {
|
||||
return request({
|
||||
url: '/stuwork/teachclassroom/batchSet',
|
||||
url: '/stuwork/teachclassroom/putDeptList',
|
||||
method: 'post',
|
||||
data
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user