13404089107
2026-04-24 55fe68b0b9de887c555fcce3fc7dbb0e6b17683f
feat: 切换API基础URL并优化微信登录功能

- 将BASE_URL从本地开发环境切换至线上生产环境
- 在manifest.json中添加payment配置项
- 重构微信登录逻辑,使用plus.oauth.getServices实现更稳定的授权流程
- 改进代码格式和缩进以提高可读性
3个文件已修改
101 ■■■■■ 已修改文件
traditionalApp/config/index.js 4 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
traditionalApp/manifest.json 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
traditionalApp/pages/login/login.vue 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
traditionalApp/config/index.js
@@ -1,6 +1,6 @@
export default {
    BASE_URL: 'http://192.168.110.188:48080',
    // BASE_URL: 'https://haizhentong.com',
    // BASE_URL: 'http://192.168.110.188:48080',
    BASE_URL: 'https://haizhentong.com',
    uploadUrl: "https://haizhentong.com/api/open/file/upload",
    imageUrl: 'http://221.182.45.100:11224/images/'
};
traditionalApp/manifest.json
@@ -73,7 +73,8 @@
                        "appid": "wx074c1f0cf5a0ecf4",
                        "UniversalLinks": "https://static-mp-dd6d96de-bdf2-4284-a975-638af4cc8ec8.next.bspapp.com/uni-universallinks/__UNI__1A90541/"
                    }
                }
                },
                "payment" : {}
            },
            "icons": {
                "android": {
traditionalApp/pages/login/login.vue
@@ -4,46 +4,33 @@
        <view class="title">欢迎登录</view>
        <view class="tabs">
            <view class="tab" :class="loginType === 'code' ? 'active' : 'normal'" @tap="switchLoginType('code')">验证码登录</view>
            <view class="tab" :class="loginType === 'password' ? 'active' : 'normal'" @tap="switchLoginType('password')">密码登录</view>
            <view class="tab" :class="loginType === 'code' ? 'active' : 'normal'" @tap="switchLoginType('code')">验证码登录
            </view>
            <view class="tab" :class="loginType === 'password' ? 'active' : 'normal'"
                @tap="switchLoginType('password')">密码登录</view>
        </view>
        <view class="form">
            <view class="input-group">
                <input
                    class="input"
                    type="number"
                    maxlength="11"
                    v-model="phone"
                    placeholder="输入手机号"
                    placeholder-class="placeholder-style"
                />
                <view
                    class="get-code-btn"
                    :class="{ disabled: countdown > 0 }"
                    v-if="loginType === 'code'"
                    @tap="handleSendCode"
                >
                <input class="input" type="number" maxlength="11" v-model="phone" placeholder="输入手机号"
                    placeholder-class="placeholder-style" />
                <view class="get-code-btn" :class="{ disabled: countdown > 0 }" v-if="loginType === 'code'"
                    @tap="handleSendCode">
                    {{ countdown > 0 ? `${countdown}s` : '获取验证码' }}
                </view>
            </view>
            <view class="input-group">
                <input
                    class="input"
                    :type="loginType === 'code' ? 'number' : 'text'"
                    :password="loginType === 'password'"
                    :maxlength="loginType === 'code' ? 6 : 32"
                    v-model="credential"
                    :placeholder="loginType === 'code' ? '输入验证码' : '输入密码'"
                    placeholder-class="placeholder-style"
                />
                <input class="input" :type="loginType === 'code' ? 'number' : 'text'"
                    :password="loginType === 'password'" :maxlength="loginType === 'code' ? 6 : 32" v-model="credential"
                    :placeholder="loginType === 'code' ? '输入验证码' : '输入密码'" placeholder-class="placeholder-style" />
            </view>
        </view>
        <view class="login-btn" @tap="handleLogin">{{ loading ? '登录中...' : '登录' }}</view>
        <view class="action-links" :class="{ 'center': loginType === 'code', 'space-between': loginType === 'password' }">
        <view class="action-links"
            :class="{ 'center': loginType === 'code', 'space-between': loginType === 'password' }">
            <text class="register-link" @tap="goRegister">没有账号?点击注册</text>
            <text class="forgot-password" v-if="loginType === 'password'" @tap="goForgotPassword">忘记密码?</text>
        </view>
@@ -199,9 +186,13 @@
                url: '/pages/home/home'
            })
        }, 300)
    } catch (error) {
        } catch (error: any) {
            const errorCode = error?.code
            const errorMessage = typeof error?.errMsg === 'string' ? error.errMsg : ''
        uni.showToast({
            title: '微信登录失败',
                title: errorCode === -7
                    ? '请重新云打包,并检查 manifest 中微信登录配置'
                    : (errorMessage || '微信登录失败'),
            icon: 'none'
        })
    } finally {
@@ -222,6 +213,53 @@
 */
const requestWechatAuthorization = () => {
    return new Promise<WechatLoginResult>((resolve, reject) => {
            // #ifdef APP-PLUS
            plus.oauth.getServices((services) => {
                const weixinService = services.find((service) => service.id === 'weixin')
                if (!weixinService) {
                    reject({
                        code: -3,
                        errMsg: '当前环境不支持微信登录'
                    })
                    return
                }
                if (!weixinService.nativeClient) {
                    reject({
                        code: -8,
                        errMsg: '请先安装微信客户端'
                    })
                    return
                }
                weixinService.authorize((event : any) => {
                    const code = normalizeOptionalText(event?.code)
                    if (!code) {
                        reject({
                            code: -99,
                            errMsg: '微信授权未返回有效code'
                        })
                        return
                    }
                    resolve({
                        code
                    })
                }, (error : any) => {
                    reject({
                        code: error?.code,
                        errMsg: error?.message || '微信授权失败'
                    })
                }, {
                    scope: 'snsapi_userinfo',
                    state: 'login'
                })
            }, (error : any) => {
                reject({
                    code: error?.code,
                    errMsg: error?.message || '获取微信登录服务失败'
                })
            })
            return
            // #endif
        uni.login({
            provider: 'weixin',
            success: (res) => {