[fix] 修改了网络请求相关的问题
This commit is contained in:
parent
fd0d380ae9
commit
9840e6d823
|
|
@ -1,5 +1,5 @@
|
||||||
# backend service base url, prod environment
|
# 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
|
# other backend service base url, prod environment
|
||||||
# VITE_OTHER_SERVICE_BASE_URL= `{
|
# VITE_OTHER_SERVICE_BASE_URL= `{
|
||||||
|
|
|
||||||
11
.env.test
11
.env.test
|
|
@ -1,7 +1,8 @@
|
||||||
# backend service base url, test environment
|
# 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
|
# # other backend service base url, test environment
|
||||||
VITE_OTHER_SERVICE_BASE_URL= `{
|
# VITE_OTHER_SERVICE_BASE_URL= `{
|
||||||
"demo": "http://localhost:9528"
|
# "demo": "http://localhost:9528"
|
||||||
}`
|
# }`
|
||||||
|
|
|
||||||
|
|
@ -7,22 +7,44 @@ export {}
|
||||||
/* prettier-ignore */
|
/* prettier-ignore */
|
||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
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']
|
AButton: typeof import('ant-design-vue/es')['Button']
|
||||||
ACard: typeof import('ant-design-vue/es')['Card']
|
ACard: typeof import('ant-design-vue/es')['Card']
|
||||||
|
ACheckbox: typeof import('ant-design-vue/es')['Checkbox']
|
||||||
ACol: typeof import('ant-design-vue/es')['Col']
|
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']
|
AEmpty: typeof import('ant-design-vue/es')['Empty']
|
||||||
AForm: typeof import('ant-design-vue/es')['Form']
|
AForm: typeof import('ant-design-vue/es')['Form']
|
||||||
AFormItem: typeof import('ant-design-vue/es')['FormItem']
|
AFormItem: typeof import('ant-design-vue/es')['FormItem']
|
||||||
AInput: typeof import('ant-design-vue/es')['Input']
|
AInput: typeof import('ant-design-vue/es')['Input']
|
||||||
AInputNumber: typeof import('ant-design-vue/es')['InputNumber']
|
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']
|
AModal: typeof import('ant-design-vue/es')['Modal']
|
||||||
APagination: typeof import('ant-design-vue/es')['Pagination']
|
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']
|
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']
|
ARow: typeof import('ant-design-vue/es')['Row']
|
||||||
|
ASegmented: typeof import('ant-design-vue/es')['Segmented']
|
||||||
ASelect: typeof import('ant-design-vue/es')['Select']
|
ASelect: typeof import('ant-design-vue/es')['Select']
|
||||||
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
|
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']
|
ATable: typeof import('ant-design-vue/es')['Table']
|
||||||
ATag: typeof import('ant-design-vue/es')['Tag']
|
ATag: typeof import('ant-design-vue/es')['Tag']
|
||||||
|
ATooltip: typeof import('ant-design-vue/es')['Tooltip']
|
||||||
ATree: typeof import('ant-design-vue/es')['Tree']
|
ATree: typeof import('ant-design-vue/es')['Tree']
|
||||||
AWatermark: typeof import('ant-design-vue/es')['Watermark']
|
AWatermark: typeof import('ant-design-vue/es')['Watermark']
|
||||||
BetterScroll: typeof import('./../components/custom/better-scroll.vue')['default']
|
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']
|
DarkModeContainer: typeof import('./../components/common/dark-mode-container.vue')['default']
|
||||||
ExceptionBase: typeof import('./../components/common/exception-base.vue')['default']
|
ExceptionBase: typeof import('./../components/common/exception-base.vue')['default']
|
||||||
FullScreen: typeof import('./../components/common/full-screen.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']
|
LangSwitch: typeof import('./../components/common/lang-switch.vue')['default']
|
||||||
LookForward: typeof import('./../components/custom/look-forward.vue')['default']
|
LookForward: typeof import('./../components/custom/look-forward.vue')['default']
|
||||||
MenuToggler: typeof import('./../components/common/menu-toggler.vue')['default']
|
MenuToggler: typeof import('./../components/common/menu-toggler.vue')['default']
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { localStg } from '@/utils/storage';
|
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) => {
|
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
|
const token = localStg.get('token'); // 获取 token
|
||||||
try {
|
try {
|
||||||
const response = await axios({
|
const response = await axios({
|
||||||
|
|
@ -21,8 +23,8 @@ export const apiRequest = async (method: 'GET' | 'POST' | 'PUT' | 'DELETE', path
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const apiRequestGet = async (path: string) => {
|
export const apiRequestGet = async (path: string, params?:any) => {
|
||||||
let url = "http://localhost:8080" + path;
|
let url = baseUrl + path;
|
||||||
const token = localStg.get('token'); // 获取 token
|
const token = localStg.get('token'); // 获取 token
|
||||||
try {
|
try {
|
||||||
return axios.get(
|
return axios.get(
|
||||||
|
|
@ -31,6 +33,26 @@ export const apiRequestGet = async (path: string) => {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`, // 添加 Authorization 头
|
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) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ const selectedKeys = ref([]);
|
||||||
// 获取部门数据
|
// 获取部门数据
|
||||||
const fetchDepartments = async () => {
|
const fetchDepartments = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await apiRequestGet('/api/department/allDepartment');
|
const response = await apiRequestGet('/department/allDepartment');
|
||||||
|
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
// 过滤重复数据并构建树结构
|
// 过滤重复数据并构建树结构
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
import { message, Tag as ATag, Divider as ADivider } from 'ant-design-vue';
|
import { message, Tag as ATag, Divider as ADivider } from 'ant-design-vue';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { localStg } from '@/utils/storage';
|
import { localStg } from '@/utils/storage';
|
||||||
|
import { apiRequestGet } from '@/utils/api';
|
||||||
// 表格列配置
|
// 表格列配置
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
|
|
@ -132,15 +132,11 @@
|
||||||
try {
|
try {
|
||||||
// 请求远端接口
|
// 请求远端接口
|
||||||
const token = localStg.get('token');
|
const token = localStg.get('token');
|
||||||
const response = await axios.get('http://localhost:8080/api/employees/allEmployees', {
|
let params = {
|
||||||
params: {
|
|
||||||
page: pagination.value.current,
|
page: pagination.value.current,
|
||||||
size: pagination.value.pageSize,
|
size: pagination.value.pageSize,
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${token}` // 添加 Authorization 头
|
|
||||||
}
|
}
|
||||||
});
|
const response = await apiRequestGet('/employees/allEmployees', params);
|
||||||
|
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
dataSource.value = response.data.data;
|
dataSource.value = response.data.data;
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ const fetchData = async () => {
|
||||||
code: searchForm.code || undefined,
|
code: searchForm.code || undefined,
|
||||||
type: searchForm.type || undefined,
|
type: searchForm.type || undefined,
|
||||||
};
|
};
|
||||||
const response = await apiRequestGet('/api/facilities/list', { params });
|
const response = await apiRequestGet('/facilities/list', params);
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
dataSource.value = response.data.data;
|
dataSource.value = response.data.data;
|
||||||
pagination.total = response.data.total || response.data.data.length;
|
pagination.total = response.data.total || response.data.data.length;
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
import axios from 'axios'; // 用于 HTTP 请求
|
import axios from 'axios'; // 用于 HTTP 请求
|
||||||
import { useRouter } from 'vue-router'; // 用于导航,假设您使用了 Vue Router
|
import { useRouter } from 'vue-router'; // 用于导航,假设您使用了 Vue Router
|
||||||
import { localStg } from '@/utils/storage';
|
import { localStg } from '@/utils/storage';
|
||||||
|
import { apiRequestPost } from '@/utils/api'; // 假设您有一个 API 请求的工具函数
|
||||||
const formRef = ref(); // 表单引用
|
const formRef = ref(); // 表单引用
|
||||||
const router = useRouter(); // 获取路由实例
|
const router = useRouter(); // 获取路由实例
|
||||||
|
|
||||||
|
|
@ -71,12 +71,7 @@
|
||||||
try {
|
try {
|
||||||
//await formRef.value.validate(); // 验证表单
|
//await formRef.value.validate(); // 验证表单
|
||||||
|
|
||||||
const token = localStg.get('token'); // 替换为你的 token 键
|
const response = await apiRequestPost('/work-orders', formState); // 发送 POST 请求
|
||||||
const response = await axios.post('http://localhost:8080/api/work-orders', formState,{
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${token}` // 添加 Authorization 头
|
|
||||||
}
|
|
||||||
}); // 发送 POST 请求
|
|
||||||
|
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
message.success('工单创建成功!');
|
message.success('工单创建成功!');
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import { ref, onMounted } from 'vue';
|
||||||
import { Table as ATable, Tag as ATag } from 'ant-design-vue';
|
import { Table as ATable, Tag as ATag } from 'ant-design-vue';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { localStg } from '@/utils/storage';
|
import { localStg } from '@/utils/storage';
|
||||||
|
import { apiRequestGet } from '@/utils/api';
|
||||||
// 表格列定义
|
// 表格列定义
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
|
|
@ -131,13 +131,10 @@ const fetchData = async (page = 1, pageSize = 10) => {
|
||||||
const token = localStg.get('token'); // 替换为你的 token 键
|
const token = localStg.get('token'); // 替换为你的 token 键
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get('http://localhost:8080/api/work-orders/my-orders', {
|
const response = await apiRequestGet('/work-orders/my-orders', {
|
||||||
params: {
|
params: {
|
||||||
page: page - 1, // 后端通常从0开始计数
|
page: page - 1, // 后端通常从0开始计数
|
||||||
size: pageSize,
|
size: pageSize,
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${token}` // 添加 Authorization 头
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ export default {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
// 模拟分页参数传递给后端
|
// 模拟分页参数传递给后端
|
||||||
const response = await apiRequestGet("/api/inspection-plans/employee/my-plan")
|
const response = await apiRequestGet("/inspection-plans/employee/my-plan")
|
||||||
|
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
planData.value = response.data.data;
|
planData.value = response.data.data;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue