持续完善用户信息...

Signed-off-by: YangWork <yang@xixingwl.cn>
This commit is contained in:
YangWork
2023-02-10 18:07:25 +08:00
parent 450c6d021e
commit 9904175cc3
4 changed files with 60 additions and 39 deletions

View File

@@ -24,7 +24,13 @@ instance.interceptors.request.use(
// 添加响应拦截器
instance.interceptors.response.use(
response => {
if (response.statusCode == 200) {
return response.data
}
// 对响应数据做些什么
console.log(response)
return response.data
},
error => {

View File

@@ -54,22 +54,23 @@
<script>
import {
mapGetters
mapGetters,
mapMutations
} from 'vuex'
export default {
name: "ywxAuthModel",
computed: {
...mapGetters({
// 把 `this.doneCount` 映射为 `this.$store.getters.doneTodosCount`
sessionKey: 'getSessionKey'
sessionKey: 'getSessionKey',
openId: 'getOpenId'
})
},
data() {
return {
// 表单数据
formData: {
account: 'LiMing',
password: 'dcloud@email.com'
account: 'xiaoxiao',
password: '20mylove'
},
formDataReg: {
nickname: '',
@@ -99,9 +100,9 @@
}]
}
},
openid: "",
loginstate: "0",
openid: "",
userEntity: null,
terminal: "",
osVersion: "",
@@ -112,6 +113,7 @@
},
onLoad: function() {},
methods: {
...mapMutations(["updateUserInfo", "saveUserInfoToStorge"]),
onChooseAvatar(e) {
console.log(e)
const {
@@ -122,15 +124,19 @@
},
submitLogin(loginform) {
let self = this;
// #ifdef MP-WEIXIN
this.formData.openId = this.openId
// #endif
this.$refs.loginform.validate().then(res => {
console.log('表单数据信息:', res);
self.$ajax.post("User/login", self.formData)
.then(e => {
if(e.code == 0)
if (e.code == 0) {
self.updateUserInfo(e.data.userinfo);
uni.reLaunch({
url: "/pages/tabbar/home/home"
})
}
});
}).catch(err => {
console.log('表单错误信息:', err);

View File

@@ -5,9 +5,9 @@
<view class="user" style="">
<image class="user-avatar" mode="aspectFit" src="../../../static/logo.png"></image>
<view class="user-info">
<h2> 用户昵称 </h2>
<text> UID 1234567897 </text>
<text> 用户昵称</text>
<h2> {{userInfo.nickname}} </h2>
<text> UID {{userInfo.uid}}</text>
<text> {{userInfo.account}}</text>
</view>
</view>
<view style="padding: 10rpx;"></view>
@@ -89,13 +89,15 @@
timestamp: state => state.moduleB.timestamp
}),
...mapGetters({
isLogin: 'userIsLogin'
isLogin: 'getuserIsLogin',
userInfo: 'getUserInfo'
})
},
data() {
return {}
},
onLoad(){
console.log(this.isLogin);
if (! this.isLogin) {
uni.redirectTo({
url:"/pages/login/login"

View File

@@ -21,11 +21,17 @@ export default {
var trDay = day < 10 ? '0' + day : day
return year + '-' + trMon + '-' + trDay + " " + hours + ":" + minu + ":" + sec;
},
userIsLogin(state){
getuserIsLogin(state){
return state.isLogin;
},
getSessionKey(state){
return state.sessionKey;
},
getOpenId(state){
return state.openId;
},
getUserInfo(state){
return state.userinfo;
}
},
mutations: {
@@ -35,6 +41,7 @@ export default {
// 更新用户信息
updateUserInfo(state, userinfo) {
state.userinfo = userinfo
state.isLogin = true;
this.commit('saveUserInfoToStorge')
},
// 将用户信息持久化存储到本地