feat: 登录扫一扫
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 46s

This commit is contained in:
sexygoat
2026-04-16 17:11:09 +08:00
parent e0db2b6df0
commit b56f68636c
2 changed files with 74 additions and 1 deletions

View File

@@ -42,7 +42,12 @@
<view class="dot"/>
<view class="dot"/>
</view>
<text v-else>登录</text>
<text v-else>立即登录</text>
</button>
<button class="btn-scan" @tap="handleScanLogin">
<image src="/static/scan-code.png" mode="aspectFit" class="scan-icon"></image>
<text>扫一扫登录</text>
</button>
</view>
@@ -72,6 +77,8 @@
if (token) {
uni.reLaunch({ url: '/pages/index/index' });
}
handleWechatCallback();
getPathDeviceId();
});
const identifier = ref('');
@@ -118,6 +125,46 @@
doLogin();
};
const handleScanLogin = () => {
// #ifdef H5
if (typeof wx === 'undefined' || !wx.scanQRCode) {
uni.showToast({ title: '请在微信中打开', icon: 'none' });
return;
}
wx.scanQRCode({
needResult: 1,
scanType: ['qrCode', 'barCode'],
success: (res) => {
const result = res.resultStr;
if (result && result.includes('device_id')) {
const match = result.match(/device_id[=]([^&]*)/);
if (match && match[1]) {
identifier.value = match[1];
handleLogin();
}
} else {
uni.showToast({ title: '无效的二维码', icon: 'none' });
}
},
fail: () => {
uni.showToast({ title: '扫码失败', icon: 'none' });
}
});
// #endif
// #ifndef H5
uni.showToast({ title: '请在微信中打开', icon: 'none' });
// #endif
};
const getPathDeviceId = () => {
const params = new URLSearchParams(window.location.search);
const deviceId = params.get('device_id');
if (deviceId) {
identifier.value = deviceId;
handleLogin();
}
};
const doLogin = async () => {
loading.value = true;
try {
@@ -341,6 +388,32 @@
box-shadow: 0 2rpx 8rpx rgba(10, 132, 255, 0.2);
}
.btn-scan {
width: 100%;
height: 88rpx;
background: var(--bg-primary);
border: 2rpx solid var(--primary);
border-radius: var(--radius-medium);
font-size: 30rpx;
font-weight: 500;
color: var(--primary);
display: flex;
align-items: center;
justify-content: center;
gap: 12rpx;
margin-top: 24rpx;
transition: all 0.3s ease;
}
.btn-scan:active {
background: rgba(10, 132, 255, 0.05);
}
.scan-icon {
width: 40rpx;
height: 40rpx;
}
.loading {
display: flex;
align-items: center;

BIN
static/scan-code.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB