MainLayout.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <template>
  2. <div class="MainLayout" @click="showWeather = false">
  3. <div class="main-title">{{title}}</div>
  4. <div class="main-left">
  5. <!-- 天气 -->
  6. <div v-show="isHome" class="main-home" @click.stop="showWeather = true">
  7. <div class="weatherBox" v-if="Object.keys(weather).length !== 0">
  8. <div class="box-left">
  9. <i class="qing" v-if="weather.day_weather === '晴'"></i>
  10. <i class="duoyun" v-else-if="weather.day_weather === '多云'"></i>
  11. <i class="yin" v-else-if="weather.day_weather === '阴'"></i>
  12. <i class="xiaoyu" v-else-if="weather.day_weather === '小雨'"></i>
  13. <i class="zyu" v-else-if="weather.day_weather === '中雨'"></i>
  14. <i class="dyu" v-else-if="weather.day_weather === '大雨'"></i>
  15. <i class="byu" v-else-if="weather.day_weather === '暴雨'"></i>
  16. <i class="xxue" v-else-if="weather.day_weather === '小雪'"></i>
  17. <i class="zxue" v-else-if="weather.day_weather === '中雪'"></i>
  18. <i class="dxue" v-else-if="weather.day_weather === '大雪'"></i>
  19. <i class="bxue" v-else-if="weather.day_weather === '暴雪'"></i>
  20. <i class="wu" v-else-if="weather.day_weather === '雾'"></i>
  21. </div>
  22. <div class="box-right">
  23. <p class="fontSize">{{weather.day_weather}}</p>
  24. <p class="fontSize">{{weather.min_degree}}-{{weather.max_degree}}℃</p>
  25. </div>
  26. </div>
  27. <div v-else @click="refresh">抓取天气数据失败,请重试</div>
  28. </div>
  29. <!-- 返回首页 -->
  30. <div v-show="!isHome" class="main-back" @click="back">首页</div>
  31. </div>
  32. <div class="main-right">
  33. <i class="maxTem" v-if="alarm.maxTem" @click="openShow(0)"></i>
  34. <i class="minTem" v-if="alarm.minTem" @click="openShow(1)"></i>
  35. <i class="shan" v-if="Object.keys(weatherInfo).length > 0" @click="openShow(2)"></i>
  36. </div>
  37. <div class="time" v-show="isHome">{{currentTime}}</div>
  38. <div class="main-bottom">
  39. <p style="margin: 0">青莲食品</p>
  40. <p style="font-size: 12px; margin: 0; color: #fff; opacity: 0.4">本软件由杭州慧牧提供技术支持</p>
  41. </div>
  42. <div class="content">
  43. <router-view></router-view>
  44. </div>
  45. <transition :name=" isHome ? 'moveL' : 'moveR' ">
  46. <div id="weather" :class="[isHome ? 'weather1' : 'weather2']" v-if="showWeather">
  47. <h2 style="color:white;">{{getFarmName()}}</h2>
  48. <div class="weatherList">
  49. <div class="grid">
  50. <div class="grid-title">今天</div>
  51. <div class="grid-content">当前天气:{{weather.day_weather}}</div>
  52. <div class="grid-content">当前气温:{{weather.degree}}℃</div>
  53. <div class="grid-content">最低温度:{{weather.min_degree}}℃</div>
  54. <div class="grid-content">最高温度:{{weather.max_degree}}℃</div>
  55. </div>
  56. <div class="grid">
  57. <div class="grid-title">明天</div>
  58. <div class="grid-content">当天天气:{{weather.tomorrow.day_weather}}</div>
  59. <div class="grid-content">最低温度:{{weather.tomorrow.min_degree}}℃</div>
  60. <div class="grid-content">最高温度:{{weather.tomorrow.max_degree}}℃</div>
  61. </div>
  62. <div class="grid">
  63. <div class="grid-title">后天</div>
  64. <div class="grid-content">当天天气:{{weather.towTomorrow.day_weather}}</div>
  65. <div class="grid-content">最低温度:{{weather.towTomorrow.min_degree}}℃</div>
  66. <div class="grid-content">最高温度:{{weather.towTomorrow.max_degree}}℃</div>
  67. </div>
  68. </div>
  69. <div class="chart">
  70. <chart-weather :data="weatherList"></chart-weather>
  71. </div>
  72. </div>
  73. </transition>
  74. <div class="farm">
  75. <label>当前牧场:</label>
  76. <el-select @change="onChange" v-model="farmId" size="mini" style="width: 150px;">
  77. <el-option v-for="item in getFarmList" :key="item.id" :label="item.farmName" :value="item.id"></el-option>
  78. </el-select>
  79. </div>
  80. <div class="alarm" v-show="alarmType">
  81. <p style="color: white">{{alarmList[active]}}</p>
  82. <p style="color: white">{{str}}</p>
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. import {getFarmId, getWeather, findUpdate, InfoWeater} from "@/utils/api";
  88. import { mapActions, mapState } from 'vuex';
  89. import { Select } from "element-ui";
  90. import chartWeather from "@/views/Home/chart/chartWeather";
  91. export default {
  92. name: "MainLayout",
  93. components: {
  94. 'el-select': Select,
  95. chartWeather
  96. },
  97. data() {
  98. return {
  99. title: '',
  100. isHome: true,
  101. currentTime: '',
  102. timer4: null,
  103. showWeather: false,
  104. weather: {},
  105. // 天气报警
  106. weatherInfo: {},
  107. xList: [],
  108. isShow: false,
  109. getFarmList: [],
  110. alarm: {
  111. maxTem: false,
  112. minTem: false,
  113. maxTemStr: '',
  114. minTemStr: '',
  115. },
  116. alarmList: ['高温报警', '低温报警', '恶劣天气报警'],
  117. active: 0,
  118. str: '',
  119. alarmType: false,
  120. weatherList: [],
  121. }
  122. },
  123. watch: {
  124. $route(newVal) {
  125. if(newVal) {
  126. this.title = newVal.meta.title;
  127. if (newVal.name === 'Home') {
  128. this.isHome = true;
  129. this.initTime();
  130. } else {
  131. this.isHome = false;
  132. clearInterval(this.timer4);
  133. }
  134. }
  135. },
  136. farmList: {
  137. handler(newVal) {
  138. if(newVal.length > 0) {
  139. this.getFarmList = []
  140. newVal.forEach(item => {
  141. if(item.rowStatus) {
  142. this.getFarmList.push(item)
  143. }
  144. })
  145. }
  146. },
  147. deep: true
  148. }
  149. },
  150. computed: {
  151. ...mapState(['farmList', 'farmId'])
  152. },
  153. methods: {
  154. ...mapActions(['GetFarm', 'setFarmIdAsync']),
  155. initTime() {
  156. var _this = this;
  157. this.timer4 = setInterval(function() {
  158. var date = new Date();
  159. var year = date.getFullYear();
  160. var month = date.getMonth() + 1;
  161. var hour = date.getHours();
  162. var minutes = date.getMinutes() ;
  163. var seconds = date.getSeconds();
  164. var strDate = date.getDate();
  165. if (month >= 1 && month <= 9) {
  166. month = "0" + month;
  167. }
  168. if (strDate >= 0 && strDate <= 9) {
  169. strDate = "0" + strDate;
  170. }
  171. if(hour >=1&& hour <= 9) {
  172. hour = "0" + hour;
  173. }
  174. if(minutes >=1&& minutes <= 9) {
  175. minutes = "0" + minutes;
  176. }
  177. if(seconds >=1&& seconds <= 9) {
  178. seconds = "0" + seconds;
  179. }
  180. _this.currentTime = year + '-' + month + '-' + strDate+" "+hour+":" +minutes+":" +seconds;
  181. }, 1000)
  182. },
  183. back() {
  184. this.$router.push('/')
  185. },
  186. init() {
  187. getFarmId().then(res => {
  188. if(res.code === 10000) {
  189. this.setFarmIdAsync(res.data);
  190. localStorage.setItem('lastFarmId', res.data);
  191. this.refresh()
  192. }
  193. })
  194. },
  195. // 刷新拿到数据
  196. refresh() {
  197. getWeather({}).then(async res => {
  198. if(res.code === 10000) {
  199. this.weather = res.data;
  200. this.weatherInfo = JSON.parse(res.data.alarm)
  201. this.weatherList = [res.data.timeList, res.data.tempList]
  202. let params = {
  203. maxTem: res.data.max_degree,
  204. minTem: res.data.min_degree
  205. }
  206. await InfoWeater(params).then(res => {
  207. if(res.code === 10000) {
  208. this.alarm = res.data;
  209. }
  210. })
  211. }
  212. })
  213. },
  214. // 选择牧场
  215. onChange(val) {
  216. let params = {
  217. id: localStorage.getItem('UserId'),
  218. lastFarmId: val
  219. }
  220. localStorage.setItem('lastFarmId', val)
  221. findUpdate(params).then(res => {
  222. console.log(res)
  223. })
  224. this.setFarmIdAsync(val);
  225. setTimeout(() => {
  226. location.reload();
  227. }, 100)
  228. },
  229. openShow(num) {
  230. this.active = num;
  231. this.alarmType = true;
  232. if(num === 0) {
  233. this.str = this.alarm.maxTemStr;
  234. } else if(num === 1) {
  235. this.str = this.alarm.minTemStr
  236. } else {
  237. this.str = '';
  238. }
  239. setTimeout(() => {
  240. this.alarmType = false;
  241. }, 5000)
  242. },
  243. getFarmName() {
  244. let str = '';
  245. this.farmList.forEach(item => {
  246. if(item.id === this.farmId) {
  247. str = item.farmName
  248. }
  249. })
  250. return str
  251. }
  252. },
  253. mounted() {
  254. this.init()
  255. this.GetFarm()
  256. this.title = this.$route.meta.title;
  257. if (this.$route.name === 'Home') {
  258. this.isHome = true;
  259. this.initTime();
  260. } else {
  261. this.isHome = false;
  262. if(this.timer4) {
  263. clearInterval(this.timer4)
  264. }
  265. }
  266. }
  267. }
  268. </script>
  269. <style scoped>
  270. .MainLayout {
  271. width: 100vw;
  272. height: 100vh;
  273. background: url("../assets/u1.jpg") no-repeat;
  274. background-size: 100% 100%;
  275. box-sizing: border-box;
  276. position: relative;
  277. }
  278. .content {
  279. width: 100%;
  280. height: 100%;
  281. background: url('../assets/home.png') no-repeat;
  282. background-size: 100% 100%;
  283. box-sizing: border-box;
  284. padding: 70px 60px;
  285. }
  286. .main-title {
  287. width: 230px;
  288. height: 25px;
  289. line-height: 25px;
  290. position: absolute;
  291. top: 25px;
  292. left: 50.5%;
  293. text-align: center;
  294. transform: translate(-50%, 0);
  295. color: #66FFFF;
  296. font-size: 22px;
  297. font-weight: 600;
  298. cursor: pointer;
  299. }
  300. .main-left {
  301. width: 180px;
  302. height: 40px;
  303. position: absolute;
  304. top: 0;
  305. left: 150px;
  306. }
  307. .main-right {
  308. width: 180px;
  309. height: 40px;
  310. position: absolute;
  311. top: 0;
  312. right: 125px;
  313. }
  314. .main-home {
  315. width: 100%;
  316. height: 100%;
  317. line-height: 40px;
  318. color: white;
  319. }
  320. .main-time {
  321. width: 100%;
  322. height: 100%;
  323. line-height: 50px;
  324. font-size: 16px;
  325. }
  326. .main-bottom {
  327. width: 200px;
  328. height: 50px;
  329. /*background-color: red;*/
  330. position: absolute;
  331. /*line-height: 50px;*/
  332. color: #66FFFF;
  333. font-size: 24px;
  334. font-weight: 600;
  335. left: 51%;
  336. bottom: 20px;
  337. transform: translate(-50% , 0);
  338. }
  339. .main-back {
  340. width: 140px;
  341. height: 30px;
  342. font-size: 14px;
  343. line-height: 30px;
  344. background: url("../assets/Home/u761.svg") no-repeat;
  345. background-size: 100% 100%;
  346. color: white;
  347. cursor: pointer;
  348. }
  349. #weather {
  350. background-color: rgba(0, 0, 0, .8);
  351. position: absolute;
  352. width: 800px;
  353. height: 800px;
  354. top: 0;
  355. }
  356. .weather1 {
  357. left: 0;
  358. }
  359. .weather2 {
  360. right: 0;
  361. }
  362. .moveL-enter-active,
  363. .moveL-leave-active {
  364. transition: all 0.3s linear;
  365. transform: translateX(0%);
  366. }
  367. .moveL-enter,
  368. .moveL-leave {
  369. transform: translateX(-100%);
  370. }
  371. .moveL-leave-to {
  372. transform: translateX(-100%);
  373. }
  374. .moveR-enter-active, .moveR-leave-active {
  375. transition: all 0.3s linear;
  376. transform: translateX(0);
  377. }
  378. .moveR-enter, .moveR-leave {
  379. transform: translateX(100%);
  380. }
  381. .moveR-leave-to{
  382. transform: translateX(100%);
  383. }
  384. .weatherBox {
  385. width: 100%;
  386. height: 100%;
  387. box-sizing: border-box;
  388. padding: 0 20px;
  389. display: flex;
  390. justify-content: center;
  391. align-items: center;
  392. cursor: pointer;
  393. }
  394. .box-left {
  395. width: 35px;
  396. height: 35px;
  397. }
  398. .box-right {
  399. width: 60px;
  400. height: 100%;
  401. margin-left: 20px;
  402. }
  403. .qing {
  404. width: 100%;
  405. height: 100%;
  406. display: inline-block;
  407. background: url("../assets/weather/qingtian.png") no-repeat;
  408. background-size: 100% 100%;
  409. }
  410. .fontSize {
  411. height: 20px;
  412. margin: 0;
  413. line-height: 20px;
  414. text-align: left;
  415. color: #28BCCA;
  416. }
  417. .duoyun {
  418. width: 100%;
  419. height: 100%;
  420. display: inline-block;
  421. background: url("../assets/weather/qingzhuanduoyun.png") no-repeat;
  422. background-size: 100% 100%;
  423. }
  424. .yin {
  425. width: 100%;
  426. height: 100%;
  427. display: inline-block;
  428. background: url("../assets/weather/yintian.png") no-repeat;
  429. background-size: 100% 100%;
  430. }
  431. .xiaoyu {
  432. width: 100%;
  433. height: 100%;
  434. display: inline-block;
  435. background: url("../assets/weather/xiaoyu.png") no-repeat;
  436. background-size: 100% 100%;
  437. }
  438. .zyu {
  439. width: 100%;
  440. height: 100%;
  441. display: inline-block;
  442. background: url("../assets/weather/zhongyu.png") no-repeat;
  443. background-size: 100% 100%;
  444. }
  445. .dyu {
  446. width: 100%;
  447. height: 100%;
  448. display: inline-block;
  449. background: url("../assets/weather/dayu.png") no-repeat;
  450. background-size: 100% 100%;
  451. }
  452. .byu {
  453. width: 100%;
  454. height: 100%;
  455. display: inline-block;
  456. background: url("../assets/weather/baoyu.png") no-repeat;
  457. background-size: 100% 100%;
  458. }
  459. .xxue{
  460. width: 100%;
  461. height: 100%;
  462. display: inline-block;
  463. background: url("../assets/weather/xiaoxue.png") no-repeat;
  464. background-size: 100% 100%;
  465. }
  466. .zxue{
  467. width: 100%;
  468. height: 100%;
  469. display: inline-block;
  470. background: url("../assets/weather/zhongxue.png") no-repeat;
  471. background-size: 100% 100%;
  472. }
  473. .dxue{
  474. width: 100%;
  475. height: 100%;
  476. display: inline-block;
  477. background: url("../assets/weather/daxue.png") no-repeat;
  478. background-size: 100% 100%;
  479. }
  480. .bxue{
  481. width: 100%;
  482. height: 100%;
  483. display: inline-block;
  484. background: url("../assets/weather/baoxue.png") no-repeat;
  485. background-size: 100% 100%;
  486. }
  487. .wu {
  488. width: 100%;
  489. height: 100%;
  490. display: inline-block;
  491. background: url("../assets/weather/wu.png") no-repeat;
  492. background-size: 100% 100%;
  493. }
  494. .time {
  495. position: absolute;
  496. bottom: 35px;
  497. right: 80px;
  498. line-height: 50px;
  499. font-size: 16px;
  500. color: #289882
  501. }
  502. .bio-dialog {
  503. width: 100%;
  504. height: 100%;
  505. position: absolute;
  506. top: 0;
  507. left: 0;
  508. background-color: rgba(0,0,0, .9);
  509. z-index: 999;
  510. }
  511. .dialog-content {
  512. width: 30%;
  513. position: absolute;
  514. top: 50%;
  515. left: 50%;
  516. transform: translate(-50%, -70%);
  517. border: 1px solid #ddd;
  518. box-sizing: border-box;
  519. padding: 20px;
  520. color: #fff;
  521. text-align: center;
  522. }
  523. .div-text {
  524. width: 400px;
  525. height: 60px;
  526. background: url("../assets/101.png") no-repeat;
  527. background-size: 100% 100%;
  528. line-height: 60px;
  529. margin: 20px auto;
  530. font-size: 20px;
  531. color: white;
  532. text-align: center;
  533. border-bottom: 1px solid #53bafd;
  534. cursor: pointer;
  535. }
  536. .div-text:hover {
  537. background-color: white;
  538. color: #53bafd;
  539. cursor: pointer;
  540. }
  541. .farm {
  542. /*width: 200px;*/
  543. height: 40px;
  544. /*background-color: red;*/
  545. position: absolute;
  546. bottom: 40px;
  547. left: 60px;
  548. line-height: 40px;
  549. text-align: left;
  550. color: #fff;
  551. font-size: 16px;
  552. }
  553. .maxTem {
  554. display: inline-block;
  555. width: 24px;
  556. height: 24px;
  557. background: url('../assets/Home/gaowen.png');
  558. background-size: contain;
  559. margin-top: 10px;
  560. cursor: pointer;
  561. }
  562. .minTem {
  563. display: inline-block;
  564. width: 24px;
  565. height: 24px;
  566. background: url('../assets/Home/diwen.png');
  567. background-size: contain;
  568. margin-top: 10px;
  569. cursor: pointer;
  570. }
  571. .shan {
  572. display: inline-block;
  573. width: 24px;
  574. height: 24px;
  575. background: url('../assets/Home/shandian.png');
  576. background-size: contain;
  577. margin-top: 10px;
  578. cursor: pointer;
  579. }
  580. .alarm {
  581. width: 200px;
  582. height: 100px;
  583. position: absolute;
  584. bottom: 500px;
  585. right: 100px;
  586. border: 1px solid red;
  587. animation: myfirst 1s;
  588. }
  589. @keyframes myfirst {
  590. 0% {
  591. opacity: 0;
  592. }
  593. 100% {
  594. opacity: 1;
  595. }
  596. }
  597. .weatherList {
  598. width: 100%;
  599. height: 200px;
  600. display: grid;
  601. grid-template-columns: repeat(3, 1fr);
  602. grid-template-rows: 1fr;
  603. grid-column-gap: 0;
  604. grid-row-gap: 0;
  605. }
  606. .grid {
  607. width: 100%;
  608. height: 100%;
  609. color: white;
  610. }
  611. .grid-title {
  612. line-height: 50px;
  613. font-size: 24px;
  614. }
  615. .grid-content {
  616. box-sizing: border-box;
  617. line-height: 30px;
  618. font-size: 16px;
  619. text-align: left;
  620. padding-left: 80px;
  621. }
  622. .chart {
  623. width: 100%;
  624. height: calc(100% - 250px);
  625. }
  626. </style>