8.15提交
This commit is contained in:
+143
-44
@@ -47,7 +47,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 登录按钮 -->
|
||||
<view class="login-button" @click="goPwdLogin" >
|
||||
<view class="login-button" @click="onSmsLogin" :class="{ disabled: !canLogin }">
|
||||
<text class="button-text">登录</text>
|
||||
</view>
|
||||
<view class="sms-login" @click="goPwdLogin">
|
||||
@@ -94,7 +94,10 @@
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted, computed } from 'vue';
|
||||
import { onShow, onLoad } from "@dcloudio/uni-app";
|
||||
import auth from "@/utils/auth";
|
||||
import api from "@/api/api.js"
|
||||
import sortObj from "@/utils/sort"
|
||||
import version from "@/utils/version.js"
|
||||
import client_type from "@/utils/client_type.js"
|
||||
import logo from "@/static/icon_login_logo.png"
|
||||
import wxImg from "@/static/weixin_login.png"
|
||||
import checkImg from "@/static/login_new_unselect.png"
|
||||
@@ -102,7 +105,8 @@
|
||||
import phoneImg from "@/static/phone.png"
|
||||
import smsImg from "@/static/sms.png"
|
||||
import pwdImg from "@/static/pwd.png"
|
||||
|
||||
import { Base64 } from 'js-base64';
|
||||
import { md5 } from 'js-md5';
|
||||
const customStyle = reactive({
|
||||
height: "100rpx",
|
||||
fontSize: "36rpx",
|
||||
@@ -142,9 +146,9 @@
|
||||
icon:'none'
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
// 发送验证码
|
||||
const sendSmsCode = () => {
|
||||
const sendSmsCode = async () => {
|
||||
if (isCountingDown.value) {
|
||||
return;
|
||||
}
|
||||
@@ -165,30 +169,76 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// 开始倒计时
|
||||
isCountingDown.value = true;
|
||||
countdown.value = 60;
|
||||
|
||||
const timer = setInterval(() => {
|
||||
countdown.value--;
|
||||
if (countdown.value <= 0) {
|
||||
clearInterval(timer);
|
||||
isCountingDown.value = false;
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
// 模拟发送验证码
|
||||
uni.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'success'
|
||||
});
|
||||
|
||||
// 这里应该调用实际的发送验证码API
|
||||
console.log('发送验证码到:', phoneNumber.value);
|
||||
try {
|
||||
const timeResult = await api.getTimeStamp();
|
||||
|
||||
let timestamp=timeResult.data.timestamp.toString();
|
||||
let postData={
|
||||
mobile: phoneNumber.value,
|
||||
version:version,
|
||||
user_uuid:'',
|
||||
client_type:'A', //client_type,
|
||||
timestamp:timestamp,
|
||||
type:2,
|
||||
}
|
||||
let obj=sortObj(postData)
|
||||
let str1 = formatString(obj).replace(" ",'');
|
||||
let str2=str1+md5(timestamp);
|
||||
let str3=md5(str2);
|
||||
let sign=Base64.encode(str3).replace('+', '-').replace('/', '_').replaceAll("=", "");
|
||||
// 调用真实API获取验证码
|
||||
const result = await api.getCode(postData,{
|
||||
sign:sign
|
||||
});
|
||||
|
||||
if (result.data.code === 200) {
|
||||
uni.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
});
|
||||
|
||||
// 开始倒计时
|
||||
isCountingDown.value = true;
|
||||
countdown.value = 60;
|
||||
|
||||
const timer = setInterval(() => {
|
||||
countdown.value--;
|
||||
if (countdown.value <= 0) {
|
||||
clearInterval(timer);
|
||||
isCountingDown.value = false;
|
||||
}
|
||||
}, 1000);
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: result.data.message || '发送失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error);
|
||||
uni.showToast({
|
||||
title: '发送验证码失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const formatString=(obj)=>{
|
||||
let str=''
|
||||
for (var key in obj) {
|
||||
if(str){
|
||||
str+=key+obj[key]
|
||||
}else{
|
||||
str=key+obj[key]
|
||||
}
|
||||
}
|
||||
console.log(str);
|
||||
return str
|
||||
}
|
||||
// 短信验证码登录
|
||||
const onSmsLogin = () => {
|
||||
const onSmsLogin = async () => {
|
||||
if (!isAgreed.value) {
|
||||
uni.showToast({
|
||||
title: '请先同意相关协议',
|
||||
@@ -229,26 +279,75 @@
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('短信验证码登录');
|
||||
uni.showLoading({
|
||||
title: '登录中...'
|
||||
});
|
||||
|
||||
// 模拟登录过程
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'success'
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: '登录中...'
|
||||
});
|
||||
const res = uni.getSystemInfoSync();
|
||||
const timeResult = await api.getTimeStamp();
|
||||
|
||||
let timestamp=timeResult.data.timestamp.toString();
|
||||
|
||||
let postData={
|
||||
mobile: phoneNumber.value,
|
||||
version:version,
|
||||
user_uuid:'',
|
||||
current_spec:res.model,
|
||||
sms:smsCode.value,
|
||||
timestamp:timestamp,
|
||||
client_type:'A'
|
||||
}
|
||||
let obj=sortObj(postData)
|
||||
let str1 = formatString(obj).replace(" ",'');
|
||||
console.log("str1:"+str1)
|
||||
let str2=str1+md5(timestamp);
|
||||
console.log("str2:"+str2)
|
||||
let str3=md5(str2);
|
||||
console.log("str3:"+str3)
|
||||
let sign=Base64.encode(str3).replace('+', '-').replace('/', '_').replaceAll("=", "");
|
||||
console.log("sign:"+sign)
|
||||
|
||||
// 调用真实API进行短信登录
|
||||
const result = await api.smsLogin(postData,{
|
||||
sign:sign
|
||||
});
|
||||
|
||||
// 跳转到首页
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
uni.hideLoading();
|
||||
|
||||
if (result.data.code === 200) {
|
||||
// 保存用户信息到本地存储
|
||||
if (result.data.data && result.data.data.token) {
|
||||
uni.setStorageSync('AUTH_TOKEN_App', result.data.data.token);
|
||||
if (result.data.data.userInfo) {
|
||||
uni.setStorageSync('USER_INFO', result.data.data.userInfo);
|
||||
}
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'none'
|
||||
});
|
||||
}, 1500);
|
||||
}, 2000);
|
||||
|
||||
// 跳转到首页
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: '/pages/index/index'
|
||||
});
|
||||
},0);
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: result.data.message || '登录失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
uni.hideLoading();
|
||||
console.error('登录失败:', error);
|
||||
uni.showToast({
|
||||
title: '登录失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 微信登录
|
||||
|
||||
Reference in New Issue
Block a user