123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- //app.js
- var http = require('http/request.js');
- var detail = require('http/detail.js');
- App({
- data: {
- loginInfo: null,
- hasLogin:false,
- userId:'',
- channel:"blackWhite",
- code:'',
- shareMsg: "找我,帮你省钱😝",
- failed: false,
- shareTicket: "",
- winHeight:''
- },
- onLaunch: function () {
- // 展示本地存储能力
- this.windowInfo();
- },
- //页面现实加载,获取群信息
- onShow: function (options) {
- this.data.shareTicket = options.shareTicket;
- },
- //获取系统消息
- windowInfo: function () {
- var that = this;
- wx.getSystemInfo({
- success: function (res) {
- that.data.winHeight=res.windowHeight
- }
- });
- },
- //检测当前用户登录态是否有效
- checkSession(info,callback) {
- var that = this;
- if (this.data.hasLogin == true) {
- callback();
- return;
- }
- wx.checkSession({
- success: function () {
- that.login(info,callback);
- },
- fail: function () {
- //登录态过期
- console.log("过期了")
- that.login(info,callback)//重新登录;
- }
- })
- },
- // 登录
- login(info,callback) {
- var that = this;
- wx.login({
- success: res => {
- // 发送 res.code 到后台换取 openId, sessionKey, unionId
- if (res.code) {
- //发起网络请求
- that.data.loginInfo = Object.assign({code:res.code}, info)
- that.data.code = res.code;
- that.hostLogin(callback);
- } else {
- console.log("获取用户登录态失败!" + res.errMsg)
- that.login(info,callback);
- }
- }
- })
- },
- hostLogin(callback) {
- var that = this;
- wx.setStorageSync('flagElasticLayer', '0')
- wx.setStorageSync('userInfo', that.data.loginInfo)
- callback();
- // wx.request({
- // url: 'http://yhq.quyaqu.com/api/mini_program/login',
- // method: 'post',
- // header: { 'Content-Type': 'application/json' },
- // success: function (res) {
- // console.log(res)
-
- // },
- // fail: function (res) {
- // console.log(res)
- // }
- // })
- // this.func.req('/user/loginByWechatApplet', 'get', {}, this.data.loginInfo, function (res) {
- // console.log(res)
- // if (res.code == 0) {
-
- // that.data.userId=res.data.userId;
- // wx.setStorage({
- // key: "userId",
- // data: res.data.userId
- // })
- // that.data.userId = res.data.userId;
- that.data.hasLogin = true;
- // }
- // })
- },
- globalData: {
- userInfo: null
- },
- func: {
- req: http.req
- },
- detailFunc: {
- detail: detail.detail
- },
- //跳转详情页
- goToDetail: function (e,zuId) {
- var goods_id = e.currentTarget.dataset.goods_id;
- var name = e.currentTarget.dataset.name;
- var origin = 0;
- if (e.currentTarget.dataset.origin !== undefined) {
- origin = e.currentTarget.dataset.origin
- }
- var category_id = zuId;
- wx.navigateTo({
- url: '/pages/detail/detail?goods_id=' + goods_id + '&goods_name=' + name + '&origin=' + origin + "&category_id=" + category_id,
- })
- }
- })
|