wjt
2024-06-22 6f44eb561c9a728e3ff4862554047abc31640ca7
修改手机号添加
5个文件已修改
102 ■■■■ 已修改文件
api/auth.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/policy.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/http.interceptor.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
policy/changePhone/changePhone.vue 74 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
policy/components/mine.vue 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/auth.js
@@ -32,4 +32,8 @@
// 新注册获取验证码 /verify/getNew
export function getNewVerify(data) {
    return http.get(`/verify/getNew`, {params: data});
}
// 更换手机号码 updatePhone
export function updatePhone(data) {
    return http.post(`/system/user/profile/updatePhone/${data.phone}`, data);
}
api/policy.js
@@ -62,7 +62,3 @@
export function orderUpd(data) {
    return http.post(`/enforce/order/doResultOrder`, data, { custom: { loading: true }});
}
// 企业被执法次数 /report/team/getCompanyCount
export function getCompanyCount(data) {
    return http.get(`/report/team/getCompanyCount`, data, { custom: { loading: true }});
}
common/http.interceptor.js
@@ -60,7 +60,7 @@
                // vm.$u.vuex('userInfo', null)
                // vm.$u.vuex('token', null)
                // uni.removeStorageSync("sessionToken")
                // uni.clearStorageSync() // 清楚所有的缓存
                uni.clearStorageSync() // 清楚所有的缓存
                uni.showToast({
                    title: '授权过期,请重新登录',
                    icon: 'none',
policy/changePhone/changePhone.vue
@@ -8,7 +8,7 @@
                        手机号
                    </view>
                    <view class="form-input">
                        <input type="number"  placeholder="请输入11位手机号"/>
                        <input type="number"  placeholder="请输入11位手机号" v-model="form.phone"/>
                    </view>
                </view>
                <view class="form-item">
@@ -16,7 +16,7 @@
                        验证码
                    </view>
                    <view class="form-input set-flex set-flex-content-between">
                        <input type="number" placeholder="请输入验证码"/>
                        <input type="number" placeholder="请输入验证码" v-model="form.code"/>
                        <view @click="getCode">
                            <text class="driver"></text>
                            <text class="getcode">{{tips}}</text>
@@ -25,15 +25,14 @@
                </view>
            </view>
            <view style="margin-top: 56rpx;">
                <view class="per-button" @click="loging">修改手机号</view>
                <view class="per-button" @click="changeCode">修改手机号</view>
            </view>
        </view>
    </view>
</template>
<script>
    // 00营商办,01执法,02企业 区分不同的登陆页面
    import { getCode, codeLogin, getInfo } from '@/api/auth.js'
    import { getNewVerify, getInfo, checkCode, updatePhone } from '@/api/auth.js'
    export default {
        data() {
            return {
@@ -50,6 +49,7 @@
            }
        },
        onLoad(options) {
            console.log(options)
            if(options.code) {
                this.form.userType = options.code
            }
@@ -81,10 +81,13 @@
                    uni.showLoading({
                        title: '正在获取验证码'
                    })
                    getCode({phone: this.form.phone }).then(val => {
                            this.startCountdown()
                            uni.hideLoading();
                            uni.$u.toast('验证码已发送');
                    getNewVerify({phone: this.form.phone }).then(val => {
                            if(val.data.code == 200) {
                                this.startCountdown()
                                uni.hideLoading();
                                this.tips = `${this.countdownTime}s后重新获取`
                                uni.$u.toast('验证码已发送');
                            }
                    })
                } else {
                    uni.$u.toast('倒计时结束后再发送');
@@ -107,13 +110,54 @@
                    this.startCountdown()
                }, 1000)
            },
            loging() {
                codeLogin(this.form).then(val => {
                    if(val.data.token) {
                        this.loginToken = val.data.token
                        uni.setStorageSync('sessionToken', this.loginToken)
                        this.getInfo()
            async checkCode() {
                try{
                    const { data } = await checkCode(this.form)
                    if(data.code == 200 && data.data) {
                        return Promise.resolve()
                    } else {
                        uni.showToast({
                            title: '验证码错误',
                            icon: 'none'
                        })
                        throw "验证码错误"
                        return Promise.reject('验证码错误')
                    }
                } catch(err) {
                    uni.showToast({
                        title: '验证码错误',
                        icon: 'none'
                    })
                    throw "验证码错误"
                }
            },
            async changeCode() {
                await this.checkCode()
                if(!this.form.phone){
                    uni.showToast({
                        title: '请输入手机号',
                        icon: 'none'
                    })
                    return
                }
                if(!this.$u.test.mobile(this.form.phone)){
                    uni.showToast({
                        title: '请输入正确的手机号',
                        icon: 'none'
                    })
                    return
                }
                updatePhone(this.form).then(val => {
                    if(val.data.code == 200) {
                        uni.showToast({
                            title: '修改成功',
                            icon: 'none'
                        })
                        setTimeout(() => {
                            uni.navigateBack()
                        }, 500)
                    }
                })
            },
            getInfo() {
policy/components/mine.vue
@@ -31,7 +31,7 @@
                <u-icon name="arrow-right"></u-icon>
            </view>
        </view>
        <view class="logout">
        <view class="logout" @click="logOut">
            退出登录
        </view>
    </view>
@@ -53,7 +53,21 @@
        methods: {
            goChangePhone() {
                uni.navigateTo({
                    url: '/policy/changePhone/changePhone'
                    url: `/policy/changePhone/changePhone?code=${this.userInfo.data.userType}`
                })
            },
            logOut() {
                uni.showModal({
                    title: '提示',
                    content: '确认退出登录?',
                    success: res => {
                        if(res.confirm) {
                            uni.clearStorageSync()
                            uni.redirectTo({
                                url: '/pages/index/index'
                            })
                        }
                    }
                })
            }
        }