You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
4.3 KiB
185 lines
4.3 KiB
1 month ago
|
|
||
|
import { toast } from '../../utils/extendApi'
|
||
|
import { getStorage, setStorage } from '../../utils/storage'
|
||
|
//导入ComponentWithStore方法
|
||
|
import { ComponentWithStore } from 'mobx-miniprogram-bindings'
|
||
|
import { userStore } from '../../stores/userstore'
|
||
|
// pages/identify/identify.js
|
||
|
ComponentWithStore({
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
storeBindings: {
|
||
|
store: userStore,
|
||
|
fields: ['id', 'identify'],
|
||
|
actions: ['setId', 'setIdentify']
|
||
|
},
|
||
|
|
||
|
data: {
|
||
|
// id:'',
|
||
|
name:'',
|
||
|
school:'',
|
||
|
selectedRole: 'student',
|
||
|
IsStudentify:true,
|
||
|
// identify:'',//避免和userStore里的数据段冲突
|
||
|
no:''
|
||
|
},
|
||
|
methods :{
|
||
|
// 处理姓名输入事件
|
||
|
onNameInput: function(e) {
|
||
|
this.setData({
|
||
|
name: e.detail.value
|
||
|
});
|
||
|
},
|
||
|
|
||
|
// 处理身份选择变化事件
|
||
|
onIdentifyChange: function(e) {
|
||
|
this.setData({
|
||
|
selectedRole: e.detail.value
|
||
|
});
|
||
|
|
||
|
// 根据需要执行其他逻辑,比如更新页面上的其他部分
|
||
|
// 例如,如果选中“教师”,则显示某些信息;如果选中“学生”,则隐藏这些信息
|
||
|
if (this.data.selectedRole === 'teacher') {
|
||
|
this.setData({
|
||
|
IsStudentify:false,
|
||
|
// identify:2
|
||
|
})
|
||
|
setStorage('identify',2)
|
||
|
this.setIdentify(2)
|
||
|
} else if (this.data.selectedRole === 'student') {
|
||
|
this.setData({
|
||
|
IsStudentify:true,
|
||
|
// identify:1
|
||
|
})
|
||
|
setStorage('identify',1)
|
||
|
|
||
|
this.setIdentify(1)
|
||
|
}
|
||
|
},
|
||
|
|
||
|
// 处理学校输入事件
|
||
|
onSchoolInput: function(e) {
|
||
|
const value = e.detail.value;
|
||
|
// 使用正则表达式匹配中文(包括汉字和标点符号等)
|
||
|
// 注意:这个正则表达式可能不够精确,但它可以作为一个基本的示例
|
||
|
const chineseRegex = /^[\u4e00-\u9fa5\u3000-\u303f\uFF00-\uFFEF]+$/;
|
||
|
if (chineseRegex.test(value)) {
|
||
|
this.setData({
|
||
|
school: value
|
||
|
});
|
||
|
} else {
|
||
|
// 如果输入的值不是中文,则恢复为上一个有效的值
|
||
|
if (value.length > 0) {
|
||
|
this.setData({
|
||
|
school: value.slice(0, -1)
|
||
|
});
|
||
|
}
|
||
|
// 也可以选择保持原值,并通过 wx.showToast 显示错误提示
|
||
|
}
|
||
|
},
|
||
|
|
||
|
// 处理学工号输入事件
|
||
|
onStudentIDInput: function(e) {
|
||
|
|
||
|
this.setData({
|
||
|
no: e.detail.value
|
||
|
})
|
||
|
},
|
||
|
onAuth(){
|
||
|
|
||
|
|
||
|
console.log(getStorage('id'))
|
||
|
console.log(this.data.name)
|
||
|
wx.request({
|
||
|
url: 'http://172.20.10.2:8600/student-api/student/common/authentication', // 请替换成实际的接口地址
|
||
|
method: 'POST',
|
||
|
data: {
|
||
|
id:this.data.id,
|
||
|
name:this.data.name,
|
||
|
school:this.data.school,
|
||
|
identify:this.data.identify,
|
||
|
no:this.data.no
|
||
|
},
|
||
|
header: {
|
||
|
'content-type': 'application/json' // 设置请求数据类型为 JSON
|
||
|
},
|
||
|
success(res) {
|
||
|
if (res.statusCode === 200) {
|
||
|
console.log('身份认证成功:', res.data);//'true' or 'false'
|
||
|
toast({ title: '认证成功' });
|
||
|
if (userStore.identify === 1) {
|
||
|
console.log('yes')
|
||
|
wx.switchTab({
|
||
|
url: '/pages/home/home',
|
||
|
success:()=>{
|
||
|
console.log("hahahah")
|
||
|
},
|
||
|
fail:()=>{
|
||
|
console.log("fail")
|
||
|
}
|
||
|
|
||
|
});
|
||
|
} else if (userStore.identify === 2) {
|
||
|
wx.switchTab({
|
||
|
url: '/pages/home/home' //教师用户跳转的页面,统一跳转到主页
|
||
|
});
|
||
|
}
|
||
|
} else {
|
||
|
console.error('身份认证失败,系统出错:', res.data);
|
||
|
}
|
||
|
},
|
||
|
fail(err) {
|
||
|
console.error('请求失败:', err);
|
||
|
}
|
||
|
});
|
||
|
}, /**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad() {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面初次渲染完成
|
||
|
*/
|
||
|
onReady() {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面显示
|
||
|
*/
|
||
|
onShow() {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面隐藏
|
||
|
*/
|
||
|
onHide() {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面卸载
|
||
|
*/
|
||
|
onUnload() {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||
|
*/
|
||
|
onPullDownRefresh() {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面上拉触底事件的处理函数
|
||
|
*/
|
||
|
onReachBottom() {
|
||
|
|
||
|
}
|
||
|
}
|
||
|
})
|