diff --git a/manifest.json b/manifest.json index f607c14..547190f 100644 --- a/manifest.json +++ b/manifest.json @@ -66,6 +66,11 @@ "urlCheck" : false }, "usingComponents" : true, + "permission": { + "scope.userLocation": { + "desc": "你的位置信息将用于小程序位置接口的效果展示" + } + }, "requiredPrivateInfos" : [ "getLocation", "onLocationChange", "chooseLocation", "chooseAddress" ] }, "vueVersion" : "2" diff --git a/pages.json b/pages.json index 586d5b2..8e66426 100644 --- a/pages.json +++ b/pages.json @@ -188,6 +188,14 @@ "enablePullDownRefresh" : false, "navigationStyle": "custom" } + }, + { + "path" : "userInfo/userInfo", + "style" : + { + "navigationBarTitleText" : "", + "enablePullDownRefresh" : false + } }] }], "globalStyle": { diff --git a/pages/index/index.vue b/pages/index/index.vue index 526cc6a..e095658 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -59,23 +59,33 @@ //轮播图数据列表 swiperList: [], //场景入口 - sceneList: [] + sceneList: [], + x:0, + y:0 }; }, computed: { ...mapState('m_user', ['token']) }, onLoad() { - this.getSwiperList(); - this.checkLogin() + this.checkLogin(); + if (this.token != "") { + this.getSwiperList(); + this.getLocation(); + } }, onShow() { this.page= "home" + if (this.token != "") { + this.getSwiperList(); + } + }, + onPullDownRefresh() { + this.getSwiperList(); }, methods: { async getSwiperList() { - const { data: res } = await uni.$http.post('/small/customImage/listAll',{page:"home"}) @@ -110,7 +120,93 @@ }) } }, + getLocation () { + let that = this + // 获取用户是否开启 授权获取当前的地理位置、速度的权限。 + uni.getSetting({ + success (res) { + console.log(res) + // 如果没有授权 + if (!res.authSetting['scope.userLocation']) { + // 则拉起授权窗口 + uni.authorize({ + scope: 'scope.userLocation', + success () { + //点击允许后--就一直会进入成功授权的回调 就可以使用获取的方法了 + uni.getLocation({ + type: 'wgs84', + success: function (res) { + that.x = res.longitude + that.y = res.latitude + console.log(res) + console.log('当前位置的经度:' + res.longitude) + console.log('当前位置的纬度:' + res.latitude) + // uni.showToast({ + // title: '当前位置的经纬度:' + res.longitude + ',' + res.latitude, + // icon: 'none' + // }) + }, fail (error) { + console.log('失败', error) + } + }) + }, + fail (error) { + //点击了拒绝授权后--就一直会进入失败回调函数--此时就可以在这里重新拉起授权窗口 + console.log('拒绝授权', error) + + uni.showModal({ + title: '提示', + content: '若点击不授权,将无法使用位置功能', + cancelText: '不授权', + cancelColor: '#999', + confirmText: '授权', + confirmColor: '#f94218', + success (res) { + console.log(res) + if (res.confirm) { + // 选择弹框内授权 + uni.openSetting({ + success (res) { + console.log(res.authSetting) + } + }) + } else if (res.cancel) { + // 选择弹框内 不授权 + console.log('用户点击不授权') + } + } + }) + } + }) + } else { + // 有权限则直接获取 + uni.getLocation({ + type: 'wgs84', + success: function (res) { + that.x = res.longitude + that.y = res.latitude + console.log(res) + console.log('当前位置的经度:' + res.longitude) + console.log('当前位置的纬度:' + res.latitude) + // uni.showToast({ + // title: '当前位置的经纬度:' + res.longitude + ',' + res.latitude, + // icon: 'none' + // }) + }, fail (error) { + uni.showToast({ + title: '请勿频繁调用!', + icon: 'none', + }) + console.log('失败', error) + } + }) + } + } + }) + + } + }, components: {tabbar} } diff --git a/pages/my/my.vue b/pages/my/my.vue index a6537ec..efe1c30 100644 --- a/pages/my/my.vue +++ b/pages/my/my.vue @@ -2,8 +2,8 @@ - - {{name}} + + {{name}} 勋章:{{medalNum}} 挑战历史:{{challengeNum}} @@ -42,7 +42,7 @@ challengeNum:0, page: "", name:"", - avatarUrl: uni.$http.baseUrl + "/profile//2024/01/18/6147d64a3b94d7b3d3cc35aaf8cbfe06.png", + avatar: uni.$http.baseUrl + "/profile//2024/01/18/6147d64a3b94d7b3d3cc35aaf8cbfe06.png", //轮播图数据列表 swiperList: [], //主页功能列表 @@ -50,8 +50,8 @@ }; }, onLoad() { - this.name = this.userinfo.nickName; - this.avatarUrl = this.userinfo.avatarUrl; + this.name = this.userName; + this.avatar = this.avatarUrl; this.getSwiperList() this.getFunctionList() this.getMyMedalList() @@ -60,6 +60,8 @@ }, onShow() { this.page = "my" + this.name = this.userName; + this.avatar = this.avatarUrl; this.getSwiperList() this.getFunctionList() this.getMyMedalList() @@ -67,6 +69,8 @@ this.getStatus() }, onPullDownRefresh() { + this.name = this.userName; + this.avatar = this.avatarUrl; this.getSwiperList() this.getFunctionList() this.getMyMedalList() @@ -74,7 +78,7 @@ this.getStatus() }, computed: { - ...mapState('m_user', ['userinfo','userId']) + ...mapState('m_user', ['userinfo','userId','userName','avatarUrl']) }, methods: { ...mapMutations('m_user', ['updateAddress', 'updateUserInfo', 'updateToken']), @@ -158,7 +162,7 @@ this.active = 1; } uni.navigateTo({ - url:'/subpkg/medal/medal?medalNum='+this.medalNum + url:'/subpkg/medal/medal?medalNum='+this.medalNum+'&avatarUrl='+this.avatar+'&name='+this.name }) }, navClickHandler(item) { @@ -167,6 +171,11 @@ url: item.pagePath }) } + }, + checkMyInfo(){ + uni.navigateTo({ + url:'/subpkg/userInfo/userInfo?avatarUrl='+this.avatar+'&name='+this.name + }) } }, components: { diff --git a/static/images/hua.gif b/static/images/hua.gif new file mode 100644 index 0000000..4a30f89 Binary files /dev/null and b/static/images/hua.gif differ diff --git a/store/user.js b/store/user.js index 90f5171..6f98973 100755 --- a/store/user.js +++ b/store/user.js @@ -7,6 +7,8 @@ export default { address: JSON.parse(uni.getStorageSync('address') || '{}'), userId: uni.getStorageSync('userId') || '', token: uni.getStorageSync('token') || '', + userName: uni.getStorageSync('userName') || '', + avatarUrl: uni.getStorageSync('avatarUrl') || '', // 用户的信息对象 userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'), // 重定向的 Object 对象 @@ -47,6 +49,20 @@ export default { saveUserIdToStorage(state) { uni.setStorageSync('userId', state.userId) }, + saveUserNameToStorage(state) { + uni.setStorageSync('userName', state.userName) + }, + updateUserName(state, userName) { + state.userName = userName + this.commit('m_user/saveUserNameToStorage') + }, + saveAvatarUrlToStorage(state) { + uni.setStorageSync('avatarUrl', state.avatarUrl) + }, + updateAvatarUrl(state, avatarUrl) { + state.avatarUrl = avatarUrl + this.commit('m_user/saveAvatarUrlToStorage') + }, updateRedirectInfo(state, info) { state.redirectInfo = info console.log(state.redirectInfo) diff --git a/subpkg/complete/complete.vue b/subpkg/complete/complete.vue index ea122d7..b71249c 100644 --- a/subpkg/complete/complete.vue +++ b/subpkg/complete/complete.vue @@ -8,6 +8,7 @@ + @@ -125,7 +126,8 @@ canvas: null, //canvas 对象 tempFilePath: "", "imageQR": '', - picStyle:"z-index:-99999" + picStyle:"z-index:-99999", + timer:null }; }, //分享到好友 @@ -152,7 +154,7 @@ this.showMedal = false this.showLayer = false clearTimeout(this.timer) - }, 2000) + }, 5000) this.roleId = options.roleId != null ? options.roleId : this.roleId this.questionFreId = options.questionFreId != null ? options.questionFreId : this.questionFreId this.sceneId = options.sceneId != null ? options.sceneId : this.sceneId; @@ -222,7 +224,8 @@ guid: this.userId }) if (!res.success) return uni.$showMsg() - this.achieveMedalImg = res.data + //this.achieveMedalImg = uni.$http.baseUrl + res.data + this.achieveMedalImg = 'http://146.56.223.227:9527' + res.data if (res.data == null || res.data == "") { this.showMedal = false this.showLayer = false @@ -379,15 +382,30 @@ -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); width: 600rpx; - height: 400rpx; + height: 600rpx; padding: 30rpx; z-index: 9999; + text-align: center; } .popup-layer .animg { width: 100%; height: 100%; } + + .popup-layer .animg:first-child { + width: 400rpx; + height: 400rpx; + } + + .popup-layer .animg:last-child { + position: absolute; + z-index: -1; + top: 45%; + left: 50%; + -webkit-transform: translate(-50%, -50%); + transform: translate(-50%, -50%); + } .popup-share { height: 500rpx; diff --git a/subpkg/login/login.vue b/subpkg/login/login.vue index b08129f..26376db 100644 --- a/subpkg/login/login.vue +++ b/subpkg/login/login.vue @@ -19,9 +19,8 @@ ...mapState('m_user', ['redirectInfo']) }, methods:{ - ...mapMutations('m_user', ['updateUserInfo', 'updateToken', 'updateUserId', 'updateRedirectInfo']), + ...mapMutations('m_user', ['updateUserInfo', 'updateToken', 'updateUserName','updateUserId','updateAvatarUrl', 'updateRedirectInfo']), getUserInfo(e) { - console.log(e) if (e.detail.errMsg === 'getUserInfo:fail auth deny') return uni.$showMsg('您取消了登录授权!') @@ -52,10 +51,15 @@ const { data: loginResult } = await uni.$http.post('/small/wechat/login', query) if (loginResult.token === "") return uni.$showMsg('登录失败!') - + // 直接把 token 保存到 vuex 中 this.updateToken(loginResult.token) + this.updateUserName(loginResult.userName) this.updateUserId(loginResult.userId) + if (loginResult.avatarUrl !=null && loginResult.avatarUrl.indexOf('http') == -1) { + loginResult.avatarUrl = uni.$http.baseUrl + loginResult.avatarUrl + } + this.updateAvatarUrl(loginResult.avatarUrl) uni.switchTab({ url: '/pages/index/index' }) diff --git a/subpkg/medal/medal.vue b/subpkg/medal/medal.vue index 1d7478c..0325bf1 100644 --- a/subpkg/medal/medal.vue +++ b/subpkg/medal/medal.vue @@ -107,13 +107,13 @@ }; }, computed: { - ...mapState('m_user', ['userinfo','userId']) + ...mapState('m_user', ['userId']) }, onLoad(options) { this.medalNum = options.medalNum this.prefix = uni.$http.baseUrl - this.name = this.userinfo.nickName; - this.avatarUrl = this.userinfo.avatarUrl; + this.name = options.name; + this.avatarUrl = options.avatarUrl; this.getMedalList(); }, methods: { diff --git a/subpkg/review/review.vue b/subpkg/review/review.vue index cab80ba..314a7b2 100644 --- a/subpkg/review/review.vue +++ b/subpkg/review/review.vue @@ -8,7 +8,7 @@ 您已完成“{{sceneName}}”场景中 “{{roleName}} - ”〞角色挑战的共计{{total}}道题目,,每道题目和您选择的答案详情如下: + ”角色挑战的共计{{total}}道题目,每道题目和您选择的答案详情如下: