任一存 2 anni fa
parent
commit
2ccf65642b

+ 49 - 0
yfyc/src/utils/index.js

@@ -1,3 +1,5 @@
+import { getCodeAPI, } from "@/api/interact.js";
+
 /**
  * 返回一个自带消抖效果的函数,下文用fnDebounced表示。
  *
@@ -80,6 +82,53 @@ export function debounce(fn, delay = 250, isImmediateCall = false, isRememberLas
   }
 }
 
+// 封装获取用户code的方法
+export function getUserCode(backUrl) {
+  //此处的ID是在文档的开发-基本配置里面
+  let appid = "wx3255043d1b21a4f7";
+  window.location.href =
+    "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
+    appid +
+    "&redirect_uri=" +
+      encodeURIComponent(backUrl) +
+    "&response_type=code&scope=snsapi_userinfo&state=bc17befd6d5060f16de95e38f6eaf69c&connect_redirect=1#wechat_redirect";
+}
+export function checkLoginStatus() {
+  let userInfo = localStorage.getItem("YFYC_userInfo");
+  if (userInfo) {
+    let nowTime = Date.now();
+    let data = JSON.parse(userInfo);
+    // 超过了6个小时
+    if (nowTime - data.time >= 1000 * 60 * 60 * 6) {
+      return false
+    } else {
+      return true
+    }
+  } else {
+    return false
+  }
+}
+export async function loginOnNeed() {
+  const query = new URLSearchParams(location.search)
+  const code = query.get('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 {
+      console.error('登录结果异常!');
+    }
+    location.href = 'https://yifangyice.4dage.com/web/index.html' + location.hash
+  }
+}
+
 export default {
   debounce,
+  getUserCode,
+  checkLoginStatus,
+  loginOnNeed,
 }

+ 23 - 5
yfyc/src/views/My/index.vue

@@ -1,9 +1,10 @@
 <template>
 <div class="mine">
   <img src="@/assets/img/my/banner-bg.png" alt="" class="bg">
-  <div class="top">
-    <img src="@/assets/img/service/avatar-default.png" alt="" class="avatar">
-    <div class="name">芜湖印象</div>
+  <div class="top" @click=onClickPersonalInfo>
+    <img v-if="userInfo && userInfo.avatarUrl" :src="userInfo.avatarUrl" alt="" class="avatar">
+    <img v-else src="@/assets/img/service/avatar-default.png" alt="" class="avatar">
+    <div class="name">{{userInfo && userInfo.nickName ? userInfo.nickName : '芜湖印象'}}</div>
   </div>
   <div class="statistics"
   >
@@ -36,6 +37,7 @@ export default {
 components: {},
 data() {
   return {
+    userInfo: {},
     statisticsList: [
       {
         key: '点赞数',
@@ -94,10 +96,24 @@ methods: {
   },
   pleaseWait() {
     globalToast("敬请期待!")
+  },
+  onClickPersonalInfo() {
+    const loginStatus = globalUtils.checkLoginStatus()
+    // const loginStatus = false
+    // const loginStatus = true
+    if (loginStatus) {
+    } else {
+      globalUtils.getUserCode('https://yifangyice.4dage.com/web/index.html#/layout/my')
+    }
   }
 },
 created() {
-
+  globalUtils.loginOnNeed()
+  document.querySelector("#app").style.maxWidth = "";
+  const userInfoRaw = localStorage.getItem('YFYC_userInfo')
+  if (userInfoRaw) {
+    this.userInfo = JSON.parse(userInfoRaw)
+  }
 },
 mounted() {
 
@@ -107,7 +123,9 @@ beforeMount() {}, //生命周期 - 挂载之前
 beforeUpdate() {}, //生命周期 - 更新之前
 updated() {}, //生命周期 - 更新之后
 beforeDestroy() {}, //生命周期 - 销毁之前
-destroyed() {}, //生命周期 - 销毁完成
+destroyed() {
+  document.querySelector("#app").style.maxWidth = "500px";
+}, //生命周期 - 销毁完成
 activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
 }
 </script>

+ 8 - 7
yfyc/src/views/Serve/Booking.vue

@@ -138,12 +138,12 @@ export default {
           remain: 80,
         },
       ],
-      timeIdx: 1,
-      name: ',jkl',
-      idCard: 'kljlk',
-      phone: 'kljlk',
-      age: 'lkjl',
-      number: '.lk;',
+      timeIdx: null,
+      name: ',',
+      idCard: '',
+      phone: '',
+      age: '',
+      number: '',
 
       isShowSuccess: false,
     }
@@ -157,10 +157,11 @@ export default {
   },
   watch: {
     name(vNew) {
-      console.log(this.name);
     }
   },
   mounted() {
+    globalUtils.loginOnNeed()
+
     new Swiper(".swiper-container", {
       slidesPerView: 2.4,
       // spaceBetween: 30,

+ 16 - 4
yfyc/src/views/Serve/index.vue

@@ -5,10 +5,10 @@
     </div>
     
     <menu>
-      <router-link class="entry" :to="{name: 'Booking'}">
+      <button class="entry" @click="onClickBooking">
         <img src="@/assets/img/service/booking.png" alt="" draggable="false">
         <div>预约</div>
-      </router-link>
+      </button>
       <router-link class="entry" :to="{name: 'FoodList'}">
         <img src="@/assets/img/service/美食.png" alt="" draggable="false">
         <div>美食</div>
@@ -250,6 +250,16 @@ methods: {
   onClickBanner() {
     this.pleaseWait()
   },
+  onClickBooking() {
+    const loginStatus = globalUtils.checkLoginStatus()
+    // const loginStatus = false
+    // const loginStatus = true
+    if (loginStatus) {
+      this.$router.push({name: 'Booking'})
+    } else {
+      globalUtils.getUserCode('https://yifangyice.4dage.com/web/index.html#/booking')
+    }
+  },
   onClickPathItem(id) {
     this.$router.push({name: 'RecommendedPathDetail', query: {id}})
   },
@@ -258,7 +268,7 @@ methods: {
   }
 },
 created() {
-document.querySelector("#app").style.maxWidth = "";
+  document.querySelector("#app").style.maxWidth = "";
 },
 mounted() {
 },
@@ -267,7 +277,9 @@ beforeMount() {}, //生命周期 - 挂载之前
 beforeUpdate() {}, //生命周期 - 更新之前
 updated() {}, //生命周期 - 更新之后
 beforeDestroy() {}, //生命周期 - 销毁之前
-destroyed() {}, //生命周期 - 销毁完成
+destroyed() {
+  document.querySelector("#app").style.maxWidth = "500px";
+}, //生命周期 - 销毁完成
 activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
 }
 </script>

+ 1 - 1
yfyc/vue.config.js

@@ -4,7 +4,7 @@ process.env.VUE_APP_VERSION = require('./package.json').version
 
 module.exports = {
   publicPath: process.env.NODE_ENV === 'development' ? '/' : './',
-  // productionSourceMap: process.env.CLI_MODE === 'prod' ? false : true,
+  productionSourceMap: process.env.NODE_ENV === 'development' ? true : false,
   configureWebpack: {
     // module: {
     //   rules: [