feat: 去变现添加 获取验证码

This commit is contained in:
2026-06-01 16:49:05 +08:00
parent 0f2a64f3b2
commit 4d16af0ad6
7 changed files with 112 additions and 11 deletions
+103 -2
View File
@@ -33,6 +33,22 @@
<view class="tip-text">请输入去变现数量</view> <view class="tip-text">请输入去变现数量</view>
</view> </view>
<view class="card code-card">
<view class="code-row">
<uni-easyinput
v-model="smsCode"
type="number"
placeholder="请输入验证码"
placeholder-style="font-size: 28rpx;color:#C6C6C6;"
:inputBorder="false"
:maxlength="6"
/>
<view class="code-btn" :class="{ disabled: smsCountdown > 0 }" @click="sendSmsCode">
{{ smsCountdown > 0 ? `${smsCountdown}s` : '获取验证码' }}
</view>
</view>
</view>
<view class="card tip-card"> <view class="card tip-card">
<view class="tip-header"> <view class="tip-header">
<view class="tip-title">兑换提示</view> <view class="tip-title">兑换提示</view>
@@ -54,10 +70,15 @@
import { onShow } from '@dcloudio/uni-app'; import { onShow } from '@dcloudio/uni-app';
import * as payApi from '@/sheep/api/home/pay'; import * as payApi from '@/sheep/api/home/pay';
import * as incrementApi from '@/sheep/api/increment'; import * as incrementApi from '@/sheep/api/increment';
import AuthUtil from '@/sheep/api/member/auth';
import sheep from '@/sheep'; import sheep from '@/sheep';
const walletBalanceCents = ref(0); const walletBalanceCents = ref(0);
const amount = ref(''); const amount = ref('');
const smsCode = ref('');
const smsCountdown = ref(0);
const smsScene = 7;
let smsTimer = null;
const sanitizeAmountInput = (val) => { const sanitizeAmountInput = (val) => {
let next = String(val ?? '').replace(/[^\d.]/g, ''); let next = String(val ?? '').replace(/[^\d.]/g, '');
@@ -112,15 +133,64 @@
amount.value = availableYuan.value > 0 ? String(availableYuan.value.toFixed(2)) : '0'; amount.value = availableYuan.value > 0 ? String(availableYuan.value.toFixed(2)) : '0';
return; return;
} }
if (!String(smsCode.value || '').trim()) {
sheep.$helper.toast('请输入验证码');
return;
}
const userStore = sheep.$store('user');
if (!userStore?.userInfo?.mobile) {
await userStore?.getInfo?.().catch(() => {});
}
const mobile = userStore?.userInfo?.mobile;
if (!mobile) {
sheep.$helper.toast('未绑定手机号');
return;
}
const money = Math.round(amt * 100); const money = Math.round(amt * 100);
const res = await incrementApi.walletLiquidation({ money }).catch(() => ({ code: -1 })); const payload = { money, mobile, scene: smsScene, code: smsCode.value };
const res = await incrementApi.walletLiquidation(payload).catch(() => ({ code: -1 }));
if (res?.code === 0) { if (res?.code === 0) {
sheep.$helper.toast('提交成功'); sheep.$helper.toast('提交成功');
amount.value = ''; amount.value = '';
smsCode.value = '';
refreshWallet(); refreshWallet();
} }
}; };
const sendSmsCode = async () => {
if (smsCountdown.value > 0) return;
const amt = amountNumber.value;
if (!amt) {
sheep.$helper.toast('请输入去变现数量');
return;
}
if (amt > availableYuan.value) {
sheep.$helper.toast('变现金额不能大于钱包余额');
return;
}
const userStore = sheep.$store('user');
if (!userStore?.userInfo?.mobile) {
await userStore?.getInfo?.().catch(() => {});
}
const mobile = userStore?.userInfo?.mobile;
if (!mobile) {
sheep.$helper.toast('未绑定手机号');
return;
}
const res = await AuthUtil.sendSmsCode({ mobile, scene: smsScene }).catch(() => ({ code: -1 }));
if (res?.code !== 0) return;
smsCountdown.value = 60;
if (smsTimer) clearInterval(smsTimer);
smsTimer = setInterval(() => {
smsCountdown.value -= 1;
if (smsCountdown.value <= 0) {
clearInterval(smsTimer);
smsTimer = null;
smsCountdown.value = 0;
}
}, 1000);
};
const goRecord = () => { const goRecord = () => {
uni.navigateTo({ uni.navigateTo({
url: '/pages/home/liquidationRecord', url: '/pages/home/liquidationRecord',
@@ -165,6 +235,7 @@
background: #f4f8f2; background: #f4f8f2;
border-radius: 24rpx; border-radius: 24rpx;
padding: 28rpx; padding: 28rpx;
box-shadow: 0 10rpx 26rpx rgba(0, 0, 0, 0.08);
} }
.balance-card { .balance-card {
@@ -202,6 +273,37 @@
padding: 24rpx 28rpx; padding: 24rpx 28rpx;
} }
.code-card {
padding: 18rpx 22rpx;
margin: 20rpx 0;
}
.code-row {
display: flex;
align-items: center;
}
.code-btn {
margin-left: 18rpx;
min-width: 168rpx;
height: 68rpx;
padding: 0 18rpx;
border-radius: 16rpx;
background: rgba(54, 110, 238, 0.12);
color: #366eee;
font-size: 26rpx;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
white-space: nowrap;
}
.code-btn.disabled {
opacity: 0.6;
}
.amount-row { .amount-row {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -276,4 +378,3 @@
justify-content: center; justify-content: center;
} }
</style> </style>
+1 -1
View File
@@ -88,7 +88,7 @@
sendCode(); sendCode();
}; };
const sendCode = async () => { const sendCode = async () => {
AuthUtil.sendSmsCode(formData.value.mobile, 3).then((res) => { AuthUtil.sendSmsCode({ mobile: formData.value.mobile, scene: 3 }).then((res) => {
if (res.code === 0) { if (res.code === 0) {
num.value = 60; num.value = 60;
timer.value = setInterval(() => { timer.value = setInterval(() => {
+2 -2
View File
@@ -111,7 +111,7 @@
sendCode(); sendCode();
}; };
const sendCode = async () => { const sendCode = async () => {
AuthUtil.sendSmsCode(formData.value.mobile, 3).then((res) => { AuthUtil.sendSmsCode({ mobile: formData.value.mobile, scene: 3 }).then((res) => {
if (res.code === 0) { if (res.code === 0) {
num.value = 60; num.value = 60;
timer.value = setInterval(() => { timer.value = setInterval(() => {
@@ -125,7 +125,7 @@
}); });
}; };
const sendCode1 = async () => { const sendCode1 = async () => {
AuthUtil.sendSmsCode(formData.value.mobile1, 3).then((res) => { AuthUtil.sendSmsCode({ mobile: formData.value.mobile1, scene: 3 }).then((res) => {
if (res.code === 0) { if (res.code === 0) {
num1.value = 60; num1.value = 60;
timer1.value = setInterval(() => { timer1.value = setInterval(() => {
+1 -1
View File
@@ -26,7 +26,7 @@
<view class="title-right" /> <view class="title-right" />
</view> </view>
<!-- 商品 --> <!-- 商品 -->
<su-sticky top="100rpx"> <su-sticky top="0">
<view class="goodsIndex"> <view class="goodsIndex">
<goods :list="tagList" v-if="tagList?.length"></goods> <goods :list="tagList" v-if="tagList?.length"></goods>
</view> </view>
+1 -1
View File
@@ -313,7 +313,7 @@
numType = 4; numType = 4;
break; break;
} }
AuthUtil.sendSmsCode(formData.mobile, numType).then((res) => { AuthUtil.sendSmsCode({ mobile: formData.mobile, scene: numType }).then((res) => {
if (res.code === 0) { if (res.code === 0) {
num.value = 60; num.value = 60;
timer.value = setInterval(() => { timer.value = setInterval(() => {
+3 -3
View File
@@ -28,13 +28,13 @@ const AuthUtil = {
}); });
}, },
// 发送手机验证码 // 发送手机验证码
sendSmsCode: (mobile, scene) => { sendSmsCode: (data) => {
return request({ return request({
url: '/member/auth/send-sms-code', url: '/member/auth/send-sms-code',
method: 'POST', method: 'POST',
data: { data: {
mobile, mobile: data?.mobile,
scene, scene: data?.scene,
}, },
custom: { custom: {
loadingMsg: '发送中', loadingMsg: '发送中',
+1 -1
View File
@@ -96,7 +96,7 @@ export function getSmsCode(event, mobile) {
scene = 1; scene = 1;
break; break;
} }
AuthUtil.sendSmsCode(mobile, scene).then((res) => { AuthUtil.sendSmsCode({ mobile, scene }).then((res) => {
if (res.code === 0) { if (res.code === 0) {
modalStore.$patch((state) => { modalStore.$patch((state) => {
state.lastTimer[event] = dayjs().unix(); state.lastTimer[event] = dayjs().unix();