home.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 ref="notice" />
  23. <!-- 工作台 -->
  24. <workbench />
  25. <!-- 数据看板 -->
  26. <spectaculars ref="spectaculars" />
  27. <!-- 巡检计划 -->
  28. <patrolScheme ref="patrolScheme" />
  29. <workorder ref="workroder" v-if="showWorkrder" :isHome="true" />
  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 "./workorderList"
  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. workorder
  50. },
  51. data() {
  52. return {
  53. uninitialized: false,
  54. usePort: this.usePort,
  55. sitename: "",
  56. place: {},
  57. headHeight: 0,
  58. weather: "",
  59. showWorkrder: false
  60. };
  61. },
  62. created() {
  63. this.getPlace();
  64. let userMsg = uni.getStorageSync("userMsg");
  65. this.sitename = `${userMsg.sitename} - ${userMsg.name}`
  66. try {
  67. this.showWorkrder = uni.getStorageSync('authList')['工单']['工单'].name == "workorder";
  68. } catch (error) {
  69. this.showWorkrder = false
  70. }
  71. },
  72. mounted() {
  73. this.getWeather();
  74. },
  75. methods: {
  76. renderData() {
  77. this.$refs.notice.getList(true);
  78. this.$refs.spectaculars.getDetail();
  79. this.$refs.patrolScheme.getDetail();
  80. if (this.showWorkrder) this.$refs.workroder.getlist(true);
  81. },
  82. getWeather() {
  83. this.$Http.basic({
  84. id: "20231012093701",
  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. },
  97. setLocation() {
  98. let that = this;
  99. uni.getSetting({
  100. success({ authSetting }) {
  101. if (authSetting['scope.userLocation']) {
  102. that.getLocation().then(s => {
  103. that.__proto__.location = s;
  104. that.getPlace();
  105. })
  106. } else {
  107. uni.showModal({
  108. title: '提示',
  109. content: '您未开启地理位置授权',
  110. cancelText: '下次再说',
  111. confirmText: '前去授权',
  112. success: ({ confirm }) => {
  113. if (confirm) uni.openSetting({
  114. success(res) {
  115. if (res.authSetting['scope.userLocation']) that.setLocation();
  116. }
  117. });
  118. }
  119. })
  120. }
  121. }
  122. })
  123. },
  124. async getPlace() {
  125. let res = this.location || await this.getLocation(),
  126. that = this;
  127. this.__proto__.location = res;
  128. qqmapsdk = new QQMapWX({
  129. key: 'UVVBZ-UOGWZ-ZUWXC-TJQMT-TUWLO-IVFTN'
  130. });
  131. qqmapsdk.reverseGeocoder({
  132. location: {
  133. latitude: res.latitude,
  134. longitude: res.longitude
  135. },
  136. success(res) {
  137. console.log("逆解析结果", res.result)
  138. that.place = res.result;
  139. },
  140. fail: res => console.error(res)
  141. });
  142. },
  143. setCustomBar(num) {
  144. const Dustom = this.$refs.Dustom;
  145. Dustom.CustomBar = Dustom.CustomBar + num;
  146. this.headHeight = Dustom.getHeight()
  147. }
  148. }
  149. }
  150. </script>
  151. <style lang="scss" scoped>
  152. .head {
  153. position: fixed;
  154. width: 100vw;
  155. top: 0;
  156. left: 0;
  157. z-index: 10000;
  158. .content {
  159. position: absolute;
  160. width: 100vw;
  161. padding: 0 10px;
  162. box-sizing: border-box;
  163. left: 0;
  164. bottom: 0;
  165. .sitename {
  166. line-height: 22px;
  167. font-size: 16px;
  168. font-family: PingFang SC-Medium, PingFang SC;
  169. font-weight: bold;
  170. color: #FFFFFF;
  171. }
  172. .location {
  173. line-height: 17px;
  174. font-size: 12px;
  175. font-family: PingFang SC-Regular, PingFang SC;
  176. color: rgba(255, 255, 255, 0.8);
  177. margin-top: 10px;
  178. .iconfont {
  179. margin-right: 5px;
  180. font-size: 12px;
  181. }
  182. }
  183. .weather-forecast {
  184. width: 100%;
  185. display: flex;
  186. align-items: center;
  187. height: 18px;
  188. margin-top: 22px;
  189. margin-bottom: 12px;
  190. .tag {
  191. width: 48px;
  192. height: 18px;
  193. line-height: 18px;
  194. text-align: center;
  195. background: #F29C37;
  196. border-radius: 2px;
  197. font-size: 10px;
  198. font-family: PingFang SC-Medium, PingFang SC;
  199. font-weight: bold;
  200. color: #FFFFFF;
  201. margin-right: 6px;
  202. }
  203. .text {
  204. height: 17px;
  205. font-size: 12px;
  206. font-family: PingFang SC-Regular, PingFang SC;
  207. color: rgba(255, 255, 255, 0.8);
  208. }
  209. }
  210. }
  211. }
  212. </style>