主要内容: - 包含12个产业的完整教务系统前端代码 - 智能启动脚本 (start-industry.sh) - 可视化产业导航页面 (index.html) - 项目文档 (README.md) 优化内容: - 删除所有node_modules和.yoyo文件夹,从7.5GB减少到2.7GB - 添加.gitignore文件避免上传不必要的文件 - 自动依赖管理和智能启动系统 产业列表: 1. 文旅产业 (5150) 2. 智能制造 (5151) 3. 智能开发 (5152) 4. 财经商贸 (5153) 5. 视觉设计 (5154) 6. 交通物流 (5155) 7. 大健康 (5156) 8. 土木水利 (5157) 9. 食品产业 (5158) 10. 化工产业 (5159) 11. 能源产业 (5160) 12. 环保产业 (5161) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
85 lines
1.9 KiB
JavaScript
85 lines
1.9 KiB
JavaScript
// 引入axios
|
||
import axios from "axios";
|
||
import store from "@/store/index";
|
||
import {
|
||
showGlobalLoading,
|
||
hideGlobalLoading,
|
||
} from "@/store/slices/loadingSlice";
|
||
const baseURL = import.meta.env.VITE_API_BASE_URL || "http://localhost:3000";
|
||
|
||
// 全局加载状态loading,基于redux
|
||
const handleGlobalLoading = (namespace, type) => {
|
||
if (!namespace) return;
|
||
store.dispatch(
|
||
type === "show"
|
||
? showGlobalLoading({ namespace })
|
||
: hideGlobalLoading({ namespace })
|
||
);
|
||
};
|
||
// 创建axios实例
|
||
const axiosInstance = axios.create({
|
||
baseURL, // 基础URL
|
||
timeout: 10000, // 请求超时时间
|
||
headers: {
|
||
"Content-Type": "application/json;charset=utf-8",
|
||
},
|
||
});
|
||
|
||
// 请求拦截器
|
||
axiosInstance.interceptors.request.use(
|
||
(config) => {
|
||
// 开发阶段使用固定的 x-user-id
|
||
// 这个ID对应种子数据中的开发默认用户
|
||
config.headers["x-user-id"] = "dev-user-id";
|
||
|
||
// 后续对接飞书后使用token
|
||
// const token = localStorage.getItem("token");
|
||
// if (token) {
|
||
// config.headers["Authorization"] = `Bearer ${token}`;
|
||
// }
|
||
return config;
|
||
},
|
||
(error) => {
|
||
return Promise.reject(error);
|
||
}
|
||
);
|
||
|
||
// 响应拦截器
|
||
axiosInstance.interceptors.response.use(
|
||
(response) => {
|
||
// 处理响应数据
|
||
const res = response.data;
|
||
return res;
|
||
},
|
||
(error) => {
|
||
// 处理响应错误
|
||
console.error("请求错误:", error);
|
||
const message =
|
||
error.response?.data?.message || error.message || "网络错误";
|
||
return Promise.reject(new Error(message));
|
||
}
|
||
);
|
||
|
||
// 导出请求方法
|
||
export default function request({
|
||
url,
|
||
apiUrl,
|
||
namespace,
|
||
method = "get",
|
||
data,
|
||
params,
|
||
headers = {},
|
||
}) {
|
||
handleGlobalLoading(namespace, "show");
|
||
// 返回Promise对象
|
||
return axiosInstance({
|
||
method,
|
||
url: `${apiUrl ? apiUrl : baseURL}${url}`,
|
||
data,
|
||
params,
|
||
headers,
|
||
}).finally(() => {
|
||
handleGlobalLoading(namespace, "hide");
|
||
});
|
||
}
|