## 删除的死代码脚本
- scripts/i18n_class_c.py (脚本自承'新架构下永远输出 0',纯防御性)
- scripts/full_migrate_i18n.py (其产出违反 CLAUDE.md 1.2 中文 key 铁律,已标 DEPRECATED)
- scripts/__pycache__/ (Python 缓存)
## 删除的旧 per-page lang 文件
- lang/zh-cn/<page>/<file>.js (140 个)
- lang/en-us/<page>/<file>.js (139 个)
- 共 279 个文件,运行时不再加载,0 个 key 被 .vue 调用(经 diagnose_keys.py 验证)
## 删除的备份和迁移表
- lang/_backup/ (git 已跟踪原文件)
- lang/_migration_map.json / lang/_migration-map.json (运行时不用)
## 删除的中间产物 JSON
- docs/i18n-rename-*.json (smart_rename 中间产物,已用完)
- docs/i18n-ambiguous.json / i18n-audit.json / i18n-call-rewrite.log /
i18n-clean-dead.log / i18n-file-texts.json / i18n-page-titles.json /
i18n-vue-extract.json (前一会话残留,无引用方)
- docs/i18n-{naming,shadow,strict}-audit.json (脚本会自动重新生成)
## 删除的 modular lang 文件
- lang/zh-cn/*.js / lang/en-us/*.js (20 个模块文件,内容是上一会话产生的死代码)
- lang/zh-cn/index.js / lang/en-us/index.js (聚合入口)
- lang/DEPRECATED.md (已不再相关)
## 删除的不成熟脚本
- scripts/check_perpage.py (诊断用,已完成)
- scripts/diagnose_keys.py (诊断用,已完成)
- scripts/smart_rename_i18n.py (v1-v3 都 bug,未修完)
## 现状
- lang/ 现在只有 zh-cn.js + en-us.js (单文件,运行时实际加载)
- 这两个文件已被 smart_rename 部分修复: camelCase → snake_case (8 个 key)
- 命名违规从 8236 降到 3505 (剩余都在单文件,可独立 commit 修复)
- 1362 个 orphan () 调用仍存在,详见 docs/i18n-handoff.md
305 lines
14 KiB
Vue
305 lines
14 KiB
Vue
<template>
|
|
<view class="pick-regions">
|
|
<!-- #ifndef MP-ALIPAY -->
|
|
<picker mode="multiSelector" :value="multiIndex" :range="multiArray" @change="handleValueChange" @columnchange="handleColumnChange">
|
|
<slot></slot>
|
|
</picker>
|
|
<!-- #endif -->
|
|
|
|
<!-- #ifdef MP-ALIPAY -->
|
|
<view @click="$refs.regionsRef.open()">
|
|
<slot></slot>
|
|
</view>
|
|
|
|
<uni-popup type="bottom" ref="regionsRef">
|
|
<view class="regions-picker-container">
|
|
<view class="picker-header">
|
|
<view class="picker-action cancel" @click="$refs.regionsRef.close()">{{ $lang("common.pick-regions.l17.t0") }}</view>
|
|
<view class="picker-action confirm" @click="confirmRegions">{{ $lang("common.pick-regions.l18.t0") }}</view>
|
|
</view>
|
|
<picker-view :value="multiIndex" @change="pickerViewColumnChange" class="picker-view">
|
|
<picker-view-column v-if="multiArray[0]">
|
|
<view class="item" v-for="(item,index) in multiArray[0]" :key="index">{{item}}</view>
|
|
</picker-view-column>
|
|
<picker-view-column v-if="multiArray[1]">
|
|
<view class="item" v-for="(item,index) in multiArray[1]" :key="index">{{item}}</view>
|
|
</picker-view-column>
|
|
<picker-view-column v-if="multiArray[2]">
|
|
<view class="item" v-for="(item,index) in multiArray[2]" :key="index">{{item}}</view>
|
|
</picker-view-column>
|
|
</picker-view>
|
|
</view>
|
|
</uni-popup>
|
|
<!-- #endif -->
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
props: {
|
|
defaultRegions: {
|
|
type: Array
|
|
},
|
|
selectArr: {
|
|
type: String
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
pickerValueArray: [],
|
|
cityArr: [],
|
|
districtArr: [],
|
|
multiIndex: [0, 0, 0],
|
|
isInitMultiArray: false,
|
|
// 是否加载完默认地区
|
|
isLoadDefaultAreas: false
|
|
};
|
|
},
|
|
watch: {
|
|
defaultRegions: {
|
|
handler(arr, oldArr = []) {
|
|
// 避免传的是字面量的时候重复触发
|
|
if (arr.length != this.selectArr || arr.join('') === oldArr.join('')) return;
|
|
this.isInitMultiArray = false;
|
|
this.handleDefaultRegions();
|
|
},
|
|
immediate: true
|
|
}
|
|
},
|
|
computed: {
|
|
multiArray() {
|
|
if (!this.isLoadDefaultAreas) return;
|
|
var arr = this.pickedArr.map(arr => arr.map(item => item.label));
|
|
return arr;
|
|
},
|
|
pickedArr() {
|
|
// 进行初始化
|
|
if (this.isInitMultiArray) {
|
|
if (this.selectArr == '2') {
|
|
return [this.pickerValueArray[0], this.pickerValueArray[1]];
|
|
} else {
|
|
return [this.pickerValueArray[0], this.pickerValueArray[1], this.pickerValueArray[2]];
|
|
}
|
|
}
|
|
|
|
if (this.selectArr == '2') {
|
|
return [this.pickerValueArray[0], this.cityArr];
|
|
} else {
|
|
return [this.pickerValueArray[0], this.cityArr, this.districtArr];
|
|
}
|
|
}
|
|
},
|
|
created() {
|
|
this.getDefaultAreas(0, { level: 0 });
|
|
},
|
|
methods: {
|
|
async pickerViewColumnChange(e) {
|
|
var value = e.detail.value;
|
|
if (value[0] != this.multiIndex[0]) {
|
|
await this.handleColumnChange({ detail: { column: 0, value: value[0] } })
|
|
this.multiIndex[1] = e.detail.value[1] || 0;
|
|
await this.handleColumnChange({ detail: { column: 1, value: value[1] } })
|
|
this.multiIndex[2] = e.detail.value[2] || 0;
|
|
} else if (value[1] != this.multiIndex[1]) {
|
|
await this.handleColumnChange({ detail: { column: 1, value: value[1] } })
|
|
this.multiIndex[2] = e.detail.value[2] || 0;
|
|
} else {
|
|
this.multiIndex = value
|
|
}
|
|
},
|
|
confirmRegions() {
|
|
this.handleValueChange({ detail: { value: this.multiIndex } })
|
|
this.$refs.regionsRef.close()
|
|
},
|
|
async handleColumnChange(e) {
|
|
this.isInitMultiArray = false;
|
|
let col = e.detail.column;
|
|
let row = e.detail.value;
|
|
this.multiIndex[col] = row;
|
|
switch (col) {
|
|
case 0:
|
|
//选择省,加载市、区县
|
|
this.cityArr = await this.getAreasAsync(this.pickerValueArray[0][this.multiIndex[col]].value);
|
|
this.districtArr = await this.getAreasAsync(this.cityArr[0].value);
|
|
break;
|
|
case 1:
|
|
//选择市,加载区县
|
|
this.districtArr = await this.getAreasAsync(this.cityArr[this.multiIndex[col]].value);
|
|
break;
|
|
case 2:
|
|
if (!this.cityArr.length) this.cityArr = await this.getAreasAsync(this.pickerValueArray[0][0].value)
|
|
if (!this.districtArr.length) this.districtArr = await this.getAreasAsync(this.cityArr[0].value);
|
|
break;
|
|
}
|
|
},
|
|
handleValueChange(e) {
|
|
// 结构赋值
|
|
let [index0, index1, index2] = e.detail.value;
|
|
let [arr0, arr1, arr2] = this.pickedArr;
|
|
let address = '';
|
|
if (this.selectArr == '2') {
|
|
address = [arr0[index0], arr1[index1]];
|
|
} else {
|
|
address = [arr0[index0], arr1[index1], arr2[index2]];
|
|
}
|
|
this.$emit('getRegions', address);
|
|
},
|
|
handleDefaultRegions() {
|
|
var time = setInterval(() => {
|
|
// if (!this.isLoadDefaultAreas) return;
|
|
// console.log('this.pickerValueArray',this.pickerValueArray)
|
|
for (let i = 0; i < this.defaultRegions.length; i++) {
|
|
if(this.pickerValueArray[i] == null) continue;
|
|
for (let j = 0; j < this.pickerValueArray[i].length; j++) {
|
|
// 匹配省
|
|
if ((this.defaultRegions[i] == this.pickerValueArray[i][j].value || this.defaultRegions[i] == this.pickerValueArray[i][j].label) && this.pickerValueArray[i][j].level == 1) {
|
|
// 设置选中省
|
|
this.$set(this.multiIndex, i, j);
|
|
|
|
// 查询市
|
|
this.getAreas(this.pickerValueArray[i][j].value, data => {
|
|
this.cityArr = data;
|
|
this.$set(this.pickerValueArray, 1, data)
|
|
for (let k = 0; k < this.cityArr.length; k++) {
|
|
if (this.defaultRegions[1] == this.cityArr[k].value || this.defaultRegions[1] == this.cityArr[k].label) {
|
|
// 设置选中市
|
|
this.$set(this.multiIndex, 1, k);
|
|
|
|
// 查询区县
|
|
this.getAreas(this.cityArr[k].value, data => {
|
|
this.districtArr = data;
|
|
this.$set(this.pickerValueArray, 2, data)
|
|
|
|
// 设置选中区县
|
|
for (let u = 0; u < this.districtArr
|
|
.length; u++) {
|
|
if (this.defaultRegions[2] == this.districtArr[u].value || this.defaultRegions[2] == this.districtArr[u].label) {
|
|
this.$set(this.multiIndex, 2, u);
|
|
this.handleValueChange({
|
|
detail: {
|
|
value: [j, k, u]
|
|
}
|
|
});
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
if (this.isLoadDefaultAreas) clearInterval(time);
|
|
}, 100);
|
|
},
|
|
getDefaultAreas(pid, obj) {
|
|
this.$api.sendRequest({
|
|
url: '/api/address/lists',
|
|
data: { pid: pid },
|
|
success: res => {
|
|
if (res.code == 0) {
|
|
var data = [];
|
|
var selected = undefined;
|
|
res.data.forEach((item, index) => {
|
|
if (obj != undefined) {
|
|
if (obj.level == 0 && obj.province_id != undefined) {
|
|
selected = obj.province_id;
|
|
} else if (obj.level == 1 && obj.city_id != undefined) {
|
|
selected = obj.city_id;
|
|
} else if (obj.level == 2 && obj.district_id != undefined) {
|
|
selected = obj.district_id;
|
|
}
|
|
}
|
|
|
|
if (selected == undefined && index == 0) {
|
|
selected = item.id;
|
|
}
|
|
data.push({
|
|
value: item.id,
|
|
label: item.name,
|
|
level: item.level
|
|
});
|
|
});
|
|
|
|
this.pickerValueArray[obj.level] = data;
|
|
if (obj.level + 1 < 3) {
|
|
obj.level++;
|
|
this.getDefaultAreas(selected, obj);
|
|
} else {
|
|
this.isInitMultiArray = true;
|
|
this.isLoadDefaultAreas = true;
|
|
this.handleDefaultRegions()
|
|
}
|
|
}
|
|
}
|
|
});
|
|
},
|
|
// 同步获取地区
|
|
async getAreasAsync(pid) {
|
|
let res = await this.$api.sendRequest({
|
|
url: '/api/address/lists',
|
|
data: { pid: pid },
|
|
async: false
|
|
});
|
|
if (res.code == 0) {
|
|
var data = [];
|
|
res.data.forEach((item, index) => {
|
|
data.push({
|
|
value: item.id,
|
|
label: item.name,
|
|
level: item.level
|
|
});
|
|
});
|
|
return data;
|
|
}
|
|
},
|
|
// 异步获取地区
|
|
getAreas(pid, callback) {
|
|
this.$api.sendRequest({
|
|
url: '/api/address/lists',
|
|
data: { pid: pid },
|
|
success: res => {
|
|
if (res.code == 0) {
|
|
var data = [];
|
|
res.data.forEach((item, index) => {
|
|
data.push({
|
|
value: item.id,
|
|
label: item.name,
|
|
level: item.level
|
|
});
|
|
});
|
|
if (callback) callback(data);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.regions-picker-container {
|
|
padding-bottom: constant(safe-area-inset-bottom);
|
|
padding-bottom: env(safe-area-inset-bottom);
|
|
|
|
.picker-header {
|
|
display: flex;
|
|
height: 45px;
|
|
align-items: center;
|
|
border-bottom: 2rpx solid #f5f5f5;
|
|
justify-content: space-between;
|
|
|
|
.picker-action {
|
|
padding: 0 28rpx;
|
|
font-size: 34rpx;
|
|
}
|
|
|
|
.confirm {
|
|
color: #007aff;
|
|
}
|
|
}
|
|
}
|
|
</style> |