zhengkaixin 4 years ago
parent
commit
2afb3c23f9
2 changed files with 64 additions and 9 deletions
  1. 32 9
      pages.json
  2. 32 0
      utils/request.js

+ 32 - 9
pages.json

@@ -1,13 +1,6 @@
 {
 	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
-		{
-			"path": "pages/index/index",
-			"style": {
-				"navigationBarTitleText": "uni-app"
-			}
-		}
-		
-	    ,{
+		{
 			//主页
             "path" : "pages/car/index",
             "style" :         
@@ -16,7 +9,15 @@
                 "enablePullDownRefresh": false
             }
             
-        }
+        },
+		{
+			"path": "pages/index/index",
+			"style": {
+				"navigationBarTitleText": "uni-app"
+			}
+		}
+		
+		
         ,{
 			//注册/登录
             "path" : "pages/car/login",
@@ -234,5 +235,27 @@
     ],
 	"globalStyle": {
 		"navigationStyle": "custom"
+	},
+	"tabBar": {
+	    "color": "#7A7E83",
+	    "selectedColor": "#3cc51f",
+	    "borderStyle": "black",
+	    "backgroundColor": "#ffffff",
+	    "list": [{
+	        "pagePath": "pages/car/index",
+	        "iconPath": "static/image/icon_component.png",
+	        "selectedIconPath": "static/image/icon_component_HL.png",
+	        "text": "主页"
+	    }, {
+	        "pagePath": "pages/news/index",
+	        "iconPath": "static/image/icon_API.png",
+	        "selectedIconPath": "static/image/icon_API_HL.png",
+	        "text": "消息"
+	    }, {
+	        "pagePath": "pages/my/index",
+	        "iconPath": "static/image/icon_API.png",
+	        "selectedIconPath": "static/image/icon_API_HL.png",
+	        "text": "我的"
+	    }]
 	}
 }

+ 32 - 0
utils/request.js

@@ -0,0 +1,32 @@
+import baseUrl from '../config/baseUrl.js'
+//记录请求次数和响应次数
+let reqCount = 0,
+	resCount = 0;
+const request = (options) => {
+	reqCount++;
+	uni.showLoading();
+	return new Promise((resolve, reject) => {
+		uni.request({
+			method: options.method,
+			url: baseUrl + options.url,
+			data: options.data,
+			header: options.header
+		}).then((response) => {
+			resCount++
+			//防止连续请求多个接口时loading闪现
+			if (reqCount === resCount) uni.hideLoading();
+			let [error, res] = response;
+			if (res.data.code != 200) {
+				reject(res.data.message)
+			} else {
+				resolve(res.data.data);
+			}
+		}).catch(error => {
+			resCount++
+			if (reqCount === resCount) uni.hideLoading();
+			let [err, res] = error;
+			reject(err)
+		})
+	});
+}
+export default request