shaogen1995 2 年 前
コミット
a456a6b6a2

BIN
yfyc/src/assets/img/home/13.jpg


BIN
yfyc/src/assets/img/home/3.jpg


BIN
yfyc/src/assets/img/home/4.jpg


BIN
yfyc/src/assets/img/home/5.jpg


BIN
yfyc/src/assets/img/home/6.jpg


+ 43 - 21
yfyc/src/views/Interact/index.vue

@@ -49,6 +49,7 @@
 </template>
 
 <script>
+import { Toast } from "vant";
 import { getCodeAPI } from "@/api/interact.js";
 export default {
   components: {},
@@ -79,25 +80,29 @@ export default {
   computed: {},
   watch: {},
   methods: {
+    // 封装获取用户code的方法
+    getUserCode() {
+      //此处的ID是在文档的开发-基本配置里面
+      let appid = "wx3255043d1b21a4f7";
+      // let url = "http://192.168.20.48:8080/#/layout/interact";
+      let url = "https://tp.wuhu.12301china.com/vote";
+      window.location.href =
+        "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
+        appid +
+        "&redirect_uri=" +
+        encodeURIComponent(url) +
+        "&response_type=code&scope=snsapi_userinfo&state=bc17befd6d5060f16de95e38f6eaf69c&connect_redirect=1#wechat_redirect";
+    },
     // 点击+号
     async addInteract() {
-      //  this.$router.push("/layout/interact/issue");
-      let code = this.getQueryCode();
-      if (code) {
-        let res = await getCodeAPI(code);
-        console.log("-----", res);
-      } else {
-        //此处的ID是在文档的开发-基本配置里面
-        let appid = "wx3255043d1b21a4f7";
-        // let url = "http://192.168.20.48:8080/#/layout/interact";
-        let url = "https://tp.wuhu.12301china.com/vote";
-        window.location.href =
-          "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
-          appid +
-          "&redirect_uri=" +
-          encodeURIComponent(url) +
-          "&response_type=code&scope=snsapi_userinfo&state=bc17befd6d5060f16de95e38f6eaf69c&connect_redirect=1#wechat_redirect";
-      }
+      let userInfo = localStorage.getItem("YFYC_userInfo");
+      let nowTime = Date.now();
+      if (userInfo) {
+        let data = JSON.parse(userInfo);
+        // 超过了6个小时
+        if (nowTime - data.time >= 1000 * 60 * 60 * 6) this.getUserCode();
+        else this.$router.push("/layout/interact/issue");
+      } else this.getUserCode();
     },
     searchFu() {
       this.getList();
@@ -113,12 +118,24 @@ export default {
       return this.$route.query.code ? this.$route.query.code : "";
     },
   },
-  created() {
+  async created() {
     document.querySelector("#app").style.maxWidth = "500px";
 
     this.getList();
+
     let code = this.getQueryCode();
-    console.log("---------", code);
+    if (code) {
+      let res = await getCodeAPI(code);
+      if (res.code === 0) {
+        localStorage.setItem("YFYC_token", res.data.token);
+        localStorage.setItem(
+          "YFYC_userInfo",
+          JSON.stringify({ ...res.data.wxUser, time: Date.now() })
+        );
+      } else {
+        Toast.fail("登录失败,请联系管理人员");
+      }
+    }
   },
   mounted() {},
   beforeCreate() {}, //生命周期 - 创建之前
@@ -133,12 +150,17 @@ export default {
 <style lang='less' scoped>
 .My {
   width: 100%;
-  height: calc(100% - 80px);
+  height: calc(100% - 130px);
   overflow-y: auto;
   padding: 20px 15px;
   position: relative;
   .issue {
-    margin: 20px 0;
+    position: fixed;
+    z-index: 10;
+    bottom: 80px;
+    left: 50%;
+    transform: translateX(-50%);
+    height: 40px;
     text-align: center;
     & > img {
       width: 40px;