diff --git a/src/api/index.ts b/src/api/index.ts index f015d1f..e1ddc18 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,6 +1,66 @@ 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'); @@ -109,5 +169,6 @@ export function waiTeacherSave(data) { userName: data.userName, phone: data.phone, userId: data.userId, + openId: data.openId, }); } diff --git a/src/assets/Ui/log.svg b/src/assets/Ui/log.svg new file mode 100644 index 0000000..95b7a98 --- /dev/null +++ b/src/assets/Ui/log.svg @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/assets/Ui/信息/劳务信息/劳务信息.svg b/src/assets/Ui/信息/劳务信息/劳务信息.svg new file mode 100644 index 0000000..e7bec2a --- /dev/null +++ b/src/assets/Ui/信息/劳务信息/劳务信息.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/router/index.ts b/src/router/index.ts index c08c35a..ffcd838 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,10 +1,9 @@ -import { createRouter, createWebHashHistory, Router } from 'vue-router'; -import {getAccessTime} from '@/api/index'; +import { createRouter, createWebHistory, Router } from 'vue-router'; import routes from './routes'; -import {showDialog } from 'Vant'; + const router: Router = createRouter({ - history: createWebHashHistory(import.meta.env.BASE_URL), + history: createWebHistory(import.meta.env.BASE_URL), routes: routes, }); diff --git a/src/router/routes.ts b/src/router/routes.ts index d1b7313..a69878d 100644 --- a/src/router/routes.ts +++ b/src/router/routes.ts @@ -66,6 +66,15 @@ export const routes = [ border: false, }, }, + { + name: 'wx', + path: '/wx', + component: () => import('@/views/wechatOauth/index.vue'), + meta: { + title: '哈尔滨师范大学评卷报名系统', + border: false, + }, + }, ], }, // 匹配不到重定向会主页 diff --git a/src/store/index.ts b/src/store/index.ts index e0ca1dc..1381834 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -18,8 +18,10 @@ interface UserState { user: User | null; // 用户信息 userId: string; // 用户 ID openId: string; // 微信 OpenID + unionId:string;// 微信 unionId groupId: number; // 用户组 ID major: number; // 专业 ID + } // 定义并导出 useUserStore @@ -30,6 +32,7 @@ export const useUserStore = defineStore('user', { user: null, userId: '', openId: '', + unionId:'', groupId: 0, major: 0, }), @@ -42,6 +45,8 @@ export const useUserStore = defineStore('user', { LoginUser: (state) => state.user, // 获取 OpenID getOpenId: (state) => state.openId, + // 获取 OpenID + getunionId: (state) => state.unionId, // 获取用户 ID getUserId: (state) => state.userId, // 获取专业 ID @@ -79,6 +84,13 @@ export const useUserStore = defineStore('user', { setOpenId(openId: string) { this.openId = openId; }, + /** + * 设置 unionId + * @param unionId - 微信 unionId + */ + setunionId(unionId: string) { + this.unionId = unionId; + }, /** * 设置用户 ID diff --git a/src/utils/request/index.ts b/src/utils/request/index.ts index 79a370c..8f1621f 100644 --- a/src/utils/request/index.ts +++ b/src/utils/request/index.ts @@ -3,8 +3,8 @@ import { showToast } from 'vant'; // 创建 axios 实例 const service: AxiosInstance = axios.create({ - //baseURL: 'http://62.234.217.137:10001/jeecg-boot', // 基础 URL - baseURL: 'http://localhost:10001/jeecg-boot', // 基础 URL + baseURL: 'http://62.234.217.137:10001/jeecg-boot', // 基础 URL + //baseURL: 'http://localhost:10001/jeecg-boot', // 基础 URL withCredentials: false, // 是否携带跨域凭证 timeout: 10000, // 请求超时时间 }); diff --git a/src/views/home/index.vue b/src/views/home/index.vue index 04e57ce..1a0be4c 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -1,20 +1,11 @@