148 lines
3.7 KiB
JavaScript
148 lines
3.7 KiB
JavaScript
const { getResourceType } = require("../../../utils/serve/teacher")
|
|
const tabService = require("../../../utils/tab-serve");
|
|
import { deviceLogin } from '../../../utils/serve/user';
|
|
import {parseQueryParams} from '../../../utils/utils'
|
|
const app = getApp()
|
|
// pages/teacher/resource/resource.js
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
isTrainer:false,
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
async onLoad(options) {
|
|
// const res = await getResourceType()
|
|
// this.setData({
|
|
// isTrainer: wx.getStorageSync('roleId') && wx.getStorageSync('roleId') == 4
|
|
// })
|
|
},
|
|
|
|
goList(e){
|
|
console.log(e)
|
|
wx.navigateTo({
|
|
url: '/subpackage/teacher/resource/resource?id='+e.currentTarget.id,
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
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('请扫码正确的登录码')
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
tabService.updateIndex(this, 0)
|
|
this.setData({
|
|
isTrainer: wx.getStorageSync('roleId') && wx.getStorageSync('roleId') == 4
|
|
})
|
|
|
|
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
|
|
}
|
|
}
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |