| | |
| | | // 用户登录接口 |
| | | export const loginByUsername = (tenantId, deptId, roleId, username, password, type, key, code) => { |
| | | return request({ |
| | | url: '/blade-auth/oauth/token', |
| | | url: '/auth/login', |
| | | method: 'post', |
| | | header: { |
| | | 'Tenant-Id': tenantId, |
| | |
| | | 'Captcha-Key': key, |
| | | 'Captcha-Code': code, |
| | | }, |
| | | params: { |
| | | data: { |
| | | tenantId, |
| | | username, |
| | | password, |
| | | checkCode:'', |
| | | mobile: false, |
| | | grant_type: 'password', |
| | | scope: 'all', |
| | | type, |
| | |
| | | // 开发环境这里改为自己的 |
| | | VITE_APP_WEBVIEW_URL: 'https://wrj.shuixiongit.com/drone-app-web-view/#/webViewWrapper', |
| | | // VITE_APP_WEBVIEW_URL: 'http://localhost:5173/drone-app-web-view/#/webViewWrapper', |
| | | VITE_API_BASE_URL: 'https://wrj.shuixiongit.com/api', |
| | | VITE_API_BASE_URL: 'http://218.202.104.82:8200', |
| | | // VITE_API_BASE_URL: 'https://aisky.org.cn/api', |
| | | VITE_APP_WS_API_URL:'wss://wrj.shuixiongit.com/drone-wss/api/v1/ws', |
| | | |
| | |
| | | userInfo.deptId, |
| | | userInfo.roleId, |
| | | userInfo.username, |
| | | md5(userInfo.password), |
| | | // md5(userInfo.password), |
| | | userInfo.password, |
| | | userInfo.type, |
| | | userInfo.key, |
| | | userInfo.code |
| | |
| | | uni.showToast({ title: '请先同意协议', icon: 'none' }); |
| | | return; |
| | | } |
| | | |
| | | |
| | | // loading.value = true; |
| | | |
| | | |
| | | try { |
| | | // 2. 获取登录凭证 (code) |
| | | const loginRes = await uni.login({ |
| | | provider: 'weixin', |
| | | timeout: 10000 |
| | | }); |
| | | |
| | | |
| | | if (!loginRes.code) { |
| | | throw new Error('获取登录码失败'); |
| | | } |
| | | console.log('获取到code:', loginRes.code); |
| | | |
| | | |
| | | // 3. 获取用户信息 (需要用户授权弹窗) |
| | | const userProfileRes = await uni.getUserProfile({ |
| | | desc: '用于完善您的会员信息', // 声明用途,会展示给用户 |
| | | lang: 'zh_CN' |
| | | }); |
| | | |
| | | |
| | | console.log('用户信息:', userProfileRes.userInfo); |
| | | |
| | | |
| | | // 4. 调用后端登录接口 |
| | | const serverRes = await uni.request({ |
| | | // url: 'https://你的域名.com/api/wx-login', // 替换为你的真实接口 |
| | |
| | | // }, |
| | | // header: { 'Content-Type': 'application/json' } |
| | | }); |
| | | |
| | | |
| | | // 5. 处理登录结果 |
| | | const { data } = serverRes; |
| | | if (data.success && data.token) { |
| | | // 保存登录状态 |
| | | uni.setStorageSync('token', data.token); |
| | | uni.setStorageSync('userInfo', data.userInfo || userProfileRes.userInfo); |
| | | |
| | | |
| | | uni.showToast({ title: '登录成功', icon: 'success' }); |
| | | |
| | | |
| | | // 登录成功后的跳转逻辑 |
| | | const pages = getCurrentPages(); |
| | | if (pages.length > 1) { |
| | |
| | | } else { |
| | | throw new Error(data.message || '登录失败'); |
| | | } |
| | | |
| | | |
| | | } catch (error) { |
| | | console.error('登录全过程失败:', error); |
| | | uni.showToast({ |
| | |
| | | @apply border-none; |
| | | } |
| | | } |
| | | |
| | | |
| | | .wechat-login-btn { |
| | | z-index: 1; |
| | | @apply flex items-center justify-center py-12rpx px-0 text-30rpx border-none; |