top-bar.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div class="container toBottom center">
  3. <!-- 名称 -->
  4. <div class="center" style="width: 18%;height: 100%">
  5. <div class="name center" style="flex-direction: column">
  6. {{title}}
  7. <span style="font-size: 17px;letter-spacing: 2px;font-weight: normal;font-style: italic;color: #dddddd">Xinyang Rongji soft Garden</span>
  8. </div>
  9. </div>
  10. <!-- 时间日期 -->
  11. <div style="width: 10%;height: 100%" class="center">
  12. <div class="time-date">
  13. <div class="full center" style="height: 30%;font-style: italic">{{dateTime.date}} {{weekStr[dateTime.week]}}</div>
  14. <div class="full center" style="height: 70%;font-size: 35px">{{dateTime.time}}</div>
  15. </div>
  16. </div>
  17. <div class="center" style="width:60%;height: 100%;justify-content: right">
  18. <el-page-header v-if="showBack" @back="$router.go(-1)" content="楼栋详情">
  19. </el-page-header>
  20. </div>
  21. <!-- 天气 -->
  22. <div class="center" style="width:7%;height: 100%;">
  23. <div class="weather">
  24. <div class="full center" style="height: 75%;font-size: 35px;font-weight: 100">{{weather.dayWeather}}</div>
  25. <div class="full center" style="height: 25%;font-style: italic;color: #dddddd">{{weather.nightTemp+'℃ ~' + weather.dayTemp+'℃'}}</div>
  26. </div>
  27. </div>
  28. <!-- 开关 -->
  29. <div @click="logout" style="width:5%;height: 100%" class="switch-bg">
  30. <div class="switch full"></div>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import {dateFormat} from "../../../util/date";
  36. import {fullscreenToggel} from "../../../util/util";
  37. import {resetRouter} from "../../../router/router";
  38. export default {
  39. name: "top-bar",
  40. async mounted() {
  41. this.currentTime();
  42. await this.getWeather();
  43. },
  44. props: {
  45. title: {type: 'String'},
  46. showBack: {type: 'Boolean',default: false}
  47. },
  48. data(){
  49. return{
  50. dateTime: {},
  51. weekStr: ['星期天','星期一','星期二','星期三','星期四','星期五','星期六',],
  52. temperature: '',
  53. weather: '',
  54. weatherClass: 'duoyun',
  55. }
  56. },
  57. watch: {
  58. weather(){
  59. this.weatherClass = this.getWeatherClass(this.weather);
  60. },
  61. },
  62. methods: {
  63. back(){
  64. this.$router.go(-1);
  65. },
  66. logout() {
  67. this.$confirm('退出系统, 是否继续?', {
  68. confirmButtonText: '确定',
  69. cancelButtonText: '取消',
  70. }).then(() => {
  71. this.$store.dispatch("LogOut").then(() => {
  72. resetRouter();
  73. this.$router.push({path: "/login"});
  74. });
  75. });
  76. },
  77. currentTime() {
  78. setInterval(this.getTime, 500);
  79. },
  80. getTime() {
  81. let date = new Date();
  82. let str = dateFormat(date);
  83. let week = date.getDay();
  84. str = str.split(" ");
  85. this.dateTime = {
  86. week: week,
  87. date: str[0],
  88. time: str[1]
  89. }
  90. },
  91. getWeatherClass(weather) {
  92. let duoyun = ['少云', '晴间多云', '多云', '阴'];
  93. let wu = ['雾', '浓雾', '强浓雾', '轻雾', '大雾', '特强浓雾'];
  94. let mai = ['霾', '中度霾', '重度霾', '严重霾'];
  95. let feng = ['有风', '平静', '微风', '和风', '清风', '强风/劲风', , '疾风', '大风', '烈风', '风暴', '狂爆风', '飓风', '热带风暴'];
  96. let yu = ['阵雨', '雷阵雨', '雷阵雨并伴有冰雹', '小雨', '中雨', '大雨', '暴雨', '大暴雨', '特大暴雨', '强阵雨', '强雷阵雨', '极端降雨', '毛毛雨/细雨', '雨', '小雨-中雨', '中雨-大雨', '大雨-暴雨', '暴雨-大暴雨', '大暴雨-特大暴雨', '雨雪天气', '雨夹雪', '阵雨夹雪', '冻雨'];
  97. let sun = ['晴'];
  98. let xue = ['雪', '阵雪', '小雪', '中雪', '大雪', '暴雪', '小雪-中雪', '中雪-大雪', '大雪-暴雪'];
  99. if (duoyun.indexOf(weather) >= 0) return 'duoyun';
  100. if (wu.indexOf(weather) >= 0) return 'wu';
  101. if (yu.indexOf(weather) >= 0) return 'yu';
  102. if (sun.indexOf(weather) >= 0) return 'sun';
  103. if (xue.indexOf(weather) >= 0) return 'xue';
  104. if (mai.indexOf(weather) >= 0) return 'mai';
  105. if (feng.indexOf(weather) >= 0) return 'feng';
  106. return 'duoyun';
  107. },
  108. async getWeather() {
  109. console.log(this.$map)
  110. let weather = new this.$AMap.Weather();
  111. //执行实时天气信息查询
  112. weather.getForecast('信阳市', (err, data) => {
  113. this.weather = data.forecasts[0];
  114. });
  115. },
  116. }
  117. }
  118. </script>
  119. <style scoped>
  120. .container{
  121. width: 100%;
  122. height: 7%;
  123. position: absolute;
  124. top: 0;
  125. overflow: hidden;
  126. background: rgba(0,0,0,0.7);
  127. }
  128. .name{
  129. width: 100%;
  130. height: 70%;
  131. letter-spacing: 10px;
  132. font-size: 30px;
  133. font-weight: 900;
  134. border-right: 1px solid;
  135. border-right-color: rgba(255,255,255,0.8);
  136. color: white;
  137. user-select: none;
  138. text-shadow: 0 0 18px rgba(0, 0, 0, 0.35);
  139. }
  140. .time-date{
  141. width: 100%;
  142. height: 70%;
  143. color: white;
  144. font-size: 20px;
  145. user-select: none;
  146. text-shadow: 0 0 18px rgba(0, 0, 0, 0.35);
  147. }
  148. .weather{
  149. width: 100%;
  150. height: 70%;
  151. color: white;
  152. font-size: 20px;
  153. user-select: none;
  154. text-shadow: 0 0 30px rgba(255, 255, 255, 0.6), 0 0 60px rgba(255, 255, 255, 0.45), 0 0 110px rgba(255, 255, 255, 0.25), 0 0 100px rgba(255, 255, 255, 0.1);
  155. }
  156. .switch{
  157. background: url("/data/switch.png") no-repeat center/30%;
  158. }
  159. .switch-bg:active,.switch-bg:hover{
  160. cursor: pointer;
  161. background: rgba(0,0,0,0.5);
  162. box-shadow: 0 0 20px 0px rgba(0, 0, 0, 0.35);
  163. text-shadow: 0 0 30px rgba(255, 255, 255, 0.6), 0 0 60px rgba(255, 255, 255, 0.45), 0 0 110px rgba(255, 255, 255, 0.25), 0 0 100px rgba(255, 255, 255, 0.1);
  164. }
  165. .switch-bg:active{
  166. transform: translate(-1px,1px);
  167. }
  168. @keyframes shake-horizontal {
  169. 0%,
  170. 100% {
  171. -webkit-transform: translateX(0);
  172. transform: translateX(0);
  173. }
  174. 10%,
  175. 30%,
  176. 50%,
  177. 70% {
  178. -webkit-transform: translateX(-10px);
  179. transform: translateX(-10px);
  180. }
  181. 20%,
  182. 40%,
  183. 60% {
  184. -webkit-transform: translateX(10px);
  185. transform: translateX(10px);
  186. }
  187. 80% {
  188. -webkit-transform: translateX(8px);
  189. transform: translateX(8px);
  190. }
  191. 90% {
  192. -webkit-transform: translateX(-8px);
  193. transform: translateX(-8px);
  194. }
  195. }
  196. /deep/ .el-page-header__title {
  197. color: white;
  198. font-size: 24px;
  199. font-weight: 500;
  200. }
  201. /deep/ .el-page-header__content {
  202. font-size: 18px;
  203. color: #acacac;
  204. }
  205. /deep/ .el-page-header__left .el-icon-back {
  206. font-size: 18px;
  207. color: white;
  208. margin-right: 6px;
  209. -ms-flex-item-align: center;
  210. align-self: center;
  211. }
  212. </style>