home.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view>
  3. <cu-custom ref="Dustom"
  4. bgImage="https://yostest175549.obs.cn-east-2.myhuaweicloud.com:443/202306151686796745663B52544232.png">
  5. <view slot="head" class="head" :style="{ height: headHeight }">
  6. <view class="content">
  7. <view class="sitename u-line-1" :style="{ 'width': usePort == 'wechat' ? '65vw' : '96vw' }">
  8. {{ sitename }}
  9. </view>
  10. <view class="location u-line-1">
  11. <text class="iconfont icon-didian" />{{ place.address || '所在位置' }}
  12. </view>
  13. <view class="weather-forecast">
  14. <view class="tag">天气预报</view>
  15. <view class="text">{{ weather }}</view>
  16. </view>
  17. </view>
  18. </view>
  19. </cu-custom>
  20. <!-- 滚动通知 -->
  21. <notice />
  22. <!-- 工作台 -->
  23. <workbench />
  24. <!-- 数据看板 -->
  25. <spectaculars />
  26. <!-- 巡检计划 -->
  27. <patrolScheme />
  28. <view style="height: calc(16.533vw + env(safe-area-inset-bottom) / 2);" />
  29. </view>
  30. </template>
  31. <script>
  32. import workbench from "./workbench.vue";
  33. import notice from "./notice.vue";
  34. import spectaculars from "./spectaculars.vue";
  35. import patrolScheme from "./patrolScheme.vue";
  36. import { getWeek, getYMD } from "../../../utils/getTime";
  37. import {
  38. getCity
  39. } from "../../../utils/tool";
  40. const QQMapWX = require("../../../utils/qqmap-wx-jssdk.min.js");
  41. var qqmapsdk;
  42. export default {
  43. name: 'Home',
  44. components: {
  45. workbench,
  46. notice,
  47. spectaculars,
  48. patrolScheme
  49. },
  50. data() {
  51. return {
  52. uninitialized: false,
  53. usePort: this.usePort,
  54. sitename: "",
  55. place: {},
  56. headHeight: 0,
  57. weather: ""
  58. };
  59. },
  60. created() {
  61. this.getPlace();
  62. let userMsg = uni.getStorageSync("userMsg");
  63. this.sitename = `${userMsg.sitename} - ${userMsg.name}`
  64. },
  65. mounted() {
  66. this.getWeather();
  67. },
  68. methods: {
  69. getWeather() {
  70. const content = uni.getStorageSync('city');
  71. if (content) {
  72. this.$Http.basic({
  73. "id": "20230608120801",
  74. content
  75. }).then(res => {
  76. console.log("获取天气信息", res)
  77. if (this.cutoff(res.msg)) {
  78. this.setCustomBar(0);
  79. } else {
  80. this.setCustomBar(66);
  81. let detail = res.data.predict.detail[0];
  82. this.weather = `${getWeek()} ${getYMD().split("年")[1]} | ${detail.night.weather.temperature}~${detail.day.weather.temperature}℃ ${res.data.real.weather.info}`
  83. }
  84. })
  85. } else {
  86. getCity.bind(this)().then(res => {
  87. res && uni.setStorageSync("city", res)
  88. this.getWeather()
  89. })
  90. }
  91. },
  92. async getPlace() {
  93. let res = this.location || await this.getLocation(),
  94. that = this;
  95. this.__proto__.location = res;
  96. qqmapsdk = new QQMapWX({
  97. key: 'UVVBZ-UOGWZ-ZUWXC-TJQMT-TUWLO-IVFTN'
  98. });
  99. qqmapsdk.reverseGeocoder({
  100. location: {
  101. latitude: res.latitude,
  102. longitude: res.longitude
  103. },
  104. success(res) {
  105. console.log("逆解析结果", res.result)
  106. that.place = res.result;
  107. },
  108. fail: res => console.error(res)
  109. });
  110. },
  111. setCustomBar(num) {
  112. const Dustom = this.$refs.Dustom;
  113. Dustom.CustomBar = Dustom.CustomBar + num;
  114. this.headHeight = Dustom.getHeight()
  115. }
  116. },
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. .head {
  121. position: fixed;
  122. width: 100vw;
  123. top: 0;
  124. left: 0;
  125. z-index: 10000;
  126. .content {
  127. position: absolute;
  128. width: 100vw;
  129. padding: 0 10px;
  130. box-sizing: border-box;
  131. left: 0;
  132. bottom: 0;
  133. .sitename {
  134. line-height: 22px;
  135. font-size: 16px;
  136. font-family: PingFang SC-Medium, PingFang SC;
  137. font-weight: bold;
  138. color: #FFFFFF;
  139. }
  140. .location {
  141. line-height: 17px;
  142. font-size: 12px;
  143. font-family: PingFang SC-Regular, PingFang SC;
  144. color: rgba(255, 255, 255, 0.8);
  145. margin-top: 10px;
  146. .iconfont {
  147. margin-right: 5px;
  148. font-size: 12px;
  149. }
  150. }
  151. .weather-forecast {
  152. width: 100%;
  153. display: flex;
  154. align-items: center;
  155. height: 18px;
  156. margin-top: 22px;
  157. margin-bottom: 12px;
  158. .tag {
  159. width: 48px;
  160. height: 18px;
  161. line-height: 18px;
  162. text-align: center;
  163. background: #F29C37;
  164. border-radius: 2px;
  165. font-size: 10px;
  166. font-family: PingFang SC-Medium, PingFang SC;
  167. font-weight: bold;
  168. color: #FFFFFF;
  169. margin-right: 6px;
  170. }
  171. .text {
  172. height: 17px;
  173. font-size: 12px;
  174. font-family: PingFang SC-Regular, PingFang SC;
  175. color: rgba(255, 255, 255, 0.8);
  176. }
  177. }
  178. }
  179. }
  180. </style>