[fix] 修改了网络请求相关的问题

This commit is contained in:
LiuYuanchi 2025-04-27 12:29:47 +08:00
parent fd0d380ae9
commit 9840e6d823
10 changed files with 78 additions and 32 deletions

View File

@ -1,5 +1,5 @@
# backend service base url, prod environment
VITE_SERVICE_BASE_URL=http://154.219.110.17:8080
VITE_SERVICE_BASE_URL=http://154.219.110.17:8080/api
# other backend service base url, prod environment
# VITE_OTHER_SERVICE_BASE_URL= `{

View File

@ -1,7 +1,8 @@
# backend service base url, test environment
VITE_SERVICE_BASE_URL=http://localhost:8080/api/
VITE_SERVICE_BASE_URL=http://localhost:8080/api
#VITE_SERVICE_BASE_URL=http://154.219.110.17:8080/api
# other backend service base url, test environment
VITE_OTHER_SERVICE_BASE_URL= `{
"demo": "http://localhost:9528"
}`
# # other backend service base url, test environment
# VITE_OTHER_SERVICE_BASE_URL= `{
# "demo": "http://localhost:9528"
# }`

View File

@ -7,22 +7,44 @@ export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
ABreadcrumb: typeof import('ant-design-vue/es')['Breadcrumb']
ABreadcrumbItem: typeof import('ant-design-vue/es')['BreadcrumbItem']
AButton: typeof import('ant-design-vue/es')['Button']
ACard: typeof import('ant-design-vue/es')['Card']
ACheckbox: typeof import('ant-design-vue/es')['Checkbox']
ACol: typeof import('ant-design-vue/es')['Col']
ADescriptions: typeof import('ant-design-vue/es')['Descriptions']
ADescriptionsItem: typeof import('ant-design-vue/es')['DescriptionsItem']
ADivider: typeof import('ant-design-vue/es')['Divider']
ADrawer: typeof import('ant-design-vue/es')['Drawer']
ADropdown: typeof import('ant-design-vue/es')['Dropdown']
AEmpty: typeof import('ant-design-vue/es')['Empty']
AForm: typeof import('ant-design-vue/es')['Form']
AFormItem: typeof import('ant-design-vue/es')['FormItem']
AInput: typeof import('ant-design-vue/es')['Input']
AInputNumber: typeof import('ant-design-vue/es')['InputNumber']
AInputPassword: typeof import('ant-design-vue/es')['InputPassword']
AInputSearch: typeof import('ant-design-vue/es')['InputSearch']
AMenu: typeof import('ant-design-vue/es')['Menu']
AMenuDivider: typeof import('ant-design-vue/es')['MenuDivider']
AMenuItem: typeof import('ant-design-vue/es')['MenuItem']
AModal: typeof import('ant-design-vue/es')['Modal']
APagination: typeof import('ant-design-vue/es')['Pagination']
APopconfirm: typeof import('ant-design-vue/es')['Popconfirm']
APopover: typeof import('ant-design-vue/es')['Popover']
AppProvider: typeof import('./../components/common/app-provider.vue')['default']
ARadio: typeof import('ant-design-vue/es')['Radio']
ARadioGroup: typeof import('ant-design-vue/es')['RadioGroup']
ARow: typeof import('ant-design-vue/es')['Row']
ASegmented: typeof import('ant-design-vue/es')['Segmented']
ASelect: typeof import('ant-design-vue/es')['Select']
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
ASpace: typeof import('ant-design-vue/es')['Space']
AStatistic: typeof import('ant-design-vue/es')['Statistic']
ASwitch: typeof import('ant-design-vue/es')['Switch']
ATable: typeof import('ant-design-vue/es')['Table']
ATag: typeof import('ant-design-vue/es')['Tag']
ATooltip: typeof import('ant-design-vue/es')['Tooltip']
ATree: typeof import('ant-design-vue/es')['Tree']
AWatermark: typeof import('ant-design-vue/es')['Watermark']
BetterScroll: typeof import('./../components/custom/better-scroll.vue')['default']
@ -31,6 +53,19 @@ declare module 'vue' {
DarkModeContainer: typeof import('./../components/common/dark-mode-container.vue')['default']
ExceptionBase: typeof import('./../components/common/exception-base.vue')['default']
FullScreen: typeof import('./../components/common/full-screen.vue')['default']
IconAntDesignReloadOutlined: typeof import('~icons/ant-design/reload-outlined')['default']
IconAntDesignSettingOutlined: typeof import('~icons/ant-design/setting-outlined')['default']
IconCarbonAdd: typeof import('~icons/carbon/add')['default']
IconGridiconsFullscreen: typeof import('~icons/gridicons/fullscreen')['default']
IconGridiconsFullscreenExit: typeof import('~icons/gridicons/fullscreen-exit')['default']
'IconIc:roundPlus': typeof import('~icons/ic/round-plus')['default']
IconIcRoundDelete: typeof import('~icons/ic/round-delete')['default']
IconIcRoundPlus: typeof import('~icons/ic/round-plus')['default']
IconIcRoundRefresh: typeof import('~icons/ic/round-refresh')['default']
IconIcRoundRemove: typeof import('~icons/ic/round-remove')['default']
IconIcRoundSearch: typeof import('~icons/ic/round-search')['default']
IconMdiDrag: typeof import('~icons/mdi/drag')['default']
IconMdiRefresh: typeof import('~icons/mdi/refresh')['default']
LangSwitch: typeof import('./../components/common/lang-switch.vue')['default']
LookForward: typeof import('./../components/custom/look-forward.vue')['default']
MenuToggler: typeof import('./../components/common/menu-toggler.vue')['default']

View File

@ -2,9 +2,11 @@
import axios from 'axios';
import { localStg } from '@/utils/storage';
let baseUrl = import.meta.env.VITE_SERVICE_BASE_URL
// 封装网络请求的接口
export const apiRequest = async (method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, data?: any) => {
let url = "http://localhost:8080" + path;
let url = baseUrl + path;
const token = localStg.get('token'); // 获取 token
try {
const response = await axios({
@ -21,8 +23,8 @@ export const apiRequest = async (method: 'GET' | 'POST' | 'PUT' | 'DELETE', path
}
};
export const apiRequestGet = async (path: string) => {
let url = "http://localhost:8080" + path;
export const apiRequestGet = async (path: string, params?:any) => {
let url = baseUrl + path;
const token = localStg.get('token'); // 获取 token
try {
return axios.get(
@ -31,6 +33,26 @@ export const apiRequestGet = async (path: string) => {
headers: {
Authorization: `Bearer ${token}`, // 添加 Authorization 头
},
params: params,
}
);
} catch (error) {
throw new Error('请求失败'); // 抛出错误
}
};
export const apiRequestPost = async (path: string,data:any, params?:any) => {
let url = baseUrl + path;
const token = localStg.get('token'); // 获取 token
try {
return axios.post(
url,
data,
{
headers: {
Authorization: `Bearer ${token}`, // 添加 Authorization 头
},
params: params,
}
);
} catch (error) {

View File

@ -97,7 +97,7 @@ const selectedKeys = ref([]);
//
const fetchDepartments = async () => {
try {
const response = await apiRequestGet('/api/department/allDepartment');
const response = await apiRequestGet('/department/allDepartment');
if (response.data.success) {
//

View File

@ -31,7 +31,7 @@
import { message, Tag as ATag, Divider as ADivider } from 'ant-design-vue';
import axios from 'axios';
import { localStg } from '@/utils/storage';
import { apiRequestGet } from '@/utils/api';
//
const columns = [
{
@ -132,15 +132,11 @@
try {
//
const token = localStg.get('token');
const response = await axios.get('http://localhost:8080/api/employees/allEmployees', {
params: {
let params = {
page: pagination.value.current,
size: pagination.value.pageSize,
},
headers: {
Authorization: `Bearer ${token}` // Authorization
}
});
const response = await apiRequestGet('/employees/allEmployees', params);
if (response.data.success) {
dataSource.value = response.data.data;

View File

@ -100,7 +100,7 @@ const fetchData = async () => {
code: searchForm.code || undefined,
type: searchForm.type || undefined,
};
const response = await apiRequestGet('/api/facilities/list', { params });
const response = await apiRequestGet('/facilities/list', params);
if (response.data.success) {
dataSource.value = response.data.data;
pagination.total = response.data.total || response.data.data.length;

View File

@ -39,7 +39,7 @@
import axios from 'axios'; // HTTP
import { useRouter } from 'vue-router'; // 使 Vue Router
import { localStg } from '@/utils/storage';
import { apiRequestPost } from '@/utils/api'; // API
const formRef = ref(); //
const router = useRouter(); //
@ -71,12 +71,7 @@
try {
//await formRef.value.validate(); //
const token = localStg.get('token'); // token
const response = await axios.post('http://localhost:8080/api/work-orders', formState,{
headers: {
Authorization: `Bearer ${token}` // Authorization
}
}); // POST
const response = await apiRequestPost('/work-orders', formState); // POST
if (response.data.success) {
message.success('工单创建成功!');

View File

@ -28,7 +28,7 @@ import { ref, onMounted } from 'vue';
import { Table as ATable, Tag as ATag } from 'ant-design-vue';
import axios from 'axios';
import { localStg } from '@/utils/storage';
import { apiRequestGet } from '@/utils/api';
//
const columns = [
{
@ -131,14 +131,11 @@ const fetchData = async (page = 1, pageSize = 10) => {
const token = localStg.get('token'); // token
try {
const response = await axios.get('http://localhost:8080/api/work-orders/my-orders', {
const response = await apiRequestGet('/work-orders/my-orders', {
params: {
page: page - 1, // 0
size: pageSize,
},
headers: {
Authorization: `Bearer ${token}` // Authorization
}
}
});
if (response.data.success) {

View File

@ -112,7 +112,7 @@ export default {
loading.value = true;
try {
//
const response = await apiRequestGet("/api/inspection-plans/employee/my-plan")
const response = await apiRequestGet("/inspection-plans/employee/my-plan")
if (response.data.success) {
planData.value = response.data.data;