Преглед изворни кода

feat(page):登录获取站点信息

Zhenghanjv пре 3 месеци
родитељ
комит
1b72aba9dd
5 измењених фајлова са 147 додато и 78 уклоњено
  1. 3 3
      app.json
  2. 15 7
      js/api.js
  3. 90 56
      pages/login/login.js
  4. 38 11
      pages/scan/scan.js
  5. 1 1
      project.private.config.json

+ 3 - 3
app.json

@@ -1,10 +1,9 @@
 {
   "pages": [
-    
+    "pages/scan/scan",
+    "pages/quantify/quantify",
     "pages/moreOrder/moreOrder",
     "pages/orderConfirm/orderConfirm",
-    "components/orderItemInfo/orderItemInfo",
-    "pages/scan/scan",
     "pages/index/index",
     "pages/login/login",
     "pages/historyOrder/historyOrder",
@@ -12,6 +11,7 @@
     "pages/logs/logs",
     "components/orderItem/orderItem",
     "components/orderInfo/orderInfo",
+    "components/orderItemInfo/orderItemInfo",
     "components/pay/pay"
   ],
   "window": {

+ 15 - 7
js/api.js

@@ -3,7 +3,7 @@ const SM4Exten = require('../js/SM4Exten');
 const miniprogramsm4 = require("../miniprogram_npm/miniprogram-sm-crypto/index").sm4;
 const secretId = "D2BCF8DE-AA24-4BF6-9C34-C8DD325E412B";//小程序应用ID
 const Secret = "6C680A47B87740138DFB299FC69A64E1";//小程序应用密钥
-const api_root = 'http://10.153.148.121:5006/'
+const api_root = 'http://192.168.88.140:5006/'
 const CurrentBuId = '12345678-9abc-def0-1234-56789abcdef0';
 
 function request(path, method = 'GET', data = null) {
@@ -15,11 +15,14 @@ function request(path, method = 'GET', data = null) {
     const timestamp = Date.now();
     let jsonString = (data != null && method != 'GET') ? JSON.stringify(data) : '';
     console.log('request :' + jsonString);
-    var stringToSign = "sign_method=" +sign_method + 
-                       "&secret_id=" +secretId+
-                       "&nonce=" +  nonce +
-                       "&timestamp=" + timestamp + 
-                       jsonString;
+     var stringToSign = "sign_method=" +sign_method + 
+                       "&secret_id=" +secretId+
+                       "&nonce=" +  nonce +
+                       "&timestamp=" + timestamp;
+    if(jsonString != '')
+    {
+      stringToSign +=  "&"+jsonString
+    }
     console.log('加密串 :' + stringToSign);
     let key =  stringToHex(Secret);//key转16进制
     key = getFirst32Chars(key);//截取前16位
@@ -173,10 +176,15 @@ function request_GetMiniProgramTransactionsUnpaidNozzle(data) {
 function request_Wechatlogin(data) {
   return request('api/Auth/Wechatlogin?code='+ data, "GET",data);
 }
+//添加用户信息
+function request_AddMiniprogramUser(data) {
+    return request('api/Site/AddMiniprogramUser', "POST",data);
+  }
 export default {
   // request_getSite,
   request_wechatPay,
   request_Wechatlogin,
   request_GetSiteInfo,
-  request_GetMiniProgramTransactionsUnpaidQuery
+  request_GetMiniProgramTransactionsUnpaidQuery,
+  request_AddMiniprogramUser
 }

+ 90 - 56
pages/login/login.js

@@ -1,4 +1,3 @@
-
 //const app = require('../../js/api');
 import api from '../../js/api'
 // pages/login/login.js
@@ -8,7 +7,7 @@ Page({
    * 页面的初始数据
    */
   data: {
-
+    userInfo: {}
   },
 
   /**
@@ -66,44 +65,44 @@ Page({
   onShareAppMessage() {
 
   },
-  pay(){
+  pay() {
     api.request_wechatPay(1)
-    .then(res => {
-     wx.requestPayment({
-       timeStamp: res.data.data.unifiedOrderResult.timeStamp,
-       nonceStr: res.data.data.unifiedOrderResult.nonceStr,
-       package: res.data.data.unifiedOrderResult.package,
-       signType: res.data.data.unifiedOrderResult.signType,
-       paySign: res.data.data.unifiedOrderResult.paySign,
-       success: res => {
-         wx.hideLoading()
-         wx.showToast({
-           title: '支付成功!',
-         })
-         setTimeout(function () {
-           wx.redirectTo({
-             url: '../scan/scan',
-           })
-         }, 2000)
-
-       },
-       fail: res => {
-         wx.hideLoading()
-         wx.showModal({
-           title: '支付失败',
-           content: res.errMsg + '请稍后再试',
-           showCancel: false,
-           success(res) {
-             if (res.confirm) {
-               wx.switchTab({
-                 url: '../home/home',
-               })
-             }
-           }
-         })
-       }
-     })
-    });
+      .then(res => {
+        wx.requestPayment({
+          timeStamp: res.data.data.unifiedOrderResult.timeStamp,
+          nonceStr: res.data.data.unifiedOrderResult.nonceStr,
+          package: res.data.data.unifiedOrderResult.package,
+          signType: res.data.data.unifiedOrderResult.signType,
+          paySign: res.data.data.unifiedOrderResult.paySign,
+          success: res => {
+            wx.hideLoading()
+            wx.showToast({
+              title: '支付成功!',
+            })
+            setTimeout(function () {
+              wx.redirectTo({
+                url: '../scan/scan',
+              })
+            }, 2000)
+
+          },
+          fail: res => {
+            wx.hideLoading()
+            wx.showModal({
+              title: '支付失败',
+              content: res.errMsg + '请稍后再试',
+              showCancel: false,
+              success(res) {
+                if (res.confirm) {
+                  wx.switchTab({
+                    url: '../home/home',
+                  })
+                }
+              }
+            })
+          }
+        })
+      });
   },
   handleAuthLogin(e) {
     console.log('一键授权登录按钮被点击');
@@ -111,30 +110,66 @@ Page({
       title: '正在登录中...',
     })
     // if(e.detail.userInfo) {
-      wx.getUserProfile({
-        desc: '用于完善用户信息',
-        success:(res) => {
-          console.log(res.userInfo)
-        },
-        fail:(err) => {
-          console.log("获取用户信息失败",err)
-        }
-      })
+    // wx.getUserProfile({
+    //   desc: '用于完善用户信息',
+    //   success:(res) => {
+    //     console.log(res.userInfo)
+    //   },
+    //   fail:(err) => {
+    //     console.log("获取用户信息失败",err)
+    //   }
+    // })
     // }
 
+    // 获取用户信息授权
+    const that = this;
+    wx.getUserProfile({
+      desc: '用于完善用户资料', // 声明获取用户信息的目的
+      success(res) {
+        console.log('用户信息:', res.userInfo);
+        var user = {
+          UserName: res.userInfo.nickName,
+          UserAvatarUrl: res.userInfo.avatarUrl,
+          UserPhoneNumber: '',
+          Address: ''
+        };
+        that.setData({
+          userInfo:user
+        })
+        that.toLogin()
+        // 将用户信息发送到服务器
+        // 例如:wx.request({ url: 'https://example.com/userInfo', data: res.userInfo })
+      },
+      fail(err) {
+        console.error('获取用户信息失败:', err);
+        wx.hideLoading()
+      },
+    });
+  },
+
+  toLogin(){
     // 调用微信登录接口
+    var that = this;
     wx.login({
       success(res) {
         if (res.code) {
           console.log('登录成功,code:', res.code);
           api.request_Wechatlogin(res.code)
-          .then(res => {
-            wx.setStorageSync('WachatID', res.data.data)
-            wx.hideLoading()
-            wx.redirectTo({
-              url: '../scan/scan',
-            })
-          });
+            .then(res => {
+              console.log("获取wid",res.data.data)
+              wx.setStorageSync('WachatID', res.data.data)
+              return api.request_AddMiniprogramUser(that.data.userInfo)
+            }).then(res => {
+              debugger
+              console.log("添加user",res)
+              wx.hideLoading()
+              wx.redirectTo({
+                url: '../scan/scan',
+              })
+            }).catch(err => {
+              console.log("报错",res)
+              wx.hideLoading()
+            });
         } else {
           wx.hideLoading()
           console.log('登录失败:', res.errMsg);
@@ -145,6 +180,5 @@ Page({
         console.error('登录接口调用失败:', err);
       },
     });
-
   }
 })

+ 38 - 11
pages/scan/scan.js

@@ -1,11 +1,13 @@
-const { default: api } = require("../../js/api");
+const {
+  default: api
+} = require("../../js/api");
 
 Page({
   data: {
     isLoggedIn: false,
     userInfo: null,
-    scanTitle:'扫码加油',
-    scanTip:'请扫描加油机键盘上的二维码'
+    scanTitle: '扫码加油',
+    scanTip: '请扫描加油机键盘上的二维码'
   },
 
   /**
@@ -13,22 +15,47 @@ Page({
    */
   onLoad(options) {
     var wxChatID = wx.getStorageSync("WachatID")
-    console.log("wxchatid",wxChatID);
-    if(wxChatID) {
+    console.log("wxchatid", wxChatID);
+    if (wxChatID) {
       api.request_GetSiteInfo().then(res => {
-        console.log(res)
+        console.log("站点信息",res)
       })
+      // 获取用户信息授权
+      // wx.getUserProfile({
+      //   desc: '用于完善用户资料', // 声明获取用户信息的目的
+      //   success(res) {
+      //     console.log('用户信息:', res.userInfo);
+      //     var user = {
+      //       UserName: res.userInfo.nickName,
+      //       UserAvatarUrl: res.userInfo.avatarUrl,
+      //       UserPhoneNumber: '',
+      //       Address: ''
+      //     };
+      //     api.request_AddMiniprogramUser(user)
+      //       .then(res => {
+      //         debugger
+      //         return api.request_GetSiteInfo()
+      //       }).then(res => {
+      //         console.log("获取站点信息", res)
+      //       });
+      //     // 将用户信息发送到服务器
+      //     // 例如:wx.request({ url: 'https://example.com/userInfo', data: res.userInfo })
+      //   },
+      //   fail(err) {
+      //     console.error('获取用户信息失败:', err);
+      //   },
+      // });
       this.setData({
         isLoggedIn: true,
         userInfo: null,
-        scanTitle:'扫码加油',
-        scanTip:'请扫码加油机键盘上的二维码'
+        scanTitle: '扫码加油',
+        scanTip: '请扫码加油机键盘上的二维码'
       })
     }
   },
 
-  toLoginOrOrderPage: function() {
-    if(!this.data.isLoggedIn) {
+  toLoginOrOrderPage: function () {
+    if (!this.data.isLoggedIn) {
       wx.redirectTo({
         url: '../login/login'
       })
@@ -39,6 +66,6 @@ Page({
     }
 
 
-    
+
   }
 });

+ 1 - 1
project.private.config.json

@@ -5,5 +5,5 @@
     "compileHotReLoad": true,
     "urlCheck": false
   },
-  "libVersion": "3.7.7"
+  "libVersion": "2.16.1"
 }