刘翔宇-旅管家 3 years ago
parent cb53ee1e4a
commit b074e234b7

@ -26,7 +26,7 @@ const install = (Vue, vm) => {
// 引用token
// 方式一存放在vuex的token假设使用了uView封装的vuex方式
// 见https://uviewui.com/components/globalVariable.html
if(vm.vuex_token){
if (vm.vuex_token) {
config.header['Authorization'] = `Bearer ${vm.vuex_token}`;
}
@ -39,21 +39,30 @@ const install = (Vue, vm) => {
// 响应拦截,如配置,每次请求结束都会执行本方法
Vue.prototype.$u.http.interceptor.response = (res) => {
console.log('res-http', res)
if (res.statusCode === 200) {
if (res.data.hasOwnProperty("errcode")) {
if (res.data.errcode === 40001) {
uni.showToast({
icon: "none",
title: "登陆过期,请重新登录"
})
setTimeout(() => {
uni.redirectTo({
url: '/pages/login/login'
})
}, 1500)
} else {
uni.showToast({
icon: "none",
title: res.data.errmsg
})
}
} else
return res.data;
} else {
uni.showToast({
icon: "fail",

@ -12,7 +12,7 @@
</view>
<!-- 搜索 -->
<view class="search">
<view class="search" v-if="false">
<view class="input-content">
<u-input placeholder="请输入要搜索的内容" height="40" :custom-style="inputStyle"></u-input>
</view>

@ -75,6 +75,23 @@
},
methods: {
login() {
if(this.form.username==""){
uni.showToast({
icon: "none",
title: `请正确填写登录名`,
});
return false
}
if(this.form.password==""){
uni.showToast({
icon: "none",
title: `请正确填写密码`,
});
return false
}
this.$u.api.login(this.form).then(res => {
this.$u.vuex("vuex_token", res.access_token);

Loading…
Cancel
Save