代码优化

This commit is contained in:
冯辉
2025-11-07 19:20:05 +08:00
parent 82fc4cf1ce
commit 4a8a5d4661
42 changed files with 1427 additions and 43 deletions

View File

@@ -85,7 +85,8 @@
</template>
<script>
import addressJson from '@/static/json/xinjiang.json';
// 改为动态加载,避免主包过大
let addressJson = null;
export default {
name: 'AreaCascadePicker',
data() {
@@ -154,12 +155,23 @@ export default {
// this.areaData = resp.data.data;
// }
// 暂时使用模拟数据
// 动态加载JSON文件使用require支持动态加载
if (!addressJson) {
try {
// 优先从主包加载(如果存在)
addressJson = require('@/static/json/xinjiang.json');
} catch (e) {
console.warn('无法加载地址数据,使用空数据', e);
addressJson = [];
}
}
// 使用模拟数据
this.areaData = this.getMockData();
} catch (error) {
console.error('加载地区数据失败:', error);
// 如果后端API不存在,使用模拟数据
this.areaData = this.getMockData();
// 如果加载失败,使用数据
this.areaData = addressJson || [];
}
},
@@ -338,7 +350,7 @@ export default {
// 模拟数据(用于演示)
getMockData() {
return addressJson
return addressJson || []
}
},
};