xsh 3 years ago
parent
commit
3cd8f31e7c
5 changed files with 153 additions and 4 deletions
  1. 27 0
      public/static/weather/index.html
  2. 2 1
      src/main.js
  3. 73 0
      src/utils/http.js
  4. 20 0
      src/utils/index.js
  5. 31 3
      src/views/MainLayout.vue

+ 27 - 0
public/static/weather/index.html

@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js"></script>
+</head>
+<body style="margin: 0;">
+    <div id="he-plugin-standard"></div>
+<script>
+    WIDGET = {
+        "CONFIG": {
+            "layout": "2",
+            "width": "300",
+            "height": "400",
+            "background": "1",
+            "dataColor": "FFFFFF",
+            "borderRadius": "5",
+            "key": "bfab9d72ee5d4719a5e96fb50436c396"
+        }
+    }
+</script>
+<script src="https://widget.qweather.net/standard/static/js/he-standard-common.js?v=2.0"></script>
+</body>
+</html>

+ 2 - 1
src/main.js

@@ -13,7 +13,7 @@ import store from './store'
 import 'lib-flexible/flexible'
 import './assets/ttf/font.css';
 import echart from 'echarts';
-import { DatePicker, Row, Col, Select, Option } from 'element-ui';
+import { DatePicker, Row, Col, Select, Option, Icon } from 'element-ui';
 
 Vue.config.productionTip = false
 Vue.prototype.$echarts = echart
@@ -22,6 +22,7 @@ Vue.use(Row)
 Vue.use(Col)
 Vue.use(Select)
 Vue.use(Option)
+Vue.use(Icon)
 
 new Vue({
   router,

+ 73 - 0
src/utils/http.js

@@ -0,0 +1,73 @@
+import axios from "axios";
+import router from "../router";
+import { Message } from 'element-ui';
+
+let pending = []; //声明一个数组用于存储每个ajax请求的取消函数和ajax标识
+let cancelToken = axios.CancelToken;
+let removePending = (ever) => {
+  for(let p in pending) {
+    if(pending[p].u === ever.url + '&' + ever.method) { //当当前请求在数组中存在时执行函数体
+      pending[p].f(); //执行取消操作
+      pending.splice(p, 1); //把这条记录从数组中移除
+    }
+  }
+}
+// 创建axios实例
+var instance = axios.create({
+  timeout: 1000 * 12,
+  baseURL: 'http://115.238.57.190:8100'
+})
+
+// 请求拦截器
+instance.interceptors.request.use(
+  config => {
+    // 登录流程控制中,根据本地是否存在token判断用户的登录情况
+    // 但是即使token存在,也有可能token是过期的,所以在每次的请求头中携带token
+    // 后台根据携带的token判断用户的登录情况,并返回给我们对应的状态码
+    // 而后我们可以在响应拦截器中,根据状态码进行一些统一的操作。
+
+    removePending(config); //在一个ajax发送前执行一下取消操作
+    config.cancelToken = new cancelToken((c)=>{
+      // 这里的ajax标识我是用请求地址&请求方式拼接的字符串,当然你可以选择其他的一些方式
+      pending.push({ u: config.url + '&' + config.method, f: c });
+    });
+    return config
+  },
+  error => Promise.error(error)
+)
+
+// 响应拦截器
+instance.interceptors.response.use(
+  // 请求成功
+  res => res.status === 200 ? Promise.resolve(res.data) : Promise.reject(res),
+  // 请求失败
+  error => {
+    const { response } = error;
+    if (response) {
+      errorHandle(response.status, response.data.message);
+      return Promise.reject(response);
+    }
+  }
+)
+
+
+/**
+ * 请求失败后的错误统一处理
+ * @param {Number} status 请求失败的状态码
+ */
+
+const errorHandle = (status, other) => {
+  // 状态码判断
+  switch (status) {
+    // 404请求不存在
+    case 404:
+      Message.error('请求的资源不存在');
+      break;
+    case 500:
+      Message.error('请求失败,请联系管理员');
+      break;
+    default:
+      console.log(other);
+  }}
+
+export default instance

+ 20 - 0
src/utils/index.js

@@ -0,0 +1,20 @@
+export function arrToIds(arr){
+    var new_ids = '';
+    for(var i = 0; i < arr.length; i++){
+        new_ids += ','+arr[i].id;
+    }
+
+    if(new_ids!=''){
+        new_ids =  new_ids.substr(1);
+    }
+    return new_ids;
+}
+
+// 时间格式化
+export function timeDate(timestamp) {
+  var date = new Date(timestamp)
+  var Y = date.getFullYear() + '-'
+  var M = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) + '-' : (date.getMonth() + 1) + '-'
+  var D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate()
+  return Y + M + D
+}

+ 31 - 3
src/views/MainLayout.vue

@@ -3,7 +3,7 @@
     <div class="main-title">{{title}}</div>
     <div class="main-left">
       <!--  天气    -->
-      <div v-show="isHome" class="main-home">天气</div>
+      <div v-show="isHome" class="main-home" @click="showWeather = true">天气</div>
       <!--  返回首页    -->
       <div v-show="!isHome" class="main-back" @click="back">首页</div>
     </div>
@@ -17,6 +17,14 @@
     <div class="content">
       <router-view></router-view>
     </div>
+    <transition name = "moveL">
+      <div id="weather" v-show="showWeather">
+        <div style="text-align: left">
+          <i class="el-icon-back" style="font-size: 24px; color: #fff" @click="showWeather = false"></i>
+        </div>
+        <iframe style="height: 400px" src="static/weather/index.html" frameborder="0"></iframe>
+      </div>
+    </transition>
   </div>
 </template>
 
@@ -28,7 +36,8 @@ export default {
       title: '',
       isHome: true,
       currentTime: '',
-      timer4: null
+      timer4: null,
+      showWeather: false
     }
   },
   watch: {
@@ -174,4 +183,23 @@ export default {
     color: white;
     cursor: pointer;
   }
-</style>
+  #weather {
+    background-color: rgba(0, 0, 0, .5);
+    position: absolute;
+    height: 450px;
+    top: 0;
+    left: 0;
+  }
+  .moveL-enter-active,
+  .moveL-leave-active {
+    transition: all 0.3s linear;
+    transform: translateX(0%);
+  }
+  .moveL-enter,
+  .moveL-leave {
+    transform: translateX(-100%);
+  }
+  .moveL-leave-to {
+    transform: translateX(-100%);
+  }
+</style>