lrf 1 year ago
parent
commit
532e4e5339
2 changed files with 126 additions and 128 deletions
  1. 38 41
      pages.json
  2. 88 87
      pages/index/index.vue

+ 38 - 41
pages.json

@@ -1,42 +1,39 @@
 {
-	"easycom": {
-		"custom": {
-			"^u--(.*)": "uview-plus/components/u-$1/u-$1.vue",
-			"^up-(.*)": "uview-plus/components/u-$1/u-$1.vue",
-			"^u-([^-].*)": "uview-plus/components/u-$1/u-$1.vue"
-		}
-	},
-	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
-		{
-			"path": "pages/index/index",
-			"style": {
-				"navigationBarTitleText": "登录加载中..."
-			}
-		}
-	    ,{
-            "path" : "pages/list/index",
-            "style" :                                                                                    
-            {
-                "navigationBarTitleText": "记录首页",
-                "enablePullDownRefresh": false
-            }
-            
-        }
-        ,{
-            "path" : "pages/list/edit",
-            "style" :                                                                                    
-            {
-                "navigationBarTitleText": "记录编辑",
-                "enablePullDownRefresh": false
-            }
-            
-        }
-    ],
-	"globalStyle": {
-		"navigationBarTextStyle": "black",
-		"navigationBarTitleText": "uni-app",
-		"navigationBarBackgroundColor": "#F8F8F8",
-		"backgroundColor": "#F8F8F8"
-	},
-	"uniIdRouter": {}
-}
+  "easycom": {
+    "custom": {
+      "^u--(.*)": "uview-plus/components/u-$1/u-$1.vue",
+      "^up-(.*)": "uview-plus/components/u-$1/u-$1.vue",
+      "^u-([^-].*)": "uview-plus/components/u-$1/u-$1.vue"
+    }
+  },
+  "pages": [
+    //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
+    {
+      "path": "pages/index/index",
+      "style": {
+        "navigationBarTitleText": "登录加载中..."
+      }
+    },
+    {
+      "path": "pages/list/index",
+      "style": {
+        "navigationBarTitleText": "记录首页",
+        "enablePullDownRefresh": false
+      }
+    },
+    {
+      "path": "pages/list/edit",
+      "style": {
+        "navigationBarTitleText": "记录编辑",
+        "enablePullDownRefresh": false
+      }
+    }
+  ],
+  "globalStyle": {
+    "navigationBarTextStyle": "black",
+    "navigationBarTitleText": "uni-app",
+    "navigationBarBackgroundColor": "#F8F8F8",
+    "backgroundColor": "#F8F8F8"
+  },
+  "uniIdRouter": {}
+}

+ 88 - 87
pages/index/index.vue

@@ -1,99 +1,100 @@
 <template>
-	<view class="content" style="height:100vh">
-		<u-loading-icon mode="circle" size="64" :vertical="true" color="#2b85e4" textColor="#2b85e4"
-			text="正在登录"></u-loading-icon>
-	</view>
+  <view class="content" style="height:100vh">
+    <u-loading-icon mode="circle" size="64" :vertical="true" color="#2b85e4" textColor="#2b85e4"
+      text="正在登录"></u-loading-icon>
+  </view>
 </template>
 
 <script setup>
-	import {
-		getCurrentInstance,
-		reactive,
-		computed
-	} from 'vue'
-	const api = getCurrentInstance()?.appContext.config.globalProperties.$api;
-	const configSign = getCurrentInstance()?.appContext.config.globalProperties.$configSign;
-	const openid = computed(() => {
-		return uni.getStorageSync('openid');
-	})
-	const login = async (js_code) => {
-		const result = await api('https://broadcast.waityou24.cn/wechat/api/login/app', 'GET', {
-			js_code,
-			config: configSign
-		});
-		if (result.errcode === 0) return result.data.openid;
-		else {
-			uni.showToast({
-				title: '登录失败请重进',
-				icon: 'fail',
-			});
-			return false;
-		}
-	};
-	const initUser = async () => {
-		uni.login({
-			success: async function(result) {
-				if (!result.code) {
-					uni.showToast({
-						title: '登录失败请重进',
-						icon: 'fail',
-					});
-					return false;
-				}
-				let openid = uni.getStorageSync('openid');
-				if (!openid) {
-					const res = await login(result.code)
-					if (res) {
-						uni.setStorageSync('openid', res);
-						openid = res;
-					}
-				}
-				if (openid) {
-					const result = await api('/user', 'POST', {
-						openid
-					});
-					if(result.errcode!=0) {
-						uni.showToast({
-							title: result.errmsg,
-							icon: 'error',
-						});
-						return false;
-					}
-					uni.navigateTo({
-						url: '/pages/list/index'
-					})
-				}
+import {
+  getCurrentInstance,
+  reactive,
+  computed
+} from 'vue'
+const api = getCurrentInstance()?.appContext.config.globalProperties.$api;
+const configSign = getCurrentInstance()?.appContext.config.globalProperties.$configSign;
+const openid = computed(() => {
+  return uni.getStorageSync('openid');
+})
+const login = async (js_code) => {
+  const result = await api('https://broadcast.waityou24.cn/wechat/api/login/app', 'GET', {
+    js_code,
+    config: configSign
+  });
+  if (result.errcode === 0) return result.data.openid;
+  else {
+    uni.showToast({
+      title: '登录失败请重进',
+      icon: 'fail',
+    });
+    return false;
+  }
+};
+const initUser = async () => {
+  uni.login({
+    success: async function (result) {
+      if (!result.code) {
+        uni.showToast({
+          title: '登录失败请重进',
+          icon: 'fail',
+        });
+        return false;
+      }
+      let openid = uni.getStorageSync('openid');
+      if (!openid) {
+        const res = await login(result.code)
+        if (res) {
+          uni.setStorageSync('openid', res);
+          openid = res;
+        }
+      }
+      if (openid) {
+        const result = await api('/user', 'POST', {
+          openid
+        });
+        if (result.errcode != 0) {
+          console.log(result)
+          uni.showToast({
+            title: result.errmsg || '',
+            icon: 'error',
+          });
+          return false;
+        }
+        uni.redirectTo({
+          url: '/pages/list/index'
+        })
+      }
 
-			}
-		})
-	};
-	initUser();
+    }
+  })
+};
+initUser();
 </script>
 
 <style>
-	.content {
-		display: flex;
-		flex-direction: column;
-		align-items: center;
-		justify-content: center;
-	}
+.content {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: center;
+}
 
-	.logo {
-		height: 200rpx;
-		width: 200rpx;
-		margin-top: 200rpx;
-		margin-left: auto;
-		margin-right: auto;
-		margin-bottom: 50rpx;
-	}
+.logo {
+  height: 200rpx;
+  width: 200rpx;
+  margin-top: 200rpx;
+  margin-left: auto;
+  margin-right: auto;
+  margin-bottom: 50rpx;
+}
 
-	.text-area {
-		display: flex;
-		justify-content: center;
-	}
+.text-area {
+  display: flex;
+  justify-content: center;
+}
 
-	.title {
-		font-size: 36rpx;
-		color: #8f8f94;
-	}
+.title {
+  font-size: 36rpx;
+  color: #8f8f94;
+}
 </style>