Pārlūkot izejas kodu

提交小程序

wang_xy 1 gadu atpakaļ
vecāks
revīzija
8d6ecda3cf
4 mainītis faili ar 24 papildinājumiem un 49 dzēšanām
  1. 4 8
      api/login.js
  2. 2 2
      config.js
  3. 0 4
      pages/index.vue
  4. 18 35
      pages/login.vue

+ 4 - 8
api/login.js

@@ -1,21 +1,17 @@
 import request from '@/utils/request'
 
 // 登录方法
-export function login(username, password, code, uuid,type) {
+export function wxLogin(code) {
   const data = {
-    username,
-    password,
-    code,
-    uuid,
-	type
+    code
   }
   return request({
-    'url': '/login',
+    'url': '/wxLogin',
     headers: {
       isToken: false
     },
     'method': 'post',
-    'data': data
+    'params': data
   })
 }
 

+ 2 - 2
config.js

@@ -3,10 +3,10 @@ module.exports = {
 
 	// baseUrl: 'https://www.xcx.cczdsz.cn/prod-api',
 	// baseUrl: 'http://192.168.4.6:8080',
-	baseUrl: 'http://192.168.4.20:8080',
+	baseUrl: 'http://127.0.0.1:8080',
 	// baseUrl: 'http://192.168.4.11:8080',
 	// baseUrl: 'http://192.168.4.14:8089',
-	baseIconUrl: 'https://www.xcx.cczdsz.cn/app/images/',
+	// baseIconUrl: 'https://www.xcx.cczdsz.cn/app/images/',
 	// 应用信息
 	appInfo: {
 		// 应用名称

+ 0 - 4
pages/index.vue

@@ -4,10 +4,6 @@
 			<view class="gg-title">
 				吉农宝
 			</view>
-			<view>
-			  <image class="userinfo-avatar" :src="userInfo.avatarUrl" mode="cover"></image>
-			  <text class="userinfo-nickname">{{userInfo.nickName}}</text>
-			</view>
 		</view>
 	</view>
 </template>

+ 18 - 35
pages/login.vue

@@ -12,52 +12,35 @@
 </template>
 
 <script>
+	import {
+		wxLogin
+	} from '@/api/login'
 	export default {
 		data() {
 			return {
 			}
 		},
 		created() {
+			this.getUserInfo();
 		},
 		methods: {
 		   getUserInfo() {
-		       var _this = this
-		       uni.showModal({
-		         title: '温馨提示',
-		         content: '亲,授权微信登录后才能正常使用小程序功能',
-		         success(res) {
-		           //如果用户点击了确定按钮
-		           if (res.confirm) {
-		             uni.getUserProfile({
-		               desc: '获取你的昵称、头像、地区及性别',
-		               success: res => {
-						   getApp().globalData.userInfo = res.userInfo,  //登录用户信息
-						   uni.switchTab({
-								url: '/pages/index'
-							})
-		               },
-		               fail: res => {
-		                 //拒绝授权
-		                 uni.showToast({
-		                   title: '您拒绝了请求,不能正常使用小程序',
-		                   icon: 'error',
-		                   duration: 2000
-		                 });
-		                 return;
-		               }
-		             });
-			 
-		           } else if (res.cancel) {
-		             //如果用户点击了取消按钮
-		             uni.showToast({
-		               title: '您拒绝了请求,不能正常使用小程序',
-		               icon: 'error',
-		               duration: 2000
-		             });
-		             return;
+			   let _this = this;
+		       uni.login({
+		         success (res) {
+		           if (res.code) {
+		             //发起网络请求
+					 wxLogin(res.code).then(res => {
+						 _this.$modal.closeLoading()
+						uni.switchTab({
+							url:'/pages/index'
+						})
+					 })
+		           } else {
+		             console.log('登录失败!' + res.errMsg)
 		           }
 		         }
-		       });
+		       })
 			}
 		},
 	}