This commit is contained in:
20932067@zju.edu.cn 2021-03-20 13:44:51 +08:00
commit c02d5e134b
4 changed files with 252 additions and 190 deletions

View File

@ -1,8 +1,8 @@
import axios from 'axios'
// import {getHeaders} from '../utils/token'
// const baseUrl = 'http://localhost:8083/api/'
const baseUrl = 'http://api.tomey.live/api/'
const baseUrl = 'http://localhost:8083/api/'
// const baseUrl = 'http://api.tomey.live/api/'
class HttpRequest {
constructor (baseUrl) {
this.baseUrl = baseUrl

11
src/api/personInfoAdd.js Normal file
View File

@ -0,0 +1,11 @@
import axios from './api.config'
import qs from 'qs'
//完善个人信息
export const personInfoEdit = (data) => {
return axios.request({
url: 'editinfo',
data: qs.stringify(data, { arrayFormat: 'brackets' })
})
}

View File

@ -2,35 +2,37 @@
<div class="addInformation">
<person-title>当前位置 :: 个人中心 >> <em>完善个人信息</em></person-title>
<div class="add-infor-cont">
<el-form :model="ruleForm"
:rules="rules" ref="ruleForm"
<el-form :model="personForm"
:rules="rules" ref="personForm"
label-position='left'
@submit.native.prevent
:status-icon='true'
label-width="7rem" class="demo-ruleForm">
<el-form-item label="名 : " prop="userName">
<el-form-item label="用户名 : " prop="userName">
<el-input
placeholder="为了安全,不可二次修改!"
v-model.trim="ruleForm.userName"></el-input>
placeholder="请输入用户名!"
v-model.trim="personForm.userName"></el-input>
</el-form-item>
<el-form-item label="性别 : " prop="gender">
<el-radio-group v-model.number="ruleForm.gender">
<el-radio-group v-model.number="personForm.gender">
<el-radio :label="1"></el-radio>
<el-radio :label="0"></el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="联系电话 : " prop="phoneNum">
<el-input v-model="ruleForm.phoneNum"></el-input>
</el-form-item>
<el-form-item label="联系地址 : " prop="address">
<el-form-item label="邮箱 : " prop="personEmail">
<el-input
placeholder="输入您的联系地址便于配送"
v-model="ruleForm.address"></el-input>
placeholder="请输入邮箱!"
v-model="personForm.personEmail"></el-input>
</el-form-item>
<el-form-item label="生日 : " prop="birthday">
<el-input
placeholder="输入您的生日 格式为 2000-01-01"
v-model="personForm.birthday"></el-input>
</el-form-item>
<el-form-item class="completed-info-btn">
<el-button type="primary"
@click="submitForm('ruleForm')">修改</el-button>
<el-button @click="resetForm('ruleForm')">重置</el-button>
@click="submitForm('personForm')">修改</el-button>
<el-button @click="resetForm('personForm')">重置</el-button>
</el-form-item>
</el-form>
</div>
@ -38,25 +40,39 @@
</template>
<script>
import {gotoNewOrder} from './../../../assets/js/gotoNewOrder'
// import {gotoNewOrder} from './../../../assets/js/gotoNewOrder'
import {personInfoEdit} from '../../../api/personInfoAdd'
import axios from 'axios'
export default {
data () {
let regexpPhoneNumber = (rule, value, callback) => {
if (value === '') {
callback(new Error('请输入联系电话!'));
}else if(!/^1[3-8][0-9]{9}$/.test(value)){
callback(new Error('手机号码格式不正确!'));
}else{
callback();
callback(new Error('请输入邮箱!'))
}
// else if (!/^1[3-8][0-9]{9}$/.test(value)) {
else if (!/^\w+((.\w+)|(-\w+))@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+).[A-Za-z0-9]+$/.test(value)) {
callback(new Error('邮箱格式不正确!'))
} else {
callback()
}
}
let regexBirthday = (rule, value, callback) => {
if (value === '') {
callback(new Error('请输入生日!'))
}
else if (!/^(19|20)\d{2}-(1[0-2]|0?[1-9])-(0?[1-9]|[1-2][0-9]|3[0-1])$/.test(value)) {
callback(new Error('生日格式不正确!'))
} else {
callback()
}
}
};
return {
ruleForm: {
personForm: {
userName: '',
phoneNum:'',
personEmail: '',
gender: 1,
address:''
birthday: ''
},
rules: {
userName: [
@ -66,27 +82,61 @@ export default {
{ pattern: /\D/, message: '不能为纯数字', trigger: 'change' },
{ pattern: /\D/, message: '不能为纯数字', trigger: 'blur' }
],
phoneNum: [
{ required: true, message: '请输入您的联系方式'},
personEmail: [
{ required: true, message: '请输入您的电子邮件'},
{ validator: regexpPhoneNumber, trigger: 'change'},
{ validator: regexpPhoneNumber, trigger: 'blur'}
],
gender: [
{ required: true, type: 'number', message: '请选择性别', trigger: 'change' }
],
address:[
{ required: true, message: '请输入联系地址', trigger: 'blur' }
birthday: [
{ required: true, message: '请输入生日 格式为 2000-01-01', trigger: 'blur' }
]
}
};
}
},
mounted () {
this.ruleForm.phoneNum = this.$store.state.user.userInfo.userId;
// this.personForm.phoneNum = this.$store.state.user.userInfo.userId
},
methods: {
submitForm (formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
// this.$refs[formName].validate((valid) => {
// this.$refs[formName].validate((valid) => {
let tip =this.personForm
console.log(tip)
let addInfo = {
username: this.personForm.userName,
email: this.personForm.personEmail,
sex: this.personForm.gender,
birthday: this.personForm.birthday
}
if (tip) {
console.log("0000000")
personInfoEdit(this.addInfo).then((res)=>{
console.log(res)
console.log("11111")
var data = res.data
if (data.success){
this.$notify({
title: '提交成功',
duration: 2000,
type: 'success'
})
sessionStorage.clear()
// this.$router.push({path: '/login'})
}else {
this.$notify({
title: '提交失败',
message:data.msg,
duration: 2000,
type: 'error'
})
}
})
}
/*if (valid) {
let addInfo = {
userName: this.ruleForm.userName,
phoneNum: this.ruleForm.phoneNum,
@ -94,35 +144,37 @@ export default {
address: this.ruleForm.address
}
axios.post(`/users/addInformation`, addInfo).then(response => {
let res = response.data;
let res = response.data
if (res.status == '0') {
this.$notify({
title: '修改成功',
message: '恭喜你! 修改成功!',
duration: 2000,
type: 'success'
});
gotoNewOrder.$emit('goNewOrder','userInformation');
this.$router.push({path:'userInformation'});
})
gotoNewOrder.$emit('goNewOrder', 'userInformation')
this.$router.push({path: 'userInformation'})
} else {
this.$notify({
title: '修改失败',
message: res.msg,
duration: 2000,
type: 'error'
});
})
}
}).catch(err => {
console.log(err);
})
} else {
return false;
}
console.log(err)
})*/
else {
this.$message({
message: tip,
type: 'error'
});
}
// })
},
resetForm (formName) {
this.$refs[formName].resetFields();
this.$refs[formName].resetFields()
}
}
}

View File

@ -44,13 +44,13 @@ export default {
data () {
let regexpPhoneNumber = (rule, value, callback) => {
if (value === '') {
callback(new Error('请输入联系电话!'));
callback(new Error('请输入联系电话!'))
} else if (!/^1[3-8][0-9]{9}$/.test(value)) {
callback(new Error('手机号码格式不正确!'));
callback(new Error('手机号码格式不正确!'))
} else {
callback();
callback()
}
}
};
return {
ruleForm: {
userName: '',
@ -78,10 +78,10 @@ export default {
{ required: true, message: '请输入联系地址', trigger: 'blur' }
]
}
};
}
},
mounted () {
this.ruleForm.phoneNum = this.$store.state.user.userInfo.userId;
this.ruleForm.phoneNum = this.$store.state.user.userInfo.userId
},
methods: {
submitForm (formName) {
@ -94,35 +94,34 @@ export default {
address: this.ruleForm.address
}
axios.post(`/users/addInformation`, addInfo).then(response => {
let res = response.data;
let res = response.data
if (res.status == '0') {
this.$notify({
title: '修改成功',
message: '恭喜你! 修改成功!',
duration: 2000,
type: 'success'
});
gotoNewOrder.$emit('goNewOrder','userInformation');
this.$router.push({path:'userInformation'});
})
gotoNewOrder.$emit('goNewOrder', 'userInformation')
this.$router.push({path: 'userInformation'})
} else {
this.$notify({
title: '修改失败',
message: res.msg,
duration: 2000,
type: 'error'
});
})
}
}).catch(err => {
console.log(err);
console.log(err)
})
} else {
return false;
return false
}
});
})
},
resetForm (formName) {
this.$refs[formName].resetFields();
this.$refs[formName].resetFields()
}
}
}