index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <div class="weather-box">
  3. <template v-if="weatherKey == 'sunny'">
  4. <sunny></sunny>
  5. </template>
  6. <template v-if="weatherKey == 'rain'">
  7. <ran></ran>
  8. </template>
  9. <template v-if="weatherKey == 'snow'">
  10. <snow></snow>
  11. </template>
  12. <template v-if="weatherKey == 'clound'">
  13. <clound></clound>
  14. </template>
  15. <div class="weather">
  16. <div class="weather-top">
  17. <div class="logo">
  18. <img src="/sk/skImage/weather/logo.png" alt="" />
  19. </div>
  20. <div class="weather-left">
  21. <div class="b-time">
  22. <span>北京时间</span>
  23. <span>{{ nowTime }}<i></i></span>
  24. </div>
  25. <div class="b-line">
  26. <span></span>
  27. <span></span>
  28. </div>
  29. <div class="b-time">
  30. <span>首尔时间</span>
  31. <span>{{ sTime }}<i></i></span>
  32. </div>
  33. <div class="weather-detail">
  34. <div class="d-top">
  35. <img :src="'/sk/skImage/weather/' + logonIcon" alt="" />
  36. <span>{{ temperature }} ℃</span>
  37. </div>
  38. <div class="d-bottom">
  39. <span>{{ nowDate }}</span>
  40. <span>{{ week }}</span>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="env-box">
  46. <div class="env-item env-box-bg">
  47. <div class="env-icon">
  48. <img
  49. :src="
  50. weatherKey == 'sunny'
  51. ? '/sk/skImage/weather/温度.png'
  52. : '/sk/skImage/weather/温度.png'
  53. "
  54. alt=""
  55. />
  56. <span>温度</span>
  57. </div>
  58. <div class="env-text">{{ envObj.Tdb }}</div>
  59. <div class="env-rate">℃</div>
  60. </div>
  61. <div class="env-item env-box-bg">
  62. <div class="env-icon">
  63. <img
  64. :src="
  65. weatherKey == 'sunny'
  66. ? '/sk/skImage/weather/湿度.png'
  67. : '/sk/skImage/weather/湿度.png'
  68. "
  69. alt=""
  70. />
  71. <span>湿度</span>
  72. </div>
  73. <div class="env-text">{{ envObj.RH }}</div>
  74. <div class="env-rate">%</div>
  75. </div>
  76. <div class="env-item env-box-bg">
  77. <div class="env-icon">
  78. <img
  79. :src="
  80. weatherKey == 'sunny'
  81. ? '/sk/skImage/weather/甲醛.png'
  82. : '/sk/skImage/weather/甲醛.png'
  83. "
  84. alt=""
  85. />
  86. <span>甲醛</span>
  87. </div>
  88. <div class="env-text">{{ envObj.HCHO }}</div>
  89. <div class="env-rate">mg/m³</div>
  90. </div>
  91. <div class="env-item env-box-bg">
  92. <div class="env-icon">
  93. <img
  94. :src="
  95. weatherKey == 'sunny'
  96. ? '/sk/skImage/weather/pm.png'
  97. : '/sk/skImage/weather/pm.png'
  98. "
  99. alt=""
  100. />
  101. <span>PM2.5</span>
  102. </div>
  103. <div class="env-text">{{ envObj.PM2d5 }}</div>
  104. <div class="env-rate">ug/m³</div>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </template>
  110. <script lang="ts">
  111. import $ from "jquery";
  112. import { nextTick } from "vue";
  113. // import { getWeather } from "@/apis/envmonitor.ts";
  114. import {
  115. defineComponent,
  116. reactive,
  117. toRefs,
  118. onMounted,
  119. onBeforeUnmount,
  120. } from "vue";
  121. import ran from "./rain.vue"; // 雨
  122. import clound from "./cloud.vue"; // 云
  123. import snow from "./snow.vue"; // 雪
  124. import sunny from "./sunny.vue"; // 晴
  125. import { getWeather, queryEnvCurrent } from "@/apis/envmonitor";
  126. import { formatEnergyDate, getWeek } from "@/utils";
  127. import { useRouter } from "vue-router";
  128. export default defineComponent({
  129. components: {
  130. ran,
  131. clound,
  132. snow,
  133. sunny,
  134. },
  135. beforeRouteEnter(to, from, next) {
  136. console.log("to===");
  137. console.log(from);
  138. if (from.name == "tiantan") {
  139. next();
  140. } else {
  141. next((e: any) => {
  142. e.pathUrl = "/sk/index";
  143. });
  144. }
  145. },
  146. setup(props) {
  147. const router = useRouter();
  148. let weatherData: any = [
  149. {
  150. text: "云",
  151. type: "clound",
  152. logonIcon: "阴.png",
  153. },
  154. {
  155. text: "雨",
  156. type: "rain",
  157. logonIcon: "雨.png",
  158. },
  159. {
  160. text: "雪",
  161. type: "snow",
  162. logonIcon: "雪.png",
  163. },
  164. {
  165. text: "晴",
  166. type: "sunny",
  167. logonIcon: "晴.png",
  168. },
  169. ];
  170. let times: any = null;
  171. let currentData: any = [];
  172. let envObj: any = {
  173. Tdb: "0", // 温度
  174. RH: "0", //湿度
  175. HCHO: "0", //甲醛
  176. PM2d5: "0",
  177. };
  178. let intevell: any = null;
  179. let timer: any = null;
  180. const proxyData = reactive({
  181. weatherData: weatherData,
  182. envObj: envObj,
  183. temperature: "",
  184. weatherKey: "",
  185. pathUrl: "/sk/home",
  186. logonIcon: "阴.png",
  187. currentData: currentData,
  188. nowTime: formatEnergyDate()[2],
  189. sTime: formatEnergyDate(2)[2],
  190. nowDate: formatEnergyDate()[0],
  191. intevell: intevell,
  192. week: getWeek(),
  193. // 设置现在时间
  194. setNowDate() {
  195. proxyData.intevell = setInterval(() => {
  196. let timeArr: any = formatEnergyDate();
  197. proxyData.nowTime = timeArr[2];
  198. proxyData.nowDate = timeArr[0];
  199. let timeArr1: any = formatEnergyDate(2);
  200. proxyData.sTime = timeArr1[2];
  201. proxyData.week = getWeek();
  202. }, 1000);
  203. },
  204. // 设置天气key的值
  205. setWeatherKey(content: any) {
  206. if (content == "sunny") {
  207. proxyData.weatherKey = "sunny";
  208. proxyData.logonIcon = "晴.png";
  209. } else if (content == "rain") {
  210. proxyData.weatherKey = "rain";
  211. proxyData.logonIcon = "雨.png";
  212. } else if (content == "snow") {
  213. proxyData.weatherKey = "snow";
  214. proxyData.logonIcon = "雪.png";
  215. } else if (content == "clound") {
  216. proxyData.weatherKey = "clound";
  217. proxyData.logonIcon = "阴.png";
  218. }
  219. },
  220. // 获取天气数据
  221. getWeatherData() {
  222. getWeather().then((res) => {
  223. let resResult: any = res;
  224. let content: any = resResult.content;
  225. proxyData.temperature = content.temperature;
  226. proxyData.setWeatherKey(content);
  227. });
  228. },
  229. timer: timer,
  230. setTimer(timeLen: any = 600000) {
  231. proxyData.timer = setInterval(() => {
  232. proxyData.setEnvData();
  233. proxyData.queryEnvCurrent();
  234. }, timeLen);
  235. },
  236. // 设置环境数据
  237. setEnvData() {
  238. proxyData.envObj = {
  239. Tdb: "0", // 温度
  240. RH: "0", //湿度
  241. HCHO: "0", //甲醛
  242. PM2d5: "0",
  243. };
  244. proxyData.currentData.map((item: any) => {
  245. if (item.code == "Tdb") {
  246. item.data = item.data ? item.data.toFixed(1) : "--";
  247. } else if (item.code == "RH") {
  248. item.data = item.data ? item.data.toFixed(0) : "--";
  249. } else if (item.code == "PM2d5") {
  250. item.data = item.data ? item.data.toFixed(0) : "--";
  251. } else {
  252. item.data = item.data ? item.data.toFixed(2) : "--";
  253. }
  254. proxyData.envObj[item.code] = item.data;
  255. });
  256. },
  257. // 获取环境数据
  258. queryEnvCurrent() {
  259. queryEnvCurrent()
  260. .then((res) => {
  261. let resResult: any = res;
  262. if (resResult.result == "success") {
  263. proxyData.currentData = resResult.data || [];
  264. } else {
  265. proxyData.currentData = [];
  266. }
  267. proxyData.setEnvData();
  268. })
  269. .catch((error: any) => {
  270. proxyData.currentData = [];
  271. });
  272. },
  273. times: times,
  274. changePage() {
  275. proxyData.times = setTimeout(() => {
  276. clearTimeout(proxyData.times);
  277. // router.push({ path: "/home" });
  278. window.location.href = proxyData.pathUrl;
  279. }, 300000);
  280. // 300000
  281. },
  282. });
  283. onBeforeUnmount(() => {
  284. clearInterval(proxyData.intevell);
  285. clearInterval(proxyData.timer);
  286. clearTimeout(proxyData.times);
  287. });
  288. onMounted(() => {
  289. proxyData.setNowDate();
  290. // 获取天气数据
  291. // proxyData.getWeatherData();
  292. let type: any = router.currentRoute.value.query.type;
  293. console.log(type);
  294. if (type) {
  295. proxyData.setWeatherKey(type);
  296. } else {
  297. type = "clound";
  298. }
  299. // 获取环境数据
  300. proxyData.queryEnvCurrent();
  301. // proxyData.changePage();
  302. // proxyData.setTimer();
  303. });
  304. return {
  305. ...toRefs(proxyData),
  306. };
  307. },
  308. });
  309. </script>
  310. 1840
  311. <style lang="scss" scoped>
  312. .weather-box {
  313. position: relative;
  314. width: 100%;
  315. height: 100%;
  316. .weather {
  317. position: absolute;
  318. box-sizing: border-box;
  319. padding: 0 40px;
  320. padding-top: 7.4vh;
  321. padding-bottom: 0;
  322. width: 100%;
  323. left: 0;
  324. top: 0;
  325. }
  326. .env-box {
  327. display: flex;
  328. justify-content: space-between;
  329. width: 100%;
  330. margin-top: 7.4vh;
  331. .env-item {
  332. box-sizing: border-box;
  333. padding: 9.2vh 4.4vw 14vh 4.4vw;
  334. width: 24%;
  335. // height: 64.2vh;
  336. // opacity: 0.3;
  337. border-radius: 32px;
  338. background: rgba(255, 255, 255, 0.5);
  339. .env-icon {
  340. text-align: center;
  341. padding-bottom: 50px;
  342. img {
  343. width: 100px;
  344. display: inline-block;
  345. vertical-align: middle;
  346. }
  347. span {
  348. display: inline-block;
  349. margin-left: 20px;
  350. vertical-align: middle;
  351. font-size: 60px;
  352. font-weight: 500;
  353. letter-spacing: 0px;
  354. line-height: 60px;
  355. color: rgba(255, 255, 255, 1);
  356. }
  357. }
  358. .env-text {
  359. text-align: center;
  360. font-family: "HarmonyOS Sans TC";
  361. font-size: 130px;
  362. line-height: 160px;
  363. font-weight: 700;
  364. letter-spacing: 0px;
  365. color: rgba(255, 255, 255, 1);
  366. }
  367. .env-rate {
  368. font-family: "HarmonyOS_Sans_TC_Regular";
  369. padding-top: 80px;
  370. font-size: 60px;
  371. font-weight: 400;
  372. letter-spacing: 0px;
  373. line-height: 0px;
  374. color: rgba(255, 255, 255, 1);
  375. text-align: center;
  376. }
  377. &:nth-child(2) {
  378. img {
  379. width: 72px;
  380. }
  381. }
  382. &:nth-child(3) {
  383. img {
  384. width: 102px;
  385. }
  386. }
  387. &:nth-child(4) {
  388. img {
  389. width: 62px;
  390. }
  391. }
  392. }
  393. .env-box-bg {
  394. background: rgba(255, 255, 255, 0.1);
  395. }
  396. }
  397. .weather-top {
  398. box-sizing: border-box;
  399. padding-left: 95px;
  400. display: flex;
  401. overflow: hidden;
  402. justify-content: space-between;
  403. .logo {
  404. width: 150px;
  405. img {
  406. width: 150px;
  407. }
  408. }
  409. .weather-left {
  410. position: relative;
  411. // text-align: right;
  412. width: 74%;
  413. white-space: nowrap;
  414. overflow: hidden;
  415. .b-time {
  416. display: inline-block;
  417. vertical-align: middle;
  418. margin-right: 90px;
  419. width: 270px;
  420. // border-bottom: 2px solid rgba(255, 255, 255, 1);
  421. i {
  422. display: block;
  423. width: 90%;
  424. height: 2px;
  425. background: rgba(255, 255, 255, 1);
  426. // border-bottom: 2px solid rgba(255, 255, 255, 1);
  427. margin: 0 auto;
  428. }
  429. span {
  430. display: block;
  431. text-align: center;
  432. &:nth-child(1) {
  433. opacity: 1;
  434. padding-bottom: 20px;
  435. /** 文本1 */
  436. font-size: 32px;
  437. font-weight: 500;
  438. letter-spacing: 0px;
  439. color: rgba(255, 255, 255, 1);
  440. }
  441. &:nth-child(2) {
  442. font-size: 64px;
  443. font-weight: 700;
  444. letter-spacing: 0px;
  445. letter-spacing: 0px;
  446. color: rgba(255, 255, 255, 1);
  447. }
  448. }
  449. &:nth-child(3) {
  450. margin-left: 90px;
  451. margin-right: 10px;
  452. }
  453. }
  454. .b-line {
  455. position: absolute;
  456. bottom: 0;
  457. left: 19vw;
  458. // left: 13.6vw;
  459. display: inline-block;
  460. vertical-align: baseline;
  461. width: 1px;
  462. // height: 4.27vh;
  463. // padding-top: 5vh;
  464. span {
  465. display: block;
  466. height: 1.67vh;
  467. // width: 1px;
  468. border: 1px solid rgba(240, 240, 240, 1);
  469. // background: rgba(240, 240, 240, 1);
  470. &:nth-child(2) {
  471. margin-top: 0.925vh;
  472. }
  473. }
  474. }
  475. }
  476. .weather-detail {
  477. // position: relative;
  478. // box-sizing: border-box;
  479. float: right;
  480. // right: 0;
  481. // padding-right: 73px;
  482. .d-top {
  483. text-align: right;
  484. padding-bottom: 12px;
  485. img {
  486. width: 73px;
  487. display: inline-block;
  488. vertical-align: middle;
  489. }
  490. span {
  491. display: inline-block;
  492. padding-left: 10px;
  493. font-size: 58px;
  494. font-weight: 400;
  495. color: rgba(242, 244, 246, 1);
  496. vertical-align: middle;
  497. }
  498. }
  499. .d-bottom {
  500. font-size: 38px;
  501. font-weight: 400;
  502. color: rgba(242, 244, 246, 1);
  503. span {
  504. &:nth-child(2) {
  505. padding-left: 10px;
  506. }
  507. }
  508. }
  509. }
  510. }
  511. }
  512. </style>