上传代码
This commit is contained in:
12
distribution/uni_modules/mo-city-group/changelog.md
Normal file
12
distribution/uni_modules/mo-city-group/changelog.md
Normal file
@ -0,0 +1,12 @@
|
||||
## 1.0.5(2025-01-15)
|
||||
- 取消网络加载数据。
|
||||
- 调整为本地分包加载策略,避免小程序卡顿以及因主包过大无法上传体验版。
|
||||
## 1.0.3(2025-01-13)
|
||||
###更新使用文档
|
||||
## 1.0.2(2025-01-13)
|
||||
更新使用方法
|
||||
## 1.0.1(2025-01-13)
|
||||
- 更新地址数据文件为网络加载方式
|
||||
- 调整为支持vue3
|
||||
## 1.0.0(2025-01-10)
|
||||
- 调整为uni_modules目录规范
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,324 @@
|
||||
<template>
|
||||
<view class="city-group" :style="diyStyle">
|
||||
<view class="flex flex-row">
|
||||
<picker v-if="isProvince" @change="provinceChange" :value="provinceIndex" :range="provinceData" :range-key="keyName">
|
||||
<view class="flex flex-row flex-items-center">
|
||||
<view>{{provinceIndex==-1?provinceTitle:provinceData[provinceIndex].name}}</view><view>▼</view>
|
||||
</view>
|
||||
</picker>
|
||||
<view class="marlr5" v-if="isProvince"></view>
|
||||
<picker v-if="isCity" @change="cityChange" :value="cityIndex" :range="cityData" :range-key="keyName">
|
||||
<view class="flex flex-row flex-items-center">
|
||||
<view>{{cityIndex==-1?cityTitle:cityData[cityIndex].name}}</view><view>▼</view>
|
||||
</view>
|
||||
</picker>
|
||||
<view class="marlr5" v-if="isCity"></view>
|
||||
<picker v-if="isArea" @change="areaChange" :value="areaIndex" :range="areaData" :range-key="keyName">
|
||||
<view class="flex flex-row flex-items-center">
|
||||
<view>{{areaIndex==-1?areaTitle:areaData[areaIndex].name}}</view><view>▼</view>
|
||||
</view>
|
||||
</picker>
|
||||
<view class="marlr5" v-if="isArea"></view>
|
||||
<picker v-if="isStreet" @change="streetChange" :value="streetIndex" :range="streetData" :range-key="keyName">
|
||||
<view class="flex flex-row flex-items-center">
|
||||
<view>{{streetIndex==-1?streetTitle:streetData[streetIndex].name}}</view><view>▼</view>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import city from './city.js'
|
||||
export default {
|
||||
name:'mo-city-group',
|
||||
data() {
|
||||
return {
|
||||
provinceData:[],
|
||||
cityData:[],
|
||||
areaData:[],
|
||||
streetData:[],
|
||||
provinceIndex:-1,
|
||||
cityIndex:-1,
|
||||
areaIndex:-1,
|
||||
streetIndex:-1
|
||||
}
|
||||
},
|
||||
props:{
|
||||
datas:{
|
||||
type:[Object,String],
|
||||
default:[]
|
||||
},
|
||||
diyStyle:{
|
||||
type:[Object],
|
||||
default:{}
|
||||
},
|
||||
province:{
|
||||
type:[String],
|
||||
default:''
|
||||
},
|
||||
city:{
|
||||
type:[String],
|
||||
default:''
|
||||
},
|
||||
area:{
|
||||
type:[String],
|
||||
default:''
|
||||
},
|
||||
street:{
|
||||
type:[String],
|
||||
default:''
|
||||
},
|
||||
keyName:{
|
||||
type:[String],
|
||||
default:'name'
|
||||
},
|
||||
isProvince:{
|
||||
type:[Boolean],
|
||||
default:true
|
||||
},
|
||||
isCity:{
|
||||
type:[Boolean],
|
||||
default:true
|
||||
},
|
||||
isArea:{
|
||||
type:[Boolean],
|
||||
default:true
|
||||
},
|
||||
isStreet:{
|
||||
type:[Boolean],
|
||||
default:true
|
||||
},
|
||||
size:{
|
||||
type:[String],
|
||||
default:''
|
||||
},
|
||||
isShowTip:{
|
||||
type:[Boolean],
|
||||
default:true
|
||||
},
|
||||
provinceTitle:{
|
||||
type:[String],
|
||||
default:'全部省份'
|
||||
},
|
||||
cityTitle:{
|
||||
type:[String],
|
||||
default:'全部城市'
|
||||
},
|
||||
areaTitle:{
|
||||
type:[String],
|
||||
default:'全部县区'
|
||||
},
|
||||
streetTitle:{
|
||||
type:[String],
|
||||
default:'全部街道'
|
||||
}
|
||||
},
|
||||
watch:{
|
||||
province: {
|
||||
handler(newval, oldValue) {
|
||||
if(this.provinceData.length){
|
||||
let index_=this.provinceData.findIndex(res=>res[this.keyName]==newval);
|
||||
if(index_>-1){
|
||||
this.provinceIndex=index_;
|
||||
}
|
||||
}
|
||||
},
|
||||
immediate:true,
|
||||
deep:true,
|
||||
},
|
||||
city: {
|
||||
handler(newval, oldValue) {
|
||||
if(this.cityData.length){
|
||||
let index_=this.cityData.findIndex(res=>res[this.keyName]==newval);
|
||||
if(index_>-1){
|
||||
this.cityIndex=index_;
|
||||
}
|
||||
}
|
||||
},
|
||||
immediate:true,
|
||||
deep:true,
|
||||
},
|
||||
area: {
|
||||
handler(newval, oldValue) {
|
||||
if(this.areaData.length){
|
||||
let index_=this.areaData.findIndex(res=>res[this.keyName]==newval);
|
||||
if(index_>-1){
|
||||
this.areaIndex=index_;
|
||||
}
|
||||
}
|
||||
},
|
||||
immediate:true,
|
||||
deep:true,
|
||||
},
|
||||
street: {
|
||||
handler(newval, oldValue) {
|
||||
if(this.streetData.length){
|
||||
let index_=this.streetData.findIndex(res=>res[this.keyName]==newval);
|
||||
if(index_>-1){
|
||||
this.streetIndex=index_;
|
||||
}
|
||||
}
|
||||
},
|
||||
immediate:true,
|
||||
deep:true,
|
||||
}
|
||||
},
|
||||
created(){
|
||||
let that=this;
|
||||
if(this.isShowTip){
|
||||
this.provinceData=[{code:'0',name:this.provinceTitle}];
|
||||
this.cityData=[{code:'0',name:this.cityTitle}];
|
||||
this.areaData=[{code:'0',name:this.areaTitle}];
|
||||
this.streetData=[{code:'0',name:this.streetTitle}];
|
||||
}
|
||||
that.init();
|
||||
},
|
||||
methods:{
|
||||
init(){
|
||||
this.initProvince().then(res=>{
|
||||
if(this.province&&this.provinceData.length){
|
||||
let index_=this.provinceData.findIndex(res=>res[this.keyName]==this.province);
|
||||
if(index_>-1){
|
||||
this.provinceIndex=index_;
|
||||
this.provinceChange({detail:{value:index_}});
|
||||
if(this.city&&this.cityData.length){
|
||||
let index_=this.cityData.findIndex(res=>res[this.keyName]==this.city);
|
||||
if(index_>-1){
|
||||
this.cityIndex=index_;
|
||||
this.cityChange({detail:{value:index_}});
|
||||
if(this.area&&this.areaData.length){
|
||||
let index_=this.areaData.findIndex(res=>res[this.keyName]==this.area);
|
||||
if(index_>-1){
|
||||
this.areaValue=index_;
|
||||
this.areaChange({detail:{value:index_}});
|
||||
if(this.street&&this.streetData.length){
|
||||
let index_=this.streetData.findIndex(res=>res[this.keyName]==this.street);
|
||||
if(index_>-1){
|
||||
this.streetValue=index_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
async initProvince(){
|
||||
return new Promise((resolve,reject)=>{
|
||||
for(let i in city){
|
||||
this.provinceData.push({
|
||||
code:city[i].code,
|
||||
name:city[i].name
|
||||
});
|
||||
if(i==city.length-1){
|
||||
resolve(this.provinceData);
|
||||
return this.provinceData;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
async provinceChange(event){
|
||||
const index=event.detail.value;
|
||||
this.provinceIndex=index;
|
||||
//console.log(index);
|
||||
this.cityIndex=-1;
|
||||
this.areaIndex=-1;
|
||||
this.streetIndex=-1;
|
||||
this.cityData=this.isShowTip? [{code:'0',name:this.cityTitle}]:[];
|
||||
this.areaData=this.isShowTip?[{code:'0',name:this.areaTitle}]:[];
|
||||
this.streetData=this.isShowTip?[{code:'0',name:this.streetTitle}]:[];
|
||||
if(this.provinceData[index].code=='0'){
|
||||
this.$emit('province-change','');
|
||||
return '';
|
||||
}
|
||||
let city_=city.filter(res=>res.code==this.provinceData[index].code);
|
||||
if(city_.length){
|
||||
//console.log(city_);
|
||||
this.cityData=[...this.cityData,...city_[0].children];
|
||||
}
|
||||
this.$emit('province-change',this.provinceData[index]);
|
||||
return this.provinceData[index];
|
||||
},
|
||||
async cityChange(event){
|
||||
const index=event.detail.value;
|
||||
this.cityIndex=index;
|
||||
this.areaIndex=-1;
|
||||
this.streetIndex=-1;
|
||||
this.areaData=this.isShowTip?[{code:'0',name:this.areaTitle}]:[];
|
||||
this.streetData=this.isShowTip?[{code:'0',name:this.streetTitle}]:[];
|
||||
if(this.cityData[index].code=='0'){
|
||||
this.$emit('city-change','');
|
||||
return '';
|
||||
}
|
||||
let city_=this.cityData.filter(res=>res.code==this.cityData[index].code);
|
||||
if(city_.length){
|
||||
//console.log(city_);
|
||||
this.areaData=[...this.areaData,...city_[0].children];
|
||||
}
|
||||
this.$emit('city-change',this.cityData[index]);
|
||||
return this.cityData[index];
|
||||
},
|
||||
async areaChange(event){
|
||||
const index=event.detail.value;
|
||||
this.areaIndex=index;
|
||||
this.streetIndex=-1;
|
||||
this.streetData=this.isShowTip?[{code:'0',name:this.streetTitle}]:[];
|
||||
if(this.areaData[index].code=='0'){
|
||||
this.$emit('area-change','');
|
||||
return '';
|
||||
}
|
||||
let city_=this.areaData.filter(res=>res.code==this.areaData[index].code);
|
||||
if(city_.length){
|
||||
//console.log(city_);
|
||||
this.streetData=[...this.streetData,...city_[0].children];
|
||||
}
|
||||
this.$emit('area-change',this.areaData[index]);
|
||||
return this.areaData[index];
|
||||
},
|
||||
async streetChange(event){
|
||||
const index=event.detail.value;
|
||||
this.streetIndex=index;
|
||||
if(this.streetData[index]=='0'){
|
||||
this.$emit('street-change','');
|
||||
return '';
|
||||
}
|
||||
this.$emit('street-change',this.streetData[index]);
|
||||
return this.streetData[index];
|
||||
},
|
||||
clearProvince(){
|
||||
this.$emit('province-clear','');
|
||||
},
|
||||
clearCity(){
|
||||
this.$emit('city-clear','');
|
||||
},
|
||||
clearArea(){
|
||||
this.$emit('area-clear','');
|
||||
},
|
||||
clearStreet(){
|
||||
this.$emit('street-clear','');
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.flex{display:flex;}
|
||||
.flex-row{flex-direction: row;}
|
||||
.flex-row-reverse{flex-direction: row-reverse;}
|
||||
.flex-column{flex-direction:column;}
|
||||
/*单轴线对齐*/
|
||||
.flex-justify-center{justify-content: center;}
|
||||
.flex-justify-end{justify-content: end;}/*margin-left:auto;可解决不右对齐问题*/
|
||||
.flex-items-start{align-items: flex-start;}
|
||||
.flex-items-center{align-items: center;}
|
||||
.flex-items-baseline{align-items: baseline;}/*第一行文字基线对齐*/
|
||||
.flex-items-end{align-items: flex-end;}
|
||||
.marlr5{margin-left:5px;margin-right:5px;}
|
||||
</style>
|
86
distribution/uni_modules/mo-city-group/package.json
Normal file
86
distribution/uni_modules/mo-city-group/package.json
Normal file
@ -0,0 +1,86 @@
|
||||
{
|
||||
"id": "mo-city-group",
|
||||
"displayName": "mo-city-group省市县区街道地区四级联动",
|
||||
"version": "1.0.5",
|
||||
"description": "省市县区街道地区四级联动。",
|
||||
"keywords": [
|
||||
"省市县",
|
||||
"街道",
|
||||
"地区",
|
||||
"地址",
|
||||
"四级联动"
|
||||
],
|
||||
"repository": "",
|
||||
"engines": {
|
||||
},
|
||||
"directories": {
|
||||
"example": ""
|
||||
},
|
||||
"dcloudext": {
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
}
|
||||
},
|
||||
"contact": {
|
||||
"qq": ""
|
||||
},
|
||||
"declaration": {
|
||||
"ads": "无",
|
||||
"data": "无",
|
||||
"permissions": "无"
|
||||
},
|
||||
"npmurl": "",
|
||||
"type": "component-vue"
|
||||
},
|
||||
"uni_modules": {
|
||||
"dependencies": ["uni-scss"],
|
||||
"encrypt": [],
|
||||
"platforms": {
|
||||
"cloud": {
|
||||
"tcb": "y",
|
||||
"aliyun": "y",
|
||||
"alipay": "n"
|
||||
},
|
||||
"client": {
|
||||
"App": {
|
||||
"app-vue": "y",
|
||||
"app-nvue": "u",
|
||||
"app-harmony": "y",
|
||||
"app-uvue": "u"
|
||||
},
|
||||
"H5-mobile": {
|
||||
"Safari": "y",
|
||||
"Android Browser": "y",
|
||||
"微信浏览器(Android)": "y",
|
||||
"QQ浏览器(Android)": "y"
|
||||
},
|
||||
"H5-pc": {
|
||||
"Chrome": "y",
|
||||
"IE": "y",
|
||||
"Edge": "y",
|
||||
"Firefox": "y",
|
||||
"Safari": "y"
|
||||
},
|
||||
"小程序": {
|
||||
"微信": "y",
|
||||
"阿里": "y",
|
||||
"百度": "y",
|
||||
"字节跳动": "y",
|
||||
"QQ": "y"
|
||||
},
|
||||
"快应用": {
|
||||
"华为": "y",
|
||||
"联盟": "y"
|
||||
},
|
||||
"Vue": {
|
||||
"vue2": "y",
|
||||
"vue3": "y"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
84
distribution/uni_modules/mo-city-group/readme.md
Normal file
84
distribution/uni_modules/mo-city-group/readme.md
Normal file
@ -0,0 +1,84 @@
|
||||
## city 地址联动
|
||||
> **组件名:mo-city-group**
|
||||
> 代码块: `mo-city-group`
|
||||
|
||||
省市县区街道地区四级联动
|
||||
理论上支持所有平台,可自行尝试
|
||||
|
||||
### [使用文档]
|
||||
###
|
||||
```javascript
|
||||
|
||||
属性:
|
||||
|
||||
|diyStyle |{} |外层自定义样式 |
|
||||
|province |String |默认省份全称 |
|
||||
|city |String |默认城市全称 |
|
||||
|area |String |默认县区全称 |
|
||||
|street |String |默认街道全称 |
|
||||
|keyName |String = [name] |要显示的对象字段名 |
|
||||
|isProvince |Boolean|true |是否显示省份 |
|
||||
|isCity |Boolean|true |是否显示城市 |
|
||||
|isArea |Boolean|true |是否显示县区 |
|
||||
|isStreet |Boolean|true |是否显示街道 |
|
||||
|isShowTip |Boolean|true |是否显示选择省市县街道的选项 |
|
||||
|provinceTitle |String = [全部省份] |不选择省份时的文字,或显示选择省市县街道选项的提示文字(isShowTip=true时有效)
|
||||
|cityTitle |String = [全部城市] |不选择城市时的文字,或显示选择省市县街道选项的提示文字(isShowTip=true时有效)
|
||||
|areaTitle |String = [全部县区] |不选择县区时的文字,或显示选择省市县街道选项的提示文字(isShowTip=true时有效)
|
||||
|streetTitle |String = [全部街道] |不选择街道时的文字,或显示选择省市县街道选项的提示文字(isShowTip=true时有效)|
|
||||
|
||||
事件:
|
||||
|provinceChange |Event|{code:0,name:'名称'} |省份选择事件 |
|
||||
|cityChange |Event|{code:0,name:'名称'} |城市选择事件 |
|
||||
|areaChange |Event|{code:0,name:'名称'} |县区选择事件 |
|
||||
|streetChange |Event|{code:0,name:'名称'} |街道选择事件 |
|
||||
|
||||
```
|
||||
### [使用示例]
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
###注意事项
|
||||
由于四级联动JS数据文件过大,小程序须在分包使用加载本组件,否则无法上传体验版。主包使用时,建议跳转到分包页面加载选择地址后,再返回给主包调用。
|
||||
|
||||
分包策略如下:
|
||||
1、把uni_modules\mo-city-group目录下的components目录整体移到你的分包目录(多个分包要遵循ABCD...能依次访问并加载的策略,或将本自定义组件放于每个分包中);
|
||||
2、pages.json文件中配置自动加载,如本组件的分包路径是pagesA/components/...
|
||||
则pages.json配置:
|
||||
"easycom": {
|
||||
"autoscan": true,
|
||||
"custom": {
|
||||
"^mo-(.*)": "@/pagesA/components/mo-$1/mo-$1.vue" //此为本组件的自动加载路径
|
||||
}
|
||||
}
|
||||
3、这时只需在分包模板文件中使用组件,无需导入组件,可自动加载分包中的本组件。
|
||||
|
||||
<template>
|
||||
<view>
|
||||
<mo-city-group class="color-whites any-font-size-12" dataUrl="http://127.0.0.1/comjs/city.js"
|
||||
:isProvince="true" :isCity="true" province="浙江省" city="台州市"
|
||||
@area-change="citygroupChangeSo($event,'area')"
|
||||
@street-change="citygroupChangeSo($event,'street')"
|
||||
@province-change="citygroupChangeSo($event,'province')"
|
||||
@city-change="citygroupChangeSo($event,'city')"></mo-city-group>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
export default{
|
||||
methods:{
|
||||
citygroupChangeSo(event,type){
|
||||
console.log(event,type)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
4、分包配置完后,记得删除uni_modules目录下的mo-city-group目录,避免小程序无法上传体验版本。
|
||||
|
||||
```
|
||||
|
||||
|
||||
#### 如使用过程中有任何问题,或者您对此组件有一些好的建议,欢迎联系微信:actioniing
|
||||
|
||||
|
Reference in New Issue
Block a user