소스 검색

适配手机

shaogen1995 8 달 전
부모
커밋
680af4d2e1
5개의 변경된 파일143개의 추가작업 그리고 50개의 파일을 삭제
  1. 10 0
      public/index.html
  2. 1 1
      public/staticData/data.js
  3. 79 16
      src/App.vue
  4. 1 1
      src/views/Home/bannerPage.vue
  5. 52 32
      src/views/Home/homePage.vue

+ 10 - 0
public/index.html

@@ -6,6 +6,16 @@
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
     <title>花垣县双龙镇十八洞村</title>
+
+    <style>
+
+      body{
+        width: 100vw;
+        height: 100vh;
+        overflow: hidden;
+      }
+    </style>
+
   </head>
   <body>
     <noscript>

+ 1 - 1
public/staticData/data.js

@@ -20,7 +20,7 @@ const dataAll = {
     list: [
       {
         id: "dajishi",
-        name: "大事",
+        name: "大事",
         list: [
           {
             id: 2013,

+ 79 - 16
src/App.vue

@@ -1,48 +1,111 @@
 <template>
   <div id="app">
     <feedbackModal v-show="modalState == 'feedback'" />
-    <router-view/>
+    <router-view />
     <audio id="bg-music" src="@/assets/audio/musicBg.mp3" loop></audio>
   </div>
 </template>
 
 <script>
-import dataAll from '/public/staticData/data';
-import feedbackModal from './views/Home/feedbackModal.vue'
+import dataAll from "/public/staticData/data";
+import feedbackModal from "./views/Home/feedbackModal.vue";
 import { mapState } from "vuex";
+
+// 适配手机端
+// let tempW = document.documentElement.clientWidth;
+// let tempH = document.documentElement.clientHeight;
+// let tempMax = tempW >= tempH ? tempW : tempH;
+// let tempMin = tempW >= tempH ? tempH : tempW;
+
+// const pageBi = Math.round(Number((tempMax / tempMin).toFixed(2)));
+
+// 设计图按照 1920 、919 来开发
+const planSize = {
+  width: 1920,
+  height:919,
+};
+
+
 export default {
-  name: 'App',
+  name: "App",
   data() {
-    return {
-    };
+    return {};
   },
   computed: {
-        ...mapState( [ "modalState" ] )
-    },
+    ...mapState(["modalState"]),
+  },
   methods: {
     // 保存静态数据在vuex中
     initStaticData() {
-      this.$store.state.dataAll = dataAll
-    }
+      this.$store.state.dataAll = dataAll;
+    },
+
+    pageFullChangeFu() {
+      let width = document.documentElement.clientWidth;
+      let height = document.documentElement.clientHeight;
+
+      let isHHTemp = false;
+
+      const rootRef = document.querySelector("#app");
+
+      if (width >= height) {
+        //横屏
+        isHHTemp = true;
+        const sizeW = width / planSize.width;
+        let sizeH = height / planSize.height;
+
+        let moveX = (planSize.width - width) / 2;
+        let moveY = (planSize.height - height) / 2;
+
+        if (width >= planSize.width) moveX = 0;
+        rootRef.style.left = "0";
+        rootRef.style.transform = `translate(${-moveX}px,${-moveY}px) scale(${sizeW},${sizeH}) rotate(0deg)`;
+        rootRef.style.transformOrigin = "center";
+
+      } else {
+        // 竖屏
+        isHHTemp = false;
+        const temp = width;
+        width = height;
+        height = temp;
+
+        const sizeW = width / planSize.width;
+        let sizeH = height / planSize.height;
+
+        rootRef.style.left = "100%";
+        rootRef.style.transform = `rotate(90deg) scale(${sizeW},${sizeH})`;
+
+        rootRef.style.transformOrigin = "left top";
+      }
+      console.log(123,isHHTemp);
+      
+    },
   },
   mounted() {
-    this.initStaticData()
+    this.initStaticData();
 
+    // 根元素
+    const rootRef = document.querySelector("#app");
+    rootRef.style.width = planSize.width + "px";
+    rootRef.style.height = planSize.height + "px";
+    this.pageFullChangeFu();
+    window.addEventListener("resize", this.pageFullChangeFu, false);
   },
   components: {
     feedbackModal,
-  }
-}
+  },
+};
 </script>
 
 <style>
 @font-face {
-  font-family: 'SourceHanSansCN-Bold';
+  font-family: "SourceHanSansCN-Bold";
   src: url(@/assets/fonts/SourceHanSansCN-Bold.otf);
 }
 #app {
-  width: 100vw;
-  height: 100vh;
+  width: 100%;
+  height: 100%;
+  position: relative;
 }
 
 * {

+ 1 - 1
src/views/Home/bannerPage.vue

@@ -2,7 +2,7 @@
   <div class="banner-home">
     <swiper class="swiper" :options="swiperOptions">
       <swiper-slide class="slide-item" v-for="index in imgList" :key="index">
-        <img style="height: 100vh;width: 100%; object-fit: cover;" :src="index" alt="" />
+        <img style="height: 100%;width: 100%; object-fit: cover;" :src="index" alt="" />
       </swiper-slide>
     </swiper>
   </div>

+ 52 - 32
src/views/Home/homePage.vue

@@ -255,7 +255,7 @@
               "
             >
               <img
-                style="min-height: 15.5vh"
+                style="min-height: 15.5%"
                 :src="`   ${
                   item.coverImg.includes('https')
                     ? item.coverImg
@@ -322,7 +322,7 @@
           </div>
           <div class="result-box" id="result-box-div">
             <!-- 日期排布 -->
-            <div v-show="productActive === '大事'" class="category-box">
+            <div v-show="productActive === '大事'" class="category-box">
               <div
                 class="box-item"
                 v-for="item in daShiJiList"
@@ -335,8 +335,8 @@
             </div>
             <div
               class="result-html"
-              v-if="productActive === '大事'"
-              :style="{ marginTop: productActive === '大事' ? '80px' : '' }"
+              v-if="productActive === '大事'"
+              :style="{ marginTop: productActive === '大事' ? '80px' : '' }"
             >
               <div
                 v-html="item.text"
@@ -550,7 +550,7 @@ export default {
       offsetTopArr: [],
       detailId: null,
       productActive: "历史",
-      // 大事高亮月份
+      // 大事高亮月份
       productYearActive: {},
       daShiJiList: [],
       productHtml: "",
@@ -755,7 +755,6 @@ export default {
       });
     },
     getInitData() {
-
       // 新简介细节(从后台获取)
       this.$request.get("/show/about/getList").then((res) => {
         let introduction = [];
@@ -768,9 +767,8 @@ export default {
 
         this.changeType(introduction[0]);
 
-        this.introduction = [...introduction,...this.dataAll.product.list];
+        this.introduction = [...introduction, ...this.dataAll.product.list];
       });
- 
     },
     openHtml(href, id) {
       if (!href) return;
@@ -790,7 +788,7 @@ export default {
     changeType(item) {
       console.log("changeType", item);
       this.productActive = item.name;
-      item.name === "大事"
+      item.name === "大事"
         ? ((this.daShiJiList = item.list), this.changeYear(item.list[0]))
         : "";
       // this.productHtml = item.rtf?decodeURIComponent(item.rtf): item.text;
@@ -928,8 +926,9 @@ export default {
   left: -50px;
 }
 
-/deep/#result-box-div img{
-max-width: 90%;}
+/deep/#result-box-div img {
+  width: 90%;
+}
 
 .home {
   width: 100%;
@@ -983,8 +982,8 @@ max-width: 90%;}
   }
 
   .openVideo-box {
-    width: 100vw;
-    height: 100vh;
+    width: 100%;
+    height: 100%;
     position: fixed;
     top: 0;
     left: 0;
@@ -1044,17 +1043,17 @@ max-width: 90%;}
       left: 0;
       width: 100%;
       height: 100%;
-      padding: 28vh 0 25vh 10%;
+      padding: 28% 0 25% 10%;
       display: flex;
       flex-direction: column;
       justify-content: space-between;
 
       .village {
         img {
-          width: 16.5vw;
+          width: 16.5%;
           height: 39.5%;
           position: absolute;
-          right: -28.3vw;
+          right: -28.3%;
           top: 23.7%;
         }
       }
@@ -1090,7 +1089,7 @@ max-width: 90%;}
     }
 
     .tabbar-list {
-      width: 20vw;
+      width: 20%;
       height: 100%;
       background: #0a2629ab;
       position: absolute;
@@ -1100,7 +1099,7 @@ max-width: 90%;}
 
       .title {
         width: 100%;
-        height: 7vh;
+        height: 7%;
         display: flex;
         justify-content: center;
         align-items: center;
@@ -1113,7 +1112,7 @@ max-width: 90%;}
 
       .list {
         width: 100%;
-        height: calc(100% - 7vh);
+        height: 93%;
         display: flex;
         flex-direction: column;
         justify-content: center;
@@ -1121,7 +1120,7 @@ max-width: 90%;}
         &-item {
           animation: numeInLeft 3s 1 0s cubic-bezier(0.215, 0.61, 0.355, 1);
           width: 100%;
-          height: 10vh;
+          height: 10%;
           display: flex;
           justify-content: space-between;
           margin-bottom: 10px;
@@ -1137,7 +1136,7 @@ max-width: 90%;}
             color: white;
 
             img {
-              width: 4vw;
+              width: 4%;
             }
 
             .item-right {
@@ -1181,7 +1180,7 @@ max-width: 90%;}
     }
 
     .babar-content {
-      width: calc(100% - 20vw);
+      width: 80%;
       // width: 70%;
       height: 100%;
       display: flex;
@@ -1269,7 +1268,7 @@ max-width: 90%;}
             position: relative;
             width: 100%;
             box-shadow: 5px 8px 10px #142c23;
-            height: 16.8vh;
+            height: 16.8%;
             background-image: url(@/assets/images/new/qjbg.png);
 
             &:hover {
@@ -1282,14 +1281,14 @@ max-width: 90%;}
 
             img {
               width: calc(100% - 10px);
-              height: calc(16.8vh - 14px);
+              height: calc(16.8% - 14px);
               object-fit: fill;
               position: absolute;
             }
 
             .border {
               width: 100%;
-              height: 16.8vh;
+              height: 16.8%;
             }
 
             .shade-box {
@@ -1436,7 +1435,7 @@ max-width: 90%;}
           box-shadow: 5px 8px 10px #142c23;
           width: 98%;
           height: 282px;
-          margin-bottom: 4vh;
+          margin-bottom: 4%;
           cursor: pointer;
           position: relative;
           z-index: 5;
@@ -1516,7 +1515,7 @@ max-width: 90%;}
           color: white;
 
           .dimension-box {
-            width: 15vw;
+            width: 15%;
             border-right: 1px;
             display: flex;
             justify-content: space-between;
@@ -1553,7 +1552,7 @@ max-width: 90%;}
 
           .category-box {
             display: flex;
-            max-width: 40vw;
+            // max-width: 40%;
             overflow: auto;
 
             .box-item {
@@ -1583,7 +1582,7 @@ max-width: 90%;}
             height: 28px;
             margin-bottom: 11px;
             position: relative;
-            width: 16.8vw;
+            width: 16.8%;
 
             input {
               border: none;
@@ -1638,12 +1637,13 @@ max-width: 90%;}
           // overflow-y: hidden;
           justify-items: center;
           height: calc(100% - 55px);
-          overflow-x: hidden;
-          overflow-y: scroll;
+          // overflow-x: hidden;
+          // overflow-y: scroll;
           // align-items: center;
           font-family: Source Han Sans SC, Source Han Sans SC;
           font-weight: 500;
           font-size: 20px;
+          overflow: auto;
           color: #ffffff !important;
           line-height: 36px;
           letter-spacing: 1px;
@@ -1779,8 +1779,11 @@ max-width: 90%;}
   top: 0;
   right: 0;
   width: 43%;
-  height: 100vh;
+  height: 100%;
   overflow: hidden;
+  /deep/div {
+    height: 100%;
+  }
 }
 
 @keyframes bounceopacity {
@@ -1863,4 +1866,21 @@ max-width: 90%;}
     transform: scale(1);
   }
 }
+
+// 手机端
+
+// @media screen and (max-width: 1200px) {
+//   .box-item {
+//     width: 80px !important;
+//   }
+//   .select-box {
+//     font-size: 26px;
+//   }
+//   .result-html {
+//     font-size: 26px;
+//   }
+//     .list-item{
+//      font-size: 26px;
+//     }
+// }
 </style>