Browse Source

修改样式

See999 4 years ago
parent
commit
09f1bd6845
6 changed files with 111 additions and 25 deletions
  1. 11 11
      .postcssrc.js
  2. 24 0
      src/libs/dpr.js
  3. 12 7
      src/libs/functionPad.js
  4. 2 1
      src/main.js
  5. 30 2
      src/pages/main/DetailsPage.vue
  6. 32 4
      src/pages/main/index.vue

+ 11 - 11
.postcssrc.js View File

@@ -6,16 +6,16 @@ module.exports = {
6 6
     "postcss-url": {},
7 7
     // to edit target browsers: use "browserslist" field in package.json
8 8
     autoprefixer: {},
9
-    // "postcss-pxtorem": {
10
-    //   // 此处为添加部分
11
-    //   rootValue: 16, // 对应16px 适配移动端750px宽度
12
-    //   unitPrecision: 5,
13
-    //   propList: ["*"],
14
-    //   selectorBlackList: [".el",".mint"],
15
-    //   replace: true,
16
-    //   mediaQuery: false,
17
-    //   minPixelValue: 0,
18
-    //   exclude: /src/
19
-    // }
9
+    "postcss-pxtorem": {
10
+      // 此处为添加部分
11
+      rootValue: 16, // 对应16px 适配移动端750px宽度
12
+      unitPrecision: 5,
13
+      propList: ["*"],
14
+      selectorBlackList: [".el",".mint"],
15
+      replace: true,
16
+      mediaQuery: false,
17
+      minPixelValue: 0,
18
+      exclude: /src/
19
+    }
20 20
   }
21 21
 };

+ 24 - 0
src/libs/dpr.js View File

@@ -0,0 +1,24 @@
1
+// function dpr(){
2
+
3
+//     if (!dpr && !scale) {
4
+//         if (isIPhone) {
5
+//             // iOS下,对于2和3的屏,用2倍的方案,其余的用1倍方案
6
+//             if (devicePixelRatio >= 3 && (!dpr || dpr >= 3)) {
7
+//                 dpr = 3;
8
+//             } else if (devicePixelRatio >= 2 && (!dpr || dpr >= 2)){
9
+//                 dpr = 2;
10
+//             } else {
11
+//                 dpr = 1;
12
+//             }
13
+//         } else {
14
+//             // 其他设备下,仍旧使用1倍的方案
15
+//             // dpr = 1;
16
+//            // 其他设备下,改为使用设备当前的dpr
17
+//             dpr = devicePixelRatio;
18
+//         }
19
+//         scale = 1 / dpr;
20
+//     }
21
+// }
22
+
23
+// dpr()
24
+

+ 12 - 7
src/libs/functionPad.js View File

@@ -1,17 +1,22 @@
1 1
 export function mediaMatches() {
2 2
   let sqls = [
3
-    // window.matchMedia("(max-width:418px)"), //和CSS一样,也要注意顺序!
3
+    window.matchMedia("(max-width:415px)"), //和CSS一样,也要注意顺序!
4 4
     window.matchMedia("(max-width:767px)"),
5
-    window.matchMedia("(max-width:992px)"),
5
+    window.matchMedia("(max-width:1024px)"),
6 6
     window.matchMedia("(max-width:1200px)")
7 7
   ];
8 8
   if (sqls[0].matches) {
9
-    console.log(">418 & <=768"); // do something...
10
-    document.documentElement.style.fontSize = 30 + "px";
11
-  } else if (sqls[2].matches) {
12
-    console.log(">768 & <=992"); // do something...
9
+    console.log("415"); // do something...
10
+    // document.documentElement.style.fontSize = 30 + "px";
11
+    document.documentElement.style.setProperty("font-size",30 + "px","important");
12
+  } else if (sqls[1].matches) {
13
+    console.log(">415 & <=767"); // do something...
14
+    // document.documentElement.style.fontSize = 40 + "px";
15
+    document.documentElement.style.setProperty("font-size",40 + "px","important");
13 16
   } else if (sqls[3].matches) {
14
-    console.log("> 992 & <=1200"); // do something...
17
+    console.log("> 767 & <=1024"); // do something...
18
+    // document.documentElement.style.fontSize = 50 + "px";
19
+    document.documentElement.style.setProperty("font-size",50 + "px","important");
15 20
   } else {
16 21
     console.log(">1200");
17 22
   }

+ 2 - 1
src/main.js View File

@@ -9,7 +9,7 @@ import "mint-ui/lib/style.css";
9 9
 import "./assets/styles/iconfont.css";
10 10
 import "./permission";
11 11
 
12
-import "lib-flexible";
12
+// import "lib-flexible";
13 13
 
14 14
 import "@/styles/reset.scss";
15 15
 import "@/styles/variables.scss";
@@ -24,6 +24,7 @@ import ElementUI from "element-ui";
24 24
 import "element-ui/lib/theme-chalk/index.css";
25 25
 import pinyin from "js-pinyin";
26 26
 // import "./libs/rem.js";
27
+// import "./libs/dpr.js";
27 28
 import {
28 29
   DropdownMenu,
29 30
   DropdownItem,

+ 30 - 2
src/pages/main/DetailsPage.vue View File

@@ -56,6 +56,7 @@
56 56
 
57 57
 <script>
58 58
 import "@/styles/style.scss";
59
+import "@/styles/media.scss";
59 60
 import SideBar from "@/pages/layout/SideBar";
60 61
 import TodayTab from "./today/TodayTab";
61 62
 import DialysisTab from "./dialysis/DialysisTab";
@@ -92,7 +93,8 @@ export default {
92 93
         window.matchMedia("(max-width:768px)"),
93 94
         window.matchMedia("(max-width:992px)"),
94 95
         window.matchMedia("(max-width:1200px)")
95
-      ]
96
+      ],
97
+      clientHeight: document.body.clientHeight
96 98
     };
97 99
   },
98 100
   created() {
@@ -108,6 +110,15 @@ export default {
108 110
     this.patient_name = patient_name;
109 111
     this.GetPatientInfoWithDiseases(this.patient_id);
110 112
   },
113
+  mounted(){
114
+    const that = this
115
+    window.onresize = () => {
116
+        return (() => {
117
+            window.clientHeight = document.body.clientHeight
118
+            that.clientHeight = window.clientHeight
119
+        })()
120
+    }
121
+  },
111 122
   methods: {
112 123
     ClickTab: function(tabIndex) {
113 124
       this.index = tabIndex;
@@ -149,8 +160,25 @@ export default {
149 160
       var patient_id = this.$route.query.patient_id;
150 161
       this.$router.push("/mypatients/" + patient_id);
151 162
     }
163
+  },
164
+  watch:{
165
+    clientHeight(val){
166
+      // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
167
+      if(!this.timer){
168
+        // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
169
+        this.clientHeight = val
170
+        this.timer = true
171
+        let that = this
172
+        setTimeout(function(){
173
+            // 打印screenWidth变化的值
174
+            console.log(that.clientHeight)
175
+            that.timer = false
176
+            that.mediaMatches();
177
+        },400)
178
+      }
179
+    }
152 180
   }
153
-};
181
+}
154 182
 </script>
155 183
 
156 184
 <style style="stylesheet/scss" lang="scss" scoped>

+ 32 - 4
src/pages/main/index.vue View File

@@ -36,7 +36,8 @@ export default {
36 36
         window.matchMedia("(max-width:767px)"),
37 37
         window.matchMedia("(max-width:1024px)"),
38 38
         window.matchMedia("(max-width:1200px)")
39
-      ]
39
+      ],
40
+      clientHeight: document.body.clientHeight
40 41
     };
41 42
   },
42 43
   components: {
@@ -61,6 +62,13 @@ export default {
61 62
     // this.timerDia = window.setInterval(() => {
62 63
     //   setTimeout(this.requestDialysisScheduals(), 0)
63 64
     // }, 10000)
65
+     const that = this
66
+    window.onresize = () => {
67
+        return (() => {
68
+            window.clientHeight = document.body.clientHeight
69
+            that.clientHeight = window.clientHeight
70
+        })()
71
+    }
64 72
   },
65 73
   // beforeDestroy () {
66 74
   //   clearInterval(this.timer)
@@ -222,13 +230,16 @@ export default {
222 230
       ];
223 231
       if (sqls[0].matches) {
224 232
         console.log("415"); // do something...
225
-        document.documentElement.style.fontSize = 30 + "px";
233
+        // document.documentElement.style.fontSize = 30 + "px";
234
+        document.documentElement.style.setProperty("font-size",30 + "px","important");
226 235
       } else if (sqls[1].matches) {
227 236
         console.log(">415 & <=767"); // do something...
228
-        document.documentElement.style.fontSize = 40 + "px";
237
+        // document.documentElement.style.fontSize = 40 + "px";
238
+        document.documentElement.style.setProperty("font-size",40 + "px","important");
229 239
       } else if (sqls[3].matches) {
230 240
         console.log("> 767 & <=1024"); // do something...
231
-        document.documentElement.style.fontSize = 50 + "px";
241
+        // document.documentElement.style.fontSize = 50 + "px";
242
+        document.documentElement.style.setProperty("font-size",50 + "px","important");
232 243
       } else {
233 244
         console.log(">1200");
234 245
       }
@@ -238,6 +249,23 @@ export default {
238 249
     readNum: function() {
239 250
       return this.unReadWaitNum + this.unReadDialysisNum;
240 251
     }
252
+  },
253
+  watch:{
254
+    clientHeight(val){
255
+      // 为了避免频繁触发resize函数导致页面卡顿,使用定时器
256
+      if(!this.timer){
257
+        // 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
258
+        this.clientHeight = val
259
+        this.timer = true
260
+        let that = this
261
+        setTimeout(function(){
262
+            // 打印screenWidth变化的值
263
+            console.log(that.clientHeight)
264
+            that.timer = false
265
+            that.mediaMatches();
266
+        },400)
267
+      }
268
+    }
241 269
   }
242 270
 };
243 271
 </script>