优化小程序

This commit is contained in:
hero920103 committed 2026-10-31 01:21:55 +08:00
1 parent 2e2b837a20
commit 727319a6eb
24 files changed
+1509 -200

No files matched your search

+13
View File
@@ -118,6 +118,19 @@ export function loginByMiniapp({ code, phoneCode = '' } = {}) {
})
}
/**
* 小程序端确认注册:网页注册页展示的小程序码扫码进入本页,
* 用户点确认后由服务端把 openid 绑定到该注册会话,网页端即可继续注册。
* @param {{ scene: string, code: string, phoneCode?: string, appid?: string }} params
*/
export function confirmMiniappRegister({ scene, code, phoneCode = '', appid = '' } = {}) {
return request({
url: '/auth/register/mini/confirm',
method: 'POST',
data: { scene, code, phone_code: phoneCode, appid }
})
}
/**
* 已登录态下把当前微信 openid 绑定到该账号(静默调用,失败不提示)。
* 小程序认证中 / 未开通手机号能力时,一键登录靠这条绑定按 openid 认人。
-39
View File
@@ -4789,9 +4789,6 @@
"cpu": [
"arm"
],
"libc": [
"glibc"
],
"license": "MIT",
"optional": true,
"os": [
@@ -4812,9 +4809,6 @@
"cpu": [
"arm"
],
"libc": [
"musl"
],
"license": "MIT",
"optional": true,
"os": [
@@ -4835,9 +4829,6 @@
"cpu": [
"arm64"
],
"libc": [
"glibc"
],
"license": "MIT",
"optional": true,
"os": [
@@ -4858,9 +4849,6 @@
"cpu": [
"arm64"
],
"libc": [
"musl"
],
"license": "MIT",
"optional": true,
"os": [
@@ -4881,9 +4869,6 @@
"cpu": [
"x64"
],
"libc": [
"glibc"
],
"license": "MIT",
"optional": true,
"os": [
@@ -4904,9 +4889,6 @@
"cpu": [
"x64"
],
"libc": [
"musl"
],
"license": "MIT",
"optional": true,
"os": [
@@ -5080,9 +5062,6 @@
"cpu": [
"arm64"
],
"libc": [
"glibc"
],
"license": "MIT",
"optional": true,
"os": [
@@ -5096,9 +5075,6 @@
"cpu": [
"arm64"
],
"libc": [
"musl"
],
"license": "MIT",
"optional": true,
"os": [
@@ -5112,9 +5088,6 @@
"cpu": [
"ppc64"
],
"libc": [
"glibc"
],
"license": "MIT",
"optional": true,
"os": [
@@ -5128,9 +5101,6 @@
"cpu": [
"riscv64"
],
"libc": [
"glibc"
],
"license": "MIT",
"optional": true,
"os": [
@@ -5144,9 +5114,6 @@
"cpu": [
"s390x"
],
"libc": [
"glibc"
],
"license": "MIT",
"optional": true,
"os": [
@@ -5160,9 +5127,6 @@
"cpu": [
"x64"
],
"libc": [
"glibc"
],
"license": "MIT",
"optional": true,
"os": [
@@ -5176,9 +5140,6 @@
"cpu": [
"x64"
],
"libc": [
"musl"
],
"license": "MIT",
"optional": true,
"os": [
+9 -1
View File
@@ -412,12 +412,20 @@
}
},
{
"path {
"path": "pages/login/forget",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "忘记密码"
}
},
},
{
"path": "pages/register/confirm",
"style": {
"navigationStyle": "custom",
"navigationBarTitleText": "确认注册"
}
},
{
"path": "pages/login/geetest-webview",
"style": {
+174
View File
@@ -0,0 +1,174 @@
<template>
<view class="rp-page">
<view class="rp-card">
<text class="rp-title">确认注册</text>
<text class="rp-desc">你正在为电脑端的账号注册完成身份确认。点击确认后,请回到电脑继续填写账号信息。</text>
<button class="rp-btn" :class="{ disabled: loading }" :disabled="loading" @tap="confirm('')">
{{ loading ? '确认中…' : '确认是我本人注册' }}
</button>
<!-- #ifdef MP-WEIXIN -->
<button class="rp-btn ghost" :disabled="loading" open-type="getPhoneNumber" @getphonenumber="onPhone">
验证手机号并确认(可选)
</button>
<!-- #endif -->
<text class="rp-status" :class="{ ok: success, err: !!errorMsg }">{{ statusText }}</text>
<view class="rp-back" @tap="backHome">
<text class="rp-link">返回首页</text>
</view>
</view>
</view>
</template>
<script setup>
/**
* 小程序码扫码注册确认页:
* 电脑端注册页展示小程序码(scene=注册会话)→ 微信扫码进入本页 →
* uni.login 取 code 调 /auth/register/mini/confirm → 电脑端轮询到已确认后继续注册。
*/
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { confirmMiniappRegister } from '@/api/auth.js'
const scene = ref('')
const loading = ref(false)
const success = ref(false)
const errorMsg = ref('')
const statusText = ref('')
onLoad((options = {}) => {
// scene 由小程序码携带,微信会自动做一次 URL 解码
scene.value = options.scene || ''
if (!scene.value) {
errorMsg.value = '缺少会话标识,请回到电脑端重新获取二维码'
statusText.value = errorMsg.value
}
})
function miniAppId() {
try {
const info = uni.getAccountInfoSync()
return (info && info.miniProgram && info.miniProgram.appId) || ''
} catch (e) {
return ''
}
}
function uniLoginCode() {
return new Promise((resolve, reject) => {
uni.login({
provider: 'weixin',
success: (res) => (res && res.code ? resolve(res.code) : reject(new Error('获取登录凭证失败'))),
fail: () => reject(new Error('获取登录凭证失败'))
})
})
}
async function confirm(phoneCode = '') {
if (loading.value) return
if (!scene.value) {
errorMsg.value = '缺少会话标识,请回到电脑端重新获取二维码'
statusText.value = errorMsg.value
return
}
loading.value = true
errorMsg.value = ''
statusText.value = '正在确认…'
try {
const code = await uniLoginCode()
await confirmMiniappRegister({ scene: scene.value, code, phoneCode, appid: miniAppId() })
success.value = true
statusText.value = '确认成功,请回到电脑继续完成注册'
uni.showToast({ title: '确认成功', icon: 'success' })
} catch (err) {
errorMsg.value = (err && err.message) || '确认失败,请返回电脑端重新获取二维码'
statusText.value = errorMsg.value
} finally {
loading.value = false
}
}
/** 手机号快速验证为可选项:未开通或用户拒绝时仍按 openid 完成确认 */
function onPhone(e) {
const detail = (e && e.detail) || {}
const errMsg = detail.errMsg || ''
if (errMsg.indexOf('deny') !== -1) {
uni.showToast({ title: '已取消手机号授权', icon: 'none' })
return
}
const phoneCode = detail.code && errMsg.indexOf('fail') === -1 ? detail.code : ''
confirm(phoneCode)
}
function backHome() {
uni.reLaunch({ url: '/pages/index/index' })
}
</script>
<style scoped>
.rp-page {
min-height: 100vh;
padding: 48rpx 32rpx;
box-sizing: border-box;
background: #f6f8fb;
}
.rp-card {
background: #ffffff;
border-radius: 20rpx;
padding: 48rpx 36rpx;
box-shadow: 0 8rpx 24rpx rgba(15, 23, 42, 0.06);
}
.rp-title {
font-size: 40rpx;
font-weight: 600;
color: #1f2937;
}
.rp-desc {
display: block;
margin-top: 16rpx;
font-size: 26rpx;
line-height: 1.7;
color: #6b7280;
}
.rp-btn {
margin-top: 40rpx;
height: 88rpx;
line-height: 88rpx;
font-size: 30rpx;
color: #ffffff;
background: #2563eb;
border-radius: 12rpx;
}
.rp-btn.ghost {
margin-top: 20rpx;
color: #2563eb;
background: #ffffff;
border: 1rpx solid #2563eb;
}
.rp-btn.disabled {
opacity: 0.6;
}
.rp-status {
display: block;
margin-top: 28rpx;
font-size: 26rpx;
color: #6b7280;
}
.rp-status.ok {
color: #16a34a;
}
.rp-status.err {
color: #dc2626;
}
.rp-back {
margin-top: 36rpx;
text-align: center;
}
.rp-link {
font-size: 26rpx;
color: #2563eb;
}
</style>