学习总汇
对于老师端个人信息的查看维护如下:
<script>
export default {
data() {
const currentDate = this.getDate({
format: true,
})
return {
docTime: {
year: '10',
month: true,
day: true,
hour: false,
minute: false,
second: false
},
show: false,
mapSrc:'',
birth_date:"",
date1:"",
date2: "",
info:{
},
new_info:{
},
person:{
tea_id:"",
tea_name:"",
search_direction:""
}
}
},
computed: {
doc_startDate() {
return this.getDate('start');
},
doc_endDate() {
return this.getDate('end');
},
master_startDate() {
return this.getDate('start');
},
master_endDate() {
return this.getDate('end');
}
},
mounted(){
this.init();
this.init2();
},
methods: {
// 获取缓存中的teaId
// 将teacher的基本信息载入界面
init(){
this.person.tea_id=2007990130;
uni.request({
url:'http://localhost:8081/teacher/loadTeacher',
data:this.person,
method :'POST',
dataType:'json',
success:(res)=>{
console.log(res.data);
uni.setStorageSync('basicInfoList', res.data.data[0]);
this.info=uni.getStorageSync('basicInfoList');
this.info.teaBirthday = this.formatDate(this.info.teaBirthday);
this.date1=this.formatDate(this.info.teaDocTime);
this.info.teaDocTime = this.formatDate(this.info.teaDocTime);
this.date2=this.formatDate(this.info.teaMasterTime);
this.info.teaMasterTime = this.formatDate(this.info.teaMasterTime);
},
});
},
init2(){
const photo = uni.getStorageSync('tea_photo');
console.log("photo",photo);
var src = 'data:image/png;base64,'+ photo
this.mapSrc = src
},
doc_time_confirm(e){
// this.date1=e.target.value
this.date1=e.target.value;
this.info.teaDocTime=e.target.value
},
master_time_confirm(e){
console.log(e.target.value);
this.date2=e.target.value;
this.info.teaMasterTime=e.target.value
},
getDate(type) {
const date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
if (type === 'start') {
year = year - 30;
} else if (type === 'end') {
year = year;
}
month = month > 9 ? month : '0' + month;
day = day > 9 ? day : '0' + day;
return `${year}-${month}-${day}`;
},
formatDate(date1) {
const date = new Date(date1);
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
console.log("正在格式化数据"+`${year}-${month}-${day}`)
return `${year}-${month}-${day}`;
},
// 提交修改teacherInfo的
summit_handler(){
console.log("123123"+this.info.teaMasterTime);
uni.setStorageSync('newInfo', this.info);
uni.request({
url:'http://localhost:8081/teacher/UpdateTeacherInfo',
data:this.info,
method:'POST',
success: (res) => {
console.log("basic_info_sucess->",res.data);
uni.showModal({
showCancel: false,
title: '提示',
content: "修改成功!",
success: function (res) {
if (res.confirm) {
console.log('用户点击确定');
uni.navigateTo({
url: '/pages/index/mine',
});
}
}
});
}
});
console.log(this.data)
}
},
}
</script>
在data中定义了一些变量,对于点击进入基本信息的界面后,需要加载出当前用户的基本信息,因此使用了一个初始化的方法init()。使用mounte对初始化的init()和init2()进行挂载,使得打开页面是进行初始化。
在此需要注意的是异步问题,在最初时代码如下:
init(){
this.person.tea_id=2007990130;
uni.request({
url:'http://localhost:8081/teacher/loadTeacher',
data:this.person,
method :'POST',
dataType:'json',
success:(res)=>{
console.log(res.data);
uni.setStorageSync('basicInfoList', res.data.data[0]);
this.info=uni.getStorageSync('basicInfoList');
},
});
this.info.teaBirthday = this.formatDate(this.info.teaBirthday);
this.date1=this.formatDate(this.info.teaDocTime);
this.info.teaDocTime = this.formatDate(this.info.teaDocTime);
this.date2=this.formatDate(this.info.teaMasterTime);
this.info.teaMasterTime = this.formatDate(this.info.teaMasterTime);
},
此时会出现请求还未返回就将数据获取并结构化,导致功能出现异常。
将数据进行绑定后,修改信息点击提交能修改数据库,通过summit_handler()发起POST进行请求实现。