feat(xb): unify DPL and HN backend, themes and registration reports
This commit is contained in:
1 parent
eb630d2caf
commit
1ded40226b
1082 files changed
+159466
-104
No files matched your search
Vendored
+576
@@ -0,0 +1,576 @@
|
||||
|
||||
import request from './request';
|
||||
import store from '@/store';
|
||||
import { SITE_CONFIG } from '@/utils/baseConfig';
|
||||
import { reloadMessages } from '@/i18n';
|
||||
|
||||
|
||||
const setCookie = (name, value, days) => {
|
||||
const siteName = SITE_CONFIG.siteName;
|
||||
|
||||
const cookieValue = JSON.stringify({
|
||||
site: siteName,
|
||||
value: value
|
||||
});
|
||||
|
||||
const isSecure = window.location.protocol === 'https:';
|
||||
const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
|
||||
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
||||
const expires = `expires=${date.toUTCString()}`;
|
||||
const domain = isLocalhost ? '' : `domain=${window.location.hostname};`;
|
||||
let cookieString = `${name}=${encodeURIComponent(cookieValue)}; ${expires}; ${domain} path=/`;
|
||||
|
||||
if (isSecure) {
|
||||
cookieString += '; secure';
|
||||
}
|
||||
|
||||
cookieString += '; SameSite=Lax';
|
||||
|
||||
document.cookie = cookieString;
|
||||
|
||||
try {
|
||||
localStorage.setItem(`cookie_${name}`, cookieValue);
|
||||
} catch (err) {
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
const checkCookie = getCookie(name);
|
||||
const success = !!checkCookie;
|
||||
|
||||
if (!success) {
|
||||
document.cookie = `${name}=${encodeURIComponent(cookieValue)}; ${expires}; path=/`;
|
||||
localStorage.setItem(`cookie_${name}_failure`, 'true');
|
||||
window.authCookieFailure = true;
|
||||
}
|
||||
}, 300);
|
||||
};
|
||||
|
||||
|
||||
export const getCookie = (name) => {
|
||||
const siteName = SITE_CONFIG.siteName;
|
||||
|
||||
const nameEQ = name + "=";
|
||||
const ca = document.cookie.split(';');
|
||||
let cookieValue = null;
|
||||
|
||||
for (let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) === 0) {
|
||||
try {
|
||||
const rawValue = c.substring(nameEQ.length, c.length);
|
||||
const decodedValue = decodeURIComponent(rawValue);
|
||||
const parsedValue = JSON.parse(decodedValue);
|
||||
|
||||
if (parsedValue && parsedValue.site === siteName) {
|
||||
cookieValue = parsedValue.value;
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Cookie 解析失败:', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!cookieValue) {
|
||||
try {
|
||||
const localValue = localStorage.getItem(`cookie_${name}`);
|
||||
if (localValue) {
|
||||
try {
|
||||
const parsedValue = JSON.parse(localValue);
|
||||
if (parsedValue && parsedValue.site === siteName) {
|
||||
cookieValue = parsedValue.value;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('LocalStorage cookie 解析失败:', err);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!cookieValue && name === 'auth_data' && window.authDataInStorage) {
|
||||
cookieValue = window.authDataInStorage;
|
||||
}
|
||||
|
||||
return cookieValue;
|
||||
};
|
||||
|
||||
|
||||
const deleteCookie = (name) => {
|
||||
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
||||
|
||||
try {
|
||||
localStorage.removeItem(`cookie_${name}`);
|
||||
localStorage.removeItem(`cookie_${name}_failure`);
|
||||
} catch (err) {
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
const checkCookie = getCookie(name);
|
||||
if (checkCookie) {
|
||||
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`;
|
||||
|
||||
const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
|
||||
const domain = isLocalhost ? '' : `domain=${window.location.hostname};`;
|
||||
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; ${domain} path=/`;
|
||||
}
|
||||
}, 100);
|
||||
};
|
||||
|
||||
|
||||
export const handleLoginSuccess = (responseData, rememberMe) => {
|
||||
try {
|
||||
window.isUserLoggedIn = undefined;
|
||||
window.authCookieFailure = false;
|
||||
window.authDataInStorage = null;
|
||||
|
||||
store.dispatch('login', responseData.token);
|
||||
|
||||
localStorage.setItem('token', responseData.token);
|
||||
if (responseData.is_admin === 1) {
|
||||
localStorage.setItem('is_admin', '1');
|
||||
}
|
||||
|
||||
if (responseData.auth_data) {
|
||||
localStorage.setItem('auth_data', responseData.auth_data);
|
||||
}
|
||||
|
||||
const days = rememberMe ? 30 : 1;
|
||||
if (responseData.auth_data) {
|
||||
setCookie('auth_data', responseData.auth_data, days);
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
const loginCheck = checkLoginStatus();
|
||||
|
||||
if (!loginCheck) {
|
||||
window.isUserLoggedIn = true;
|
||||
|
||||
if (responseData.auth_data) {
|
||||
window.authDataInStorage = responseData.auth_data;
|
||||
localStorage.setItem('cookie_auth_data', responseData.auth_data);
|
||||
}
|
||||
}
|
||||
|
||||
reloadMessages().catch(() => {
|
||||
});
|
||||
}, 500);
|
||||
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const login = async (loginData) => {
|
||||
const { rememberMe, ...requestData } = loginData;
|
||||
|
||||
const response = await request({
|
||||
url: '/passport/auth/login',
|
||||
method: 'post',
|
||||
data: requestData
|
||||
});
|
||||
|
||||
let responseData = response;
|
||||
if ((response && response.data) || (response && typeof response === 'object' && Object.prototype.hasOwnProperty.call(response, 'data'))) {
|
||||
responseData = response.data;
|
||||
}
|
||||
|
||||
if (!responseData || !(responseData.token || responseData.auth_data)) {
|
||||
throw new Error('登录数据不完整');
|
||||
}
|
||||
|
||||
const handledResponse = handleLoginSuccess(responseData, rememberMe);
|
||||
|
||||
if (handledResponse.success) {
|
||||
return {
|
||||
success: true,
|
||||
token: responseData.token,
|
||||
auth_data: responseData.auth_data,
|
||||
is_admin: responseData.is_admin
|
||||
};
|
||||
} else {
|
||||
throw new Error(handledResponse.error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export function register(data) {
|
||||
return request({
|
||||
url: '/passport/auth/register',
|
||||
method: 'post',
|
||||
data
|
||||
}).then(response => {
|
||||
let responseData = response.data || response;
|
||||
|
||||
if (responseData.token) {
|
||||
store.dispatch('login', responseData.token);
|
||||
|
||||
window.isUserLoggedIn = true;
|
||||
}
|
||||
|
||||
if (responseData.auth_data) {
|
||||
setCookie('auth_data', responseData.auth_data, 1);
|
||||
|
||||
localStorage.setItem('auth_data', responseData.auth_data);
|
||||
|
||||
window.authDataInStorage = responseData.auth_data;
|
||||
}
|
||||
|
||||
if (typeof responseData.is_admin !== 'undefined') {
|
||||
localStorage.setItem('is_admin', responseData.is_admin);
|
||||
}
|
||||
|
||||
console.log('注册成功,准备重新加载语言文件');
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
const result = await reloadMessages();
|
||||
console.log('注册后重新加载语言包结果:', result);
|
||||
|
||||
window.dispatchEvent(new CustomEvent('languageChanged'));
|
||||
} catch (error) {
|
||||
console.error('注册后重载语言包失败:', error);
|
||||
}
|
||||
}, 100);
|
||||
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function resetPassword(data) {
|
||||
return request({
|
||||
url: '/passport/auth/forget',
|
||||
method: 'post',
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function getUserInfo() {
|
||||
return request({
|
||||
url: '/user/info',
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export const logout = async () => {
|
||||
try {
|
||||
_clearAllAuthData();
|
||||
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
reloadMessages().then(() => {
|
||||
resolve({
|
||||
success: true,
|
||||
redirectToLogin: true,
|
||||
redirectUrl: '/login?logout=true'
|
||||
});
|
||||
}).catch(() => {
|
||||
resolve({
|
||||
success: true,
|
||||
redirectToLogin: true,
|
||||
redirectUrl: '/login?logout=true'
|
||||
});
|
||||
});
|
||||
}, 200);
|
||||
});
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
redirectToLogin: true,
|
||||
redirectUrl: '/login?logout=true'
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export function getWebsiteConfig() {
|
||||
return request({
|
||||
url: '/guest/comm/config',
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function sendEmailVerify(data) {
|
||||
const sendData = { ...data };
|
||||
|
||||
if (window.EZ_CONFIG && window.EZ_CONFIG.PANEL_TYPE === 'Xiao-V2board' &&
|
||||
typeof sendData.isForgetPassword !== 'undefined') {
|
||||
sendData.isforget = sendData.isForgetPassword ? 1 : 0;
|
||||
delete sendData.isForgetPassword;
|
||||
}
|
||||
|
||||
return request({
|
||||
url: '/passport/comm/sendEmailVerify',
|
||||
method: 'post',
|
||||
data: sendData
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export const checkLoginStatus = () => {
|
||||
const now = Date.now();
|
||||
if (window._lastLoginCheck && (now - window._lastLoginCheckTime < 1000)) {
|
||||
return window._lastLoginCheck;
|
||||
}
|
||||
|
||||
if (window._isLoggingOut === true) {
|
||||
_cacheLoginStatus(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
if (urlParams.get('logout') === 'true') {
|
||||
_clearAllAuthData();
|
||||
_cacheLoginStatus(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (window.isUserLoggedIn === false) {
|
||||
_cacheLoginStatus(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
const token = localStorage.getItem('token') || sessionStorage.getItem('token');
|
||||
if (!token || token === 'undefined' || token === 'null' || token === '') {
|
||||
_clearAllAuthData();
|
||||
_cacheLoginStatus(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
const authData = localStorage.getItem('auth_data') ||
|
||||
sessionStorage.getItem('auth_data') ||
|
||||
window.authDataInStorage;
|
||||
|
||||
if (!authData || authData === 'undefined' || authData === 'null' || authData === '') {
|
||||
if (window.isUserLoggedIn === true) {
|
||||
_cacheLoginStatus(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
_clearAllAuthData();
|
||||
_cacheLoginStatus(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const vuexAuth = store.getters.isLoggedIn;
|
||||
if (!vuexAuth) {
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
const userInfoStr = localStorage.getItem('userInfo');
|
||||
let userInfo = null;
|
||||
|
||||
try {
|
||||
if (userInfoStr) {
|
||||
userInfo = JSON.parse(userInfoStr);
|
||||
if (!userInfo || typeof userInfo !== 'object') {
|
||||
userInfo = null;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
userInfo = null;
|
||||
localStorage.removeItem('userInfo');
|
||||
}
|
||||
|
||||
const isLoggedIn = !!token && !!authData;
|
||||
|
||||
if (isLoggedIn) {
|
||||
window.isUserLoggedIn = true;
|
||||
}
|
||||
|
||||
_cacheLoginStatus(isLoggedIn);
|
||||
return isLoggedIn;
|
||||
};
|
||||
|
||||
|
||||
const _cacheLoginStatus = (status) => {
|
||||
window._lastLoginCheck = status;
|
||||
window._lastLoginCheckTime = Date.now();
|
||||
};
|
||||
|
||||
|
||||
const _clearAllAuthData = () => {
|
||||
window.isUserLoggedIn = false;
|
||||
window.authDataInStorage = null;
|
||||
window.authCookieFailure = false;
|
||||
|
||||
const authKeys = [
|
||||
'token',
|
||||
'auth_data',
|
||||
'cookie_auth_data',
|
||||
'userInfo',
|
||||
'is_admin',
|
||||
'vuex',
|
||||
'user',
|
||||
'auth'
|
||||
];
|
||||
|
||||
authKeys.forEach(key => {
|
||||
localStorage.removeItem(key);
|
||||
});
|
||||
|
||||
const sessionKeys = [
|
||||
'token',
|
||||
'auth_data',
|
||||
'vuex',
|
||||
'user',
|
||||
'auth'
|
||||
];
|
||||
|
||||
sessionKeys.forEach(key => {
|
||||
sessionStorage.removeItem(key);
|
||||
});
|
||||
|
||||
const cookiePaths = ['/', '/dashboard', '/user', '/admin'];
|
||||
const cookieNames = ['auth_data', 'XSRF-TOKEN', 'laravel_session', 'token'];
|
||||
|
||||
cookieNames.forEach(name => {
|
||||
cookiePaths.forEach(path => {
|
||||
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path};`;
|
||||
});
|
||||
|
||||
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
||||
deleteCookie(name);
|
||||
});
|
||||
|
||||
try {
|
||||
if (store && typeof store.commit === 'function') {
|
||||
store.commit('CLEAR_USER');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Vuex状态清除失败', e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const forceLogout = () => {
|
||||
window.isUserLoggedIn = false;
|
||||
window.authDataInStorage = null;
|
||||
window.authCookieFailure = false;
|
||||
|
||||
const authKeys = [
|
||||
'token',
|
||||
'auth_data',
|
||||
'cookie_auth_data',
|
||||
'userInfo',
|
||||
'is_admin',
|
||||
'vuex',
|
||||
'user',
|
||||
'auth'
|
||||
];
|
||||
|
||||
authKeys.forEach(key => {
|
||||
localStorage.removeItem(key);
|
||||
});
|
||||
|
||||
const sessionKeys = [
|
||||
'token',
|
||||
'auth_data',
|
||||
'vuex',
|
||||
'user',
|
||||
'auth'
|
||||
];
|
||||
|
||||
sessionKeys.forEach(key => {
|
||||
sessionStorage.removeItem(key);
|
||||
});
|
||||
|
||||
const cookiePaths = ['/', '/dashboard', '/user', '/admin'];
|
||||
const cookieNames = ['auth_data', 'XSRF-TOKEN', 'laravel_session', 'token'];
|
||||
|
||||
cookieNames.forEach(name => {
|
||||
cookiePaths.forEach(path => {
|
||||
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path};`;
|
||||
});
|
||||
|
||||
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
|
||||
|
||||
deleteCookie(name);
|
||||
});
|
||||
|
||||
try {
|
||||
if (store && typeof store.commit === 'function') {
|
||||
store.commit('CLEAR_USER');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Vuex状态清除失败', e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const tokenLogin = (verifyToken, redirect) => {
|
||||
return request({
|
||||
url: `/passport/auth/token2Login`,
|
||||
method: 'get',
|
||||
params: {
|
||||
verify: verifyToken,
|
||||
redirect: redirect || ''
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export const checkUserLoginStatus = async () => {
|
||||
const authData = localStorage.getItem('auth_data') || sessionStorage.getItem('auth_data');
|
||||
const token = localStorage.getItem('token') || sessionStorage.getItem('token');
|
||||
|
||||
if (!token || !authData) {
|
||||
forceLogout();
|
||||
return { isLoggedIn: false };
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await request({
|
||||
url: '/user/checkLogin',
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': authData
|
||||
}
|
||||
});
|
||||
|
||||
if (response && response.data && response.data.is_login === true) {
|
||||
window.isUserLoggedIn = true;
|
||||
return { isLoggedIn: true };
|
||||
} else {
|
||||
console.log('登录已过期或失效,清除登录状态');
|
||||
forceLogout();
|
||||
|
||||
const currentRoute = window.location.pathname;
|
||||
const isAuthPage = /\/(login|register|forgot-password)/.test(currentRoute);
|
||||
|
||||
if (!isAuthPage) {
|
||||
window.location.href = '/#/login';
|
||||
}
|
||||
|
||||
return { isLoggedIn: false, message: '登录已过期,请重新登录' };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('检查登录状态失败:', error);
|
||||
|
||||
if (error.response && error.response.data && error.response.data.message === '未登录或登陆已过期') {
|
||||
forceLogout();
|
||||
|
||||
const currentRoute = window.location.pathname;
|
||||
const isAuthPage = /\/(login|register|forgot-password)/.test(currentRoute);
|
||||
|
||||
if (!isAuthPage) {
|
||||
window.location.href = '/#/login';
|
||||
}
|
||||
|
||||
return { isLoggedIn: false, message: '登录已过期,请重新登录' };
|
||||
}
|
||||
|
||||
return { isLoggedIn: null, error: error.message || '网络错误' };
|
||||
}
|
||||
};
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
import { SITE_CONFIG } from '@/utils/baseConfig';
|
||||
|
||||
const parseSiteScopedValue = (rawValue, siteName) => {
|
||||
if (!rawValue) return '';
|
||||
|
||||
try {
|
||||
const parsedValue = JSON.parse(rawValue);
|
||||
if (parsedValue && parsedValue.site === siteName) {
|
||||
return parsedValue.value;
|
||||
}
|
||||
} catch (err) {
|
||||
return rawValue;
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
const readAuthCookieFallback = async () => {
|
||||
const cookieAuthData = document.cookie
|
||||
.split('; ')
|
||||
.find(row => row.startsWith('auth_data='));
|
||||
|
||||
if (!cookieAuthData) return '';
|
||||
|
||||
const encodedValue = cookieAuthData.split('=')[1];
|
||||
const decodedValue = decodeURIComponent(encodedValue);
|
||||
return parseSiteScopedValue(decodedValue, SITE_CONFIG.siteName) || encodedValue;
|
||||
};
|
||||
|
||||
const readCookieValue = (name) => {
|
||||
const nameEQ = `${name}=`;
|
||||
const cookies = document.cookie.split(';');
|
||||
|
||||
for (let i = 0; i < cookies.length; i += 1) {
|
||||
let cookie = cookies[i];
|
||||
while (cookie.charAt(0) === ' ') cookie = cookie.substring(1);
|
||||
|
||||
if (cookie.indexOf(nameEQ) === 0) {
|
||||
const rawValue = cookie.substring(nameEQ.length);
|
||||
const decodedValue = decodeURIComponent(rawValue);
|
||||
return parseSiteScopedValue(decodedValue, SITE_CONFIG.siteName) || rawValue;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
export const readAuthData = async () => {
|
||||
let authData = localStorage.getItem('auth_data');
|
||||
|
||||
if (!authData) {
|
||||
authData = readCookieValue('auth_data') || await readAuthCookieFallback();
|
||||
}
|
||||
|
||||
if (!authData && window.authDataInStorage) {
|
||||
authData = window.authDataInStorage;
|
||||
}
|
||||
|
||||
if (!authData) {
|
||||
const backupData = localStorage.getItem('cookie_auth_data');
|
||||
if (backupData) {
|
||||
authData = parseSiteScopedValue(backupData, SITE_CONFIG.siteName) || backupData;
|
||||
}
|
||||
}
|
||||
|
||||
return authData || '';
|
||||
};
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
const statusMessages = {
|
||||
400: '请求参数错误',
|
||||
401: '未授权,请重新登录',
|
||||
403: '拒绝访问',
|
||||
404: '请求的资源不存在'
|
||||
};
|
||||
|
||||
export const normalizeRequestError = (error) => {
|
||||
if (error.response?.data?.message) {
|
||||
error.response.message = error.response.data.message;
|
||||
return error;
|
||||
}
|
||||
|
||||
if (error.response) {
|
||||
const statusCode = error.response.status;
|
||||
error.response.message = statusMessages[statusCode] || `请求失败 (${statusCode})`;
|
||||
return error;
|
||||
}
|
||||
|
||||
if (error.message?.includes('timeout')) {
|
||||
error.message = '请求超时';
|
||||
} else if (error.message?.includes('Network Error')) {
|
||||
error.message = '网络错误,请检查您的网络连接';
|
||||
}
|
||||
|
||||
return error;
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
export const applyCustomHeaders = (headers, customHeadersConfig) => {
|
||||
if (!customHeadersConfig?.enabled || !customHeadersConfig.headers) {
|
||||
return headers;
|
||||
}
|
||||
|
||||
Object.entries(customHeadersConfig.headers).forEach(([headerName, headerValue]) => {
|
||||
headers[headerName] = headerValue;
|
||||
});
|
||||
|
||||
return headers;
|
||||
};
|
||||
Vendored
+80
@@ -0,0 +1,80 @@
|
||||
import request from './request';
|
||||
|
||||
|
||||
export function getUserInfo() {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/info',
|
||||
|
||||
method: 'get'
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
export function getSubscribe() {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/getSubscribe',
|
||||
|
||||
method: 'get'
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
export function getNotices() {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/notice/fetch',
|
||||
|
||||
method: 'get'
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
export function getUserStats() {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/getStat',
|
||||
|
||||
method: 'get'
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
export function getUserConfig() {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/comm/config',
|
||||
|
||||
method: 'get'
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
export function setNextPeriod() {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/newPeriod',
|
||||
|
||||
method: 'POST'
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
import request from './request';␍
|
||||
␍
|
||||
␍
|
||||
export function fetchKnowledgeList(language) {␍
|
||||
return request({␍
|
||||
url: `/user/knowledge/fetch?language=${language}`,␍
|
||||
method: 'get'␍
|
||||
}).then(response => {␍
|
||||
if (typeof response === 'object') {␍
|
||||
return response;␍
|
||||
}␍
|
||||
␍
|
||||
throw new Error('Invalid response format');␍
|
||||
}).catch(error => {␍
|
||||
console.error('Error fetching knowledge list:', error);␍
|
||||
throw error;␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function fetchKnowledgeDetail(id, language) {␍
|
||||
return request({␍
|
||||
url: `/user/knowledge/fetch?id=${id}&language=${language}`,␍
|
||||
method: 'get'␍
|
||||
}).then(response => {␍
|
||||
if (typeof response === 'object') {␍
|
||||
return response;␍
|
||||
}␍
|
||||
␍
|
||||
throw new Error('Invalid response format');␍
|
||||
}).catch(error => {␍
|
||||
console.error('Error fetching knowledge detail:', error);␍
|
||||
throw error;␍
|
||||
});␍
|
||||
}␍
|
||||
|
||||
Vendored
+62
@@ -0,0 +1,62 @@
|
||||
|
||||
import request from './request';
|
||||
|
||||
|
||||
export function getInviteData() {
|
||||
return request({
|
||||
url: '/user/invite/fetch',
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function getInviteDetails(current, pageSize) {
|
||||
return request({
|
||||
url: '/user/invite/details',
|
||||
method: 'get',
|
||||
params: {
|
||||
current,
|
||||
page_size: pageSize
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function getCommissionConfig() {
|
||||
return request({
|
||||
url: '/user/comm/config',
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function generateInviteCode() {
|
||||
return request({
|
||||
url: '/user/invite/save',
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function transferCommission(amount) {
|
||||
return request({
|
||||
url: '/user/transfer',
|
||||
method: 'post',
|
||||
data: {
|
||||
transfer_amount: amount
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function withdrawCommission(amount, account, method) {
|
||||
return request({
|
||||
url: '/user/ticket/withdraw',
|
||||
method: 'post',
|
||||
data: {
|
||||
withdraw_amount: amount,
|
||||
withdraw_account: account,
|
||||
withdraw_method: method
|
||||
}
|
||||
});
|
||||
}
|
||||
Vendored
+65
@@ -0,0 +1,65 @@
|
||||
import request from './request';␍
|
||||
␍
|
||||
␍
|
||||
export function fetchOrderList() {␍
|
||||
return request({␍
|
||||
url: '/user/order/fetch',␍
|
||||
method: 'get'␍
|
||||
}).then(response => {␍
|
||||
if (typeof response === 'object') {␍
|
||||
return response;␍
|
||||
}␍
|
||||
␍
|
||||
throw new Error('Invalid response format');␍
|
||||
}).catch(error => {␍
|
||||
console.error('Error fetching order list:', error);␍
|
||||
throw error;␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function cancelOrder(tradeNo) {␍
|
||||
return new Promise((resolve, reject) => {␍
|
||||
if (!tradeNo) {␍
|
||||
reject(new Error('订单号不能为空'));␍
|
||||
return;␍
|
||||
}␍
|
||||
␍
|
||||
request({␍
|
||||
url: `/user/order/cancel`,␍
|
||||
method: 'post',␍
|
||||
data: {␍
|
||||
trade_no: tradeNo␍
|
||||
}␍
|
||||
})␍
|
||||
.then(response => {␍
|
||||
if (response && typeof response === 'object') {␍
|
||||
resolve(response);␍
|
||||
} else {␍
|
||||
reject(new Error('返回数据格式不正确'));␍
|
||||
}␍
|
||||
})␍
|
||||
.catch(error => {␍
|
||||
console.error('取消订单失败:', error);␍
|
||||
␍
|
||||
let errorMessage = '取消订单失败';␍
|
||||
␍
|
||||
if (error) {␍
|
||||
if (typeof error.message === 'string') {␍
|
||||
errorMessage = error.message;␍
|
||||
} else if (error.response && error.response.data) {␍
|
||||
const responseData = error.response.data;␍
|
||||
if (typeof responseData === 'string') {␍
|
||||
errorMessage = responseData;␍
|
||||
} else if (responseData.message) {␍
|
||||
errorMessage = responseData.message;␍
|
||||
} else if (responseData.error) {␍
|
||||
errorMessage = responseData.error;␍
|
||||
}␍
|
||||
}␍
|
||||
}␍
|
||||
␍
|
||||
reject(new Error(errorMessage));␍
|
||||
});␍
|
||||
});␍
|
||||
}
|
||||
Vendored
+133
@@ -0,0 +1,133 @@
|
||||
|
||||
import axios from 'axios';
|
||||
import { API_BASE_URL, getApiBaseUrl, isXiaoV2board, isXboard, CUSTOM_HEADERS_CONFIG } from '@/utils/baseConfig';
|
||||
import { mapApiPath } from './utils/pathMapper';
|
||||
import { getAvailableApiUrl } from '@/utils/apiAvailabilityChecker';
|
||||
import { getEncrypUrl, randomIv } from "@/api/utils/encryption";
|
||||
import { readAuthData } from '@/api/client/authToken';
|
||||
import { applyCustomHeaders } from '@/api/client/headers';
|
||||
import { normalizeRequestError } from '@/api/client/errors';
|
||||
|
||||
const isEncrypted = window.EZ_CONFIG &&
|
||||
window.EZ_CONFIG.API_MIDDLEWARE_ENABLED &&
|
||||
window.EZ_CONFIG.API_MIDDLEWARE_KEY &&
|
||||
window.EZ_CONFIG.API_MIDDLEWARE_KEY !== '';
|
||||
|
||||
const request = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
timeout: 30000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
// 只有在加密模式下才添加 X-IV 头
|
||||
...(isEncrypted && { 'X-IV': randomIv() }),
|
||||
}
|
||||
});
|
||||
|
||||
const clearExpiredAuthState = () => {
|
||||
window.isUserLoggedIn = false;
|
||||
window.authDataInStorage = null;
|
||||
window.authCookieFailure = false;
|
||||
|
||||
[
|
||||
'token',
|
||||
'auth_data',
|
||||
'cookie_auth_data',
|
||||
'userInfo',
|
||||
'is_admin',
|
||||
'vuex',
|
||||
'user',
|
||||
'auth'
|
||||
].forEach(key => {
|
||||
localStorage.removeItem(key);
|
||||
sessionStorage.removeItem(key);
|
||||
});
|
||||
|
||||
['auth_data', 'XSRF-TOKEN', 'laravel_session', 'token'].forEach(name => {
|
||||
['/', '/dashboard', '/user', '/admin'].forEach(path => {
|
||||
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path};`;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
request.interceptors.request.use(
|
||||
async config => {
|
||||
config.baseURL = getApiBaseUrl();
|
||||
|
||||
if (window.EZ_CONFIG && window.EZ_CONFIG.API_MIDDLEWARE_ENABLED) {
|
||||
const originalUrl = config.url;
|
||||
|
||||
const path = originalUrl.startsWith("http") ? mapApiPath(config.url) : `${window.EZ_CONFIG.API_MIDDLEWARE_PATH}/${btoa(getEncrypUrl(config.url))}`
|
||||
|
||||
config.url = isEncrypted ? path : mapApiPath(config.url);
|
||||
|
||||
if (import.meta.env.DEV) {
|
||||
console.log(`API路径映射: ${originalUrl} -> ${config.url}`);
|
||||
}
|
||||
}
|
||||
else if (window.EZ_CONFIG && window.EZ_CONFIG.API_BASE_URLS &&
|
||||
Array.isArray(window.EZ_CONFIG.API_BASE_URLS) &&
|
||||
window.EZ_CONFIG.API_BASE_URLS.length > 1) {
|
||||
const availableApiUrl = getAvailableApiUrl();
|
||||
if (availableApiUrl) {
|
||||
config.baseURL = availableApiUrl;
|
||||
}
|
||||
}
|
||||
|
||||
if ((isXiaoV2board() || isXboard()) && config.method === 'post' && config.data) {
|
||||
const formData = new URLSearchParams();
|
||||
for (const key in config.data) {
|
||||
if (Object.prototype.hasOwnProperty.call(config.data, key)) {
|
||||
formData.append(key, config.data[key]);
|
||||
}
|
||||
}
|
||||
|
||||
config.data = formData;
|
||||
config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
}
|
||||
|
||||
const authData = await readAuthData();
|
||||
|
||||
if (authData) {
|
||||
config.headers['Authorization'] = authData;
|
||||
}
|
||||
|
||||
try {
|
||||
applyCustomHeaders(config.headers, CUSTOM_HEADERS_CONFIG);
|
||||
} catch (error) {
|
||||
console.error('应用自定义标头失败:', error);
|
||||
}
|
||||
|
||||
return config;
|
||||
},
|
||||
error => {
|
||||
console.error('请求拦截器错误:', error);
|
||||
return Promise.reject(new Error('请求配置错误'));
|
||||
}
|
||||
);
|
||||
|
||||
request.interceptors.response.use(
|
||||
async response => {
|
||||
try {
|
||||
const res = response.data;
|
||||
|
||||
if (res && res.message === '未登录或登陆已过期') {
|
||||
console.log('检测到登录已过期,执行登出操作');
|
||||
clearExpiredAuthState();
|
||||
window.location.href = '/#/login';
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
|
||||
return res;
|
||||
} catch (err) {
|
||||
console.error('响应数据处理错误:', err);
|
||||
return Promise.reject(new Error('响应数据处理错误'));
|
||||
}
|
||||
},
|
||||
error => {
|
||||
console.error('请求错误:', error);
|
||||
|
||||
return Promise.reject(normalizeRequestError(error));
|
||||
}
|
||||
);
|
||||
|
||||
export default request;
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
import request from './request';␍
|
||||
␍
|
||||
␍
|
||||
export function fetchServerNodes() {␍
|
||||
return request({␍
|
||||
url: '/user/server/fetch',␍
|
||||
method: 'get'␍
|
||||
}).then(response => {␍
|
||||
if (typeof response === 'object') {␍
|
||||
return response;␍
|
||||
}␍
|
||||
␍
|
||||
throw new Error('Invalid response format');␍
|
||||
}).catch(error => {␍
|
||||
console.error('Error fetching server nodes:', error);␍
|
||||
throw error;␍
|
||||
});␍
|
||||
}
|
||||
Vendored
+94
@@ -0,0 +1,94 @@
|
||||
import request from './request';␍
|
||||
␍
|
||||
␍
|
||||
export function fetchPlans() {␍
|
||||
return request({␍
|
||||
url: '/user/plan/fetch',␍
|
||||
method: 'get'␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function getCommConfig() {␍
|
||||
return request({␍
|
||||
url: '/user/comm/config',␍
|
||||
method: 'get'␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function fetchPlanById(id) {␍
|
||||
return request({␍
|
||||
url: `/user/plan/fetch?id=${id}`,␍
|
||||
method: 'get'␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function verifyCoupon(code, planId) {␍
|
||||
return request({␍
|
||||
url: '/user/coupon/check',␍
|
||||
method: 'post',␍
|
||||
data: {␍
|
||||
code: code,␍
|
||||
plan_id: planId␍
|
||||
}␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function submitOrder(data) {␍
|
||||
return request({␍
|
||||
url: '/user/order/save',␍
|
||||
method: 'post',␍
|
||||
data␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function getOrderDetail(tradeNo) {␍
|
||||
return request({␍
|
||||
url: `/user/order/detail?trade_no=${tradeNo}`,␍
|
||||
method: 'get'␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function getPaymentMethods() {␍
|
||||
return request({␍
|
||||
url: '/user/order/getPaymentMethod',␍
|
||||
method: 'get'␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function checkOrderStatus(tradeNo) {␍
|
||||
return request({␍
|
||||
url: `/user/order/check?trade_no=${tradeNo}`,␍
|
||||
method: 'get'␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function cancelOrder(tradeNo) {␍
|
||||
return request({␍
|
||||
url: '/user/order/cancel',␍
|
||||
method: 'post',␍
|
||||
data: {␍
|
||||
trade_no: tradeNo␍
|
||||
}␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function checkoutOrder(tradeNo, methodId) {␍
|
||||
return request({␍
|
||||
url: '/user/order/checkout',␍
|
||||
method: 'post',␍
|
||||
data: {␍
|
||||
trade_no: tradeNo,␍
|
||||
method: methodId␍
|
||||
}␍
|
||||
});␍
|
||||
}␍
|
||||
|
||||
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
␍
|
||||
import request from './request';␍
|
||||
␍
|
||||
␍
|
||||
export function fetchTicketList() {␍
|
||||
return request({␍
|
||||
url: '/user/ticket/fetch',␍
|
||||
method: 'get'␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function createTicket(data) {␍
|
||||
return request({␍
|
||||
url: '/user/ticket/save',␍
|
||||
method: 'post',␍
|
||||
data␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function getTicketDetail(id) {␍
|
||||
return request({␍
|
||||
url: `/user/ticket/fetch?id=${id}`,␍
|
||||
method: 'get'␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function replyTicket(id, message) {␍
|
||||
return request({␍
|
||||
url: '/user/ticket/reply',␍
|
||||
method: 'post',␍
|
||||
data: {␍
|
||||
id,␍
|
||||
message␍
|
||||
}␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function closeTicket(id) {␍
|
||||
return request({␍
|
||||
url: '/user/ticket/close',␍
|
||||
method: 'post',␍
|
||||
data: {␍
|
||||
id␍
|
||||
}␍
|
||||
});␍
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
␍
|
||||
import request from './request';␍
|
||||
␍
|
||||
␍
|
||||
export function getTrafficLog() {␍
|
||||
return request({␍
|
||||
url: '/user/stat/getTrafficLog',␍
|
||||
method: 'get'␍
|
||||
});␍
|
||||
}
|
||||
Vendored
+170
@@ -0,0 +1,170 @@
|
||||
|
||||
|
||||
import request from './request';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export function getUserInfo() {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/info',
|
||||
|
||||
method: 'get'
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export function getIpLocationInfo() {
|
||||
|
||||
return request({
|
||||
|
||||
url: 'https://myip.ipip.net/json',
|
||||
|
||||
method: 'get',
|
||||
|
||||
baseURL: ''
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export function redeemGiftCard(giftcard) {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/redeemgiftcard',
|
||||
|
||||
method: 'post',
|
||||
|
||||
data: { giftcard }
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export function changePassword(data) {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/changePassword',
|
||||
|
||||
method: 'post',
|
||||
|
||||
data
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export function resetSecurity() {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/resetSecurity',
|
||||
|
||||
method: 'get'
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export function updateRemindSettings(data) {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/update',
|
||||
|
||||
method: 'post',
|
||||
|
||||
data
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export function getActiveSession() {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/getActiveSession',
|
||||
|
||||
method: 'get'
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export function getCommConfig() {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/comm/config',
|
||||
|
||||
method: 'get'
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export function getTelegramBotInfo() {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/telegram/getBotInfo',
|
||||
|
||||
method: 'get'
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export function getUserSubscribe() {
|
||||
|
||||
return request({
|
||||
|
||||
url: '/user/getSubscribe',
|
||||
|
||||
method: 'get'
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
import CryptoJS from "crypto-js";
|
||||
|
||||
const key = window.EZ_CONFIG.API_MIDDLEWARE_KEY;
|
||||
|
||||
// 获取或生成 IV
|
||||
export const randomIv = () => {
|
||||
const saveIv = localStorage.getItem('temp_iv');
|
||||
if (saveIv) {
|
||||
return saveIv;
|
||||
} else {
|
||||
const b = new Uint8Array(8);
|
||||
crypto.getRandomValues(b);
|
||||
const hex = Array.from(b, x => x.toString(16).padStart(2, '0')).join('');
|
||||
localStorage.setItem('temp_iv', hex);
|
||||
|
||||
return hex;
|
||||
}
|
||||
};
|
||||
|
||||
// 加密方法
|
||||
export function Encrypt(data, k, i) {
|
||||
try {
|
||||
const key = CryptoJS.enc.Utf8.parse(k); // 十六位十六进制数作为密钥
|
||||
const iv = CryptoJS.enc.Utf8.parse(i); // 十六位十六进制数作为密钥偏移量
|
||||
var srcs = CryptoJS.enc.Utf8.parse(data);
|
||||
var encrypted = CryptoJS.AES.encrypt(srcs, key, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
});
|
||||
return encrypted.toString();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
// 解密方法
|
||||
export function Decrypt(data, k, i) {
|
||||
try {
|
||||
const key = CryptoJS.enc.Utf8.parse(k); // 十六位十六进制数作为密钥
|
||||
const iv = CryptoJS.enc.Utf8.parse(i); // 十六位十六进制数作为密钥偏移量
|
||||
var decrypt = CryptoJS.AES.decrypt(data, key, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
});
|
||||
var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
|
||||
return decryptedStr.toString();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
export const getEncrypUrl = (url) => {
|
||||
const iv = randomIv();
|
||||
const encrypted = Encrypt(url, key, iv);
|
||||
return encrypted;
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
|
||||
|
||||
const pathMappings = {
|
||||
'/guest/comm/config': '/g/conf',
|
||||
'/user/comm/config': '/c/conf',
|
||||
|
||||
'/passport/auth/login': '/auth/login',
|
||||
'/passport/auth/register': '/auth/reg',
|
||||
'/passport/auth/forget': '/auth/forget',
|
||||
'/passport/auth/token2Login': '/auth/token2Login',
|
||||
'/passport/comm/sendEmailVerify': '/mail/verify',
|
||||
'/user/checkLogin': '/auth/check',
|
||||
|
||||
'/user/info': '/u/info',
|
||||
'/user/changePassword': '/u/pwd',
|
||||
'/user/resetSecurity': '/u/reset',
|
||||
'/user/update': '/u/update',
|
||||
'/user/redeemgiftcard': '/u/gift',
|
||||
'/user/getActiveSession': '/u/session',
|
||||
|
||||
'/user/getSubscribe': '/sub/get',
|
||||
'/user/getStat': '/stat/get',
|
||||
'/user/stat/getTrafficLog': '/traffic/log',
|
||||
|
||||
'/user/plan/fetch': '/plan/list',
|
||||
'/user/coupon/check': '/coup/check',
|
||||
'/user/order/save': '/order/new',
|
||||
'/user/order/fetch': '/order/list',
|
||||
'/user/order/detail': '/order/detail',
|
||||
'/user/order/cancel': '/order/cancel',
|
||||
'/user/order/checkout': '/order/pay',
|
||||
'/user/order/check': '/order/check',
|
||||
'/user/order/getPaymentMethod': '/pay/methods',
|
||||
|
||||
'/user/server/fetch': '/node/list',
|
||||
|
||||
'/user/ticket/fetch': '/ticket/list',
|
||||
'/user/ticket/save': '/ticket/new',
|
||||
'/user/ticket/reply': '/ticket/reply',
|
||||
'/user/ticket/close': '/ticket/close',
|
||||
'/user/ticket/withdraw': '/withdraw',
|
||||
|
||||
'/user/invite/fetch': '/inv/info',
|
||||
'/user/invite/save': '/inv/new',
|
||||
'/user/invite/details': '/inv/detail',
|
||||
'/user/transfer': '/comm/transfer',
|
||||
|
||||
'/user/notice/fetch': '/notice/list',
|
||||
|
||||
'/user/knowledge/fetch': '/knowledge/list'
|
||||
};
|
||||
|
||||
|
||||
export function mapApiPath(originalPath) {
|
||||
try {
|
||||
if (!window.EZ_CONFIG || !window.EZ_CONFIG.API_MIDDLEWARE_ENABLED) {
|
||||
return originalPath;
|
||||
}
|
||||
|
||||
const [path, query] = originalPath.split('?');
|
||||
|
||||
if (pathMappings[path]) {
|
||||
return query ? `${pathMappings[path]}?${query}` : pathMappings[path];
|
||||
}
|
||||
|
||||
let matchedPrefix = '';
|
||||
let mappedPath = '';
|
||||
|
||||
Object.keys(pathMappings).forEach(prefix => {
|
||||
if (path.startsWith(prefix) && prefix.length > matchedPrefix.length) {
|
||||
matchedPrefix = prefix;
|
||||
mappedPath = pathMappings[prefix];
|
||||
}
|
||||
});
|
||||
|
||||
if (matchedPrefix) {
|
||||
const remainingPath = path.slice(matchedPrefix.length);
|
||||
const newPath = mappedPath + remainingPath;
|
||||
return query ? `${newPath}?${query}` : newPath;
|
||||
}
|
||||
|
||||
return originalPath;
|
||||
} catch (error) {
|
||||
console.error('路径映射错误:', error);
|
||||
return originalPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function parseQueryParams(url) {
|
||||
try {
|
||||
const queryString = url.split('?')[1];
|
||||
if (!queryString) return {};
|
||||
|
||||
const params = {};
|
||||
queryString.split('&').forEach(param => {
|
||||
const [key, value] = param.split('=');
|
||||
params[key] = decodeURIComponent(value || '');
|
||||
});
|
||||
|
||||
return params;
|
||||
} catch (error) {
|
||||
console.error('查询参数解析错误:', error);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
mapApiPath,
|
||||
parseQueryParams
|
||||
};
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
␍
|
||||
import request from './request';␍
|
||||
␍
|
||||
␍
|
||||
export function getUserConfig() {␍
|
||||
return request({␍
|
||||
url: '/user/comm/config',␍
|
||||
method: 'get'␍
|
||||
});␍
|
||||
}␍
|
||||
␍
|
||||
␍
|
||||
export function createOrderDeposit(amount) {␍
|
||||
return request({␍
|
||||
url: '/user/order/save',␍
|
||||
method: 'post',␍
|
||||
data: {␍
|
||||
period: 'deposit',␍
|
||||
deposit_amount: amount,␍
|
||||
plan_id: 0
|
||||
}␍
|
||||
});␍
|
||||
}␍
|
||||
|
||||
Reference in new issue
Block a user