Files
houyi-uniapp/pages/me/userName - 副本.vue
PC-202306242200\Administrator 85b89ccea7 first commit
2026-03-28 23:27:25 +08:00

130 lines
3.4 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view style="padding: 30rpx;">
<u--form labelPosition="left" :model="form" :rules="rules" errorType="border-bottom" ref="uForm"
labelWidth="150rpx">
<u-form-item label="用户名" prop="username" borderBottom>
<u--input v-model="form.username" border="none" placeholder="请输入用户名"></u--input>
</u-form-item>
<u-form-item label="登录密码" prop="password" borderBottom>
<u--input v-model="form.password" type="password" border="none" placeholder="请输入登录密码"></u--input>
</u-form-item>
<u-form-item label="手机号" prop="mobile" borderBottom>
<u--input v-model="form.mobile" type="number" border="none" disabled
disabledColor="#FFF"></u--input>
</u-form-item>
<u-form-item label="验证码" prop="code" borderBottom>
<u-code-input v-model="form.code" :maxlength="4" mode="line"></u-code-input>
<view slot="right">
<u-toast ref="uToast"></u-toast>
<u-code :seconds="code.seconds" ref="uCode" @change="codeChange"></u-code>
<u-button type="primary" @tap="getCode">{{code.tips}}</u-button>
</view>
</u-form-item>
</u--form>
<view style="height: 80rpx;"></view>
<u-button type="primary" @click="upMobile">完成</u-button>
</view>
</template>
<script>
export default {
data() {
return {
form: {
mobile: "",
code: '',
username: "",
password: ""
},
rules: {
'username': {
type: 'string',
required: true,
message: '请输入用户名',
trigger: ['blur', 'change']
},
'password': {
type: 'string',
required: true,
message: '请输入登录密码',
trigger: ['blur', 'change']
},
'mobile': {
type: 'string',
required: true,
message: '请输入手机号',
trigger: ['blur', 'change']
},
'code': {
type: 'string',
required: true,
message: '请输入验证码',
trigger: ['blur', 'change']
},
},
code: {
tips: '获取验证码',
// refCode: null,
seconds: 60,
}
}
},
onLoad(options) {
this.form.mobile = options.phone
},
methods: {
upMobile() {
this.$refs.uForm.validate().then(res => {
this.$http.post('/shop/v10/user/username', this.form).then((res) => {
if (res.code == 0) {
uni.navigateBack({
delta: 2,
complete: () => {
setTimeout(() => {
this.$store.commit('auth/resetUser');
this.$store.commit('auth/resetToken');
uni.navigateTo({
url: `/pages/me/login`,
})
}, 100)
},
})
}
})
}).catch(errors => {
uni.$u.toast(errors[0].message)
})
},
codeChange(text) {
this.code.tips = text;
},
getCode() {
if (this.form.mobile.length != 11) {
uni.$u.toast('请输入手机号');
return;
}
if (this.$refs.uCode.canGetCode) {
// 模拟向后端请求验证码
uni.showLoading({
title: '正在获取验证码'
})
this.$http.get('/com/sms/sendcode', this.form).then(res => {
if (res.success) {
uni.hideLoading();
// 这里此提示会被this.start()方法中的提示覆盖
uni.$u.toast('验证码已发送有效期5分钟');
// 通知验证码组件内部开始倒计时
this.$refs.uCode.start();
}
})
} else {
uni.$u.toast('倒计时结束后再发送');
}
},
}
}
</script>
<style>
</style>