Browse Source

token验证及ui优化

h5_css
yanyan 3 years ago
parent
commit
633bfcdef3
  1. 5
      manifest.json
  2. 8
      pages.json
  3. 104
      pages/index/index.vue
  4. 23
      pages/my/my.vue
  5. BIN
      static/images/hua.gif
  6. 16
      store/user.js
  7. 26
      subpkg/complete/complete.vue
  8. 8
      subpkg/login/login.vue
  9. 6
      subpkg/medal/medal.vue
  10. 2
      subpkg/review/review.vue
  11. 118
      subpkg/userInfo/userInfo.vue
  12. 7
      utils/http.js

5
manifest.json

@ -66,6 +66,11 @@
"urlCheck" : false "urlCheck" : false
}, },
"usingComponents" : true, "usingComponents" : true,
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},
"requiredPrivateInfos" : [ "getLocation", "onLocationChange", "chooseLocation", "chooseAddress" ] "requiredPrivateInfos" : [ "getLocation", "onLocationChange", "chooseLocation", "chooseAddress" ]
}, },
"vueVersion" : "2" "vueVersion" : "2"

8
pages.json

@ -188,6 +188,14 @@
"enablePullDownRefresh" : false, "enablePullDownRefresh" : false,
"navigationStyle": "custom" "navigationStyle": "custom"
} }
},
{
"path" : "userInfo/userInfo",
"style" :
{
"navigationBarTitleText" : "",
"enablePullDownRefresh" : false
}
}] }]
}], }],
"globalStyle": { "globalStyle": {

104
pages/index/index.vue

@ -59,23 +59,33 @@
//轮播图数据列表 //轮播图数据列表
swiperList: [], swiperList: [],
//场景入口 //场景入口
sceneList: [] sceneList: [],
x:0,
y:0
}; };
}, },
computed: { computed: {
...mapState('m_user', ['token']) ...mapState('m_user', ['token'])
}, },
onLoad() { onLoad() {
this.getSwiperList(); this.checkLogin();
this.checkLogin() if (this.token != "") {
this.getSwiperList();
this.getLocation();
}
}, },
onShow() { onShow() {
this.page= "home" this.page= "home"
if (this.token != "") {
this.getSwiperList();
}
},
onPullDownRefresh() {
this.getSwiperList();
}, },
methods: { methods: {
async getSwiperList() { async getSwiperList() {
const { const {
data: res data: res
} = await uni.$http.post('/small/customImage/listAll',{page:"home"}) } = await uni.$http.post('/small/customImage/listAll',{page:"home"})
@ -110,6 +120,92 @@
}) })
} }
}, },
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} components: {tabbar}

23
pages/my/my.vue

@ -2,8 +2,8 @@
<view class="wrap"> <view class="wrap">
<view class="stabar"></view> <view class="stabar"></view>
<view class="mainwrap"> <view class="mainwrap">
<view class="perinfo"> <span class="type-name"><img :src="avatarUrl"></img></span> <view class="perinfo"> <span class="type-name"><img :src="avatar"></img></span>
<view class="dycd"> <span class="myname">{{name}}</span> <view class="dycd"> <span class="myname" @click="checkMyInfo()">{{name}}</span>
<view class="myitem"> <span @click="showMedal()">勋章:{{medalNum}}<i :style="{'background-color':active == 0 ?'red':'none'}"></i></span> <span>挑战历史:{{challengeNum}}</span> </view> <view class="myitem"> <span @click="showMedal()">勋章:{{medalNum}}<i :style="{'background-color':active == 0 ?'red':'none'}"></i></span> <span>挑战历史:{{challengeNum}}</span> </view>
</view> </view>
</view> </view>
@ -42,7 +42,7 @@
challengeNum:0, challengeNum:0,
page: "", page: "",
name:"", name:"",
avatarUrl: uni.$http.baseUrl + "/profile//2024/01/18/6147d64a3b94d7b3d3cc35aaf8cbfe06.png", avatar: uni.$http.baseUrl + "/profile//2024/01/18/6147d64a3b94d7b3d3cc35aaf8cbfe06.png",
//轮播图数据列表 //轮播图数据列表
swiperList: [], swiperList: [],
//主页功能列表 //主页功能列表
@ -50,8 +50,8 @@
}; };
}, },
onLoad() { onLoad() {
this.name = this.userinfo.nickName; this.name = this.userName;
this.avatarUrl = this.userinfo.avatarUrl; this.avatar = this.avatarUrl;
this.getSwiperList() this.getSwiperList()
this.getFunctionList() this.getFunctionList()
this.getMyMedalList() this.getMyMedalList()
@ -60,6 +60,8 @@
}, },
onShow() { onShow() {
this.page = "my" this.page = "my"
this.name = this.userName;
this.avatar = this.avatarUrl;
this.getSwiperList() this.getSwiperList()
this.getFunctionList() this.getFunctionList()
this.getMyMedalList() this.getMyMedalList()
@ -67,6 +69,8 @@
this.getStatus() this.getStatus()
}, },
onPullDownRefresh() { onPullDownRefresh() {
this.name = this.userName;
this.avatar = this.avatarUrl;
this.getSwiperList() this.getSwiperList()
this.getFunctionList() this.getFunctionList()
this.getMyMedalList() this.getMyMedalList()
@ -74,7 +78,7 @@
this.getStatus() this.getStatus()
}, },
computed: { computed: {
...mapState('m_user', ['userinfo','userId']) ...mapState('m_user', ['userinfo','userId','userName','avatarUrl'])
}, },
methods: { methods: {
...mapMutations('m_user', ['updateAddress', 'updateUserInfo', 'updateToken']), ...mapMutations('m_user', ['updateAddress', 'updateUserInfo', 'updateToken']),
@ -158,7 +162,7 @@
this.active = 1; this.active = 1;
} }
uni.navigateTo({ uni.navigateTo({
url:'/subpkg/medal/medal?medalNum='+this.medalNum url:'/subpkg/medal/medal?medalNum='+this.medalNum+'&avatarUrl='+this.avatar+'&name='+this.name
}) })
}, },
navClickHandler(item) { navClickHandler(item) {
@ -167,6 +171,11 @@
url: item.pagePath url: item.pagePath
}) })
} }
},
checkMyInfo(){
uni.navigateTo({
url:'/subpkg/userInfo/userInfo?avatarUrl='+this.avatar+'&name='+this.name
})
} }
}, },
components: { components: {

BIN
static/images/hua.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

16
store/user.js

@ -7,6 +7,8 @@ export default {
address: JSON.parse(uni.getStorageSync('address') || '{}'), address: JSON.parse(uni.getStorageSync('address') || '{}'),
userId: uni.getStorageSync('userId') || '', userId: uni.getStorageSync('userId') || '',
token: uni.getStorageSync('token') || '', token: uni.getStorageSync('token') || '',
userName: uni.getStorageSync('userName') || '',
avatarUrl: uni.getStorageSync('avatarUrl') || '',
// 用户的信息对象 // 用户的信息对象
userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'), userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
// 重定向的 Object 对象 // 重定向的 Object 对象
@ -47,6 +49,20 @@ export default {
saveUserIdToStorage(state) { saveUserIdToStorage(state) {
uni.setStorageSync('userId', state.userId) 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) { updateRedirectInfo(state, info) {
state.redirectInfo = info state.redirectInfo = info
console.log(state.redirectInfo) console.log(state.redirectInfo)

26
subpkg/complete/complete.vue

@ -8,6 +8,7 @@
<view class="marsk" v-if="showLayer"></view> <view class="marsk" v-if="showLayer"></view>
<view class="popup-layer" v-if="showMedal"> <view class="popup-layer" v-if="showMedal">
<image class="animg" :src="achieveMedalImg"></image> <image class="animg" :src="achieveMedalImg"></image>
<image class="animg" src="/static/images/hua.gif"></image>
</view> </view>
<view class="mainwrap2"> <view class="mainwrap2">
@ -125,7 +126,8 @@
canvas: null, //canvas 对象 canvas: null, //canvas 对象
tempFilePath: "", tempFilePath: "",
"imageQR": '', "imageQR": '',
picStyle:"z-index:-99999" picStyle:"z-index:-99999",
timer:null
}; };
}, },
//分享到好友 //分享到好友
@ -152,7 +154,7 @@
this.showMedal = false this.showMedal = false
this.showLayer = false this.showLayer = false
clearTimeout(this.timer) clearTimeout(this.timer)
}, 2000) }, 5000)
this.roleId = options.roleId != null ? options.roleId : this.roleId this.roleId = options.roleId != null ? options.roleId : this.roleId
this.questionFreId = options.questionFreId != null ? options.questionFreId : this.questionFreId this.questionFreId = options.questionFreId != null ? options.questionFreId : this.questionFreId
this.sceneId = options.sceneId != null ? options.sceneId : this.sceneId; this.sceneId = options.sceneId != null ? options.sceneId : this.sceneId;
@ -222,7 +224,8 @@
guid: this.userId guid: this.userId
}) })
if (!res.success) return uni.$showMsg() 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 == "") { if (res.data == null || res.data == "") {
this.showMedal = false this.showMedal = false
this.showLayer = false this.showLayer = false
@ -379,9 +382,10 @@
-webkit-transform: translate(-50%, -50%); -webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
width: 600rpx; width: 600rpx;
height: 400rpx; height: 600rpx;
padding: 30rpx; padding: 30rpx;
z-index: 9999; z-index: 9999;
text-align: center;
} }
.popup-layer .animg { .popup-layer .animg {
@ -389,6 +393,20 @@
height: 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 { .popup-share {
height: 500rpx; height: 500rpx;
background-color: #e4eafe; background-color: #e4eafe;

8
subpkg/login/login.vue

@ -19,9 +19,8 @@
...mapState('m_user', ['redirectInfo']) ...mapState('m_user', ['redirectInfo'])
}, },
methods:{ methods:{
...mapMutations('m_user', ['updateUserInfo', 'updateToken', 'updateUserId', 'updateRedirectInfo']), ...mapMutations('m_user', ['updateUserInfo', 'updateToken', 'updateUserName','updateUserId','updateAvatarUrl', 'updateRedirectInfo']),
getUserInfo(e) { getUserInfo(e) {
console.log(e)
if (e.detail.errMsg === 'getUserInfo:fail auth deny') return uni.$showMsg('您取消了登录授权!') if (e.detail.errMsg === 'getUserInfo:fail auth deny') return uni.$showMsg('您取消了登录授权!')
@ -55,7 +54,12 @@
// 直接把 token 保存到 vuex 中 // 直接把 token 保存到 vuex 中
this.updateToken(loginResult.token) this.updateToken(loginResult.token)
this.updateUserName(loginResult.userName)
this.updateUserId(loginResult.userId) 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({ uni.switchTab({
url: '/pages/index/index' url: '/pages/index/index'
}) })

6
subpkg/medal/medal.vue

@ -107,13 +107,13 @@
}; };
}, },
computed: { computed: {
...mapState('m_user', ['userinfo','userId']) ...mapState('m_user', ['userId'])
}, },
onLoad(options) { onLoad(options) {
this.medalNum = options.medalNum this.medalNum = options.medalNum
this.prefix = uni.$http.baseUrl this.prefix = uni.$http.baseUrl
this.name = this.userinfo.nickName; this.name = options.name;
this.avatarUrl = this.userinfo.avatarUrl; this.avatarUrl = options.avatarUrl;
this.getMedalList(); this.getMedalList();
}, },
methods: { methods: {

2
subpkg/review/review.vue

@ -8,7 +8,7 @@
<view class="mainwrap2"> <view class="mainwrap2">
<view class="background-info"> <view class="background-info">
您已完成“<font style="color:#fd6d1f;">{{sceneName}}</font>”场景中 “<font style="color:#fd6d1f;">{{roleName}} 您已完成“<font style="color:#fd6d1f;">{{sceneName}}</font>”场景中 “<font style="color:#fd6d1f;">{{roleName}}
</font>”〞角色挑战的共计{{total}}道题目,,每道题目和您选择的答案详情如下: </font>”角色挑战的共计{{total}}道题目,每道题目和您选择的答案详情如下:
</view> </view>
<view class="thumbtack"> <view class="thumbtack">
<label class="left"> <label class="left">

118
subpkg/userInfo/userInfo.vue

@ -0,0 +1,118 @@
<template>
<view>
<view class="item">
<view class="tip">编辑用户昵称</view>
<input type="nickname" @blur="updateUserNameMethod" v-model="name" >
</view>
<view class="line"></view>
<view class="item" @click="chooseImage()">
<view class="tip">点击修改头像</view>
<image :src="avatarUrl"></image>
</view>
</view>
</template>
<script>
import {mapState,mapMutations} from 'vuex'
export default {
data() {
return {
avatarUrl:"",
name:""
};
},
onLoad(options) {
wx.cloud.init({ traceUser: true});
this.avatarUrl = options.avatarUrl
this.name = options.name
},
computed: {
...mapState('m_user', ['userId'])
},
methods:{
...mapMutations('m_user', ['updateUserName','updateAvatarUrl', 'updateRedirectInfo']),
//选择图片
chooseImage() {
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sizeType: ['compressed'], //可以指定是原图还是压缩图,这里用压缩
sourceType: ['album', 'camera'], //从相册选择
success: (res) => {
this.updateUserAvatarUrl(res.tempFiles[0].tempFilePath)
}
})
},
//编辑名称
async updateUserNameMethod(){
const {
data: res
} = await uni.$http.post('/small/wechat/editInfo',{guid:this.userId,nickname:this.name})
if (!res.success) return uni.$showMsg()
this.updateUserName(this.name)
uni.showToast({
icon:'none',
title:'编辑成功'
})
},
async updateUserAvatarUrl(url){
//wx.uploadFile本身有一个this,所以要通过外部var _this = this 把this带进来
var _this = this 
wx.uploadFile({
url: uni.$http.baseUrl + '/small/wechat/editUserAvatar',
filePath: url,
name: 'file',
formData:{
'guid':this.userId
},
success:function(res){
if (res.data!=null) {
const obj = JSON.parse(res.data);
if (obj==null || !obj.success) return uni.$showMsg()
_this.avatarUrl = uni.$http.baseUrl + obj.data;
_this.updateAvatarUrl(uni.$http.baseUrl + obj.data)
uni.showToast({
icon:'none',
title:'编辑成功'
})
}
},
})
},
}
}
</script>
<style lang="scss">
.item {
display: flex;
align-items: center;
justify-content: space-between;
margin: 15rpx;
border-bottom: 1rpx solid gray;
padding-bottom: 20rpx;
}
.tip {
font-size: 44rpx;
margin: 20rpx;
color: red;
}
.item image {
width: 200rpx;
height: 200rpx;
border-radius: 10rpx;
margin: 10rpx 30rpx;
}
.item input {
flex: 1;
border: 1px solid gray;
border-radius: 20rpx;
padding: 5rpx 15rpx;
}
</style>

7
utils/http.js

@ -2,12 +2,17 @@ import urlConfig from '@/utils/config.js'
export default function $http(options) { export default function $http(options) {
const { method, url, data } = options const { method, url, data } = options
const header = {}
let $store = getCurrentPages()[0].$vm.$store
header['User-Type'] = 'applet'
header['Authentication'] = $store.state["m_user"].token
return new Promise((reslove, reject) => { return new Promise((reslove, reject) => {
uni.request({ uni.request({
method, method,
url: urlConfig + url, url: urlConfig + url,
data, data,
header: header,
dataType: 'json' dataType: 'json'
}).then(res => { }).then(res => {
if (res[1].data.success) { if (res[1].data.success) {

Loading…
Cancel
Save