import { http } from '@/utils/request'; /** * 获取微信授权 URL * @param {string} baseUrl - 授权后跳转的 URL(需后端处理) * @param {string} scope - 授权作用域(如 snsapi_userinfo) * @returns {Promise} 返回微信授权 URL */ export async function getCode(baseUrl = window.location.href, scope = 'snsapi_userinfo') { try { const response = await http.get('/h5/wechat/code', { params: { baseUrl, scope } // 传递参数给后端 }); console.log(response) // 处理可能的 redirect: 前缀(兼容后端直接返回 URL 或 redirect:URL) let authUrl = response.result; if (typeof authUrl === 'string' && authUrl.startsWith('redirect:')) { authUrl = authUrl.substring('redirect:'.length).trim(); } // 直接返回授权 URL,由前端控制跳转 return authUrl; } catch (error) { console.error('获取微信授权 URL 失败:', error); throw error; } } export async function getUserInfo(code,state) { try { const response = await http.get('/h5/wechat/auth', { params: { code,state } // 传递参数给后端 }); console.log(response) // 处理可能的 redirect: 前缀(兼容后端直接返回 URL 或 redirect:URL) //let authUrl = response.result; //if (typeof authUrl === 'string' && authUrl.startsWith('redirect:')) { // authUrl = authUrl.substring('redirect:'.length).trim(); //} return response; } catch (error) { console.error('获取微信授权 URL 失败:', error); throw error; } } export async function AutocheckUser(openId) { try { const response = await http.post('/h5/wechat/AutocheckUser', { openId }, // JSON 数据 { headers: { 'Content-Type': 'application/json' // 明确指定 JSON 格式 } } ); return response.result; } catch (error) { console.error('用户检查失败:', error); throw error; } } // 获取访问时间段 export async function getAccessTime() { const response = await http.get('/h5/cees/ceesUser/getH5Time'); return response; } /** * 账号密码登录 * @returns UseAxiosReturn */ export function loginPassword() { return http.post(`/api/login`, { data: { name: '123' }, }); } //获取专业 export async function getMajor(code) { const response = await http.post('/h5/cees/ceesUser/getMajor', { userId: code, }); // 如果响应成功,返回专业信息 return response; } //检查用户身份 export async function checkUser(code) { const response = await http.post('/h5/cees/ceesUser/checkUser', { userId: code, }); return response; } // 研究生保存数据 export function save(data) { return http.post('/h5/cees/ceesStudent/save', { userName: data.userName, studentId: data.studentId, phone: data.phone, checked: data.checked, userId: data.userId, openId: data.openId, unionId: data.unionId, }); } // 获取用户身份 export async function getUser(userId) { const response = await http.get('/h5/cees/ceesUser/getUser', { params: { userId: userId, }, }); return response; } // 根据groupId获取分组名 export async function getGroupName(groupId) { const response = await http.get('/h5/cees/ceesUser/getGroupName', { params: { groupId: groupId, }, }); return response; } // 根据dormitoryId获取分组名 export async function getDormitoryName(dormitoryId) { const response = await http.get('/h5/cees/ceesWaiTeacher/getDormitoryName', { params: { dormitoryId: dormitoryId, }, }); return response; } // 本校老师保存数据 export function localTeacherSave(data) { return http.post('/h5/cees/ceesLocalTeacher/save', { userName: data.userName, teacherId: data.teacherId, phone: data.phone, checked: data.checked, userId: data.userId, openId: data.openId, unionId: data.unionId, }); } // 外校老师保存数据 export function waiTeacherSave(data) { if (data.sex == '男') { data.sex = 0; } if (data.sex == '女') { data.sex = 1; } return http.post('/h5/cees/ceesWaiTeacher/save', { age: data.age, bankAddress: data.bankAddress, bankName: data.bankName, carNumber: data.carNumber, carStatus: data.carStatus, dormitoryStatus: data.dormitoryStatus, identityId: data.identityId, jobTitle: data.jobTitle, office: data.office, pyCard: data.pyCard, sex: data.sex, userCardId: data.userCardId, workName: data.workName, workPhone: data.workPhone, userName: data.userName, phone: data.phone, userId: data.userId, openId: data.openId, }); }