小程序商城前端登录操作步骤代码编写

本文基于pgshop3.1版本进行修改,修复文章模块的登录功能,操作步骤如下

文章详情模块修改的内容

1、修改/pages/news_details/index.js

增加导入认证登录的函数import authLogin from '../../utils/autuLogin.js';如下图所示

import authLogin from '../../utils/autuLogin.js';

1.1、增加推广人标记,如下图所示

if(options.spid){
  app.globalData.spid=options.spid;
}

1.2、如果已经登录过,增加读取授权用户uid

代码如下:

if (app.globalData.isLog){
   this.getUserInfo();
}else{
   authLogin();
}

1.3、在最底部增加getUserInfo()函数

  /*
  * 获取用户信息
  */
  getUserInfo: function () {
    var that = this;
    getUserInfo().then(res => {
      that.setData({ 'sharePacket.isState': res.data.is_promoter ? false : true, uid: res.data.uid });
    });
  },

2、修改/pages/news_details/index.json,增加"authorize": "/components/authorize/authorize"如下图所示

"authorize":"/components/authorize/authorize"

3、修改/pages/news_details/index.wxml,在最后面增加<authorize bind:onLoadFun='onLoadFun'></authorize>如下图所示

完成以上3大步骤,保存后进入文章详情页面,你会看到以下的界面

发布了108 篇原创文章 · 获赞 10 · 访问量 20万+

猜你喜欢

转载自blog.csdn.net/emtit2008/article/details/105115460