Jelajahi Sumber

上传文件至 'src/service'

deng 1 tahun lalu
induk
melakukan
16854e1975
2 mengubah file dengan 102 tambahan dan 0 penghapusan
  1. 46 0
      src/service/api.js
  2. 56 0
      src/service/request.js

+ 46 - 0
src/service/api.js

@@ -0,0 +1,46 @@
+import request from "./request";
+
+export const DownLoad = params => request({
+    url: "file",
+    params,
+});
+export const GetAnnouncement = params => request({
+    url: "jt/announcement",
+    params,
+});
+export const GetContact = params => request({
+    url: "jt/contact",
+    params,
+});
+export const GetDesc = params => request({
+    url: "jt/desc",
+    params,
+});
+export const GetDf = params => request({
+    url: "jt/df",
+    params,
+});
+export const GetHw = params => request({
+    url: "jt/hw",
+    params,
+});
+export const GetLx = params => request({
+    url: "jt/lx",
+    params,
+});
+export const GetNews = params => request({
+    url: "jt/news",
+    params,
+});
+export const GetPage_pic = params => request({
+    url: "jt/page_pic",
+    params,
+});
+export const GetProject = params => request({
+    url: "jt/program",
+    params,
+});
+export const GetVision = params => request({
+    url: "jt/vision",
+    params,
+});

+ 56 - 0
src/service/request.js

@@ -0,0 +1,56 @@
+import axios from "axios"
+import { message } from "antd";
+
+const prefix = '/api/v1/';
+
+const request = axios.create({
+    baseURL: `${prefix}`,
+    timeout: 50000,
+    method:"get",
+})
+
+request.interceptors.request.use(config => {
+    if (config?.params?.current) {
+        config.params.page = config.params.current
+        delete config.params.current
+    }
+    if (config?.params?.pageSize) {
+        config.params.page_size = config.params.pageSize
+        delete config.params.pageSize
+    }
+
+    if (config?.data?.method) {
+        delete config.data.method
+    }
+    return config
+})
+
+
+
+request.interceptors.response.use(response => {
+    let res = response.data;
+    if (!res.code) {
+        if (res.data?.list) {
+            return {
+                success: true,
+                data: res.data.list,
+                total: res.data.total,
+                ...res.data
+            }
+        }
+    }
+
+    if (res.code) {
+        const error = res.message
+        message.error(error)
+        throw error
+    }
+    return res
+}, async error => {
+    if (error && error.response && error.response.status !== 200) {
+        message.error("服务器异常")
+        throw error
+    }
+})
+
+export default request