home.vue 6.0 KB

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