add
This commit is contained in:
@@ -289,7 +289,7 @@ const shareToFriend = () => {
|
|||||||
? "扫码查看幸福查推广信息"
|
? "扫码查看幸福查推广信息"
|
||||||
: "扫码申请幸福查代理权限",
|
: "扫码申请幸福查代理权限",
|
||||||
link: shareUrl,
|
link: shareUrl,
|
||||||
imgUrl: "https://www.www.xingfucha.cn/logo.jpg"
|
imgUrl: "https://www.xingfucha.cn/logo.jpg"
|
||||||
};
|
};
|
||||||
|
|
||||||
configWeixinShare(shareConfig);
|
configWeixinShare(shareConfig);
|
||||||
|
|||||||
@@ -3,10 +3,32 @@ import { createFetch } from "@vueuse/core";
|
|||||||
import router from "@/router"; // 假设你使用 Vue Router
|
import router from "@/router"; // 假设你使用 Vue Router
|
||||||
import { useUserStore } from "@/stores/userStore";
|
import { useUserStore } from "@/stores/userStore";
|
||||||
import { useAgentStore } from "@/stores/agentStore";
|
import { useAgentStore } from "@/stores/agentStore";
|
||||||
|
|
||||||
|
// 将服务端返回的 "ErrCode:xxx,ErrMsg:xxx" 纯文本转为 JSON,避免 JSON 解析报错
|
||||||
|
const safeJsonFetch = async (input, init) => {
|
||||||
|
const response = await fetch(input, init);
|
||||||
|
const text = await response.text();
|
||||||
|
try {
|
||||||
|
JSON.parse(text);
|
||||||
|
return new Response(text, { status: response.status, statusText: response.statusText, headers: response.headers });
|
||||||
|
} catch {
|
||||||
|
const match = text.match(/ErrCode:(\d+)[,,]\s*ErrMsg:(.*)/s);
|
||||||
|
const jsonBody = match
|
||||||
|
? JSON.stringify({ code: parseInt(match[1], 10), msg: (match[2] || '').trim() || '请求失败' })
|
||||||
|
: JSON.stringify({ code: 500, msg: text || '请求失败,请稍后重试' });
|
||||||
|
return new Response(jsonBody, {
|
||||||
|
status: response.status,
|
||||||
|
statusText: response.statusText,
|
||||||
|
headers: new Headers({ ...Object.fromEntries(response.headers.entries()), 'Content-Type': 'application/json' }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// 创建全局的 fetch 实例
|
// 创建全局的 fetch 实例
|
||||||
const useApiFetch = createFetch({
|
const useApiFetch = createFetch({
|
||||||
baseUrl: "/api/v1", // 你的 API 基础路径
|
baseUrl: "/api/v1", // 你的 API 基础路径
|
||||||
options: {
|
options: {
|
||||||
|
fetch: safeJsonFetch,
|
||||||
async beforeFetch({ url, options }) {
|
async beforeFetch({ url, options }) {
|
||||||
showLoadingToast({
|
showLoadingToast({
|
||||||
message: "加载中...",
|
message: "加载中...",
|
||||||
@@ -39,35 +61,50 @@ const useApiFetch = createFetch({
|
|||||||
},
|
},
|
||||||
async afterFetch({ data, response }) {
|
async afterFetch({ data, response }) {
|
||||||
closeToast();
|
closeToast();
|
||||||
|
// 兼容 code/msg 与 errcode/errmsg 两种响应格式
|
||||||
|
const code = data?.code ?? data?.errcode;
|
||||||
|
const msg = data?.msg ?? data?.errmsg ?? '';
|
||||||
|
|
||||||
// 全局处理响应
|
// 全局处理响应
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
// 清除本地存储的 token
|
// 有错误文案时先弹出让用户看到
|
||||||
|
if (msg) {
|
||||||
|
showToast({ message: msg });
|
||||||
|
}
|
||||||
localStorage.removeItem("token");
|
localStorage.removeItem("token");
|
||||||
localStorage.removeItem('refreshAfter')
|
localStorage.removeItem('refreshAfter')
|
||||||
localStorage.removeItem('accessExpire')
|
localStorage.removeItem('accessExpire')
|
||||||
// 跳转到登录页
|
|
||||||
router.replace("/login");
|
router.replace("/login");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.code !== 200) {
|
if (code !== undefined && code !== 200) {
|
||||||
if (data.code === 100009) {
|
if (code === 100009) {
|
||||||
// 改进的存储管理
|
if (msg) showToast({ message: msg });
|
||||||
localStorage.removeItem('token')
|
localStorage.removeItem('token')
|
||||||
localStorage.removeItem('refreshAfter')
|
localStorage.removeItem('refreshAfter')
|
||||||
localStorage.removeItem('accessExpire')
|
localStorage.removeItem('accessExpire')
|
||||||
localStorage.removeItem('userInfo')
|
localStorage.removeItem('userInfo')
|
||||||
localStorage.removeItem('agentInfo')
|
localStorage.removeItem('agentInfo')
|
||||||
|
|
||||||
// 重置状态
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const agentStore = useAgentStore();
|
const agentStore = useAgentStore();
|
||||||
userStore.resetUser()
|
userStore.resetUser()
|
||||||
agentStore.resetAgent()
|
agentStore.resetAgent()
|
||||||
location.reload()
|
location.reload()
|
||||||
|
} else if (code === 100011) {
|
||||||
}
|
// 封禁用户:弹出提示并清理登录状态
|
||||||
if (data.code !== 200002 && data.code !== 200003 && data.code !== 200004 && data.code !== 100009) {
|
showToast({ message: msg || '您已被封禁' });
|
||||||
showToast({ message: data.msg });
|
localStorage.removeItem('token')
|
||||||
|
localStorage.removeItem('refreshAfter')
|
||||||
|
localStorage.removeItem('accessExpire')
|
||||||
|
localStorage.removeItem('userInfo')
|
||||||
|
localStorage.removeItem('agentInfo')
|
||||||
|
const userStore = useUserStore();
|
||||||
|
const agentStore = useAgentStore();
|
||||||
|
userStore.resetUser()
|
||||||
|
agentStore.resetAgent()
|
||||||
|
router.replace("/login");
|
||||||
|
} else if (code !== 200002 && code !== 200003 && code !== 200004) {
|
||||||
|
showToast({ message: msg || '请求失败,请稍后重试' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { data, response };
|
return { data, response };
|
||||||
@@ -75,17 +112,15 @@ const useApiFetch = createFetch({
|
|||||||
async onFetchError({ error, response }) {
|
async onFetchError({ error, response }) {
|
||||||
console.log("error", error);
|
console.log("error", error);
|
||||||
closeToast();
|
closeToast();
|
||||||
if (response.status === 401) {
|
const errMsg = typeof error === "string" ? error : (error?.message || "网络异常,请稍后重试");
|
||||||
// 清除本地存储的 token
|
if (response && response.status === 401) {
|
||||||
|
showToast({ message: errMsg });
|
||||||
localStorage.removeItem("token");
|
localStorage.removeItem("token");
|
||||||
localStorage.removeItem('refreshAfter')
|
localStorage.removeItem('refreshAfter')
|
||||||
localStorage.removeItem('accessExpire')
|
localStorage.removeItem('accessExpire')
|
||||||
// 跳转到登录页
|
|
||||||
router.replace("/login");
|
router.replace("/login");
|
||||||
} else {
|
} else {
|
||||||
if (typeof error === "string") {
|
showToast({ message: errMsg });
|
||||||
showToast({ message: error });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return { error };
|
return { error };
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ export function useWeixinShare() {
|
|||||||
title: "幸福查|大数据风险报告查询与代理平台,支持个人和企业多场景风控应用",
|
title: "幸福查|大数据风险报告查询与代理平台,支持个人和企业多场景风控应用",
|
||||||
desc: "提供个人信用评估、人事背调、信贷风控、企业风险监测等服务",
|
desc: "提供个人信用评估、人事背调、信贷风控、企业风险监测等服务",
|
||||||
link: window.location.href.split("#")[0], // 获取当前页面URL,不包括hash
|
link: window.location.href.split("#")[0], // 获取当前页面URL,不包括hash
|
||||||
imgUrl: "https://www.www.xingfucha.cn/logo.jpg",
|
imgUrl: "https://www.xingfucha.cn/logo.jpg",
|
||||||
};
|
};
|
||||||
|
|
||||||
const config = { ...defaultConfig, ...shareConfig };
|
const config = { ...defaultConfig, ...shareConfig };
|
||||||
@@ -197,28 +197,28 @@ export function useWeixinShare() {
|
|||||||
title: "幸福查 - 大数据风险报告示例",
|
title: "幸福查 - 大数据风险报告示例",
|
||||||
desc: "查看完整的大数据风险报告示例,了解个人信用评估等服务",
|
desc: "查看完整的大数据风险报告示例,了解个人信用评估等服务",
|
||||||
link: window.location.href.split("#")[0],
|
link: window.location.href.split("#")[0],
|
||||||
imgUrl: "https://www.www.xingfucha.cn/logo.jpg",
|
imgUrl: "https://www.xingfucha.cn/logo.jpg",
|
||||||
};
|
};
|
||||||
} else if (route.includes("/agent")) {
|
} else if (route.includes("/agent")) {
|
||||||
shareConfig = {
|
shareConfig = {
|
||||||
title: "幸福查 - 免费开通代理权限",
|
title: "幸福查 - 免费开通代理权限",
|
||||||
desc: "免费开通代理权限,享受大数据风险报告查询服务代理收益",
|
desc: "免费开通代理权限,享受大数据风险报告查询服务代理收益",
|
||||||
link: window.location.href.split("#")[0],
|
link: window.location.href.split("#")[0],
|
||||||
imgUrl: "https://www.www.xingfucha.cn/logo.jpg",
|
imgUrl: "https://www.xingfucha.cn/logo.jpg",
|
||||||
};
|
};
|
||||||
} else if (route.includes("/help")) {
|
} else if (route.includes("/help")) {
|
||||||
shareConfig = {
|
shareConfig = {
|
||||||
title: "幸福查 - 帮助中心",
|
title: "幸福查 - 帮助中心",
|
||||||
desc: "详细的使用指南、常见问题解答、操作教程",
|
desc: "详细的使用指南、常见问题解答、操作教程",
|
||||||
link: window.location.href.split("#")[0],
|
link: window.location.href.split("#")[0],
|
||||||
imgUrl: "https://www.www.xingfucha.cn/logo.jpg",
|
imgUrl: "https://www.xingfucha.cn/logo.jpg",
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
shareConfig = {
|
shareConfig = {
|
||||||
title: "幸福查|大数据风险报告查询与代理平台,支持个人和企业多场景风控应用",
|
title: "幸福查|大数据风险报告查询与代理平台,支持个人和企业多场景风控应用",
|
||||||
desc: "提供个人信用评估、人事背调、信贷风控、企业风险监测等服务",
|
desc: "提供个人信用评估、人事背调、信贷风控、企业风险监测等服务",
|
||||||
link: window.location.href.split("#")[0],
|
link: window.location.href.split("#")[0],
|
||||||
imgUrl: "https://www.www.xingfucha.cn/logo.jpg",
|
imgUrl: "https://www.xingfucha.cn/logo.jpg",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ export default defineConfig({
|
|||||||
strictPort: true, // 如果端口被占用则抛出错误而不是使用下一个可用端口
|
strictPort: true, // 如果端口被占用则抛出错误而不是使用下一个可用端口
|
||||||
proxy: {
|
proxy: {
|
||||||
"/api/v1": {
|
"/api/v1": {
|
||||||
// target: "http://127.0.0.1:8888", // 本地接口地址
|
target: "http://127.0.0.1:8888", // 本地接口地址
|
||||||
target: "https://www.xingfucha.cn", // 本地接口地址
|
// target: "https://www.xingfucha.cn", // 本地接口地址
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ var vite_config_default = defineConfig({
|
|||||||
proxy: {
|
proxy: {
|
||||||
"/api/v1": {
|
"/api/v1": {
|
||||||
// target: "http://127.0.0.1:8888", // 本地接口地址
|
// target: "http://127.0.0.1:8888", // 本地接口地址
|
||||||
target: "https://www.www.xingfucha.cn",
|
target: "https://www.xingfucha.cn",
|
||||||
// 本地接口地址
|
// 本地接口地址
|
||||||
changeOrigin: true
|
changeOrigin: true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user