This commit is contained in:
zpc 2025-07-10 20:19:31 +08:00
parent 6251b9675a
commit a79ef58513
3 changed files with 261 additions and 255 deletions

View File

@ -9,6 +9,7 @@ import { normalizeResponseKeys, getRouteMap } from '@/common/system/routeMap.js'
import { platform } from '@/common/platform/PlatformFactory';
import { getLocalStorage, setLocalStorage } from './cacheService';
import qs from 'qs';
import { getOS } from '@/common/utils'
class HttpRequest {
/**
* 生成唯一的nonce值
@ -121,12 +122,13 @@ class HttpRequest {
// 创建签名并准备请求数据和头信息
const { data: signedData } = HttpRequest._createSignature(data, host);
data = signedData;
let os = getOS();
// 根据请求方法设置不同的headers
const header = {
platform: client,
token: token,
version: platform.getVersion(),
os: os,
'content-type': requestMethod === 'POST'
? 'application/x-www-form-urlencoded'
: 'application/json'
@ -203,7 +205,7 @@ class HttpRequest {
console.log('getOrCache', cacheKey, '缓存命中');
return cacheData;
}
const res = await HttpRequest.request(url, data, 'GET', showLoading);
setLocalStorage(cacheKey, res, time);
return res;

View File

@ -123,7 +123,7 @@ export function wxAppLogin() {
uni.login({
provider: 'weixin',
onlyAuthorize: true,
success: async function(loginRes) {
success: async function (loginRes) {
console.log("loginResloginResloginRes", loginRes);
if (loginRes.code) {
const userInfo = await getUserWxInfo(loginRes.code);
@ -145,23 +145,26 @@ export function wxAppLogin() {
}
return;
},
fail: function(e) {
fail: function (e) {
console.log(e);
uni.hideLoading();
}
});
});
}
let os = '';
/**
*
*/
export function getOS() {
if (os != '') {
return os;
}
// #ifdef APP-PLUS
const systemInfo = uni.getSystemInfoSync();
return systemInfo.platform === 'ios' ? 'ios' : 'android';
// #endif
// 非 App 环境返回 undefined 或其他值
return undefined;
return 'web';
}

View File

@ -46,283 +46,284 @@
</template>
<script setup>
import {
ref,
onUnmounted,
defineAsyncComponent
} from 'vue';
import {
sendSms
} from '@/common/server/other';
import {
mobileLogin,
wxAppLogin
} from '@/common/server/user';
import {
setCache
} from '@/common/system/cacheService';
let redirectUrl = "";
onLoad((options) => {
console.log(options, "optionsoptionsoptionsoptionsoptions");
if (options.page) {
redirectUrl = decodeURIComponent(options.page);
}
});
let pageLoading = ref(false);
let pageContainer = ref(null);
let phone = ref('');
let code = ref('');
let isAgree = ref(false);
let countdown = ref(0);
let timer = null;
//
const toggleAgree = () => {
isAgree.value = !isAgree.value;
console.log('协议状态已切换:', isAgree.value);
};
//
const openAgreement = (type) => {
console.log('打开协议页面:', type);
// navigateTo(`/pages/other/agreement?type=${type}`);3594
yds.navigateToAgreement(type)
};
const wxLogin = async () => {
const resLoginInfo = await yds.wxAppLogin();
console.log(resLoginInfo);
const res = await wxAppLogin(resLoginInfo.unionId, resLoginInfo.nickName, resLoginInfo.avatarUrl);
if (res.status == 1) {
showToast('登录成功');
setCache('token', res.data);
await sleep(500);
pageLoading.value = false;
yds.navigateTo('/pages/me/me');
}
import {
ref,
onUnmounted,
defineAsyncComponent
} from 'vue';
import {
sendSms
} from '@/common/server/other';
import {
mobileLogin,
wxAppLogin
} from '@/common/server/user';
import {
setCache
} from '@/common/system/cacheService';
let redirectUrl = "";
onLoad((options) => {
console.log(options, "optionsoptionsoptionsoptionsoptions");
if (options.page) {
redirectUrl = decodeURIComponent(options.page);
}
});
let pageLoading = ref(false);
let pageContainer = ref(null);
let phone = ref('');
let code = ref('');
let isAgree = ref(false);
let countdown = ref(0);
let timer = null;
//
const toggleAgree = () => {
isAgree.value = !isAgree.value;
console.log('协议状态已切换:', isAgree.value);
};
//
const sendCode = async () => {
if (countdown.value > 0) {
return;
};
console.log('发送验证码前检查协议:', isAgree.value);
if (!isAgree.value) {
yds.showToast('请同意用户协议和隐私政策');
return;
}
if (!phone.value || phone.value.length !== 11) {
yds.showToast('请输入正确的手机号');
return;
}
pageLoading.value = true;
//
countdown.value = 60;
timer = setInterval(() => {
countdown.value--;
if (countdown.value <= 0) {
clearInterval(timer);
}
}, 1000);
const isSuccess = await sendSms(phone.value);
if (!isSuccess) {
showToast('发送失败');
return;
}
pageLoading.value = false;
showToast('验证码已发送!');
};
//
const handleLogin = async () => {
console.log('登录前检查协议:', isAgree.value);
if (!phone.value || phone.value.length !== 11) {
showToast('请输入正确的手机号');
return;
}
if (!code.value || code.value.length !== 4) {
showToast('请输入正确的验证码');
return;
}
if (!isAgree.value) {
showToast('请同意用户协议和隐私政策');
return;
}
pageLoading.value = true;
const res = await mobileLogin(phone.value, code.value);
if (res.status != 1) {
showToast('登录失败');
return;
}
//
//
const openAgreement = (type) => {
console.log('打开协议页面:', type);
// navigateTo(`/pages/other/agreement?type=${type}`);3594
yds.navigateToAgreement(type)
};
const wxLogin = async () => {
const resLoginInfo = await yds.wxAppLogin();
console.log(resLoginInfo);
const res = await wxAppLogin(resLoginInfo.unionId, resLoginInfo.nickName, resLoginInfo.avatarUrl);
if (res.status == 1) {
showToast('登录成功');
setCache('token', res.data);
await sleep(500);
pageLoading.value = false;
if (redirectUrl != "") {
if (!redirectUrl.startsWith("/")) {
redirectUrl = "/" + redirectUrl;
}
//
const pages = getCurrentPages();
yds.navigateTo('/pages/me/me');
}
}
// redirect URL
if (pages.length > 1) {
const prevPage = pages[pages.length - 2];
// ()
let prevPageUrl = '/' + prevPage.route;
if (prevPage.options && Object.keys(prevPage.options).length > 0) {
const paramStr = Object.keys(prevPage.options)
.map(key => `${key}=${prevPage.options[key]}`)
.join('&');
prevPageUrl += '?' + paramStr;
}
// redirect URLURL
const redirectUrlPath = redirectUrl.split('?')[0];
const prevPageUrlPath = prevPageUrl.split('?')[0];
if (redirectUrlPath === prevPageUrlPath) {
//
console.log('重定向URL与上一页相同直接返回');
uni.navigateBack();
return true;
}
}
yds.navigateTo(redirectUrl);
} else {
yds.navigateTo('/pages/me/me');
}
//
const sendCode = async () => {
if (countdown.value > 0) {
return;
};
//
const handleRefuse = () => {
uni.navigateBack();
};
console.log('发送验证码前检查协议:', isAgree.value);
//
onUnmounted(() => {
if (timer) {
if (!isAgree.value) {
yds.showToast('请同意用户协议和隐私政策');
return;
}
if (!phone.value || phone.value.length !== 11) {
yds.showToast('请输入正确的手机号');
return;
}
pageLoading.value = true;
//
countdown.value = 60;
timer = setInterval(() => {
countdown.value--;
if (countdown.value <= 0) {
clearInterval(timer);
}
});
}, 1000);
const isSuccess = await sendSms(phone.value);
if (!isSuccess) {
showToast('发送失败');
return;
}
pageLoading.value = false;
showToast('验证码已发送!');
};
//
const handleLogin = async () => {
console.log('登录前检查协议:', isAgree.value);
if (!phone.value || phone.value.length !== 11) {
showToast('请输入正确的手机号');
return;
}
if (!code.value || code.value.length !== 4) {
showToast('请输入正确的验证码');
return;
}
if (!isAgree.value) {
showToast('请同意用户协议和隐私政策');
return;
}
pageLoading.value = true;
const res = await mobileLogin(phone.value, code.value);
if (res.status != 1) {
showToast('登录失败');
pageLoading.value = false;
return;
}
//
showToast('登录成功');
setCache('token', res.data);
await sleep(500);
pageLoading.value = false;
if (redirectUrl != "") {
if (!redirectUrl.startsWith("/")) {
redirectUrl = "/" + redirectUrl;
}
//
const pages = getCurrentPages();
// redirect URL
if (pages.length > 1) {
const prevPage = pages[pages.length - 2];
// ()
let prevPageUrl = '/' + prevPage.route;
if (prevPage.options && Object.keys(prevPage.options).length > 0) {
const paramStr = Object.keys(prevPage.options)
.map(key => `${key}=${prevPage.options[key]}`)
.join('&');
prevPageUrl += '?' + paramStr;
}
// redirect URLURL
const redirectUrlPath = redirectUrl.split('?')[0];
const prevPageUrlPath = prevPageUrl.split('?')[0];
if (redirectUrlPath === prevPageUrlPath) {
//
console.log('重定向URL与上一页相同直接返回');
uni.navigateBack();
return true;
}
}
yds.navigateTo(redirectUrl);
} else {
yds.navigateTo('/pages/me/me');
}
};
//
const handleRefuse = () => {
uni.navigateBack();
};
//
onUnmounted(() => {
if (timer) {
clearInterval(timer);
}
});
</script>
<style lang="scss" scoped>
.page {
.page {
width: 100%;
height: 100%;
min-height: 100vh;
}
.welcome {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
&__logo {
width: 96px;
height: 96px;
margin-top: 5vh;
border-radius: 50%;
}
&__animation {
width: 200rpx;
height: 200rpx;
}
&__tips {
margin-top: 10px;
}
}
//
.login-form {
padding: 20px;
width: 90%;
margin: 0 auto;
}
.input-item {
border-bottom: 1px solid #eee;
padding: 15px 0;
margin-bottom: 15px;
input {
width: 100%;
height: 100%;
min-height: 100vh;
font-size: 16px;
}
}
.code-input {
display: flex;
justify-content: space-between;
align-items: center;
input {
flex: 1;
}
.welcome {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
.send-code-btn {
background-color: #333;
color: #fff;
padding: 6px 12px;
border-radius: 4px;
font-size: 14px;
}
}
&__logo {
width: 96px;
height: 96px;
margin-top: 5vh;
border-radius: 50%;
}
.agreement {
display: flex;
align-items: center;
margin: 20px 0;
&__animation {
width: 200rpx;
height: 200rpx;
}
&__tips {
margin-top: 10px;
}
.agreement-text {
font-size: 14px;
color: #666;
margin-left: 5px;
}
//
.login-form {
padding: 20px;
width: 90%;
margin: 0 auto;
.link {
color: #333;
}
}
.input-item {
border-bottom: 1px solid #eee;
padding: 15px 0;
margin-bottom: 15px;
.button-group {
display: flex;
justify-content: space-between;
margin-top: 40px;
input {
width: 100%;
font-size: 16px;
}
}
.code-input {
display: flex;
justify-content: space-between;
align-items: center;
input {
flex: 1;
}
.send-code-btn {
background-color: #333;
color: #fff;
padding: 6px 12px;
border-radius: 4px;
font-size: 14px;
}
}
.agreement {
.btn {
height: 45px;
border-radius: 4px;
font-size: 16px;
display: flex;
align-items: center;
margin: 20px 0;
.agreement-text {
font-size: 14px;
color: #666;
margin-left: 5px;
}
.link {
color: #333;
}
justify-content: center;
}
.button-group {
display: flex;
justify-content: space-between;
margin-top: 40px;
.btn {
height: 45px;
border-radius: 4px;
font-size: 16px;
display: flex;
align-items: center;
justify-content: center;
}
.btn-refuse {
flex: 1;
background-color: #c0ff00;
color: #333;
margin-right: 10px;
}
.btn-login {
flex: 2;
background-color: #333;
color: #fff;
}
.btn-refuse {
flex: 1;
background-color: #c0ff00;
color: #333;
margin-right: 10px;
}
.btn-login {
flex: 2;
background-color: #333;
color: #fff;
}
}
</style>