ThermometerCard.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <template>
  2. <div>
  3. <div class="thermometerContainer" :style="{'width':width,'height':height,'margin-left':marginLeft}">
  4. <!-- <div class="container" :style="{'width':width,'height':height}"> -->
  5. <div class="time" :style="{'font-size':fontSize,'margin-left':marginleftTime}">
  6. {{nowTime}} 实况
  7. </div>
  8. <div class="thermometerAndTemperature">
  9. <div class="temperature" :style="{'margin-left':marginleftTemper,'margin-top':marginbottom}">
  10. {{weatherProphetData_17Hour[0].temperature}}<span>℃</span>
  11. </div>
  12. <div :class="[thermometerClassName,totalClassName]" :style="{'margin-left':marginleftPicture}">
  13. </div>
  14. </div>
  15. <div class="realFeelWindDirectionSpeed" :style="{'margin-left':marginleftThree}">
  16. <div class="realFeel" :style="{'margin-left':marginleftThree,'font-size':fontSize}">
  17. <div class="realFeelIcon"></div>&nbsp;体感温度:{{weatherProphetData_17Hour[0].realfeel}}℃
  18. </div>
  19. <div class="windDirection" :style="{'margin-left':marginleftThree,'font-size':fontSize}">
  20. <div class="windDirectionIcon"></div>&nbsp;风向:{{weatherProphetData_17Hour[0].winddirection}}
  21. </div>
  22. <div class="speed" :style="{'margin-left':marginleftSpeed,'font-size':fontSize}">
  23. <div class="speedIcon"></div>&nbsp;风速:{{weatherProphetData_17Hour[0].speed}}km/h
  24. </div>
  25. </div>
  26. <div class="weatherDayTemperatureSunrise" :style="{'font-size':fontSize}" v-show="weatherSwitch==true">
  27. <div class="dayTemperature" :style="{'font-size':fontSize,'width':widths,'margin-left':marginleftTemperature}">
  28. <div class="dayTemperatureIcon"></div>&nbsp;温度:{{weatherProphetData_1[0].temperature1}}℃
  29. </div>
  30. <div class="daySunrise" :style="{'font-size':fontSize,'width':widths,'margin-left':marginleftSunrise}">
  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" :style="{'font-size':fontSize}" v-show="weatherSwitch==false">
  39. <div class="nightTemperature" :style="{'font-size':fontSize,'width':widths,'margin-left':marginleftTemperature}">
  40. <div class="nightTemperatureIcon"></div>&nbsp;温度:{{weatherProphetData_1[0].temperature2}}℃
  41. </div>
  42. <div class="nightSunrise" :style="{'font-size':fontSize,'width':widths,'margin-left':marginleftSunrise}">
  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. windowWidth:"",
  98. windowHeight:"",
  99. marginLeft:'',
  100. marginleft:'',
  101. marginLEft:'',
  102. fontSize:"",
  103. marginLEFT:'',
  104. widths:'',
  105. marginleftThree:'',
  106. marginleftPicture:'',
  107. marginbottom:'',
  108. marginleftTemper:'',
  109. marginleftTemperature:'',
  110. choiceMarginRight:'',
  111. marginleftTime:'',
  112. marginleftSunrise:'',
  113. marginleftSpeed:'',
  114. }
  115. },
  116. created: function() {
  117. this.windowWidth=uni.getSystemInfoSync().windowWidth;
  118. this.windowHeight=uni.getSystemInfoSync().windowHeight;
  119. let that = this;
  120. setInterval(function() {
  121. that.getNowTime();
  122. }, 1000);
  123. if(this.windowWidth>=768){
  124. this.marginLeft="5%";
  125. this.marginleftThree="5%"
  126. this.marginleft="30%";
  127. this.marginLEft="10%";
  128. this.fontSize="16px";
  129. this.marginLEFT="20%";
  130. this.widths=100+"px";
  131. this.marginbottom="-1%";
  132. this.marginleftPicture="35%";
  133. this.marginleftTemper="20%";
  134. this.marginleftTemperature="60px";
  135. this.marginleftTime="50px";
  136. this.marginleftSunrise="106px";
  137. this.marginleftSpeed="80px";
  138. }else{
  139. this.marginLeft="5%";
  140. this.marginLEft="0";
  141. this.marginleft="0";
  142. this.marginLEFT="0";
  143. this.fontSize="14px";
  144. this.marginbottom="0";
  145. this.widths=80+"px";
  146. this.marginleftTime="0";
  147. this.marginleftTime="30px";
  148. }
  149. // this.getHourWeatherData("90", "360", this.weatherProphetData_17Hour,this.weatherProphetData_1)
  150. },
  151. methods: {
  152. weatherDaySwitch:function(){
  153. this.weatherSwitch=true;
  154. this.$emit("listenEven","day");
  155. },
  156. weatherNightSwitch:function(){
  157. this.weatherSwitch=false;
  158. this.$emit("listenEven","night");
  159. },
  160. getNowTime: function() {
  161. var nowTime = new Date(new Date().getTime()).Format("hh:mm");
  162. this.nowTime = nowTime;
  163. },
  164. // getDayWeatherData:function(weatherProphetData_1){
  165. // this.weatherProphetData_1 = weatherProphetData_1;
  166. // console.log(this.weatherProphetData_1)
  167. // },
  168. getHourWeatherData: function(width, height, weatherProphetData_17Hour,weatherProphetData_1) {
  169. console.log(width);
  170. this.weatherProphetData_1=weatherProphetData_1;
  171. this.weatherProphetData_17Hour = weatherProphetData_17Hour;
  172. this.width = width + "%";
  173. this.height = height + "px";
  174. //判断温度计的度数,list[0].maximumtem%5后 1、2取0 , 3、4取5
  175. if (parseInt(weatherProphetData_17Hour[0].temperature) % 5 == 0) {
  176. this.thermometerClassName = "thermometer_" + parseInt(weatherProphetData_17Hour[0].temperature);
  177. } else if (parseInt(weatherProphetData_17Hour[0].temperature) % 5 == 1 || parseInt(weatherProphetData_17Hour[0].temperature) %
  178. 5 == 2) {
  179. this.thermometerClassName = "thermometer_" + (parseInt(weatherProphetData_17Hour[0].temperature / 5) * 5);
  180. } else if (parseInt(weatherProphetData_17Hour[0].temperature) % 5 == 3 || parseInt(weatherProphetData_17Hour[0].temperature) %
  181. 5 == 4) {
  182. this.thermometerClassName = "thermometer_" + ((parseInt(weatherProphetData_17Hour[0].temperature / 5) + 1) * 5);
  183. } else if (parseInt(weatherProphetData_17Hour[0].temperature) % 5 == -1 || parseInt(weatherProphetData_17Hour[0].temperature) %
  184. 5 == -2) {
  185. this.thermometerClassName = "thermometer_" + (parseInt(weatherProphetData_17Hour[0].temperature / 5) * -5);
  186. } else if (parseInt(weatherProphetData_17Hour[0].temperature) % 5 == -3 || parseInt(weatherProphetData_17Hour[0].temperature) %
  187. 5 == -4) {
  188. this.thermometerClassName = "thermometer_" + ((parseInt(weatherProphetData_17Hour[0].temperature / 5) + 1) * -5);
  189. }
  190. }
  191. }
  192. }
  193. </script>
  194. <style scoped="scoped">
  195. .thermometerContainer {
  196. width: 65%;
  197. height: 100%;
  198. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#024F93), color-stop(1.5, #cccccc), to(#437193));
  199. background: rgba(0, 0, 0, 0.1);
  200. float: left;
  201. margin: 0px auto;
  202. border-radius: 20px;
  203. margin: 20px;
  204. }
  205. .container {
  206. width: 370px;
  207. height: 370px;
  208. margin: 0px auto;
  209. }
  210. .time {
  211. width: 100px;
  212. height: 30px;
  213. color: white;
  214. font-size: 16px;
  215. margin-left: 30px;
  216. margin-top: 30px;
  217. font-family: "microsoft yahei";
  218. }
  219. .thermometerAndTemperature {
  220. width: 100%;
  221. height: 200px;
  222. }
  223. .temperature {
  224. width: 100px;
  225. height: 100px;
  226. float: left;
  227. margin-top: 40px;
  228. margin-left: 20px;
  229. font-size: 68px;
  230. font-family: "microsoft yahei";
  231. text-align: center;
  232. line-height: 140px;
  233. color: white;
  234. }
  235. .temperature span {
  236. font-size: 37px;
  237. font-family: "microsoft yahei";
  238. }
  239. .thermometer {
  240. width: 104px;
  241. height: 186px;
  242. margin-left: 85px;
  243. float: left;
  244. margin-top: -30px;
  245. }
  246. .realFeelWindDirectionSpeed {
  247. width: 100%;
  248. height: 80px;
  249. font-size: 15px;
  250. margin-top: -30px;
  251. margin-left: 15px;
  252. }
  253. .realFeel {
  254. width: 150px;
  255. height: 40px;
  256. float: left;
  257. margin-left: 20px;
  258. line-height: 40px;
  259. font-size: 14px;
  260. font-family: "microsoft yahei";
  261. color: white;
  262. }
  263. .realFeelIcon {
  264. width: 20px;
  265. height: 20px;
  266. margin-top: 10px;
  267. float: left;
  268. background: url(../../static/picture/thermometerCard/pic_tu_01.png) no-repeat;
  269. }
  270. .windDirection {
  271. width: 150px;
  272. height: 40px;
  273. float: left;
  274. line-height: 40px;
  275. margin-left: 3px;
  276. font-size: 14px;
  277. font-family: "microsoft yahei";
  278. color: white;
  279. }
  280. .windDirectionIcon {
  281. width: 20px;
  282. height: 20px;
  283. margin-top: 10px;
  284. margin-left: 15px;
  285. float: left;
  286. background: url(../../static/picture/thermometerCard/pic_tu_02.png) no-repeat;
  287. }
  288. .weatherDayTemperatureSunrise {
  289. width: 90%;
  290. height: 30px;
  291. font-size: 15px;
  292. margin-top: 10px;
  293. margin-left: 14px;
  294. float: left;
  295. }
  296. .weatherDayAndNightButton{
  297. width: 100px;
  298. height: 20px;
  299. font-size: 15px;
  300. text-align: right;
  301. /* margin-top: 10px; */
  302. /* margin-left: 14px; */
  303. float: right;
  304. }
  305. .dayButtonWhite{
  306. margin-left: 15px;
  307. text-align: center;
  308. line-height: 20px;
  309. width: 28%;
  310. height: 20px;
  311. color: white;
  312. font-size: 14px;
  313. border-style: solid;
  314. border-top-width: 0px;
  315. border-right-width: 0px;
  316. border-bottom-width: 3px;
  317. border-bottom-color: #FFEE35;
  318. border-left-width: 0px;
  319. font-family: "microsoft yahei";
  320. float: left;
  321. }
  322. .dayButtonBlack{
  323. margin-left: 15px;
  324. line-height: 20px;
  325. text-align: center;
  326. width: 28%;
  327. height: 20px;
  328. color: #DEDEDE;
  329. font-size: 14px;
  330. font-family: "microsoft yahei";
  331. float: left;
  332. }
  333. .nightButtonWhite{
  334. margin-left: 15px;
  335. text-align: center;
  336. line-height: 20px;
  337. width: 28%;
  338. height: 20px;
  339. color: white;
  340. font-size: 14px;
  341. border-style: solid;
  342. border-top-width: 0px;
  343. border-right-width: 0px;
  344. border-bottom-width: 3px;
  345. border-bottom-color: #FFEE35;
  346. border-left-width: 0px;
  347. font-family: "microsoft yahei";
  348. float: left;
  349. }
  350. .nightButtonBlack{
  351. margin-left: 15px;
  352. line-height: 20px;
  353. text-align: center;
  354. width: 28%;
  355. height: 20px;
  356. color: #DEDEDE;
  357. font-size: 14px;
  358. font-family: "microsoft yahei";
  359. float: left;
  360. }
  361. .dayTemperature {
  362. width: 85px;
  363. height: 40px;
  364. float: left;
  365. margin-left: 20px;
  366. margin-top: -10px;
  367. line-height: 40px;
  368. font-size: 14px;
  369. font-family: "microsoft yahei";
  370. color: white;
  371. }
  372. .daySunrise {
  373. width: 85px;
  374. height: 40px;
  375. float: left;
  376. margin-top: -10px;
  377. /* margin-left: -60px; */
  378. line-height: 40px;
  379. font-size: 14px;
  380. font-family: "microsoft yahei";
  381. color: white;
  382. }
  383. .weatherNightTemperatureSunrise {
  384. width: 90%;
  385. height: 30px;
  386. font-size: 15px;
  387. margin-top: 10px;
  388. margin-left: 14px;
  389. float: left;
  390. }
  391. .nightTemperature {
  392. width: 85px;
  393. height: 40px;
  394. float: left;
  395. margin-left: 20px;
  396. margin-top: -10px;
  397. line-height: 40px;
  398. font-size: 14px;
  399. font-family: "microsoft yahei";
  400. color: white;
  401. }
  402. .nightSunrise {
  403. width: 85px;
  404. height: 40px;
  405. float: left;
  406. margin-top: -10px;
  407. /* margin-left: -60px; */
  408. line-height: 40px;
  409. font-size: 14px;
  410. font-family: "microsoft yahei";
  411. color: white;
  412. }
  413. .speed {
  414. width: 150px;
  415. height: 40px;
  416. float: left;
  417. margin-left: 20px;
  418. line-height: 40px;
  419. font-size: 14px;
  420. font-family: "microsoft yahei";
  421. color: white;
  422. }
  423. .speedIcon {
  424. width: 20px;
  425. height: 20px;
  426. margin-top: 10px;
  427. float: left;
  428. background: url(../../static/picture/thermometerCard/pic_tu_03.png) no-repeat;
  429. }
  430. /*0℃*/
  431. .thermometer_0 {
  432. background: url(../../static/picture/thermometerCard/thermometer/0C.png) no-repeat 0px 0px;
  433. }
  434. /*5℃*/
  435. .thermometer_5 {
  436. background: url(../../static/picture/thermometerCard/thermometer/5C.png) no-repeat 0px 0px;
  437. }
  438. /*-5℃*/
  439. .thermometer_-5 {
  440. background: url(../../static/picture/thermometerCard/thermometer/-5C.png) no-repeat 0px 0px;
  441. }
  442. /*10℃*/
  443. .thermometer_10 {
  444. background: url(../../static/picture/thermometerCard/thermometer/10C.png) no-repeat 0px 0px;
  445. }
  446. /*-10℃*/
  447. .thermometer_-10 {
  448. background: url(../../static/picture/thermometerCard/thermometer/-10C.png) no-repeat 0px 0px;
  449. }
  450. /*15℃*/
  451. .thermometer_15 {
  452. background: url(../../static/picture/thermometerCard/thermometer/15C.png) no-repeat 0px 0px;
  453. }
  454. /*-15℃*/
  455. .thermometer_-15 {
  456. background: url(../../static/picture/thermometerCard/thermometer/-15C.png) no-repeat 0px 0px;
  457. }
  458. /*20℃*/
  459. .thermometer_20 {
  460. background: url(../../static/picture/thermometerCard/thermometer/20C.png) no-repeat 0px 0px;
  461. }
  462. /*-20℃*/
  463. .thermometer_-20 {
  464. background: url(../../static/picture/thermometerCard/thermometer/-20C.png) no-repeat 0px 0px;
  465. }
  466. /*30℃*/
  467. .thermometer_30 {
  468. background: url(../../static/picture/thermometerCard/thermometer/30C.png) no-repeat 0px 0px;
  469. }
  470. /*-30℃*/
  471. .thermometer_-30 {
  472. background: url(../../static/picture/thermometerCard/thermometer/-30C.png) no-repeat 0px 0px;
  473. }
  474. /*40℃*/
  475. .thermometer_40 {
  476. background: url(../../static/picture/thermometerCard/thermometer/40C.png) no-repeat 0px 0px;
  477. }
  478. /*-40℃*/
  479. .thermometer_-40 {
  480. background: url(../../static/picture/thermometerCard/thermometer/-40C.png) no-repeat 0px 0px;
  481. }
  482. /*45℃*/
  483. .thermometer_45 {
  484. background: url(../../static/picture/thermometerCard/thermometer/45C.png) no-repeat 0px 0px;
  485. }
  486. /*-45℃*/
  487. .thermometer_-45 {
  488. background: url(../../static/picture/thermometerCard/thermometer/-45C.png) no-repeat 0px 0px;
  489. }
  490. /*50℃*/
  491. .thermometer_50 {
  492. background: url(../../static/picture/thermometerCard/thermometer/50C.png) no-repeat 0px 0px;
  493. }
  494. /*-50℃*/
  495. .thermometer_-50 {
  496. background: url(../../static/picture/thermometerCard/thermometer/-50C.png) no-repeat 0px 0px;
  497. }
  498. </style>