// pages/zzdy/index.js import { getWxid } from "../../api/zzdy" Page({ /** * 页面的初始数据 */ data: { tabs: [{ name: "首页", icon: "../../icon/zzdy/index.png", selected: "../../icon/zzdy/index-s.png" }, { name: "我的", icon: "../../icon/zzdy/mine.png", selected: "../../icon/zzdy/mine-s.png" } ], tabIndex: 0, uuid: "" }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let that = this that.init(options) }, init(e) { let that = this if (e) { if (e.uuid) { that.setData({ uuid: String(e.uuid) }) } } wx.getStorage({ key: "openid", success(res) {}, fail(err) { that.getOpenid() } }) }, // 获取openid getOpenid() { wx.login({ success: (res) => { if (res.code) { getWxid(res.code).then(res => { if (res.code == 200) { wx.setStorageSync('openid', res.openid) } else { wx.showModal({ content: '获取openid失败,请稍后再试', title: "提示", }) } }).catch(err => { wx.showModal({ content: '获取openid失败,请稍后再试', title: "提示", }) }) } }, }) }, // 选项卡点击事件 tabBtn(e) { let that = this var index = e.currentTarget.dataset.index that.setData({ tabIndex: index }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { // let that = this // wx.cloud.callFunction({ // // 云函数名称 // name: 'getToken', // success: function (res) { // wx.setStorage({ // key: "ACCESS_TOKEN", // data: res.result.access_token // }) // }, // fail: console.error // }) }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })