148 lines
3.7 KiB
JavaScript
Raw Normal View History

2025-06-06 15:17:30 +08:00
const { getResourceType } = require("../../../utils/serve/teacher")
const tabService = require("../../../utils/tab-serve");
2026-04-16 13:38:33 +08:00
import { deviceLogin } from '../../../utils/serve/user';
import {parseQueryParams} from '../../../utils/utils'
const app = getApp()
2025-06-06 15:17:30 +08:00
// pages/teacher/resource/resource.js
Page({
/**
* 页面的初始数据
*/
data: {
2025-06-09 17:19:11 +08:00
isTrainer:false,
2025-06-06 15:17:30 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
async onLoad(options) {
2025-06-13 14:39:20 +08:00
// const res = await getResourceType()
// this.setData({
// isTrainer: wx.getStorageSync('roleId') && wx.getStorageSync('roleId') == 4
// })
2025-06-06 15:17:30 +08:00
},
goList(e){
console.log(e)
wx.navigateTo({
url: '/subpackage/teacher/resource/resource?id='+e.currentTarget.id,
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
2026-04-16 13:38:33 +08:00
goScan(){
wx.scanCode({
success:res=>{
console.log(res)
if(res.result.includes('opt=teacherLogin')){
console.log('教师登录')
const pobj = parseQueryParams(res.result)
console.log('参数obj',pobj)
if(pobj.code && pobj.schoolCode){
wx.showModal({
title: '确定登录一体机吗',
complete: async (res) => {
if (res.confirm) {
wx.showLoading({
title: '',
})
const log = await deviceLogin(`code=${pobj.code}&schoolCode=${pobj.schoolCode}`)
console.log(log)
if(log.success){
wx.showToast({
icon:log.success? 'success' : 'none',
title:log.success? '登录成功' : '登录失败,请稍后重试',
})
}
}
}
})
}
}else{
app.showToast('请扫码正确的登录码')
}
}
})
},
2025-06-06 15:17:30 +08:00
/**
* 生命周期函数--监听页面显示
*/
onShow() {
tabService.updateIndex(this, 0)
2025-06-13 14:39:20 +08:00
this.setData({
isTrainer: wx.getStorageSync('roleId') && wx.getStorageSync('roleId') == 4
})
2026-04-16 13:38:33 +08:00
if(app.globalData.schoolCode && app.globalData.code){
console.log('登录设备==========')
console.log(app.globalData.schoolCode,app.globalData.code)
console.log('登录设备==========')
wx.showModal({
title: '确定登录一体机吗',
complete: async (res) => {
if (res.cancel) {
app.globalData.schoolCode = null
app.globalData.code = null
}
if (res.confirm) {
wx.showLoading({
title: '',
})
const log = await deviceLogin(`code=${app.globalData.code}&schoolCode=${app.globalData.schoolCode}`)
console.log(log)
wx.showToast({
icon:log.success? 'success' : 'none',
title:log.success? '登录成功' : '登录失败,请稍后重试',
})
app.globalData.schoolCode = null
app.globalData.code = null
}
}
})
}
2025-06-06 15:17:30 +08:00
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})