feat: base request 调整
This commit is contained in:
parent
41fc6c4b14
commit
80b2c0bf7d
|
|
@ -4,8 +4,8 @@ import { MessagePlugin } from "tdesign-vue-next"
|
|||
import { useRouter } from 'vue-router';
|
||||
|
||||
function get_api_url() {
|
||||
if (process.env.NODE_ENV === 'development' || (process.env.NODE_ENV === 'production' && window.location.host.indexOf('localhost') > -1)) {
|
||||
return process.env.VUE_APP_API_BASEURL
|
||||
if (import.meta.env.MODE === 'development' || (import.meta.env.MODE === 'production' && window.location.host.indexOf('localhost') > -1)) {
|
||||
return import.meta.env.VITE_API_BASEURL
|
||||
}
|
||||
return 'http://' + window.location.host + '/api'
|
||||
}
|
||||
|
|
@ -39,14 +39,10 @@ instance.interceptors.response.use(
|
|||
},
|
||||
error => {
|
||||
let err_msg = "请求错误";
|
||||
console.log(error)
|
||||
if (error.response) {
|
||||
switch (error.response.status) {
|
||||
case 401:
|
||||
if (error.response.data?.err_code == 'no_active_account') {
|
||||
err_msg = "账户密码错误或已禁用"
|
||||
} else {
|
||||
err_msg = "认证失败,请重新登录"
|
||||
}
|
||||
if (authToken.access) { authToken.access = null }
|
||||
if (authToken.refresh) { authToken.refresh = null }
|
||||
if (error.config.url.indexOf('/login') == -1) {
|
||||
|
|
|
|||
|
|
@ -30,8 +30,9 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { authToken, systemInfo } from '@/store/index.js'
|
||||
import { authToken, systemInfo, userInfo } from '@/store/index.js'
|
||||
import { MessagePlugin } from "tdesign-vue-next"
|
||||
import http from "@/api/request.js";
|
||||
const router = useRouter();
|
||||
const formData = ref({
|
||||
username: "",
|
||||
|
|
@ -40,12 +41,15 @@ const formData = ref({
|
|||
const submitLoading = ref(false);
|
||||
const handleLogin = () => {
|
||||
submitLoading.value = true;
|
||||
setTimeout(() => {
|
||||
http.post("/login/", formData.value).then(res=>{
|
||||
MessagePlugin.success("登录成功");
|
||||
authToken.access = "123456";
|
||||
authToken.access = res.access;
|
||||
Object.assign(userInfo, res.userInfo);
|
||||
submitLoading.value = false;
|
||||
router.replace({ path: "/home" });
|
||||
}, 300);
|
||||
}).catch(e=>{
|
||||
submitLoading.value = false;
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<style scoped>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { reactive, watch } from "vue";
|
||||
|
||||
export const systemInfo = reactive(JSON.parse(localStorage.getItem("systemInfo")) || {
|
||||
base_name: "XT_WEB_TD"
|
||||
base_name: "系统名称"
|
||||
})
|
||||
|
||||
watch(systemInfo, (newVal) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue