Browse Source

no message

xiaoxin 3 years ago
parent
commit
63c30196ff
4 changed files with 67 additions and 36 deletions
  1. 14 1
      manifest.json
  2. 20 2
      pages/home/home.vue
  3. 3 33
      pages/index/index.vue
  4. 30 0
      util/api.js

+ 14 - 1
manifest.json

@@ -56,5 +56,18 @@
 		},
 		"usingComponents": true
 	},
-	"vueVersion": "3"
+	"vueVersion": "3",
+	"h5": {
+		"title": "校车预约",
+		"devServer": {
+			"disableHostCheck": true,
+			"proxy": {
+				"/carbook": {
+					"target": "https://chtech.ncjti.edu.cn/carstop/carbook", //目标接口域名
+					"changeOrigin": true, //是否跨域
+					"secure": false // 设置支持https协议的代理
+				}
+			}
+		}
+	}
 }

+ 20 - 2
pages/home/home.vue

@@ -74,10 +74,16 @@
 		onLoad
 	} from "@dcloudio/uni-app"
 
-	onLoad(() => {
+	import {
+		myRequest
+	} from "../../util/api.js"
 
+	onLoad(() => {
+		wxcode.value = uni.getStorageSync('wxcode')
+		alert(wxcode.value)
+		getUserInfo()
 	})
-
+	const wxcode = ref('')
 	const currentIndex1 = ref(null)
 	const currentIndex2 = ref(null)
 	const currentTime = ref(null)
@@ -92,6 +98,18 @@
 	const busList = ref(['车牌尾号:6601(63/63)', '车牌尾号:6661(63/63)', '车牌尾号:6001(63/63)'])
 	// const busList = ref([])
 
+	const getUserInfo = async () => {
+		const res = await myRequest({
+			url: '/carBook/useropenid.action',
+			method: 'post',
+			data: {
+				wxcode: wxcode.value
+			}
+		})
+		alert(JSON.stringify(res))
+		console.log(res);
+	}
+
 	// 改变选中项回调
 	const handleChangeCurrentIndex = (index, type, value) => {
 		if (type === 1) {

+ 3 - 33
pages/index/index.vue

@@ -9,17 +9,11 @@
 	} from "@dcloudio/uni-app"
 
 	const APPKEY = '4AA7B3944BDF3739'
-	const APPID = 'wxd87cbe1db0437303'
 	const ocode = '1015730314'
-	const SCOPE = 'snsapi_base'
-	const URL = 'https://chtech.ncjti.edu.cn/jiaofei/jiaofeiManage/'
-	const URL2 = 'http://192.168.161.78:5173/#/pages/index/index'
+	const URL = 'http://192.168.161.78:5173/#/pages/index/index'
 
 	onLoad(() => {
-		// loginFilter()
-		uni.switchTab({
-			url: "/pages/home/home"
-		})
+		loginFilter()
 	})
 
 	const loginFilter = () => {
@@ -29,25 +23,7 @@
 			if (!wxcode) {
 				getWxcodeURL()
 			} else {
-				alert(wxcode)
 				uni.setStorageSync('wxcode', wxcode)
-				getCode()
-			}
-		} else {
-			getCode()
-		}
-	}
-
-	const getCode = () => {
-		const code = uni.getStorageSync('code');
-		if (!code) {
-			const code = getQueryString('code')
-			if (!code) {
-				alert(666)
-				getCodeURL()
-			} else {
-				alert(code)
-				uni.setStorageSync('code', code)
 				uni.switchTab({
 					url: "/pages/home/home"
 				})
@@ -62,13 +38,7 @@
 	const getWxcodeURL = () => {
 		window.
 		location.href =
-			`https://open.wecard.qq.com/connect/oauth/authorize?app_key=${APPKEY}&response_type=code&scope=snsapi_base&ocode=${ocode}&redirect_uri=${encodeURIComponent(URL2)}`
-	}
-
-	const getCodeURL = () => {
-		window.
-		location.href =
-			`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APPID}&redirect_uri=${encodeURIComponent(URL)}&response_type=code&scope=${SCOPE}#wechat_redirect`
+			`https://open.wecard.qq.com/connect/oauth/authorize?app_key=${APPKEY}&response_type=code&scope=snsapi_base&ocode=${ocode}&redirect_uri=${encodeURIComponent(URL)}`
 	}
 
 	//获取当前URL指定参数

+ 30 - 0
util/api.js

@@ -0,0 +1,30 @@
+// 线上地址
+// const BASE_URL = "https://chtech.ncjti.edu.cn/campusclock"
+// 本地地址
+const BASE_URL = "/carbook"
+export const myRequest = (options) => {
+	uni.showLoading({
+		title: "加载中",
+		mask: true,
+	});
+	return new Promise((resolve, reject) => {
+		uni.request({
+			url: BASE_URL + options.url,
+			method: options.method || "GET",
+			data: options.data || {},
+			success: (res) => {
+				uni.hideLoading();
+				resolve(res.data)
+			},
+			fail: (err) => {
+				uni.hideLoading();
+				uni.showToast({
+					title: "请求数据失败",
+					icon: "none",
+					mask: true
+				})
+				reject(err)
+			}
+		})
+	})
+}