Browse Source

token验证及ui优化

h5_css
yanyan 2 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. 10
      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
},
"usingComponents" : true,
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},
"requiredPrivateInfos" : [ "getLocation", "onLocationChange", "chooseLocation", "chooseAddress" ]
},
"vueVersion" : "2"

8
pages.json

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

104
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}
}

23
pages/my/my.vue

@ -2,8 +2,8 @@
<view class="wrap">
<view class="stabar"></view>
<view class="mainwrap">
<view class="perinfo"> <span class="type-name"><img :src="avatarUrl"></img></span>
<view class="dycd"> <span class="myname">{{name}}</span>
<view class="perinfo"> <span class="type-name"><img :src="avatar"></img></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>
</view>
@ -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: {

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') || '{}'),
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)

26
subpkg/complete/complete.vue

@ -8,6 +8,7 @@
<view class="marsk" v-if="showLayer"></view>
<view class="popup-layer" v-if="showMedal">
<image class="animg" :src="achieveMedalImg"></image>
<image class="animg" src="/static/images/hua.gif"></image>
</view>
<view class="mainwrap2">
@ -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;

10
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'
})

6
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: {

2
subpkg/review/review.vue

@ -8,7 +8,7 @@
<view class="mainwrap2">
<view class="background-info">
您已完成<font style="color:#fd6d1f;">{{sceneName}}</font>场景中 <font style="color:#fd6d1f;">{{roleName}}
</font>角色挑战的共计{{total}}道题目每道题目和您选择的答案详情如下
</font>角色挑战的共计{{total}}道题目每道题目和您选择的答案详情如下
</view>
<view class="thumbtack">
<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.uploadFilethisvar _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) {
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) => {
uni.request({
method,
method,
url: urlConfig + url,
data,
header: header,
dataType: 'json'
}).then(res => {
if (res[1].data.success) {

Loading…
Cancel
Save