Explorar el Código

fix(frontend): 地址选择器改用标准 API 封装 - 修复省市选择控件无法使用

组件内 5 处 this.$http.get 引用全项目未定义的 Vue.prototype.$http,运行时 TypeError 被静默吞掉导致省份列表恒为空。改用 utils/api.js 的 getProvinces/getStreetChildren/getStreetPath。

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Xiaogang Liao hace 1 mes
padre
commit
5b8313aadb
Se han modificado 1 ficheros con 7 adiciones y 5 borrados
  1. 7 5
      cfc-frontend/components/address-picker.vue

+ 7 - 5
cfc-frontend/components/address-picker.vue

@@ -32,6 +32,8 @@
 </template>
 
 <script>
+import { getProvinces, getStreetChildren, getStreetPath } from '@/utils/api.js'
+
 export default {
   name: 'AddressPicker',
   props: {
@@ -76,7 +78,7 @@ export default {
   methods: {
     async loadProvinces() {
       try {
-        const res = await this.$http.get('/api/streets/provinces')
+        const res = await getProvinces()
         this.provinces = res.data || []
       } catch (e) {
         console.error('加载省份失败', e)
@@ -85,7 +87,7 @@ export default {
     
     async loadCities(provinceId) {
       try {
-        const res = await this.$http.get(`/api/streets/children/${provinceId}`)
+        const res = await getStreetChildren(provinceId)
         this.cities = res.data || []
       } catch (e) {
         console.error('加载城市失败', e)
@@ -94,7 +96,7 @@ export default {
     
     async loadDistricts(cityId) {
       try {
-        const res = await this.$http.get(`/api/streets/children/${cityId}`)
+        const res = await getStreetChildren(cityId)
         this.districts = res.data || []
       } catch (e) {
         console.error('加载区县失败', e)
@@ -103,7 +105,7 @@ export default {
     
     async loadStreets(districtId) {
       try {
-        const res = await this.$http.get(`/api/streets/children/${districtId}`)
+        const res = await getStreetChildren(districtId)
         this.streets = res.data || []
       } catch (e) {
         console.error('加载街道失败', e)
@@ -112,7 +114,7 @@ export default {
     
     async loadAddressById(streetId) {
       try {
-        const res = await this.$http.get(`/api/streets/${streetId}/path`)
+        const res = await getStreetPath(streetId)
         const path = res.data || []
         
         if (path.length >= 1) this.selectedProvince = path[0]