山东大学暑期实训(5)

 学习总汇

        对于老师端个人信息的查看维护如下:

<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进行请求实现。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值