this.checkProvince = this.region.province?.province || ''
时间: 2024-05-19 21:13:31 浏览: 13
This code uses optional chaining to access the `province` property of the `region` object. If `region` is `undefined` or `null`, the expression will short-circuit and return `undefined`. If `region` is defined, but `province` property is not defined, the expression will also return `undefined`.
If `province` property is defined in `region` object, it will return the value of `province` property. If the value of `province` is falsy (e.g. an empty string), it will return an empty string as a default value.
The result of this expression is then assigned to the `checkProvince` variable.
相关问题
优化代码 handleWinClick(e) { if (e.target.matches) { if ( this.istopSearch == true && !e.target.matches('#my-km-popper') && this.zhName === '综合' && !e.target.matches('#ywbd-km-popper') ) { this.istopSearch = false; this.isHistyqry = false; } } else { // 兼容ie if ( this.istopSearch == true && !e.target.msMatchesSelector('#my-km-popper') && this.zhName === '综合' && !e.target.msMatchesSelector('#ywbd-km-popper') ) { this.istopSearch = false; this.isHistyqry = false; } } // 新tab搜索 if (e.target.matches) { if ( this.isMenuTabshow == true && this.zhName === '综合' && !e.target.matches('#my-km-popper') && !e.target.matches('#ywbd-km-popper') && e.target.className.indexOf('el-tabs__item') < 0 ) { this.isMenuTabshow = false; } } else { if ( this.isMenuTabshow == true && this.zhName === '综合' && !e.target.msMatchesSelector('#my-km-popper') && !e.target.msMatchesSelector('#ywbd-km-popper') && !e.target.msMatchesSelector('#tab') && e.target.className.indexOf('el-tabs__item') < 0 ) { this.isMenuTabshow = false; } } }, defaultType() { let parmas = { region: '^GET_CUR_REGION', paraType: 'QUERY_MENU_FLAG', paraCode: 'QUERY_MENU_FLAG', }; this.$http .post('hallCommon_IBusiCommCSV_qryBsParaDetail', parmas) .then(({ bsParaDetail = [] }) => { if (!isNull(bsParaDetail)) { if (bsParaDetail[0].para1 == 'Y') { //默认是综合 this.zhName = '综合'; } else { this.zhName = '菜单'; } } else { this.zhName = '菜单'; } }); },
可以将重复的判断条件提取出来,避免重复代码。同时可以使用三元运算符来简化代码。重构后的代码如下:
```
const isZhName = this.zhName === '综合';
const isMyKmPopper = e.target.matches('#my-km-popper') || e.target.msMatchesSelector('#my-km-popper');
const isYwbdKmPopper = e.target.matches('#ywbd-km-popper') || e.target.msMatchesSelector('#ywbd-km-popper');
const isElTabsItem = e.target.className.indexOf('el-tabs__item') < 0;
// 处理 istopSearch
if (e.target.matches ? (!isMyKmPopper && isZhName && !isYwbdKmPopper && this.istopSearch) : (!isMyKmPopper && isZhName && !isYwbdKmPopper && this.istopSearch)) {
this.istopSearch = false;
this.isHistyqry = false;
}
// 处理 isMenuTabshow
if (e.target.matches ? (!isMyKmPopper && !isYwbdKmPopper && !isElTabsItem && isZhName && this.isMenuTabshow) : (!isMyKmPopper && !isYwbdKmPopper && !e.target.msMatchesSelector('#tab') && !isElTabsItem && isZhName && this.isMenuTabshow)) {
this.isMenuTabshow = false;
}
// 处理 defaultType
const parmas = {
region: '^GET_CUR_REGION',
paraType: 'QUERY_MENU_FLAG',
paraCode: 'QUERY_MENU_FLAG',
};
this.$http.post('hallCommon_IBusiCommCSV_qryBsParaDetail', parmas).then(({ bsParaDetail = [] }) => {
if (!isNull(bsParaDetail)) {
this.zhName = bsParaDetail[0].para1 === 'Y' ? '综合' : '菜单';
} else {
this.zhName = '菜单';
}
});
```
// 分页 handleSizeChange(val) { this.pageSize = val this.handleNodeClick() }, handleCurrentChange(val) { this.page = val this.handleNodeClick() }, async getTreeListList() { const { data } = await businessTreeApi() this.departlist = JSON.parse(data.data) }, // 右侧上部分信息 async handleNodeClick(type) { console.log(type) if (type) { this.id = type.id } const List = (await businessApi(this.id)).data.data // this.datalist.agentId = type.id ? type.id : id // console.log(this.datalist) // const {data}= await courierPagingApi(this.datalist) // console.log(data); console.log(List) if (List.type === 1) { this.form.type = '一级转运中心' } else if (List.type === 2) { this.form.type = '二级转运中心' } else this.form.type = '营业部' this.form.number = List.id // v-model 数字 // this.form.type=List.type==3?'营业部':'', // 类型 this.form.name = List.name // 名字 this.form.region = List.province.name // 省 this.form.city = List.city.name // 城市 this.form.county = List.county.name // 县区 this.form.address = List.address // 详细地址 this.form.people = List.managerName // 负责人 this.form.phone = List.phone // 电话 this.form.longitude = List.longitude // 经度 this.form.latitude = List.latitude // 维度 // ------------------------------------ let obj = { page: this.page, pageSize: this.pageSize, agencyId: this.id } // 页码 const { data } = await getUserPageApi(obj) this.total = data.data.counts console.log(data.data) this.tableData = data.data.items this.total = Number(data.data.counts) // 下拉框数据 const res = await editAreasApi() console.log(res) this.economize = res.data.data if (this.value) { const ress = await editAreasApi(this.value) console.log(ress) } }, onSubmit() { this.isOk = !this.isOk } // 编辑数据 }
这段代码是关于一个树形结构的页面分页展示和编辑数据的处理,其中包括以下几个方法:
1. `handleSizeChange(val)`:处理每页展示数据量的变化,并调用`handleNodeClick()`方法重新渲染数据。
2. `handleCurrentChange(val)`:处理当前页码的变化,并调用`handleNodeClick()`方法重新渲染数据。
3. `getTreeListList()`:获取树形结构的数据,并将其解析为JSON格式。
4. `handleNodeClick(type)`:处理节点的点击事件,并根据节点类型展示对应的数据。同时,根据当前节点的ID,获取该节点下的用户数据,并展示在页面中。另外,还会获取下拉框数据。
5. `onSubmit()`:处理编辑数据的提交事件。
总体来说,这段代码实现了一个树形结构的页面展示和编辑数据的功能。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)