104 lines
2.7 KiB
JavaScript
104 lines
2.7 KiB
JavaScript
|
|
/**
|
|||
|
|
* API 统一入口
|
|||
|
|
* 集中管理所有 API 模块
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
import auth from './auth.js'
|
|||
|
|
import apartment from './apartment.js'
|
|||
|
|
import room from './room.js'
|
|||
|
|
import tenant from './tenant.js'
|
|||
|
|
import renter from './renter.js'
|
|||
|
|
import rental from './rental.js'
|
|||
|
|
import statistics from './statistics.js'
|
|||
|
|
import bill from './bill.js'
|
|||
|
|
import meterReading from './meterReading.js'
|
|||
|
|
import setting from './setting.js'
|
|||
|
|
import billing from './billing.js'
|
|||
|
|
|
|||
|
|
// 为每个API模块添加别名方法,以兼容不同调用方式
|
|||
|
|
const addAliases = (apiModule) => {
|
|||
|
|
// 如果模块有 getList 但没有 list,添加 list 别名
|
|||
|
|
if (apiModule.getList && !apiModule.list) {
|
|||
|
|
apiModule.list = apiModule.getList
|
|||
|
|
}
|
|||
|
|
// 如果模块有 list 但没有 getList,添加 getList 别名
|
|||
|
|
if (apiModule.list && !apiModule.getList) {
|
|||
|
|
apiModule.getList = apiModule.list
|
|||
|
|
}
|
|||
|
|
// 同样处理 getDetail 和 detail
|
|||
|
|
if (apiModule.getDetail && !apiModule.detail) {
|
|||
|
|
apiModule.detail = apiModule.getDetail
|
|||
|
|
}
|
|||
|
|
if (apiModule.detail && !apiModule.getDetail) {
|
|||
|
|
apiModule.getDetail = apiModule.detail
|
|||
|
|
}
|
|||
|
|
// 处理 statistics 相关别名
|
|||
|
|
if (apiModule.getDashboard && !apiModule.getDashboardStats) {
|
|||
|
|
apiModule.getDashboardStats = apiModule.getDashboard
|
|||
|
|
}
|
|||
|
|
if (apiModule.getApartmentStats && !apiModule.getApartmentRoomStatusStats) {
|
|||
|
|
apiModule.getApartmentRoomStatusStats = apiModule.getApartmentStats
|
|||
|
|
}
|
|||
|
|
// 处理 bill 统计别名
|
|||
|
|
if (apiModule.getStatistics && !apiModule.getBillStats) {
|
|||
|
|
apiModule.getBillStats = apiModule.getStatistics
|
|||
|
|
}
|
|||
|
|
return apiModule
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 处理所有API模块
|
|||
|
|
const authApi = addAliases(auth)
|
|||
|
|
const apartmentApi = addAliases(apartment)
|
|||
|
|
const roomApi = addAliases(room)
|
|||
|
|
const tenantApi = addAliases(tenant)
|
|||
|
|
const renterApi = addAliases(renter)
|
|||
|
|
const rentalApi = addAliases(rental)
|
|||
|
|
const statisticsApi = addAliases(statistics)
|
|||
|
|
const billApi = addAliases(bill)
|
|||
|
|
const meterReadingApi = addAliases(meterReading)
|
|||
|
|
const settingApi = addAliases(setting)
|
|||
|
|
const billingApi = addAliases(billing)
|
|||
|
|
|
|||
|
|
// API 模块集合
|
|||
|
|
const api = {
|
|||
|
|
auth: authApi,
|
|||
|
|
apartment: apartmentApi,
|
|||
|
|
room: roomApi,
|
|||
|
|
tenant: tenantApi,
|
|||
|
|
renter: renterApi,
|
|||
|
|
rental: rentalApi,
|
|||
|
|
statistics: statisticsApi,
|
|||
|
|
bill: billApi,
|
|||
|
|
meterReading: meterReadingApi,
|
|||
|
|
setting: settingApi,
|
|||
|
|
billing: billingApi
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 导出各模块 API
|
|||
|
|
export {
|
|||
|
|
authApi,
|
|||
|
|
apartmentApi,
|
|||
|
|
roomApi,
|
|||
|
|
tenantApi,
|
|||
|
|
renterApi,
|
|||
|
|
rentalApi,
|
|||
|
|
statisticsApi,
|
|||
|
|
billApi,
|
|||
|
|
meterReadingApi,
|
|||
|
|
settingApi,
|
|||
|
|
billingApi
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 安装函数 - 用于 Vue 插件安装
|
|||
|
|
* @param {Object} Vue - Vue 实例
|
|||
|
|
* @param {Object} options - 配置选项
|
|||
|
|
*/
|
|||
|
|
export const install = (Vue, options = {}) => {
|
|||
|
|
// 将 API 挂载到 Vue 原型
|
|||
|
|
Vue.prototype.$api = api
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 默认导出
|
|||
|
|
export default api
|