瀏覽代碼

优化获取天气情况接口

xiaohaizhao 1 年之前
父節點
當前提交
a52570f44e
共有 3 個文件被更改,包括 14 次插入45 次删除
  1. 13 25
      pages/index/modules/home.vue
  2. 0 2
      pages/login/login.vue
  3. 1 18
      utils/tool.js

+ 13 - 25
pages/index/modules/home.vue

@@ -40,9 +40,6 @@ import spectaculars from "./spectaculars.vue";
 import patrolScheme from "./patrolScheme.vue";
 import { getWeek, getYMD } from "../../../utils/getTime";
 import workorder from "./workorderList"
-import {
-	getCity
-} from "../../../utils/tool";
 const QQMapWX = require("../../../utils/qqmap-wx-jssdk.min.js");
 var qqmapsdk;
 export default {
@@ -80,28 +77,19 @@ export default {
 	},
 	methods: {
 		getWeather() {
-			const content = uni.getStorageSync('city');
-			content.date = Date.now()
-			if (content) {
-				this.$Http.basic({
-					"id": "20230608120801",
-					content
-				}).then(res => {
-					console.log("获取天气信息", res)
-					if (this.cutoff(res.msg)) {
-						this.setCustomBar(0);
-					} else {
-						this.setCustomBar(66);
-						let detail = res.data.predict.detail[0];
-						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}`
-					}
-				})
-			} else {
-				getCity.bind(this)().then(res => {
-					res && uni.setStorageSync("city", res)
-					this.getWeather()
-				})
-			}
+			this.$Http.basic({
+				id: "20231012093701",
+				content: {}
+			}).then(res => {
+				console.log("获取天气信息", res)
+				if (this.cutoff(res.msg)) {
+					this.setCustomBar(0);
+				} else {
+					this.setCustomBar(66);
+					let detail = res.data.predict.detail[0];
+					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}`
+				}
+			})
 		},
 		setLocation() {
 			let that = this;

+ 0 - 2
pages/login/login.vue

@@ -31,7 +31,6 @@
 import account from "./modules/account.vue";
 import phone from "./modules/phone.vue";
 import otherLogin from "./modules/otherLogin.vue";
-import { getCity } from "../../utils/tool";
 export default {
 	components: {
 		account,
@@ -47,7 +46,6 @@ export default {
 	},
 	onLoad() {
 		this.loginMethod = uni.getStorageSync('loginMethod') || 'account';//登录方式
-		getCity.bind(this)().then(res => res && uni.setStorageSync("city", res))
 		if (uni.getStorageSync("isAgreement")) this.isAgreement = true;
 	},
 	methods: {

+ 1 - 18
utils/tool.js

@@ -177,24 +177,7 @@ function mount() {
     }
 }
 
-function getCity() {
-    return new Promise((resolve, reject) => {
-        // #ifdef H5
-        wx.request({
-            url: 'http://www.nmc.cn/rest/position',
-            method: "GET",
-            timeout: 30000,
-            success: res => resolve(res.data)
-        })
-        // #endif
-        // #ifndef H5
-        this.$Http.getLocationCode().then(res => resolve(res))
-        // #endif
-    })
-}
-
 module.exports = {
     mount,
-    setBar,
-    getCity
+    setBar
 }