kaishi.js 3.4 KB
// pages/kaishi/kaishi.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        imgUrls: [
            '../../imgs/lunbo1@3x.png',
            '../../imgs/lunbo2@3x.png',
            '../../imgs/lunbo3@3x.png'
        ],
        indexs: 0,
        color: '#cccccc',
        indicatorDots: false,
        autoplay: true,
        activecolor: '#ffffff',
        interval: 5000,
        duration: 1000
    },

    start(e) {
        let that = this;
        app.globalData.userInfo = e.detail.userInfo;
        wx.login({
            success: function (s) {
                let url = 'wxapp/public/getSessionKey';
                if (s.code) {
                    var code = s.code;
                    var param = {
                        code: s.code
                    }
                    app.post(url, param).then((res) => {
                        console.log(res);
                        console.log(e);
                        that.login(res.data.openid, res.data.session_key, e.detail.encryptedData, e.detail.iv, e.detail.rawData, e.detail.signature);
                    }).catch((errMsg) => {
                        console.log(errMsg);
                    })
                }
            }
        });
    },
    login(openid, session_key, encrypted_data, iv,r,s) {
        let that = this;
        let param = {
            openid: openid,
            session_key: session_key,
            encrypted_data: encrypted_data,
            iv: iv,
            rawData: r,
            signature: s
        }
        let url = 'wxapp/public/login';
        // wx.navigateTo({
        //     url: '/pages/login/login',
        //     success: function (res) { },
        //     fail: function (res) { },
        //     complete: function (res) { },
        // })
        app.post(url, param).then((res) => {
            console.log(res)
            wx.setStorageSync('token', res.data.token);
            let u = "wxapp/public/isMobile";
            let header = {
                "XX-Token": res.data.token
            }
            let data = {
                type: 1
            }
            app.post(u, data, header).then((r) => {
                console.log(r)
            }).catch((err) => {

            })
            // wx.navigateTo({
            //     url: '/pages/login/login',
            //     success: function (res) { },
            //     fail: function (res) { },
            //     complete: function (res) { },
            // })
        }).catch((errMsg) => {
            console.log(errMsg);
        })
    },
    changeindexs(e) {
        this.setData({
            indexs: e.detail.current
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})