From a94dc0b6b88bf64e39e8f833ca033b44112de58b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89?= <814457906@qq.com> Date: Mon, 16 Oct 2023 13:36:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/login/login.vue | 54 ++++----------------------------------- pages/startup/startup.vue | 36 +++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 50 deletions(-) diff --git a/pages/login/login.vue b/pages/login/login.vue index abe5a53..5e22b75 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -25,53 +25,17 @@ return { phonecode: undefined, logincode: undefined, - code: undefined, timer: undefined, - cityCode: '1', - openid: '', + cityCode: null, // scenenurseStationId: undefined, }; }, onShow() { - this.getAddress(); this.phonecode = undefined this.logincode = undefined - this.code = undefined // this.scenenurseStationId = uni.getStorageSync('scenenurseStationId'); }, 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: '获取地址失败,请打开定位', - }) - } - }) - }, getPhoneNumberp(val) { let that = this; if (val.detail.code) { @@ -85,14 +49,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 +61,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 +70,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 +88,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: '获取地址失败,请打开定位', + }) + } + }) + }, + }, }