diff --git a/src/api/detail.ts b/src/api/detail.ts new file mode 100644 index 0000000..78c51d2 --- /dev/null +++ b/src/api/detail.ts @@ -0,0 +1,19 @@ +import { request } from '@/utils/request'; +import type { ProjectListResult, PurchaseListResult } from '@/api/model/detailModel'; + +const Api = { + PurchaseList: '/get-purchase-list', + ProjectList: '/get-project-list', +}; + +export function getPurchaseList() { + return request.get({ + url: Api.PurchaseList, + }); +} + +export function getProjectList() { + return request.get({ + url: Api.ProjectList, + }); +} diff --git a/src/api/list.ts b/src/api/list.ts new file mode 100644 index 0000000..e84218b --- /dev/null +++ b/src/api/list.ts @@ -0,0 +1,19 @@ +import { request } from '@/utils/request'; +import type { CardListResult, ListResult } from '@/api/model/listModel'; + +const Api = { + BaseList: '/get-list', + CardList: '/get-card-list', +}; + +export function getList() { + return request.get({ + url: Api.BaseList, + }); +} + +export function getCardList() { + return request.get({ + url: Api.CardList, + }); +} diff --git a/src/api/model/detailModel.ts b/src/api/model/detailModel.ts new file mode 100644 index 0000000..c144b48 --- /dev/null +++ b/src/api/model/detailModel.ts @@ -0,0 +1,23 @@ +export interface PurchaseListResult { + list: Array; +} +export interface PurchaseInfo { + adminName: string; + index: string; + pdName: string; + pdNum: string; + pdType: string; + purchaseNum: number; + updateTime: Date; +} + +export interface ProjectListResult { + list: Array; +} +export interface ProjectInfo { + adminName: string; + adminPhone: string; + index: number; + name: string; + updateTime: Date; +} diff --git a/src/api/model/listModel.ts b/src/api/model/listModel.ts new file mode 100644 index 0000000..453114d --- /dev/null +++ b/src/api/model/listModel.ts @@ -0,0 +1,26 @@ +export interface ListResult { + list: Array; +} +export interface ListModel { + adminName: string; + amount: string; + contractType: number; + index: number; + name: string; + no: string; + paymentType: number; + status: number; + updateTime: Date; +} + +export interface CardListResult { + list: Array; +} +export interface CardList { + banner: string; + description: string; + index: number; + isSetup: boolean; + name: string; + type: number; +} diff --git a/src/pages/detail/advanced/index.vue b/src/pages/detail/advanced/index.vue index 7da16be..fe61985 100644 --- a/src/pages/detail/advanced/index.vue +++ b/src/pages/detail/advanced/index.vue @@ -120,8 +120,7 @@ export default { import { ref, onMounted } from 'vue'; import { prefix } from '@/config/global'; import { BASE_INFO_DATA, TABLE_COLUMNS_DATA as columns, PRODUCT_LIST } from './constants'; -import { request } from '@/utils/request'; -import { ResDataType } from '@/types/interface'; +import { getPurchaseList } from '@/api/detail'; import Product from './components/Product.vue'; @@ -145,15 +144,12 @@ const stepUpdate = () => { const fetchData = async () => { try { - const res: ResDataType = await request.get({ url: '/api/get-purchase-list' }); - if (res.code === 0) { - const { list = [] } = res.data; - data.value = list; - pagination.value = { - ...pagination.value, - total: list.length, - }; - } + const { list } = await getPurchaseList(); + data.value = list; + pagination.value = { + ...pagination.value, + total: list.length, + }; } catch (e) { console.log(e); } diff --git a/src/pages/detail/deploy/index.vue b/src/pages/detail/deploy/index.vue index 9b26352..2f6921e 100644 --- a/src/pages/detail/deploy/index.vue +++ b/src/pages/detail/deploy/index.vue @@ -89,8 +89,7 @@ import { BASE_INFO_DATA, TABLE_COLUMNS as columns } from './constants'; import { changeChartsTheme } from '@/utils/color'; import { prefix } from '@/config/global'; -import { ResDataType } from '@/types/interface'; -import { request } from '@/utils/request'; +import { getProjectList } from '@/api/detail'; echarts.use([ TitleComponent, @@ -115,15 +114,12 @@ const pagination = ref({ const fetchData = async () => { try { - const res: ResDataType = await request.get({ url: '/api/get-project-list' }); - if (res.code === 0) { - const { list = [] } = res.data; - data.value = list; - pagination.value = { - ...pagination.value, - total: list.length, - }; - } + const { list } = await getProjectList(); + data.value = list; + pagination.value = { + ...pagination.value, + total: list.length, + }; } catch (e) { console.log(e); } diff --git a/src/pages/list/base/index.vue b/src/pages/list/base/index.vue index e8e5151..889c8e1 100644 --- a/src/pages/list/base/index.vue +++ b/src/pages/list/base/index.vue @@ -81,8 +81,7 @@ import { MessagePlugin } from 'tdesign-vue-next'; import { CONTRACT_STATUS, CONTRACT_TYPES, CONTRACT_PAYMENT_TYPES } from '@/constants'; import Trend from '@/components/trend/index.vue'; -import { ResDataType } from '@/types/interface'; -import { request } from '@/utils/request'; +import { getList } from '@/api/list'; import { useSettingStore } from '@/store'; import { COLUMNS } from './constants'; @@ -102,15 +101,12 @@ const dataLoading = ref(false); const fetchData = async () => { dataLoading.value = true; try { - const res: ResDataType = await request.get({ url: '/api/get-list' }); - if (res.code === 0) { - const { list = [] } = res.data; - data.value = list; - pagination.value = { - ...pagination.value, - total: list.length, - }; - } + const { list } = await getList(); + data.value = list; + pagination.value = { + ...pagination.value, + total: list.length, + }; } catch (e) { console.log(e); } finally { diff --git a/src/pages/list/card/index.vue b/src/pages/list/card/index.vue index beef005..c6f7679 100644 --- a/src/pages/list/card/index.vue +++ b/src/pages/list/card/index.vue @@ -73,8 +73,7 @@ import { SearchIcon } from 'tdesign-icons-vue-next'; import { MessagePlugin } from 'tdesign-vue-next'; import ProductCard from '@/components/product-card/index.vue'; import DialogForm from './components/DialogForm.vue'; -import { request } from '@/utils/request'; -import { ResDataType } from '@/types/interface'; +import { getCardList } from '@/api/list'; const INITIAL_DATA = { name: '', @@ -93,15 +92,12 @@ const dataLoading = ref(true); const fetchData = async () => { try { - const res: ResDataType = await request.get({ url: '/api/get-card-list' }); - if (res.code === 0) { - const { list = [] } = res.data; - productList.value = list; - pagination.value = { - ...pagination.value, - total: list.length, - }; - } + const { list } = await getCardList(); + productList.value = list; + pagination.value = { + ...pagination.value, + total: list.length, + }; } catch (e) { console.log(e); } finally { diff --git a/src/pages/list/components/CommonTable.vue b/src/pages/list/components/CommonTable.vue index b91e931..eef4454 100644 --- a/src/pages/list/components/CommonTable.vue +++ b/src/pages/list/components/CommonTable.vue @@ -116,8 +116,7 @@ import { ref, computed, onMounted } from 'vue'; import { MessagePlugin } from 'tdesign-vue-next'; import Trend from '@/components/trend/index.vue'; -import { request } from '@/utils/request'; -import { ResDataType } from '@/types/interface'; +import { getList } from '@/api/list'; import { useSettingStore } from '@/store'; import { @@ -198,15 +197,12 @@ const dataLoading = ref(false); const fetchData = async () => { dataLoading.value = true; try { - const res: ResDataType = await request.get({ url: '/api/get-list' }); - if (res.code === 0) { - const { list = [] } = res.data; - data.value = list; - pagination.value = { - ...pagination.value, - total: list.length, - }; - } + const { list } = await getList(); + data.value = list; + pagination.value = { + ...pagination.value, + total: list.length, + }; } catch (e) { console.log(e); } finally { diff --git a/src/types/axios.d.ts b/src/types/axios.d.ts index 0a28f0c..6f044c2 100644 --- a/src/types/axios.d.ts +++ b/src/types/axios.d.ts @@ -19,9 +19,7 @@ export interface RequestOptions { export interface Result { code: number; - type: 'success' | 'error' | 'warning'; - message: string; - result: T; + data: T; } export interface AxiosRequestConfigRetry extends AxiosRequestConfig { diff --git a/src/types/interface.d.ts b/src/types/interface.d.ts index 4a201b8..7299deb 100644 --- a/src/types/interface.d.ts +++ b/src/types/interface.d.ts @@ -1,11 +1,6 @@ import { RouteRecordName } from 'vue-router'; import STYLE_CONFIG from '@/config/style'; -export interface ResDataType { - code: number; - data: any; -} - export interface MenuRoute { path: string; title?: string; diff --git a/src/utils/request/index.ts b/src/utils/request/index.ts index 7fe70f6..5828458 100644 --- a/src/utils/request/index.ts +++ b/src/utils/request/index.ts @@ -40,16 +40,16 @@ const transform: AxiosTransform = { throw new Error('请求接口错误'); } - // 这里 message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式 - const { message } = data; + // 这里 code为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式 + const { code } = data; // 这里逻辑可以根据项目进行修改 - const hasSuccess = data && !Reflect.has(data, 'error'); + const hasSuccess = data && code === 0; if (hasSuccess) { - return data; + return data.data; } - throw new Error(message); + throw new Error(`请求接口错误, 错误码: ${code}`); }, // 请求前处理配置 @@ -162,7 +162,7 @@ function createAxios(opt?: Partial) { // 接口地址 apiUrl: host, // 是否自动添加接口前缀 - isJoinPrefix: false, + isJoinPrefix: true, // 接口前缀 // 例如: https://www.baidu.com/api // urlPrefix: '/api'