ThermometerCard.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <template>
  2. <div>
  3. <div class="thermometerContainer" :style="{'width':width,'height':height}">
  4. <!-- <div class="container" :style="{'width':width,'height':height}"> -->
  5. <div class="time">
  6. {{nowTime}} 实况
  7. </div>
  8. <div class="thermometerAndTemperature">
  9. <div class="temperature">
  10. {{weatherProphetData_17Hour[0].temperature}}<span>℃</span>
  11. </div>
  12. <div :class="[thermometerClassName,totalClassName]" style="transform: scale(0.80);margin-left: 28%;margin-top: -14%;">
  13. </div>
  14. </div>
  15. <div class="realFeelWindDirectionSpeed">
  16. <div class="realFeel">
  17. <div class="realFeelIcon"></div>&nbsp;体感温度:{{weatherProphetData_17Hour[0].realfeel}}℃
  18. </div>
  19. <div class="windDirection">
  20. <div class="windDirectionIcon"></div>&nbsp;风向:{{weatherProphetData_17Hour[0].winddirection}}风
  21. </div>
  22. <div class="speed">
  23. <div class="speedIcon"></div>&nbsp;风速:{{weatherProphetData_17Hour[0].speed}}km/h
  24. </div>
  25. </div>
  26. <div class="weatherDayTemperatureSunrise" v-show="weatherSwitch==true">
  27. <div class="dayTemperature">
  28. <div class="dayTemperatureIcon"></div>&nbsp;温度:{{weatherProphetData_1[0].temperature1}}℃
  29. </div>
  30. <div class="daySunrise">
  31. <div class="daySunriseIcon"></div>&nbsp;日出:{{weatherProphetData_1[0].sunrise}}
  32. </div>
  33. <div class="weatherDayAndNightButton">
  34. <div :class="[weatherSwitch==true?'dayButtonWhite':'dayButtonBlack']" @click="weatherDaySwitch()">白天</div>
  35. <div :class="[weatherSwitch==false?'nightButtonWhite':'nightButtonBlack']" @click="weatherNightSwitch()">夜间</div>
  36. </div>
  37. </div>
  38. <div class="weatherNightTemperatureSunrise" v-show="weatherSwitch==false">
  39. <div class="nightTemperature">
  40. <div class="nightTemperatureIcon"></div>&nbsp;温度:{{weatherProphetData_1[0].temperature2}}℃
  41. </div>
  42. <div class="nightSunrise">
  43. <div class="nightSunriseIcon"></div>&nbsp;日落:{{weatherProphetData_1[0].sunset}}
  44. </div>
  45. <div class="weatherDayAndNightButton">
  46. <div :class="[weatherSwitch==true?'dayButtonWhite':'dayButtonBlack']" @click="weatherDaySwitch()">白天</div>
  47. <div :class="[weatherSwitch==false?'nightButtonWhite':'nightButtonBlack']" @click="weatherNightSwitch()">夜间</div>
  48. </div>
  49. </div>
  50. <!-- </div> -->
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. Date.prototype.Format = function(fmt) {
  56. var o = {
  57. "M+": this.getMonth() + 1, //月份
  58. "d+": this.getDate(), //日
  59. "h+": this.getHours(), //小时
  60. "m+": this.getMinutes(), //分
  61. "s+": this.getSeconds(), //秒
  62. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  63. "S": this.getMilliseconds() //毫秒
  64. };
  65. if (/(y+)/.test(fmt))
  66. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  67. for (var k in o)
  68. if (new RegExp("(" + k + ")").test(fmt))
  69. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  70. return fmt;
  71. };
  72. //调用--
  73. // var mytime=new Date(后台传来的毫秒格式的时间);
  74. // var newtime=mytime.Format("需转化的时间格式比如--yyyy-MM-hh");
  75. export default {
  76. data: function() {
  77. return {
  78. nowTime: "",
  79. weatherProphetData_17Hour: [{
  80. realfeel:'',
  81. speed:'',
  82. temperature:'',
  83. winddirection:'',
  84. }],
  85. weatherProphetData_1: [{
  86. speed:'',
  87. temperature1:'',
  88. sunrise:'',
  89. temperature2:'',
  90. sunset:''
  91. }],
  92. thermometerClassName: "",
  93. totalClassName: "thermometer",
  94. width: "",
  95. height: "",
  96. weatherSwitch:true
  97. }
  98. },
  99. created: function() {
  100. let that = this;
  101. setInterval(function() {
  102. that.getNowTime();
  103. }, 1000);
  104. // this.getHourWeatherData("90", "360", this.weatherProphetData_17Hour,this.weatherProphetData_1)
  105. },
  106. methods: {
  107. weatherDaySwitch:function(){
  108. this.weatherSwitch=true;
  109. this.$emit("listenEven","day");
  110. },
  111. weatherNightSwitch:function(){
  112. this.weatherSwitch=false;
  113. this.$emit("listenEven","night");
  114. },
  115. getNowTime: function() {
  116. var nowTime = new Date(new Date().getTime()).Format("hh:mm");
  117. this.nowTime = nowTime;
  118. },
  119. // getDayWeatherData:function(weatherProphetData_1){
  120. // this.weatherProphetData_1 = weatherProphetData_1;
  121. // console.log(this.weatherProphetData_1)
  122. // },
  123. getHourWeatherData: function(width, height, weatherProphetData_17Hour,weatherProphetData_1) {
  124. this.weatherProphetData_1=weatherProphetData_1;
  125. this.weatherProphetData_17Hour = weatherProphetData_17Hour;
  126. this.width = width + "%";
  127. this.height = height + "px";
  128. //判断温度计的度数,list[0].maximumtem%5后 1、2取0 , 3、4取5
  129. if (parseInt(weatherProphetData_17Hour[0].temperature) % 5 == 0) {
  130. this.thermometerClassName = "thermometer_" + parseInt(weatherProphetData_17Hour[0].temperature);
  131. } else if (parseInt(weatherProphetData_17Hour[0].temperature) % 5 == 1 || parseInt(weatherProphetData_17Hour[0].temperature) %
  132. 5 == 2) {
  133. this.thermometerClassName = "thermometer_" + (parseInt(weatherProphetData_17Hour[0].temperature / 5) * 5);
  134. } else if (parseInt(weatherProphetData_17Hour[0].temperature) % 5 == 3 || parseInt(weatherProphetData_17Hour[0].temperature) %
  135. 5 == 4) {
  136. this.thermometerClassName = "thermometer_" + ((parseInt(weatherProphetData_17Hour[0].temperature / 5) + 1) * 5);
  137. } else if (parseInt(weatherProphetData_17Hour[0].temperature) % 5 == -1 || parseInt(weatherProphetData_17Hour[0].temperature) %
  138. 5 == -2) {
  139. this.thermometerClassName = "thermometer_" + (parseInt(weatherProphetData_17Hour[0].temperature / 5) * -5);
  140. } else if (parseInt(weatherProphetData_17Hour[0].temperature) % 5 == -3 || parseInt(weatherProphetData_17Hour[0].temperature) %
  141. 5 == -4) {
  142. this.thermometerClassName = "thermometer_" + ((parseInt(weatherProphetData_17Hour[0].temperature / 5) + 1) * -5);
  143. }
  144. }
  145. }
  146. }
  147. </script>
  148. <style scoped="scoped">
  149. .thermometerContainer {
  150. width: 65%;
  151. height: 100%;
  152. /* background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#024F93), color-stop(1.5, #cccccc), to(#437193));
  153. background: rgba(0, 0, 0, 0.1); */
  154. background-color: #535252;
  155. float: left;
  156. margin: 0px auto;
  157. border-radius: 20px;
  158. margin-top: 1%;
  159. margin-left: 5%;
  160. }
  161. .container {
  162. width: 370px;
  163. height: 370px;
  164. margin: 0px auto;
  165. }
  166. .time {
  167. width: 100px;
  168. height: 30px;
  169. color: white;
  170. font-size: 16px;
  171. margin-left: 7%;
  172. margin-top: 3%;
  173. font-family: "microsoft yahei";
  174. }
  175. .thermometerAndTemperature {
  176. width: 100%;
  177. height: 150px;
  178. }
  179. .temperature {
  180. width: 100px;
  181. height: 100px;
  182. float: left;
  183. margin-top: 4.5%;
  184. margin-left: 5%;
  185. font-size: 68px;
  186. font-family: "microsoft yahei";
  187. text-align: center;
  188. line-height: 140px;
  189. color: white;
  190. }
  191. .temperature span {
  192. font-size: 37px;
  193. font-family: "microsoft yahei";
  194. }
  195. .thermometer {
  196. width: 104px;
  197. height: 186px;
  198. margin-left: 85px;
  199. float: left;
  200. margin-top: -30px;
  201. }
  202. .realFeelWindDirectionSpeed {
  203. width: 100%;
  204. height: 80px;
  205. font-size: 15px;
  206. margin-top: -6%;
  207. margin-left: 15px;
  208. }
  209. .realFeel {
  210. width: 150px;
  211. height: 40px;
  212. float: left;
  213. margin-left: 1.5%;
  214. margin-top: -5%;
  215. line-height: 40px;
  216. font-size: 14px;
  217. font-family: "microsoft yahei";
  218. color: white;
  219. }
  220. .realFeelIcon {
  221. width: 20px;
  222. height: 20px;
  223. margin-top: 10px;
  224. float: left;
  225. background: url(../../../../static/picture/thermometerCard/pic_tu_01.png) no-repeat;
  226. }
  227. .windDirection {
  228. width: 150px;
  229. height: 40px;
  230. float: right;
  231. margin-right: 6%;
  232. margin-top: 4.5%;
  233. line-height: 40px;
  234. font-size: 14px;
  235. font-family: "microsoft yahei";
  236. color: white;
  237. }
  238. .windDirectionIcon {
  239. width: 20px;
  240. height: 20px;
  241. margin-top: 10px;
  242. margin-left: 10%;
  243. float: left;
  244. background: url(../../../../static/picture/thermometerCard/pic_tu_02.png) no-repeat;
  245. }
  246. .weatherDayTemperatureSunrise {
  247. width: 100%;
  248. height: 30px;
  249. font-size: 15px;
  250. margin-top: -5%;
  251. float: left;
  252. }
  253. .weatherDayAndNightButton{
  254. width: 35%;
  255. height: 20px;
  256. font-size: 14px;
  257. float: left;
  258. margin-left: 1%;
  259. }
  260. .dayButtonWhite{
  261. margin-left: 25%;
  262. text-align: center;
  263. line-height: 20px;
  264. width: 29%;
  265. height: 20px;
  266. color: white;
  267. font-size: 14px;
  268. border-style: solid;
  269. border-top-width: 0px;
  270. border-right-width: 0px;
  271. border-bottom-width: 3px;
  272. border-bottom-color: #FFEE35;
  273. border-left-width: 0px;
  274. font-family: "microsoft yahei";
  275. float: left;
  276. }
  277. .dayButtonBlack{
  278. margin-left: 25%;
  279. line-height: 20px;
  280. text-align: center;
  281. width: 29%;
  282. height: 20px;
  283. color: #DEDEDE;
  284. font-size: 14px;
  285. font-family: "microsoft yahei";
  286. float: left;
  287. }
  288. .nightButtonWhite{
  289. margin-left: 5%;
  290. text-align: center;
  291. line-height: 20px;
  292. width: 29%;
  293. height: 20px;
  294. color: white;
  295. font-size: 14px;
  296. border-style: solid;
  297. border-top-width: 0px;
  298. border-right-width: 0px;
  299. border-bottom-width: 3px;
  300. border-bottom-color: #FFEE35;
  301. border-left-width: 0px;
  302. font-family: "microsoft yahei";
  303. float: left;
  304. }
  305. .nightButtonBlack{
  306. margin-left: 5%;
  307. line-height: 20px;
  308. text-align: center;
  309. width: 29%;
  310. height: 20px;
  311. color: #DEDEDE;
  312. font-size: 14px;
  313. font-family: "microsoft yahei";
  314. float: left;
  315. }
  316. .dayTemperature {
  317. width: 26%;
  318. height: 40px;
  319. float: left;
  320. margin-left: 5.5%;
  321. margin-top: -10px;
  322. line-height: 40px;
  323. font-size: 14px;
  324. font-family: "microsoft yahei";
  325. color: white;
  326. }
  327. .daySunrise {
  328. width: 26%;
  329. height: 40px;
  330. float: left;
  331. margin-top: -10px;
  332. /* margin-left: -60px; */
  333. line-height: 40px;
  334. font-size: 14px;
  335. font-family: "microsoft yahei";
  336. color: white;
  337. }
  338. .weatherNightTemperatureSunrise {
  339. width: 100%;
  340. height: 30px;
  341. font-size: 15px;
  342. margin-top: -5%;
  343. float: left;
  344. }
  345. .nightTemperature {
  346. width: 26%;
  347. height: 40px;
  348. float: left;
  349. margin-left: 5.5%;
  350. margin-top: -10px;
  351. line-height: 40px;
  352. font-size: 14px;
  353. font-family: "microsoft yahei";
  354. color: white;
  355. }
  356. .nightSunrise {
  357. width: 26%;
  358. height: 40px;
  359. float: left;
  360. margin-top: -10px;
  361. /* margin-left: -60px; */
  362. line-height: 40px;
  363. font-size: 14px;
  364. font-family: "microsoft yahei";
  365. color: white;
  366. }
  367. .speed {
  368. width: 150px;
  369. height: 40px;
  370. float: left;
  371. margin-top: -2%;
  372. margin-left: 1.5%;
  373. line-height: 40px;
  374. font-size: 14px;
  375. font-family: "microsoft yahei";
  376. color: white;
  377. }
  378. .speedIcon {
  379. width: 20px;
  380. height: 20px;
  381. margin-top: 10px;
  382. float: left;
  383. background: url(../../../../static/picture/thermometerCard/pic_tu_03.png) no-repeat;
  384. }
  385. /*0℃*/
  386. .thermometer_0 {
  387. background: url(../../../../static/picture/thermometerCard/thermometer/0C.png) no-repeat 0px 0px;
  388. }
  389. /*5℃*/
  390. .thermometer_5 {
  391. background: url(../../../../static/picture/thermometerCard/thermometer/5C.png) no-repeat 0px 0px;
  392. }
  393. /*-5℃*/
  394. .thermometer_-5 {
  395. background: url(../../../../static/picture/thermometerCard/thermometer/-5C.png) no-repeat 0px 0px;
  396. }
  397. /*10℃*/
  398. .thermometer_10 {
  399. background: url(../../../../static/picture/thermometerCard/thermometer/10C.png) no-repeat 0px 0px;
  400. }
  401. /*-10℃*/
  402. .thermometer_-10 {
  403. background: url(../../../../static/picture/thermometerCard/thermometer/-10C.png) no-repeat 0px 0px;
  404. }
  405. /*15℃*/
  406. .thermometer_15 {
  407. background: url(../../../../static/picture/thermometerCard/thermometer/15C.png) no-repeat 0px 0px;
  408. }
  409. /*-15℃*/
  410. .thermometer_-15 {
  411. background: url(../../../../static/picture/thermometerCard/thermometer/-15C.png) no-repeat 0px 0px;
  412. }
  413. /*20℃*/
  414. .thermometer_20 {
  415. background: url(../../../../static/picture/thermometerCard/thermometer/20C.png) no-repeat 0px 0px;
  416. }
  417. /*-20℃*/
  418. .thermometer_-20 {
  419. background: url(../../../../static/picture/thermometerCard/thermometer/-20C.png) no-repeat 0px 0px;
  420. }
  421. /* 25℃*/
  422. .thermometer_25 {
  423. background: url(../../../../static/picture/thermometerCard/thermometer/25C.png) no-repeat 0px 0px;
  424. }
  425. /* -25℃*/
  426. .thermometer_-25 {
  427. background: url(../../../../static/picture/thermometerCard/thermometer/-25C.png) no-repeat 0px 0px;
  428. }
  429. /*30℃*/
  430. .thermometer_30 {
  431. background: url(../../../../static/picture/thermometerCard/thermometer/30C.png) no-repeat 0px 0px;
  432. }
  433. /*-30℃*/
  434. .thermometer_-30 {
  435. background: url(../../../../static/picture/thermometerCard/thermometer/-30C.png) no-repeat 0px 0px;
  436. }
  437. /*40℃*/
  438. .thermometer_40 {
  439. background: url(../../../../static/picture/thermometerCard/thermometer/40C.png) no-repeat 0px 0px;
  440. }
  441. /*-40℃*/
  442. .thermometer_-40 {
  443. background: url(../../../../static/picture/thermometerCard/thermometer/-40C.png) no-repeat 0px 0px;
  444. }
  445. /*45℃*/
  446. .thermometer_45 {
  447. background: url(../../../../static/picture/thermometerCard/thermometer/45C.png) no-repeat 0px 0px;
  448. }
  449. /*-45℃*/
  450. .thermometer_-45 {
  451. background: url(../../../../static/picture/thermometerCard/thermometer/-45C.png) no-repeat 0px 0px;
  452. }
  453. /*50℃*/
  454. .thermometer_50 {
  455. background: url(../../../../static/picture/thermometerCard/thermometer/50C.png) no-repeat 0px 0px;
  456. }
  457. /*-50℃*/
  458. .thermometer_-50 {
  459. background: url(../../../../static/picture/thermometerCard/thermometer/-50C.png) no-repeat 0px 0px;
  460. }
  461. </style>