@@ -5,32 +5,38 @@ import ajax from '@/uni_modules/u-ajax'
|
|||||||
|
|
||||||
// 创建请求实例
|
// 创建请求实例
|
||||||
const instance = ajax.create({
|
const instance = ajax.create({
|
||||||
// 初始配置
|
// 初始配置
|
||||||
baseURL: 'https://dev.xixingwl.cn/api'
|
baseURL: 'https://dev.xixingwl.cn/api'
|
||||||
})
|
})
|
||||||
|
|
||||||
// 添加请求拦截器
|
// 添加请求拦截器
|
||||||
instance.interceptors.request.use(
|
instance.interceptors.request.use(
|
||||||
config => {
|
config => {
|
||||||
// 在发送请求前做些什么
|
// 在发送请求前做些什么
|
||||||
return config
|
return config
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
// 对请求错误做些什么
|
// 对请求错误做些什么
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// 添加响应拦截器
|
// 添加响应拦截器
|
||||||
instance.interceptors.response.use(
|
instance.interceptors.response.use(
|
||||||
response => {
|
response => {
|
||||||
// 对响应数据做些什么
|
if (response.statusCode == 200) {
|
||||||
return response.data
|
|
||||||
},
|
return response.data
|
||||||
error => {
|
}
|
||||||
// 对响应错误做些什么
|
// 对响应数据做些什么
|
||||||
return Promise.reject(error)
|
console.log(response)
|
||||||
}
|
|
||||||
|
return response.data
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
// 对响应错误做些什么
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// 导出 create 创建后的实例
|
// 导出 create 创建后的实例
|
||||||
|
|||||||
@@ -54,22 +54,23 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {
|
import {
|
||||||
mapGetters
|
mapGetters,
|
||||||
|
mapMutations
|
||||||
} from 'vuex'
|
} from 'vuex'
|
||||||
export default {
|
export default {
|
||||||
name: "ywxAuthModel",
|
name: "ywxAuthModel",
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters({
|
...mapGetters({
|
||||||
// 把 `this.doneCount` 映射为 `this.$store.getters.doneTodosCount`
|
sessionKey: 'getSessionKey',
|
||||||
sessionKey: 'getSessionKey'
|
openId: 'getOpenId'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
// 表单数据
|
// 表单数据
|
||||||
formData: {
|
formData: {
|
||||||
account: 'LiMing',
|
account: 'xiaoxiao',
|
||||||
password: 'dcloud@email.com'
|
password: '20mylove'
|
||||||
},
|
},
|
||||||
formDataReg: {
|
formDataReg: {
|
||||||
nickname: '',
|
nickname: '',
|
||||||
@@ -99,9 +100,9 @@
|
|||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
openid: "",
|
|
||||||
loginstate: "0",
|
loginstate: "0",
|
||||||
openid: "",
|
|
||||||
userEntity: null,
|
userEntity: null,
|
||||||
terminal: "",
|
terminal: "",
|
||||||
osVersion: "",
|
osVersion: "",
|
||||||
@@ -112,6 +113,7 @@
|
|||||||
},
|
},
|
||||||
onLoad: function() {},
|
onLoad: function() {},
|
||||||
methods: {
|
methods: {
|
||||||
|
...mapMutations(["updateUserInfo", "saveUserInfoToStorge"]),
|
||||||
onChooseAvatar(e) {
|
onChooseAvatar(e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
const {
|
const {
|
||||||
@@ -122,16 +124,20 @@
|
|||||||
},
|
},
|
||||||
submitLogin(loginform) {
|
submitLogin(loginform) {
|
||||||
let self = this;
|
let self = this;
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
this.formData.openId = this.openId
|
||||||
|
// #endif
|
||||||
this.$refs.loginform.validate().then(res => {
|
this.$refs.loginform.validate().then(res => {
|
||||||
console.log('表单数据信息:', res);
|
console.log('表单数据信息:', res);
|
||||||
self.$ajax.post("User/login", self.formData)
|
self.$ajax.post("User/login", self.formData)
|
||||||
.then(e => {
|
.then(e => {
|
||||||
if(e.code == 0)
|
if (e.code == 0) {
|
||||||
uni.reLaunch({
|
self.updateUserInfo(e.data.userinfo);
|
||||||
url: "/pages/tabbar/home/home"
|
uni.reLaunch({
|
||||||
})
|
url: "/pages/tabbar/home/home"
|
||||||
|
})
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log('表单错误信息:', err);
|
console.log('表单错误信息:', err);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
<view class="user" style="">
|
<view class="user" style="">
|
||||||
<image class="user-avatar" mode="aspectFit" src="../../../static/logo.png"></image>
|
<image class="user-avatar" mode="aspectFit" src="../../../static/logo.png"></image>
|
||||||
<view class="user-info">
|
<view class="user-info">
|
||||||
<h2> 用户昵称 </h2>
|
<h2> {{userInfo.nickname}} </h2>
|
||||||
<text> UID 1234567897 </text>
|
<text> UID {{userInfo.uid}}</text>
|
||||||
<text> 用户昵称</text>
|
<text> {{userInfo.account}}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view style="padding: 10rpx;"></view>
|
<view style="padding: 10rpx;"></view>
|
||||||
@@ -89,13 +89,15 @@
|
|||||||
timestamp: state => state.moduleB.timestamp
|
timestamp: state => state.moduleB.timestamp
|
||||||
}),
|
}),
|
||||||
...mapGetters({
|
...mapGetters({
|
||||||
isLogin: 'userIsLogin'
|
isLogin: 'getuserIsLogin',
|
||||||
|
userInfo: 'getUserInfo'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
onLoad(){
|
onLoad(){
|
||||||
|
console.log(this.isLogin);
|
||||||
if (! this.isLogin) {
|
if (! this.isLogin) {
|
||||||
uni.redirectTo({
|
uni.redirectTo({
|
||||||
url:"/pages/login/login"
|
url:"/pages/login/login"
|
||||||
|
|||||||
@@ -21,11 +21,17 @@ export default {
|
|||||||
var trDay = day < 10 ? '0' + day : day
|
var trDay = day < 10 ? '0' + day : day
|
||||||
return year + '-' + trMon + '-' + trDay + " " + hours + ":" + minu + ":" + sec;
|
return year + '-' + trMon + '-' + trDay + " " + hours + ":" + minu + ":" + sec;
|
||||||
},
|
},
|
||||||
userIsLogin(state){
|
getuserIsLogin(state){
|
||||||
return state.isLogin;
|
return state.isLogin;
|
||||||
},
|
},
|
||||||
getSessionKey(state){
|
getSessionKey(state){
|
||||||
return state.sessionKey;
|
return state.sessionKey;
|
||||||
|
},
|
||||||
|
getOpenId(state){
|
||||||
|
return state.openId;
|
||||||
|
},
|
||||||
|
getUserInfo(state){
|
||||||
|
return state.userinfo;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
@@ -35,6 +41,7 @@ export default {
|
|||||||
// 更新用户信息
|
// 更新用户信息
|
||||||
updateUserInfo(state, userinfo) {
|
updateUserInfo(state, userinfo) {
|
||||||
state.userinfo = userinfo
|
state.userinfo = userinfo
|
||||||
|
state.isLogin = true;
|
||||||
this.commit('saveUserInfoToStorge')
|
this.commit('saveUserInfoToStorge')
|
||||||
},
|
},
|
||||||
// 将用户信息持久化存储到本地
|
// 将用户信息持久化存储到本地
|
||||||
|
|||||||
Reference in New Issue
Block a user