刘洋 1 年間 前
コミット
c93ee901b9

+ 1 - 1
src/App.vue

@@ -16,7 +16,7 @@ const appStore = useAppStore();
 appStore.getGlobalConfig();
 const code = getUrlParam("code");
 if (!code) {
-  // LibForWeixin.auth();
+  LibForWeixin.auth();
 } else {
   // userStore.requestOpenId(code);
   router.push({ name: "WxLogin", query: { code } });

+ 2 - 1
src/api/apiConfig/index.js

@@ -127,7 +127,8 @@ axiosInstance.interceptors.response.use(
     if (error?.response?.data?.message) {
       error.message = error?.response?.data?.message;
     }
-    showToast(error.message);
+    const whiteUrls = ["/api/student/login/get/openid"];
+    !whiteUrls.includes(error?.config?.url) && showToast(error.message);
     return Promise.reject(error);
   }
 );

+ 11 - 2
src/api/user.js

@@ -1,12 +1,14 @@
 import request from "@/api/apiConfig";
 
 //获取openId
-//暂时是假接口,等冯德胜出接口再替换
 export function fetchOpenId(code) {
   return request({
-    url: "/api/system/getOpenId",
+    url: "/api/student/wechat/get/openid",
     method: "post",
     data: { code },
+    headers: {
+      "Content-Type": "application/x-www-form-urlencoded",
+    },
   });
 }
 
@@ -30,6 +32,13 @@ export function logout() {
     },
   });
 }
+export function wxBind(openId) {
+  return request({
+    url: "/api/student/wechat/binding",
+    method: "post",
+    data: { openId },
+  });
+}
 export function wxUnbind() {
   return request({
     url: "/api/student/wechat/unbind",

+ 4 - 4
src/main.js

@@ -4,15 +4,15 @@ import router from "@/router";
 import store from "./store";
 import directives from "./directives";
 import filters from "@/filters";
-import vconsole from "vconsole";
+// import vconsole from "vconsole";
 import globalComponents from "@/components";
 // import "amfe-flexible";
 import "@/utils/rem";
 import "@/assets/styles/index.less";
 
-if (import.meta.env.VITE_ENV !== "prod") {
-  new vconsole();
-}
+// if (import.meta.env.VITE_ENV !== "prod") {
+//   new vconsole();
+// }
 
 const app = createApp(App);
 app.use(router).use(store).use(directives).use(globalComponents);

+ 5 - 2
src/pages/login.vue

@@ -55,14 +55,17 @@ import { useUserStore, useAppStore } from "@/store";
 const router = useRouter();
 const appStore = useAppStore();
 const userStore = useUserStore();
-const account = ref("1509000120002");
-const password = ref("123456");
+// const account = ref("1509000120002");
+const account = ref("");
+// const password = ref("123456");
+const password = ref("");
 const passwordShow = ref(false);
 const onSubmit = () => {
   login({ account: account.value, password: password.value }).then((res) => {
     if (res?.id) {
       userStore.setLoginInfo(res);
       router.push("/index");
+      userStore.bindWx();
     }
   });
 };

+ 20 - 1
src/pages/tab-pages/mine.vue

@@ -22,13 +22,22 @@
     <van-button plain block type="success" class="mt-16" @click="logout"
       >退出登录</van-button
     >
+    <div class="hid" @click="countAdd"></div>
   </div>
 </template>
 <script name="Mine" setup>
-import { computed } from "vue";
+import { computed, ref } from "vue";
 import { useUserStore } from "@/store";
 import { useRouter } from "vue-router";
+import vconsole from "vconsole";
 
+const count = ref(0);
+function countAdd() {
+  count.value = count.value + 1;
+  if (count.value == 20) {
+    new vconsole();
+  }
+}
 const router = useRouter();
 const userStore = useUserStore();
 userStore.requestStuInfo();
@@ -51,8 +60,18 @@ function logout() {
 </script>
 <style lang="less" scoped>
 .mine {
+  position: relative;
   .cell-group2 {
     margin-top: 16px !important;
   }
+  .hid {
+    background: transparent;
+    width: 30px;
+    height: 30px;
+    right: 0;
+    bottom: calc(var(--van-tabbar-height) + env(safe-area-inset-bottom) + 10px);
+    position: absolute;
+    z-index: 1;
+  }
 }
 </style>

+ 3 - 2
src/pages/wxLogin.vue

@@ -4,7 +4,7 @@
 <script name="WxLogin" setup>
 import { useRoute, useRouter } from "vue-router";
 import { useUserStore } from "@/store";
-import { wxLogin } from "@/api/user";
+import { wxLogin, fetchOpenId } from "@/api/user";
 const userStore = useUserStore();
 const route = useRoute();
 const router = useRouter();
@@ -15,8 +15,9 @@ async function _wxLogin() {
     loadingType: "spinner",
     duration: 0,
   });
-  const openId = await userStore.requestOpenId(code);
+  const openId = await fetchOpenId(code).catch(() => {});
   if (openId) {
+    userStore.setOpenId(openId);
     let res = await wxLogin(openId);
     closeToast();
     if (res?.id) {

+ 7 - 9
src/store/modules/user.js

@@ -1,5 +1,5 @@
 import { defineStore } from "pinia";
-import { getStuInfo, fetchOpenId, logout, wxUnbind } from "@/api/user";
+import { getStuInfo, fetchOpenId, logout, wxUnbind, wxBind } from "@/api/user";
 import router from "@/router/index";
 
 const useUserStore = defineStore("user", {
@@ -20,14 +20,12 @@ const useUserStore = defineStore("user", {
         this.stuInfo = res;
       });
     },
-    async requestOpenId(code) {
-      let res = await fetchOpenId(code).catch(() => {});
-      if (res) {
-        let openid = typeof res === "string" ? res : res?.openid;
-        this.openId = openid;
-        return openid;
-      } else {
-        return false;
+    setOpenId(openId) {
+      this.openId = openId;
+    },
+    bindWx() {
+      if (this.openId) {
+        this.wxBind();
       }
     },
     async logout(bool) {