diff --git a/pages/login/login.vue b/pages/login/login.vue index abe5a53..3610d0f 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -25,18 +25,18 @@ return { phonecode: undefined, logincode: undefined, - code: undefined, timer: undefined, - cityCode: '1', - openid: '', + cityCode: null, // scenenurseStationId: undefined, }; }, onShow() { - this.getAddress(); + let location = uni.getStorageSync('location') + if (!location) { + this.getAddress() + } this.phonecode = undefined this.logincode = undefined - this.code = undefined // this.scenenurseStationId = uni.getStorageSync('scenenurseStationId'); }, methods: { @@ -85,14 +85,10 @@ }); } }, - login() { let that = this; - // getWeChatUser(that.logincode).then(res => { - // if (res.code == 200) { isRegistered(that.logincode, that.phonecode).then(resp => { uni.setStorageSync("openid", resp.data.openid) - that.openid = resp.data.openid if (resp.data.code == '0') { that.$refs.uToast.show({ title: '未注册,请先注册', @@ -101,9 +97,7 @@ url: '/pages/register/register', }) } else if (resp.data.code == '1') { - that.cityCode = '1' - console.log(that.openid) - getCurrentUser(that.openid, that.cityCode).then(res => { + getCurrentUser(resp.data.openid, resp.data.cityCode).then(res => { if (res.code == 200) { that.$refs.uToast.show({ title: '登录成功', @@ -112,10 +106,10 @@ }) uni.setStorageSync('patientId', res.data.id); uni.setStorageSync('userinfo', res.data); - if (this.timer) { - clearTimeout(this.timer) + if (that.timer) { + clearTimeout(that.timer) } - this.timer = setTimeout(e => { + that.timer = setTimeout(e => { uni.navigateBack({ delta: 1 }) @@ -130,12 +124,10 @@ }) } }) - }, pwdlogin() { var that = this uni.clearStorageSync(); - that.login() // createMobileToken().then(res => { // uni.setStorageSync("token", res.data.token) diff --git a/pages/startup/startup.vue b/pages/startup/startup.vue index fba95d7..222826a 100644 --- a/pages/startup/startup.vue +++ b/pages/startup/startup.vue @@ -42,6 +42,7 @@ }, onShow() { var that = this + this.getAddress(); createMobileToken().then(res => { uni.setStorageSync("token", res.data.token) }) @@ -51,7 +52,40 @@ }); }, 2000); }, - methods: {}, + methods: { + //获取当前位置 + getAddress() { + let that = this; + uni.getLocation({ + type: 'wgs84', + success: (res) => { + let location = res.latitude + ',' + res.longitude + //调用逆解析接口 + uni.request({ + url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=location', //腾讯官方逆解析接口,可直接复制 + data: { + location: location, + 'key': "Q4DBZ-UIMC2-B63UX-CUZ6A-S3UT7-TBF3V", //自己申请的Key + }, + method: "GET", + success(res) { + uni.setStorageSync('location', res.data.result.address_component.city) + }, + fail: res => { + console.log(res.errMsg, '解析失败返回的错误信息'); + } + }) + }, + //失败 + fail: (res) => { + uni.showToast({ + icon: 'none', + title: '获取地址失败,请打开定位', + }) + } + }) + }, + }, }