MainLayout.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <div class="MainLayout">
  3. <div class="main-title">{{title}}</div>
  4. <div class="main-left">
  5. <!-- 天气 -->
  6. <div v-show="isHome" class="main-home" @click="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. </div>
  21. <div class="box-right">
  22. <p class="fontSize">{{weather.day_weather}}</p>
  23. <p class="fontSize">{{weather.min_degree}}-{{weather.max_degree}}℃</p>
  24. </div>
  25. </div>
  26. <div v-else @click="refresh">抓取天气数据失败,请重试</div>
  27. </div>
  28. <!-- 返回首页 -->
  29. <div v-show="!isHome" class="main-back" @click="back">首页</div>
  30. </div>
  31. <div class="main-right">
  32. <!-- 时间 -->
  33. <div v-show="isHome" class="main-time">
  34. <div v-if="Object.keys(weatherInfo).length !== 0">111</div>
  35. </div>
  36. <!-- 天气 -->
  37. <div v-show="!isHome" class="main-home" @click="showWeather = true">
  38. <div class="weatherBox" v-if="Object.keys(weather).length !== 0">
  39. <div class="box-left">
  40. <i class="qing" v-if="weather.day_weather === '晴'"></i>
  41. <i class="duoyun" v-else-if="weather.day_weather === '多云'"></i>
  42. <i class="yin" v-else-if="weather.day_weather === '阴'"></i>
  43. <i class="xiaoyu" v-else-if="weather.day_weather === '小雨'"></i>
  44. <i class="zyu" v-else-if="weather.day_weather === '中雨'"></i>
  45. <i class="dyu" v-else-if="weather.day_weather === '大雨'"></i>
  46. <i class="byu" v-else-if="weather.day_weather === '暴雨'"></i>
  47. <i class="xxue" v-else-if="weather.day_weather === '小雪'"></i>
  48. <i class="zxue" v-else-if="weather.day_weather === '中雪'"></i>
  49. <i class="dxue" v-else-if="weather.day_weather === '大雪'"></i>
  50. <i class="bxue" v-else-if="weather.day_weather === '暴学'"></i>
  51. </div>
  52. <div class="box-right">
  53. <p class="fontSize">{{weather.day_weather}}</p>
  54. <p class="fontSize">{{weather.min_degree}}-{{weather.max_degree}}℃</p>
  55. </div>
  56. </div>
  57. <div v-else @click="refresh">抓取天气数据失败,请重试</div>
  58. </div>
  59. </div>
  60. <div class="time">{{currentTime}}</div>
  61. <div class="main-bottom">青莲食品</div>
  62. <div class="content">
  63. <router-view></router-view>
  64. </div>
  65. <transition :name=" isHome ? 'moveL' : 'moveR' ">
  66. <div id="weather" :class="[isHome ? 'weather1' : 'weather2']" v-if="showWeather">
  67. <div style="text-align: left">
  68. <i class="el-icon-back" style="font-size: 24px; color: #fff; cursor: pointer" @click="showWeather = false"></i>
  69. </div>
  70. <iframe style="width: 800px; height: 800px; z-index: 9999" src="static/weather/index.html" frameborder="0"></iframe>
  71. </div>
  72. </transition>
  73. </div>
  74. </template>
  75. <script>
  76. import {getFarmId, getWeather} from "@/utils/api";
  77. import { mapActions } from 'vuex'
  78. export default {
  79. name: "MainLayout",
  80. data() {
  81. return {
  82. title: '',
  83. isHome: true,
  84. currentTime: '',
  85. timer4: null,
  86. showWeather: false,
  87. weather: {},
  88. // 天气报警
  89. weatherInfo: {},
  90. }
  91. },
  92. watch: {
  93. $route(newVal) {
  94. if(newVal) {
  95. this.title = newVal.meta.title;
  96. if (newVal.name === 'Home') {
  97. this.isHome = true;
  98. this.initTime();
  99. } else {
  100. this.isHome = false;
  101. clearInterval(this.timer4);
  102. }
  103. }
  104. }
  105. },
  106. methods: {
  107. ...mapActions(['GetFarm', 'setFarmIdAsync']),
  108. initTime() {
  109. var _this = this;
  110. this.timer4 = setInterval(function() {
  111. var date = new Date();
  112. var year = date.getFullYear();
  113. var month = date.getMonth() + 1;
  114. var hour = date.getHours();
  115. var minutes = date.getMinutes() ;
  116. var seconds = date.getSeconds();
  117. var strDate = date.getDate();
  118. if (month >= 1 && month <= 9) {
  119. month = "0" + month;
  120. }
  121. if (strDate >= 0 && strDate <= 9) {
  122. strDate = "0" + strDate;
  123. }
  124. if(hour >=1&& hour <= 9) {
  125. hour = "0" + hour;
  126. }
  127. if(minutes >=1&& minutes <= 9) {
  128. minutes = "0" + minutes;
  129. }
  130. if(seconds >=1&& seconds <= 9) {
  131. seconds = "0" + seconds;
  132. }
  133. _this.currentTime = year + '-' + month + '-' + strDate+" "+hour+":" +minutes+":" +seconds;
  134. }, 1000)
  135. },
  136. back() {
  137. this.$router.push('/')
  138. },
  139. init() {
  140. getFarmId().then(res => {
  141. if(res.code === 10000) {
  142. this.setFarmIdAsync(res.data);
  143. localStorage.setItem('lastFarmId', res.data);
  144. this.refresh()
  145. }
  146. })
  147. },
  148. // 刷新拿到数据
  149. refresh() {
  150. getWeather({}).then(res => {
  151. if(res.code === 10000) {
  152. this.weather = res.data;
  153. this.weatherInfo = JSON.parse(res.data.alarm)
  154. console.log(this.weatherInfo)
  155. }
  156. })
  157. }
  158. },
  159. mounted() {
  160. this.init()
  161. this.GetFarm()
  162. this.title = this.$route.meta.title;
  163. if (this.$route.name === 'Home') {
  164. this.isHome = true;
  165. this.initTime();
  166. } else {
  167. this.isHome = false;
  168. if(this.timer4) {
  169. clearInterval(this.timer4)
  170. }
  171. }
  172. }
  173. }
  174. </script>
  175. <style scoped>
  176. .MainLayout {
  177. width: 100vw;
  178. height: 100vh;
  179. background: url("../assets/u1.jpg") no-repeat;
  180. background-size: 100% 100%;
  181. box-sizing: border-box;
  182. padding: 20px 20px;
  183. position: relative;
  184. }
  185. .content {
  186. width: 100%;
  187. height: 100%;
  188. background: url('../assets/home.png') no-repeat;
  189. background-size: 100% 100%;
  190. box-sizing: border-box;
  191. padding: 70px 60px;
  192. }
  193. .main-title {
  194. width: 230px;
  195. height: 52px;
  196. line-height: 52px;
  197. position: absolute;
  198. top: 25px;
  199. left: 50.5%;
  200. text-align: center;
  201. transform: translate(-50%, 0);
  202. color: #66FFFF;
  203. font-size: 18px;
  204. font-weight: 600;
  205. }
  206. .main-left {
  207. width: 180px;
  208. height: 40px;
  209. position: absolute;
  210. top: 15px;
  211. left: 150px;
  212. }
  213. .main-right {
  214. width: 180px;
  215. height: 40px;
  216. position: absolute;
  217. top: 15px;
  218. right: 150px;
  219. }
  220. .main-home {
  221. width: 100%;
  222. height: 100%;
  223. line-height: 40px;
  224. color: white;
  225. }
  226. .main-time {
  227. width: 100%;
  228. height: 100%;
  229. line-height: 50px;
  230. font-size: 16px;
  231. }
  232. .main-bottom {
  233. width: 200px;
  234. height: 50px;
  235. /*background-color: red;*/
  236. position: absolute;
  237. line-height: 50px;
  238. color: #66FFFF;
  239. font-size: 24px;
  240. font-weight: 600;
  241. left: 51%;
  242. bottom: 35px;
  243. transform: translate(-50% , 0);
  244. }
  245. .main-back {
  246. width: 140px;
  247. height: 30px;
  248. font-size: 14px;
  249. line-height: 30px;
  250. background: url("../assets/Home/u761.svg") no-repeat;
  251. background-size: 100% 100%;
  252. color: white;
  253. cursor: pointer;
  254. }
  255. #weather {
  256. background-color: rgba(0, 0, 0, .5);
  257. position: absolute;
  258. width: 800px;
  259. height: 800px;
  260. top: 0;
  261. }
  262. .weather1 {
  263. left: 0;
  264. }
  265. .weather2 {
  266. right: 0;
  267. }
  268. .moveL-enter-active,
  269. .moveL-leave-active {
  270. transition: all 0.3s linear;
  271. transform: translateX(0%);
  272. }
  273. .moveL-enter,
  274. .moveL-leave {
  275. transform: translateX(-100%);
  276. }
  277. .moveL-leave-to {
  278. transform: translateX(-100%);
  279. }
  280. .moveR-enter-active, .moveR-leave-active {
  281. transition: all 0.3s linear;
  282. transform: translateX(0);
  283. }
  284. .moveR-enter, .moveR-leave {
  285. transform: translateX(100%);
  286. }
  287. .moveR-leave-to{
  288. transform: translateX(100%);
  289. }
  290. .weatherBox {
  291. width: 100%;
  292. height: 100%;
  293. box-sizing: border-box;
  294. padding: 0 20px;
  295. display: flex;
  296. justify-content: center;
  297. align-items: center;
  298. cursor: pointer;
  299. }
  300. .box-left {
  301. width: 35px;
  302. height: 35px;
  303. }
  304. .box-right {
  305. width: 60px;
  306. height: 100%;
  307. margin-left: 20px;
  308. }
  309. .qing {
  310. width: 100%;
  311. height: 100%;
  312. display: inline-block;
  313. background: url("../assets/weather/qingtian.png") no-repeat;
  314. background-size: 100% 100%;
  315. }
  316. .fontSize {
  317. height: 20px;
  318. margin: 0;
  319. line-height: 20px;
  320. text-align: left;
  321. color: #28BCCA;
  322. }
  323. .duoyun {
  324. width: 100%;
  325. height: 100%;
  326. display: inline-block;
  327. background: url("../assets/weather/qingzhuanduoyun.png") no-repeat;
  328. background-size: 100% 100%;
  329. }
  330. .yin {
  331. width: 100%;
  332. height: 100%;
  333. display: inline-block;
  334. background: url("../assets/weather/yintian.png") no-repeat;
  335. background-size: 100% 100%;
  336. }
  337. .xiaoyu {
  338. width: 100%;
  339. height: 100%;
  340. display: inline-block;
  341. background: url("../assets/weather/xiaoyu.png") no-repeat;
  342. background-size: 100% 100%;
  343. }
  344. .zyu {
  345. width: 100%;
  346. height: 100%;
  347. display: inline-block;
  348. background: url("../assets/weather/zhongyu.png") no-repeat;
  349. background-size: 100% 100%;
  350. }
  351. .dyu {
  352. width: 100%;
  353. height: 100%;
  354. display: inline-block;
  355. background: url("../assets/weather/dayu.png") no-repeat;
  356. background-size: 100% 100%;
  357. }
  358. .byu {
  359. width: 100%;
  360. height: 100%;
  361. display: inline-block;
  362. background: url("../assets/weather/baoyu.png") no-repeat;
  363. background-size: 100% 100%;
  364. }
  365. .xxue{
  366. width: 100%;
  367. height: 100%;
  368. display: inline-block;
  369. background: url("../assets/weather/xiaoxue.png") no-repeat;
  370. background-size: 100% 100%;
  371. }
  372. .zxue{
  373. width: 100%;
  374. height: 100%;
  375. display: inline-block;
  376. background: url("../assets/weather/zhongxue.png") no-repeat;
  377. background-size: 100% 100%;
  378. }
  379. .dxue{
  380. width: 100%;
  381. height: 100%;
  382. display: inline-block;
  383. background: url("../assets/weather/daxue.png") no-repeat;
  384. background-size: 100% 100%;
  385. }
  386. .bxue{
  387. width: 100%;
  388. height: 100%;
  389. display: inline-block;
  390. background: url("../assets/weather/baoxue.png") no-repeat;
  391. background-size: 100% 100%;
  392. }
  393. .time {
  394. position: absolute;
  395. bottom: 35px;
  396. right: 80px;
  397. line-height: 50px;
  398. font-size: 16px;
  399. color: #289882
  400. }
  401. </style>