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