diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..145e790 --- /dev/null +++ b/.env.development @@ -0,0 +1,5 @@ +VITE_PUBLIC_PATH = / + +VITE_API_BASE_URL = 'http://test-admin.haituaigc.com' + +VITE_API_CHAT_URL = 'http://openai-test.haituaigc.com' \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..145e790 --- /dev/null +++ b/.env.production @@ -0,0 +1,5 @@ +VITE_PUBLIC_PATH = / + +VITE_API_BASE_URL = 'http://test-admin.haituaigc.com' + +VITE_API_CHAT_URL = 'http://openai-test.haituaigc.com' \ No newline at end of file diff --git a/src/assets/images/avatar@2x.png b/src/assets/images/avatar@2x.png new file mode 100644 index 0000000..3eada69 Binary files /dev/null and b/src/assets/images/avatar@2x.png differ diff --git a/src/assets/images/icon_email.png b/src/assets/images/icon_email.png new file mode 100644 index 0000000..12f0f2a Binary files /dev/null and b/src/assets/images/icon_email.png differ diff --git a/src/assets/images/icon_email_h.png b/src/assets/images/icon_email_h.png new file mode 100644 index 0000000..3472939 Binary files /dev/null and b/src/assets/images/icon_email_h.png differ diff --git a/src/assets/images/icon_msg.png b/src/assets/images/icon_msg.png new file mode 100644 index 0000000..65cc185 Binary files /dev/null and b/src/assets/images/icon_msg.png differ diff --git a/src/assets/images/icon_msg_h.png b/src/assets/images/icon_msg_h.png new file mode 100644 index 0000000..a48090d Binary files /dev/null and b/src/assets/images/icon_msg_h.png differ diff --git a/src/assets/images/icon_pwd.png b/src/assets/images/icon_pwd.png new file mode 100644 index 0000000..4601af4 Binary files /dev/null and b/src/assets/images/icon_pwd.png differ diff --git a/src/assets/images/icon_pwd_h.png b/src/assets/images/icon_pwd_h.png new file mode 100644 index 0000000..61cf1f4 Binary files /dev/null and b/src/assets/images/icon_pwd_h.png differ diff --git a/src/components/auth/Login.vue b/src/components/auth/Login.vue new file mode 100644 index 0000000..396b98f --- /dev/null +++ b/src/components/auth/Login.vue @@ -0,0 +1,371 @@ + + + + + \ No newline at end of file diff --git a/src/components/auth/Register.vue b/src/components/auth/Register.vue new file mode 100644 index 0000000..463796f --- /dev/null +++ b/src/components/auth/Register.vue @@ -0,0 +1,211 @@ + + + + + \ No newline at end of file diff --git a/src/components/auth/index.vue b/src/components/auth/index.vue new file mode 100644 index 0000000..d717446 --- /dev/null +++ b/src/components/auth/index.vue @@ -0,0 +1,82 @@ + + + + + \ No newline at end of file diff --git a/src/io/http.js b/src/io/http.js index c3ebf5d..f5f75c7 100755 --- a/src/io/http.js +++ b/src/io/http.js @@ -16,6 +16,11 @@ const http = (url = '', data = {}, type = 'POST', otherConfig = {}) => { promise = axios({ method: type, url, + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + 'Accept': 'application/json; charset=UTF-8', + 'isLoading': config.isLoading, + }, params: data, timeout: config.timeout }); diff --git a/src/io/httpConfig.js b/src/io/httpConfig.js index c52b58a..4a144c3 100755 --- a/src/io/httpConfig.js +++ b/src/io/httpConfig.js @@ -7,15 +7,35 @@ import axios from 'axios'; import { localCache } from './cache'; import router from "@/router"; -import hostAPI from '@/config/host.config' import { showToast } from 'vant'; +import { useAuthModal } from '@/stores/authModal'; +import hostAPI from '@/config/host.config' export default function () { let _token = ''; let requestCount = 0;//请求数量 + const authModal = useAuthModal(); + + const showLoading = ()=>{ + if (requestCount === 0) { + let renderDom = document.createElement('div'); + renderDom.style.cssText = 'width:100%; height: 100%; position: absolute;left:0;top:0;z-index:9999;background-color: rgba(0,0,0,0.5);display: flex;justify-content: center; align-items: center;' + renderDom.setAttribute('id', 'requestLoading'); + renderDom.innerHTML = 'loading...'; + document.body.appendChild(renderDom); + } + requestCount++; + } + const hideLoading = ()=>{ + requestCount--; + if (requestCount === 0) { + document.body.removeChild(document.getElementById('requestLoading')); + } + }; + // axios.defaults.baseURL = '//' + window.location.host; - axios.defaults.baseURL = hostAPI; + axios.defaults.baseURL = import.meta.env.VITE_API_BASE_URL; // 请求超时时间为10秒 axios.defaults.timeout = 10000; @@ -23,7 +43,6 @@ export default function () { // 请求发送拦截,并在头部加入token axios.interceptors.request.use( function (config) { - let nextToken = localCache.get('auth') && localCache.get('auth').token; let toeknType = localCache.get('auth') && localCache.get('auth').token_type; if (config.url.indexOf('/auth/login') > -1) { @@ -39,11 +58,11 @@ export default function () { if (_token) { config.headers['Authorization'] = `${toeknType} ${_token}`; // 存在将token写入请求头 } - // if (config.headers.isLoading !== false) showLoading(); + if (config.headers.isLoading !== false) showLoading(); return config; }, function (error) { - // if (error.config.headers.isLoading !== false) hideLoading(); + if (error.config.headers.isLoading !== false) hideLoading(); return Promise.reject(error); } ); @@ -58,18 +77,19 @@ export default function () { showToast('账号过期或异地登录, 请重新登录'); localCache.remove('auth'); localCache.remove('userInfo'); - window.location.pathname='/home'; + authModal.setAuthModalType('login'); + authModal.showAuthModal(); // router.replace({name: 'Home', params: {auth: 'over'}}); } } } catch (e) { showToast('后台' + response.data.status + '错误返回格式不正确'); } - // if (response.config.headers.isLoading !== false) hideLoading(); + if (response.config.headers.isLoading !== false) hideLoading(); return response; }, function (error) { - // if (error.config.headers.isLoading !== false) hideLoading(); + if (error.config.headers.isLoading !== false) hideLoading(); if (error.response) { switch (error.response.data.status) { case 401: @@ -77,7 +97,8 @@ export default function () { showToast('账号过期或异地登录, 请重新登录'); localCache.remove('auth'); localCache.remove('userInfo'); - window.location.pathname='/home'; + authModal.setAuthModalType('login'); + authModal.showAuthModal(); break; case 500: // 500 服务端请求错误 diff --git a/src/io/request.js b/src/io/request.js new file mode 100644 index 0000000..954ae38 --- /dev/null +++ b/src/io/request.js @@ -0,0 +1,67 @@ + +import axios from 'axios' +import { localCache } from '@/io/cache' +import { message } from 'ant-design-vue' +const service = axios.create({ + baseURL: import.meta.env.VITE_API_BASE_URL, + timeout: 200000, + withCredentials: true +}) + + +service.interceptors.request.use( + config => { + const token = localCache.get('auth') && localCache.get('auth').token; + if (token) { + config.headers[ + 'Authorization' + ] = `Bearer ${token}` + } + if (config.requestBaseUrl == 'chat') { + config.baseURL = import.meta.env.VITE_API_CHAT_URL + } + return config + }, + error => { + return Promise.reject(error) + } +) + +service.interceptors.response.use( + + response => { + const { requestBaseUrl } = response.config + const res = response.data + if (requestBaseUrl == 'chat') { + return res + } else { + if (res.status != 0) { + message.error(res.msg || 'Error') + return Promise.reject(res.message || 'Error') + } else { + return res.data + } + } + }, + error => { + const res = error.response.data + const { requestBaseUrl } = error.config + if (requestBaseUrl == 'chat') { + if (res.errcode == 401) { + // localCache.remove('auth'); + // localCache.remove('userInfo'); + } + message.error(res.errmsg || 'Error') + return Promise.reject(res) + } else { + + message.error(res.errmsg || 'Error') + return Promise.reject(error) + } + + + + } +) + +export default service \ No newline at end of file diff --git a/src/layouts/Header.vue b/src/layouts/Header.vue index 039d047..b823cb4 100644 --- a/src/layouts/Header.vue +++ b/src/layouts/Header.vue @@ -3,13 +3,13 @@
首页