Codex Assistant
1 天以前 ba94ceae1315174798ae1967ef62268c6d16cd5b
web/src/api/region.js
@@ -1,6 +1,6 @@
import { API_CONFIG, graphqlRequest } from '@/config/api'
// GraphQL请求函数 - 使用统一的graphqlRequest
// GraphQL 请求函数 - 统一使用 graphqlRequest
// 获取所有地区
export const getRegions = async () => {
@@ -15,16 +15,16 @@
      }
    }
  `
  try {
    const data = await graphqlRequest(query)
    return data.regions || []
    const result = await graphqlRequest(query)
    return result.data.regions || []
  } catch (error) {
    throw new Error(error.message || '获取地区列表失败')
  }
}
// 根据ID获取地区
// 根据 ID 获取地区详情
export const getRegion = async (id) => {
  const query = `
    query GetRegion($id: ID!) {
@@ -37,10 +37,10 @@
      }
    }
  `
  try {
    const data = await graphqlRequest(query, { id })
    return data.region
    const result = await graphqlRequest(query, { id })
    return result.data.region
  } catch (error) {
    throw new Error(error.message || '获取地区详情失败')
  }
@@ -59,7 +59,7 @@
      }
    }
  `
  try {
    const data = await graphqlRequest(mutation, { input: regionData })
    return data.saveRegion
@@ -75,7 +75,7 @@
      deleteRegion(id: $id)
    }
  `
  try {
    const data = await graphqlRequest(mutation, { id })
    return data.deleteRegion
@@ -96,16 +96,16 @@
      }
    }
  `
  try {
    const data = await graphqlRequest(query)
    return data.provinces || []
    const result = await graphqlRequest(query)
    return result.data.provinces || []
  } catch (error) {
    throw new Error(error.message || '获取省份列表失败')
  }
}
// 根据省份ID获取城市
// 根据省份 ID 获取城市
export const getCities = async (provinceId) => {
  const query = `
    query GetCities($provinceId: ID!) {
@@ -117,16 +117,16 @@
      }
    }
  `
  try {
    const data = await graphqlRequest(query, { provinceId })
    return data.cities || []
    const result = await graphqlRequest(query, { provinceId })
    return result.data.cities || []
  } catch (error) {
    throw new Error(error.message || '获取城市列表失败')
  }
}
// 根据城市ID获取区县
// 根据城市 ID 获取区县
export const getDistricts = async (cityId) => {
  const query = `
    query GetDistricts($cityId: ID!) {
@@ -138,16 +138,36 @@
      }
    }
  `
  try {
    const data = await graphqlRequest(query, { cityId })
    return data.districts || []
    const result = await graphqlRequest(query, { cityId })
    return result.data.districts || []
  } catch (error) {
    throw new Error(error.message || '获取区县列表失败')
  }
}
// RegionApi 对象,包含所有区域相关的API方法
// 获取叶子地区列表
export const getLeafRegions = async () => {
  const query = `
    query LeafRegions {
      leafRegions {
        id
        name
        leafFlag
      }
    }
  `
  try {
    const result = await graphqlRequest(query)
    return result.data.leafRegions || []
  } catch (error) {
    throw new Error(error.message || '获取叶子地区列表失败')
  }
}
// RegionApi 对象,包含所有区域相关的 API 方法
export const RegionApi = {
  getRegions,
  getRegion,
@@ -155,5 +175,6 @@
  deleteRegion,
  getProvinces,
  getCities,
  getDistricts
}
  getDistricts,
  getLeafRegions
}