diff --git a/pages/home/index.vue b/pages/home/index.vue index 560f2af..7ff198b 100644 --- a/pages/home/index.vue +++ b/pages/home/index.vue @@ -18,7 +18,16 @@ - {{ selectedCity }} + + + + + + + + + {{ selectedCity }} + @@ -340,8 +349,10 @@ export default { // 判断是否需要弹出申请加入弹窗(isAgency为false,且每天只弹一次) // that.checkShowApplyModal(); - that.loadSelectedCityFromCache().then(() => { - this.getList(); + that.initSelectedCityByAgencyInfo().then(() => { + that.loadSelectedCityFromCache().then(() => { + this.getList(); + }); }); // 尝试从缓存获取miniApp-info,如果不存在则请求API获取 @@ -407,6 +418,9 @@ export default { isUseNewJob: getApp().globalData.isUseNewJob, appid: getApp().globalData.appId, selectedCity: "全国", + cityLoading: true, + currentInfo: {}, + currentCity: "", themeColor: getApp().globalData.themeColor, envVersion: uni.getStorageSync("ENV_VERSION"), // 小程序环境判断 isMember: uni.getStorageSync("IS_MINIAPP_MEMBER"), // 登陆者是否当前小程序成员的判断 @@ -597,6 +611,77 @@ export default { } }); }, + getLocation() { + let that = this; + return new Promise((resolve, reject) => { + uni.authorize({ + scope: "scope.userLocation", + success() { + uni.getLocation({ + type: "wgs84", + success(res) { + that.currentInfo = { + latitude: res.latitude, + longitude: res.longitude, + timestamp: new Date().getTime(), + }; + resolve(); + }, + fail(err) { + resolve(); + }, + }); + }, + fail(err) { + uni.showToast({ + title: "请开启定位权限以显示距职位距离", + icon: "none", + }); + resolve(); + }, + }); + }); + }, + getCityNameByLatLng() { + let that = this; + return new Promise((resolve, reject) => { + if (!this.currentInfo.latitude || !this.currentInfo.longitude) { + resolve(); + return; + } + this.G.Get("/location/getCityNameByLatLng", { lng: this.currentInfo.longitude, lat: this.currentInfo.latitude }, (res) => { + if (res) { + that.currentCity = res.replace("市", ""); + } + resolve(); + }); + }); + }, + initSelectedCityByAgencyInfo() { + let that = this; + let agencyInfo = uni.getStorageSync("agencyInfo"); + return new Promise((resolve) => { + if (agencyInfo && agencyInfo.fdbHomeCity !== undefined) { + if (agencyInfo.fdbHomeCity == 1) { + that.cityLoading = false; + resolve(); + } else if (agencyInfo.fdbHomeCity == 0) { + that.getLocation().then(() => { + that.getCityNameByLatLng().then(() => { + if (that.currentCity) { + that.selectedCity = that.currentCity; + } + that.cityLoading = false; + resolve(); + }); + }); + } + } else { + that.cityLoading = false; + resolve(); + } + }); + }, checkScroll() { let that = this; uni @@ -1407,4 +1492,34 @@ export default { .defaultShadow { box-shadow: 0px 2px 3px 0px rgba(214, 214, 214, 0.3); } +.loading-dot { + display: flex; + align-items: center; + justify-content: center; + height: 20px; +} + +.dot { + width: 4px; + height: 4px; + border-radius: 50%; + background-color: #999; + margin: 0 2px; + animation: dotPulse 1.4s infinite ease-in-out; +} + +.dot1 { animation-delay: 0s; } +.dot2 { animation-delay: 0.2s; } +.dot3 { animation-delay: 0.4s; } + +@keyframes dotPulse { + 0%, 80%, 100% { + transform: scale(0); + opacity: 0.5; + } + 40% { + transform: scale(1); + opacity: 1; + } +}