Explorar o código

feat: 小程序登录

DaMowang %!s(int64=3) %!d(string=hai) anos
pai
achega
1649d8d812
Modificáronse 3 ficheiros con 25 adicións e 23 borrados
  1. 23 14
      src/pages/my/index.vue
  2. 2 8
      src/request/api.js
  3. 0 1
      src/request/request.js

+ 23 - 14
src/pages/my/index.vue

@@ -421,28 +421,35 @@ export default {
     }
   },
   onShow: function () {
+    this.login();
+
     let token = uni.getStorageSync('token');
     if (!token) {
+      // this.login();
+    }
+  },
+  methods: {
+    login(){
       // #ifdef  MP-WEIXIN
-      this.showAuth = true;
-      appEv.authorizeUserInfo((res) => {
-        if (res) {
-          this.shopInfo = app.globalData.shopInfo;
-          this.showAuth = false;
-          this.loadData();
+      wx.login({
+        success (res) {
+          if (res.code) {
+            post("appletLogin",{ code: res.code }).then(res => {
+              console.log(res);
+            })
+          }
         }
-      });
+      })
       // #endif
-
+      
       // #ifdef  H5 || APP-PLUS
       this.goto("/pages/my/login")
       // #endif
-    } else {
-      this.user_id = userId;
-      this.loadData();
-    }
-  },
-  methods: {
+    },
+
+
+
+
     // 获取用户信息
     loadData() {
       u_post("ShuZiTeaYW/my/index", {
@@ -495,6 +502,8 @@ export default {
     SetHint: function () {
       appEv.errTips("此功能暂未开放");
     },
+
+    //是否实名
     async isrealName(){
       let n = await u_post("ShuZiTeaYW/userInfo/realName");
       return n.status == 200

+ 2 - 8
src/request/api.js

@@ -1,14 +1,7 @@
 import host from "./config.js"
 import api from "./request.js"
-var app = getApp();
 const user = uni.getStorageSync('systemUserInfo');
 
-// function getUserId() {
-	// var userId;
-	// userId = app.globalData.systemUserInfo && app.globalData.systemUserInfo.userId ? app.globalData.systemUserInfo.userId : '';
-	// return userId
-// };
-
 export function get(url, params, baseURL) {
 	return api({
 		url,
@@ -22,6 +15,7 @@ export function post(url, params, baseURL) {
 		url,
 		params,
 		method: "POST",
+		header: { "Content-Type": "application/x-www-form-urlencoded" },
 		baseURL,
 	})
 }
@@ -31,11 +25,11 @@ export function u_post(url, params, baseURL) {
 		...params,
 		userId: user.userId
 	}
-	// params['userId'] = user.userId;
 	return api({
 		url,
 		params,
 		method: "POST",
+		header: { "Content-Type": "application/x-www-form-urlencoded" },
 		baseURL,
 	})
 }

+ 0 - 1
src/request/request.js

@@ -2,7 +2,6 @@ import host from "./config.js"
 
 export default ({ url, method, params, header, baseURL }) => {
 	baseURL = baseURL ? baseURL : host.Hhost;
-	header = header ? header : { "Content-Type": "application/x-www-form-urlencoded" }
 
 	return new Promise((resolve, reject) => {
 		uni.request({