home.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. <navigator url="/pages/login/selectSite" class="sitename u-line-1"
  8. :style="{ 'width': usePort == 'wechat' ? '65vw' : '96vw' }">
  9. {{ sitename }}
  10. </navigator>
  11. <view class="location u-line-1" @click.stop="setLocation">
  12. <text class="iconfont icon-didian" />{{ place.address || '重新获取所在位置' }}
  13. </view>
  14. <view class="weather-forecast">
  15. <view class="tag">天气预报</view>
  16. <view class="text">{{ weather }}</view>
  17. </view>
  18. </view>
  19. </view>
  20. </cu-custom>
  21. <!-- 滚动通知 -->
  22. <notice />
  23. <!-- 工作台 -->
  24. <workbench />
  25. <!-- 数据看板 -->
  26. <spectaculars />
  27. <!-- 巡检计划 -->
  28. <patrolScheme />
  29. <workorder v-if="showWorkrder" />
  30. <view style="height: calc(16.533vw + env(safe-area-inset-bottom) / 2);" />
  31. </view>
  32. </template>
  33. <script>
  34. import workbench from "./workbench.vue";
  35. import notice from "./notice.vue";
  36. import spectaculars from "./spectaculars.vue";
  37. import patrolScheme from "./patrolScheme.vue";
  38. import { getWeek, getYMD } from "../../../utils/getTime";
  39. import workorder from "./workorder"
  40. import {
  41. getCity
  42. } from "../../../utils/tool";
  43. const QQMapWX = require("../../../utils/qqmap-wx-jssdk.min.js");
  44. var qqmapsdk;
  45. export default {
  46. name: 'Home',
  47. components: {
  48. workbench,
  49. notice,
  50. spectaculars,
  51. patrolScheme,
  52. workorder
  53. },
  54. data() {
  55. return {
  56. uninitialized: false,
  57. usePort: this.usePort,
  58. sitename: "",
  59. place: {},
  60. headHeight: 0,
  61. weather: "",
  62. showWorkrder: false
  63. };
  64. },
  65. created() {
  66. this.getPlace();
  67. let userMsg = uni.getStorageSync("userMsg");
  68. this.sitename = `${userMsg.sitename} - ${userMsg.name}`
  69. try {
  70. this.showWorkrder = uni.getStorageSync('authList')['工单']['工单'].name == "workorder"
  71. } catch (error) {
  72. this.showWorkrder = false
  73. }
  74. },
  75. mounted() {
  76. this.getWeather();
  77. },
  78. methods: {
  79. getWeather() {
  80. const content = uni.getStorageSync('city');
  81. content.date = Date.now()
  82. if (content) {
  83. this.$Http.basic({
  84. "id": "20230608120801",
  85. content
  86. }).then(res => {
  87. console.log("获取天气信息", res)
  88. if (this.cutoff(res.msg)) {
  89. this.setCustomBar(0);
  90. } else {
  91. this.setCustomBar(66);
  92. let detail = res.data.predict.detail[0];
  93. this.weather = `${getWeek()} ${getYMD().split("年")[1]} | ${detail.day.weather.temperature == '9999' ? detail.night.weather.temperature : detail.night.weather.temperature + '~' + detail.day.weather.temperature}℃ ${res.data.real.weather.info}`
  94. }
  95. })
  96. } else {
  97. getCity.bind(this)().then(res => {
  98. res && uni.setStorageSync("city", res)
  99. this.getWeather()
  100. })
  101. }
  102. },
  103. setLocation() {
  104. let that = this;
  105. uni.getSetting({
  106. success({ authSetting }) {
  107. if (authSetting['scope.userLocation']) {
  108. that.getLocation().then(s => {
  109. that.__proto__.location = s;
  110. that.getPlace();
  111. })
  112. } else {
  113. uni.showModal({
  114. title: '提示',
  115. content: '您未开启地理位置授权',
  116. cancelText: '下次再说',
  117. confirmText: '前去授权',
  118. success: ({ confirm }) => {
  119. if (confirm) uni.openSetting({
  120. success(res) {
  121. if (res.authSetting['scope.userLocation']) that.setLocation();
  122. }
  123. });
  124. }
  125. })
  126. }
  127. }
  128. })
  129. },
  130. async getPlace() {
  131. let res = this.location || await this.getLocation(),
  132. that = this;
  133. this.__proto__.location = res;
  134. qqmapsdk = new QQMapWX({
  135. key: 'UVVBZ-UOGWZ-ZUWXC-TJQMT-TUWLO-IVFTN'
  136. });
  137. qqmapsdk.reverseGeocoder({
  138. location: {
  139. latitude: res.latitude,
  140. longitude: res.longitude
  141. },
  142. success(res) {
  143. console.log("逆解析结果", res.result)
  144. that.place = res.result;
  145. },
  146. fail: res => console.error(res)
  147. });
  148. },
  149. setCustomBar(num) {
  150. const Dustom = this.$refs.Dustom;
  151. Dustom.CustomBar = Dustom.CustomBar + num;
  152. this.headHeight = Dustom.getHeight()
  153. }
  154. },
  155. }
  156. </script>
  157. <style lang="scss" scoped>
  158. .head {
  159. position: fixed;
  160. width: 100vw;
  161. top: 0;
  162. left: 0;
  163. z-index: 10000;
  164. .content {
  165. position: absolute;
  166. width: 100vw;
  167. padding: 0 10px;
  168. box-sizing: border-box;
  169. left: 0;
  170. bottom: 0;
  171. .sitename {
  172. line-height: 22px;
  173. font-size: 16px;
  174. font-family: PingFang SC-Medium, PingFang SC;
  175. font-weight: bold;
  176. color: #FFFFFF;
  177. }
  178. .location {
  179. line-height: 17px;
  180. font-size: 12px;
  181. font-family: PingFang SC-Regular, PingFang SC;
  182. color: rgba(255, 255, 255, 0.8);
  183. margin-top: 10px;
  184. .iconfont {
  185. margin-right: 5px;
  186. font-size: 12px;
  187. }
  188. }
  189. .weather-forecast {
  190. width: 100%;
  191. display: flex;
  192. align-items: center;
  193. height: 18px;
  194. margin-top: 22px;
  195. margin-bottom: 12px;
  196. .tag {
  197. width: 48px;
  198. height: 18px;
  199. line-height: 18px;
  200. text-align: center;
  201. background: #F29C37;
  202. border-radius: 2px;
  203. font-size: 10px;
  204. font-family: PingFang SC-Medium, PingFang SC;
  205. font-weight: bold;
  206. color: #FFFFFF;
  207. margin-right: 6px;
  208. }
  209. .text {
  210. height: 17px;
  211. font-size: 12px;
  212. font-family: PingFang SC-Regular, PingFang SC;
  213. color: rgba(255, 255, 255, 0.8);
  214. }
  215. }
  216. }
  217. }
  218. </style>