提交
This commit is contained in:
1388
front-end/app-shared/package-lock.json
generated
Normal file
1388
front-end/app-shared/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
front-end/app-shared/package.json
Normal file
22
front-end/app-shared/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "app-shared",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"dev": "vite --port 5555 --strictPort",
|
||||
"build": "vite build",
|
||||
"serve": "vite preview --port 5555 --strictPort",
|
||||
"all": "npm run build && npm run serve"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.12.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@originjs/vite-plugin-federation": "^1.4.1",
|
||||
"typescript": "~5.8.0",
|
||||
"vite": "^7.0.6"
|
||||
}
|
||||
}
|
||||
5
front-end/app-shared/src/config/HttpConfig.ts
Normal file
5
front-end/app-shared/src/config/HttpConfig.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export class HttpConfig {
|
||||
public static DevBaseUrl: string = "http://127.0.0.1:3000/api"
|
||||
public static prodBaseUrl: string = "http://127.0.0.1:3000/api/"
|
||||
public static apiList: string = ""
|
||||
}
|
||||
4
front-end/app-shared/src/config/ThemeConfig.ts
Normal file
4
front-end/app-shared/src/config/ThemeConfig.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export class ThemeConfig {
|
||||
public static primaryColor: string = '#1890ff'; // 主色调
|
||||
public static layoutType: 'side' | 'top' = 'side'; // 侧边栏布局
|
||||
}
|
||||
2
front-end/app-shared/src/config/index.ts
Normal file
2
front-end/app-shared/src/config/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './HttpConfig';
|
||||
export * from './ThemeConfig';
|
||||
1
front-end/app-shared/src/constants/README.md
Normal file
1
front-end/app-shared/src/constants/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# 临时占位,上传空文件夹,保存文件结构用,后面删除
|
||||
1
front-end/app-shared/src/exceptions/README.md
Normal file
1
front-end/app-shared/src/exceptions/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# 临时占位,上传空文件夹,保存文件结构用,后面删除
|
||||
3
front-end/app-shared/src/index.ts
Normal file
3
front-end/app-shared/src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './infra';
|
||||
export * from './utils';
|
||||
export * from './config';
|
||||
93
front-end/app-shared/src/infra/AxiosInfra.ts
Normal file
93
front-end/app-shared/src/infra/AxiosInfra.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import axios, {AxiosError, type AxiosInstance, type AxiosRequestConfig} from "axios";
|
||||
import {UrlCheckUtils} from '../utils/index'
|
||||
|
||||
|
||||
class AxiosInfra {
|
||||
public instance: AxiosInstance;
|
||||
|
||||
public constructor() {
|
||||
this.instance = axios.create({
|
||||
baseURL: UrlCheckUtils.check(),
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
});
|
||||
this.ResponseInterceptor();
|
||||
this.RequestInterceptor();
|
||||
}
|
||||
|
||||
public async get(params: AxiosRequestConfig): Promise<any> {
|
||||
return await this.instance.get(<string>params.url, {
|
||||
params: params.data,
|
||||
headers: Object.assign({ Authorization: localStorage.getItem("token") }, params.headers)
|
||||
});
|
||||
}
|
||||
|
||||
public async post(params: AxiosRequestConfig): Promise<any> {
|
||||
return await this.instance.post(<string>params.url, params.data, {
|
||||
headers: Object.assign({ Authorization: localStorage.getItem("token") }, params.headers)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Put 请求
|
||||
* 请求参数请参考接口:RequestParams
|
||||
* @param params
|
||||
*/
|
||||
public async put(params: AxiosRequestConfig): Promise<any> {
|
||||
return await this.instance.put(<string>params.url, params.data)
|
||||
}
|
||||
|
||||
/**
|
||||
* delete 请求
|
||||
* 请求参数请参考接口:RequestParams
|
||||
* @param params
|
||||
*/
|
||||
public async delete(params: AxiosRequestConfig): Promise<any> {
|
||||
return await this.instance.delete(<string>params.url, { params: params.data })
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应拦截器
|
||||
* @constructor
|
||||
*/
|
||||
public async ResponseInterceptor(): Promise<any> {
|
||||
this.instance.interceptors.response.use(
|
||||
(response: any) => {
|
||||
return response.data.result;
|
||||
},
|
||||
(error: AxiosError) => {
|
||||
console.log(`
|
||||
❌ 请求错误 ❌
|
||||
1、基地址: ${error.config?.baseURL}
|
||||
2、短地址: ${error.config?.url}
|
||||
3、请求 方式: ${error.config?.method}
|
||||
4、请求 参数: ${JSON.stringify(error.config?.params)}
|
||||
5、请求 头 : ${JSON.stringify(error.config?.headers)}
|
||||
|
||||
------------------------------------------------------------
|
||||
|
||||
6、错误信息为: ${error.message}
|
||||
7、错误代码为: ${error.stack}
|
||||
`);
|
||||
return Promise.reject(error)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加请求拦截器
|
||||
* @constructor
|
||||
*/
|
||||
public async RequestInterceptor(): Promise<any> {
|
||||
this.instance.interceptors.request.use((config: any) => {
|
||||
return config
|
||||
}, function (error: AxiosError) {
|
||||
return Promise.reject(error)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export default new AxiosInfra();
|
||||
1
front-end/app-shared/src/infra/index.ts
Normal file
1
front-end/app-shared/src/infra/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export {default as http} from "./AxiosInfra"
|
||||
1
front-end/app-shared/src/lib/README.md
Normal file
1
front-end/app-shared/src/lib/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# 临时占位,上传空文件夹,保存文件结构用,后面删除
|
||||
1
front-end/app-shared/src/types/env.d.ts
vendored
Normal file
1
front-end/app-shared/src/types/env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
12
front-end/app-shared/src/utils/UrlCheckUtils.ts
Normal file
12
front-end/app-shared/src/utils/UrlCheckUtils.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import {HttpConfig} from '../config'
|
||||
|
||||
export class UrlCheckUtils {
|
||||
|
||||
public static check() {
|
||||
if (import.meta.env.MODE === 'production') {
|
||||
return HttpConfig.prodBaseUrl;
|
||||
} else {
|
||||
return HttpConfig.DevBaseUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
front-end/app-shared/src/utils/index.ts
Normal file
1
front-end/app-shared/src/utils/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './UrlCheckUtils';
|
||||
40
front-end/app-shared/tsconfig.json
Normal file
40
front-end/app-shared/tsconfig.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*.d.ts",
|
||||
"src/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist",
|
||||
"**/*.test.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "bundler",
|
||||
"verbatimModuleSyntax": false,
|
||||
"target": "ES2020",
|
||||
"module": "ESNext",
|
||||
// 模块导出优化
|
||||
"resolveJsonModule": true,
|
||||
// 允许导入JSON文件
|
||||
"isolatedModules": true,
|
||||
// 确保每个文件可被独立转译(Vite等工具要求)
|
||||
"skipLibCheck": true,
|
||||
// 跳过库类型检查,加快编译速度
|
||||
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"./src/app/*"
|
||||
],
|
||||
"@shared/*": [
|
||||
"./src/shared/*"
|
||||
],
|
||||
"@features/*": [
|
||||
"./src/features/*"
|
||||
],
|
||||
"@domains/*": [
|
||||
"./src/domains/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
31
front-end/app-shared/vite.config.ts
Normal file
31
front-end/app-shared/vite.config.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import {defineConfig} from 'vite'
|
||||
import federation from '@originjs/vite-plugin-federation';
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
federation({
|
||||
name: 'shared',
|
||||
exposes: {
|
||||
"./config": "./src/config/index.ts",
|
||||
"./infra": "./src/infra/index.ts",
|
||||
"./utils": "./src/utils/index.ts",
|
||||
},
|
||||
shared: {
|
||||
axios: {generate: false, requiredVersion: '^1.12.2'}
|
||||
}
|
||||
})
|
||||
],
|
||||
build: {
|
||||
target: 'esnext',
|
||||
minify: false,
|
||||
cssCodeSplit: true,
|
||||
rollupOptions: {
|
||||
input: './src/index.ts',
|
||||
output: {
|
||||
format: 'esm',
|
||||
minifyInternalExports: false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user