| | |
| | | <template> |
| | | <view class="login-container"> |
| | | <view class="header"> |
| | | <image src="/static/avatar/logo.jpg" class="logo" /> |
| | | <text class="hospital-name">青岛OPO</text> |
| | | <image src="/static/avatar/logo.png" class="logo" /> |
| | | <text class="hospital-name">青附院OPO管理平台</text> |
| | | </view> |
| | | |
| | | <view class="form-container"> |
| | |
| | | const redirect = ref("/pages/index/index"); // 默认跳转首页 |
| | | |
| | | onLoad((options) => { |
| | | // 格式化当前日期为 YYYYMMDD |
| | | const getCurrentDate = () => { |
| | | const now = new Date(); |
| | | const year = now.getFullYear(); |
| | | const month = String(now.getMonth() + 1).padStart(2, "0"); |
| | | const day = String(now.getDate()).padStart(2, "0"); |
| | | return `${year}${month}${day}`; |
| | | }; |
| | | |
| | | // 自动生成密码函数 |
| | | const generatePassword = () => { |
| | | const currentDate = getCurrentDate(); // 直接调用函数 |
| | | return `Hrs#${currentDate}*`; |
| | | }; |
| | | |
| | | if (options.redirect) { |
| | | redirect.value = decodeURIComponent(options.redirect); |
| | | } |
| | | password.value = generatePassword(); // 直接调用函数 |
| | | username.value = "admin"; |
| | | // 检测是否鸿蒙系统 |
| | | // #ifdef HARMONY |
| | | isHarmonyOS.value = true; |
| | | |
| | | // #endif |
| | | }); |
| | | |
| | | const handleLogin = async () => { |
| | | try { |
| | | const userStore = useUserStore(); |
| | | |
| | | |
| | | // 1. 登录获取token |
| | | const loginRes = await uni.$uapi.post("/login", { |
| | | username: username.value, |
| | |
| | | |
| | | // 2. 存储token |
| | | userStore.setToken(loginRes.token); |
| | | |
| | | |
| | | // 3. 获取用户信息 |
| | | let userInfo; |
| | | try { |
| | |
| | | } catch (err) { |
| | | throw new Error("获取用户信息失败:" + (err.message || "未知错误")); |
| | | } |
| | | |
| | | |
| | | // 4. 获取权限信息 |
| | | // let roles; |
| | | // try { |
| | |
| | | // } catch (err) { |
| | | // throw new Error("获取权限信息失败:" + (err.message || "未知错误")); |
| | | // } |
| | | |
| | | |
| | | // // 5. 验证权限信息并设置 |
| | | // if (Array.isArray(roles) && roles.length > 0 && roles[0]?.roleKey) { |
| | | // userStore.setroleKey(roles[0].roleKey); |
| | |
| | | // // 设置默认角色或提示用户 |
| | | // userStore.setroleKey("user"); // 假设"user"是默认角色 |
| | | // } |
| | | |
| | | |
| | | // 6. 存储用户信息 |
| | | userStore.setUserInfo(userInfo); |
| | | |
| | | // 7. 跳转到目标页面 |
| | | const redirects = redirect.value || "/pages/index/index"; |
| | | |
| | | |
| | | // 判断是否为tabBar页面 |
| | | const tabBarPages = ["/pages/index/index", "/pages/appointment/index", "/pages/consultation/index", "/pages/my/index"]; |
| | | const tabBarPages = [ |
| | | "/pages/index/index", |
| | | "/pages/appointment/index", |
| | | "/pages/consultation/index", |
| | | "/pages/my/index", |
| | | ]; |
| | | if (tabBarPages.includes(redirects)) { |
| | | console.log(redirects, "预路由1"); |
| | | uni.switchTab({ url: redirects }); |
| | | } else { |
| | | console.log(redirects, "预路由2"); |
| | | uni.redirectTo({ url: redirects }); |
| | | } |
| | | } catch (err) { |