底座全局数据协调
This commit is contained in:
@@ -35,23 +35,22 @@
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import {mapMutations} from 'vuex'
|
||||
import {mapMutations, mapState} from 'vuex'
|
||||
|
||||
export default {
|
||||
name: "home",
|
||||
data() {
|
||||
return {
|
||||
code: '',
|
||||
token: null,
|
||||
user: null,
|
||||
apps: [],
|
||||
search: ""
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapState(['user', 'token']),
|
||||
isApprove() {
|
||||
return this.user && this.user.status == 2;
|
||||
return this.user?.status == 2;
|
||||
},
|
||||
appsList() {
|
||||
let {search} = this
|
||||
@@ -79,10 +78,8 @@ export default {
|
||||
})
|
||||
},
|
||||
getAuth() {
|
||||
this.token = uni.getStorageSync("token");
|
||||
this.user = uni.getStorageSync("userInfo");
|
||||
this.$nextTick(() => {
|
||||
this.token && this.getUserInfo()
|
||||
this.getUserInfo()
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
@@ -33,21 +33,25 @@ const store = new Vuex.Store({
|
||||
withoutToken: true
|
||||
}).then(res => {
|
||||
if (res?.access_token) {
|
||||
state.token = res.token_type + ' ' + res.access_token
|
||||
uni.setStorageSync("token", res.token_type + ' ' + res.access_token)
|
||||
params?.then(true)
|
||||
store.commit("setToken", res.token_type + ' ' + res.access_token)
|
||||
params?.then?.(true)
|
||||
} else {
|
||||
uni.showToast({title: res?.msg})
|
||||
params?.then(false)
|
||||
params?.then?.(false)
|
||||
}
|
||||
})
|
||||
}).finally(err => console.error(err))
|
||||
} else params?.then(false)
|
||||
},
|
||||
setToken(state, token) {
|
||||
state.token = token
|
||||
},
|
||||
setUserInfo(state, user) {
|
||||
state.user = user
|
||||
},
|
||||
getUserInfo(state, cb) {
|
||||
http.instance.post("/app/appwechatuser/check").then(res => {
|
||||
if (res?.data) {
|
||||
state.user = res.data
|
||||
uni.setStorageSync('userInfo', res.data)
|
||||
store.commit("setUserInfo", res.data)
|
||||
cb && cb(true)
|
||||
} else {
|
||||
cb && cb(false)
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
import config from '@/utils/config';
|
||||
import util from 'dvcp-wui/utils/util';
|
||||
import store from "../store"
|
||||
|
||||
const Fly = require('flyio/dist/npm/wx');
|
||||
var instance = new Fly();
|
||||
var refrashToken = new Fly();
|
||||
let instance = new Fly();
|
||||
const baseURL = config.baseUrl;
|
||||
let count = 0;
|
||||
instance.config.timeout = 50000;
|
||||
instance.config.baseURL = baseURL;
|
||||
|
||||
const getToken = () => {
|
||||
if (uni.getStorageSync('token')) return uni.getStorageSync('token');
|
||||
else return '';
|
||||
if (store.state.token) return store.state.token;
|
||||
else return '';
|
||||
};
|
||||
|
||||
instance.interceptors.request.use((config) => {
|
||||
if (!config.withoutToken && getToken()) {
|
||||
config.headers['Authorization'] = getToken();
|
||||
}
|
||||
|
||||
if (!config.withoutToken) {
|
||||
config.headers['Authorization'] = getToken();
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
@@ -29,39 +28,13 @@ instance.interceptors.response.use(
|
||||
util.$toast({title: response.data.msg, duration: 3000});
|
||||
} else if (response.data.code == 2) {
|
||||
//首次静默登录异常不做任何返回
|
||||
} else if (response.data.code === 401) {
|
||||
} else if (response.data.code == 401) {
|
||||
if (count > 3) {
|
||||
return;
|
||||
}
|
||||
count = count + 1;
|
||||
this.lock();
|
||||
|
||||
count++;
|
||||
return util.$getLoginCode().then((res) => {
|
||||
return refrashToken
|
||||
.post(
|
||||
`${baseURL}/auth/wechat-con/token`,
|
||||
{
|
||||
code: res.code
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: 'Basic dmlsbGNsb3VkOnZpbGxjbG91ZA=='
|
||||
}
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
if (response.data.access_token) {
|
||||
uni.setStorageSync('token', `bearer ${response.data.access_token}`);
|
||||
response.request.headers.Authorization = `bearer ${response.data.access_token}`;
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
util.$hideLoading();
|
||||
this.unlock();
|
||||
})
|
||||
.then(() => {
|
||||
return instance.request(response.request);
|
||||
});
|
||||
store.commit("getToken", {code: res.code})
|
||||
});
|
||||
} else {
|
||||
count = 0;
|
||||
|
||||
@@ -16,7 +16,7 @@ const configs = {
|
||||
dev: {
|
||||
areaId: '341021104000',
|
||||
areaName: '郑村镇',
|
||||
baseUrl: 'http://192.168.1.105:9000'
|
||||
baseUrl: 'http://192.168.1.87:9000'
|
||||
}
|
||||
}
|
||||
// 当前选中配置
|
||||
|
||||
Reference in New Issue
Block a user