Преглед изворни кода

把首页的医院图片轮播移到医院介绍页面

lighter пре 4 година
родитељ
комит
878ece2e61
2 измењених фајлова са 27 додато и 29 уклоњено
  1. 15 28
      src/views/Home.vue
  2. 12 1
      src/views/hospital-info/HospitalIntroduction.vue

+ 15 - 28
src/views/Home.vue

@@ -1,9 +1,4 @@
 <template>
-  <van-swipe :autoplay="3000" indicator-color="white" style="height: 170px" vertical>
-    <van-swipe-item v-for="image in images" :key="image">
-      <van-image :src="image" height="170px" />
-    </van-swipe-item>
-  </van-swipe>
   <router-view></router-view>
   <van-tabbar route>
     <van-tabbar-item replace to="/hospitalService" icon="home-o"> 医疗服务 </van-tabbar-item>
@@ -17,18 +12,11 @@ import Cookies from 'js-cookie'
 import { getOpenId, getPatientIdByOpenId } from '../api/patient-id-cards'
 import store from '../store'
 import { useRouter } from 'vue-router'
-import { getLocalOpenId } from '../utils/check-patient-id'
-import blueprint from '../assets/hospital-blueprint.jpg'
-import hall from '../assets/hall.jpg'
-import nurseStation from '../assets/nurse-station.jpg'
-import childrenCenter from '../assets/children-center.jpg'
 import { computed, onMounted } from 'vue'
 export default {
   name: 'Home',
   setup() {
     const router = useRouter()
-    const openId = getLocalOpenId()
-    const images = [blueprint, hall, nurseStation, childrenCenter]
     const cardSize = computed(() => {
       return store.state.patientCards.length
     })
@@ -41,29 +29,28 @@ export default {
         router.push('/' + to)
       }
     }
-    const queryPatientCards = (openId) => {
-      getPatientIdByOpenId(openId).then((res) => {
-        if (res.length > 0) {
-          store.commit('SET_PATIENTCARDS', res)
-        }
-        toFirstTab()
-      })
-    }
     onMounted(() => {
       if (cardSize.value === 0) {
         const code = router.currentRoute.value.params.code
-        getOpenId(code).then((res) => {
-          Cookies.set('openId', res)
-          localStorage.openId = res
-          queryPatientCards(res)
-        })
+        if (code) {
+          getOpenId(code).then((res) => {
+            Cookies.set('openId', res)
+            localStorage.openId = res
+            getPatientIdByOpenId(res).then((cards) => {
+              if (cards.length > 0) {
+                store.commit('SET_PATIENTCARDS', cards)
+              }
+              toFirstTab()
+            })
+          })
+        } else {
+          toFirstTab()
+        }
       } else {
         toFirstTab()
       }
     })
-    return {
-      images,
-    }
+    return {}
   },
 }
 </script>

+ 12 - 1
src/views/hospital-info/HospitalIntroduction.vue

@@ -1,5 +1,10 @@
 <template>
-  <window-size :showBackNav="false" :offset="170">
+  <window-size :showBackNav="false" :offset="0">
+    <van-swipe :autoplay="3000" indicator-color="white" style="height: 170px" vertical>
+      <van-swipe-item v-for="image in images" :key="image">
+        <van-image :src="image" height="170px" />
+      </van-swipe-item>
+    </van-swipe>
     <div ref="headDiv">
       <van-cell icon="hotel-o" title="湖南泰和医院"></van-cell>
       <div style="height: 5px"></div>
@@ -44,11 +49,16 @@
 
 <script>
 import store from '../../store'
+import blueprint from '../../assets/hospital-blueprint.jpg'
+import hall from '../../assets/hall.jpg'
+import nurseStation from '../../assets/nurse-station.jpg'
+import childrenCenter from '../../assets/children-center.jpg'
 import { onMounted, reactive, ref } from 'vue'
 import { getJsApiSHA1 } from '../../api/wx-jsapi'
 export default {
   name: 'HospitalIntroduction',
   setup() {
+    const images = [blueprint, hall, nurseStation, childrenCenter]
     const headDiv = ref(null)
     const mScroll = reactive({
       height: '',
@@ -81,6 +91,7 @@ export default {
       mScroll.height = store.state.windowSize.h - 220 - headDiv.value.offsetHeight + 'px'
     })
     return {
+      images,
       headDiv,
       mScroll,
       showRoute,