Преглед на файлове

Merge branch 'master' of ssh://192.168.1.202:8088/lx/shares

lx преди 5 години
родител
ревизия
18bc5fb56d
променени са 4 файла, в които са добавени 55 реда и са изтрити 19 реда
  1. 5 18
      app.js
  2. 27 0
      pages/auth/auth.js
  3. 17 0
      pages/item/item.js
  4. 6 1
      utils/api.js

+ 5 - 18
app.js

@@ -1,5 +1,5 @@
 //app.js
-var Api = require('utils/api.js');
+
 App({
   onLaunch: function () {
     // 展示本地存储能力
@@ -25,21 +25,7 @@ App({
     // 登录
     wx.login({
       success: res => {
-        // 发送 res.code 到后台换取 openId, sessionKey, unionId
-        if (res.code) {
-          //发起网络请求
-          wx.request({
-            url: Api.postgetOpenId(),
-            data: {
-              code: res.code
-            },
-            success (res) {
-              console.log(res)
-            }
-          })
-        } else {
-          console.log('登录失败!' + res.errMsg)
-        }
+
       }
     })
     // 获取用户信息
@@ -49,7 +35,7 @@ App({
           // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
           wx.getUserInfo({
             success: res => {
-              console.log(res)
+      
               // 可以将 res 发送给后台解码出 unionId
       
               this.globalData.userInfo = res.userInfo
@@ -71,7 +57,8 @@ App({
   },
   
   globalData: {
-    userInfo: null
+    userInfo: null,
+    openid:null
   },
 
 })

+ 27 - 0
pages/auth/auth.js

@@ -1,5 +1,6 @@
 // pages/auth/auth.js
 const app = getApp();
+var Api = require('../../utils/api.js');
 Page({
 
   /**
@@ -18,6 +19,32 @@ Page({
         }
       }
     })
+        // 登录
+        wx.login({
+          success: res => {
+            console.log(res)
+            // 发送 res.code 到后台换取 openId, sessionKey, unionId
+            if (res.code) {
+              //发起网络请求
+              wx.request({
+                url: Api.postgetOpenId(),
+                data: {
+                  codeId: res.code
+                },
+                success (res) {
+                  console.log(res)
+                  if(res.statusCode==200){
+                    // app.globalData.openid=res.data.data.openid
+                    wx.setStorageSync('openid', res.data.data.openid)
+        
+                  }
+                }
+              })
+            } else {
+              console.log('登录失败!' + res.errMsg)
+            }
+          }
+        })
   },
 
   /**

+ 17 - 0
pages/item/item.js

@@ -312,6 +312,7 @@ Page({
         Name:"appl",
         value:"545455",
         color:'crimson',
+        plateId:""
       },
       newsData:[],
   },
@@ -356,6 +357,7 @@ Page({
     var Name = "object.Name"
     var value = "object.value"
     var color='object.color'
+    var plateId='object.plateId'
     let  Values,colors
     if(JSON.parse(options.row).industryTag){
        Values="+"+JSON.parse(options.row).industryValue.toFixed(2)+"%";
@@ -365,13 +367,28 @@ Page({
       colors="#07c160"
 
     }
+    console.log(app.globalData.userInfo)
     this.setData({
    [Name]:JSON.parse(options.row).industryName,
+   [plateId]:JSON.parse(options.row).industryId,
    [value]:Values,
    [color]:colors,
     })
   that.posthisfind(JSON.parse(options.row).industryId,)
   that.postpredfind(JSON.parse(options.row).industryId,)
+  that.postfollow()
+  },
+  postfollow:function(){
+    var that = this;
+     console.log(app.globalData.userInfo)
+    var data={
+      plateId: this.data.object.plateId,
+      plateName: this.data.object.Name,
+      userId: wx.getStorageSync('openid'),
+      userName: app.globalData.userInfo.nickName,
+    }
+    console.log(data)
+    var postfollow = wxRequest.postRequest(Api.postfollow(),data);
   },
     //获取数据
     posthisfind:function(row){

+ 6 - 1
utils/api.js

@@ -43,7 +43,12 @@ module.exports = {
   },
     // login
     postgetOpenId: function (obj) {
-      var url =HOST_URI + '/api/getOpenId';
+      var url =HOST_URI + '/api/user/openId';
       return url;
     },
+        // 关注接口
+        postfollow: function (obj) {
+          var url =HOST_URI + '/api/follow';
+          return url;
+        },
 }