121 lines
2.7 KiB
JavaScript
121 lines
2.7 KiB
JavaScript
// index.js
|
|
// 获取应用实例
|
|
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
index: 1,
|
|
noticeList: [{}, {}, {}, {}, {}], //开班通告
|
|
answerList: [{}, {}, {}, {}, {}], //报考问答
|
|
userIcon: '../../images/icons/ic_user_default.png',
|
|
nickName: '点击授权',
|
|
},
|
|
onLoad() {
|
|
this.getUserInfo()
|
|
},
|
|
//获取个人信息
|
|
getUserInfo() {
|
|
let _self = this
|
|
try {
|
|
var name = wx.getStorageSync('nickName')
|
|
var icon = wx.getStorageSync('userIcon')
|
|
if (name) {
|
|
_self.setData({
|
|
nickName: name
|
|
})
|
|
}
|
|
if (icon) {
|
|
_self.setData({
|
|
userIcon: icon
|
|
})
|
|
} else {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '小程序需要您微信头像以及昵称用于展示,请授权.',
|
|
showCancel: false,
|
|
success(res) {
|
|
if (res.confirm) {
|
|
_self.getUserProfile(3)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
} catch (e) {
|
|
|
|
}
|
|
},
|
|
//显示更多数据
|
|
showMoreList() {
|
|
if (this.data.index == 1) {
|
|
wx.navigateTo({
|
|
url: '../notices/noticeslist',
|
|
})
|
|
} else {
|
|
wx.navigateTo({
|
|
url: '../answer/answerlist',
|
|
})
|
|
}
|
|
},
|
|
tabSelect(e) {
|
|
this.setData({
|
|
index: e.currentTarget.dataset.id
|
|
})
|
|
},
|
|
choosePage(e) {
|
|
var pagePath = ''
|
|
switch (e.currentTarget.dataset.page) {
|
|
case '1': //培训机构查询
|
|
pagePath = '../institutions/institutionslist'
|
|
break
|
|
case '2': //成绩查询
|
|
pagePath = '../results/resultslist'
|
|
break
|
|
case '3': //准考证查询
|
|
pagePath = '../card/cardlist'
|
|
break
|
|
case '4': //考试网点查询
|
|
pagePath = '../branches/brancheslist'
|
|
break
|
|
}
|
|
wx.navigateTo({
|
|
url: pagePath,
|
|
})
|
|
}, // 获取个人信息
|
|
getUserProfile(e) {
|
|
let _self = this
|
|
wx.getUserProfile({
|
|
desc: '获取微信头像以及昵称用于展示',
|
|
success: (res) => {
|
|
wx.setStorage({
|
|
data: res.userInfo.nickName,
|
|
key: 'nickName',
|
|
})
|
|
wx.setStorage({
|
|
data: res.userInfo.avatarUrl,
|
|
key: 'userIcon',
|
|
})
|
|
_self.setData({
|
|
nickName: res.userInfo.nickName,
|
|
userIcon: res.userInfo.avatarUrl
|
|
})
|
|
},
|
|
fail(err) {
|
|
console.log(err)
|
|
wx.showToast({
|
|
title: '获取个人信息失败',
|
|
icon: 'error'
|
|
})
|
|
}
|
|
})
|
|
},
|
|
showNoticeDetail(e) {
|
|
var item = e.currentTarget.dataset.item
|
|
wx.navigateTo({
|
|
url: '../notices/noticedetail',
|
|
})
|
|
},
|
|
|
|
showAnswerDetail(e) {
|
|
var item = e.currentTarget.dataset.item
|
|
}
|
|
}) |