优化物业账号下切换小区功能

This commit is contained in:
wuxw 2025-06-04 19:06:46 +08:00
parent 65dba00306
commit 0e3df9ef62
5 changed files with 214 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import { setCommunitys,setCurrentCommunity } from "@/utils/vc"
import { setCommunitys,setCurrentCommunity,getCurrentCommunity } from "@/utils/vc"
import request from '@/utils/request'
export function _loadCommunityInfo(_param) {
return new Promise((resolve, reject) => {
@ -51,4 +51,32 @@ export function getDict(tableName,tableColumns) {
reject(error)
})
})
}
export function getCommunityId() {
return getCurrentCommunity().communityId
}
export function getCommunityName() {
return getCurrentCommunity().name
}
export function getMyEnteredCommunitys(_param) {
return new Promise((resolve, reject) => {
request({
url: '/community.listMyEnteredCommunitys',
method: 'get',
params: {
..._param
}
}).then(response => {
const res = response.data
// 获取验证码成功
resolve(res)
}).catch(error => {
reject(error)
})
})
}

View File

@ -0,0 +1,106 @@
<template>
<div>
<el-dialog title="切换小区" :visible.sync="dialogVisible" width="70%" :close-on-click-modal="false">
<div class="filter-container text-right">
<el-input :placeholder="$t('communityManage.table.name')" v-model="navCommunityInfo.searchCommunityName"
style="width: 300px;" class="filter-item"></el-input>
<el-button class="filter-item" type="primary" icon="el-icon-search" @click="_queryEnterCommunity">
{{ $t('common.search') }}
</el-button>
</div>
<el-table :data="communitys" border fit highlight-current-row style="width: 100%; margin-top: 20px;">
<el-table-column :label="$t('communityManage.table.communityId')" prop="communityId"
align="center"></el-table-column>
<el-table-column :label="$t('communityManage.table.name')" prop="name" align="center"></el-table-column>
<el-table-column :label="$t('common.operation')" align="center">
<template slot-scope="scope">
<el-button size="mini" @click="_chooseCurrentCommunity(scope.row)">
{{ $t('common.select') }}
</el-button>
</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<el-pagination @current-change="handleCurrentChange" :current-page="currentPage" :page-size="pageSize"
layout="total, prev, pager, next" :total="total"></el-pagination>
</div>
</el-dialog>
</div>
</template>
<script>
import { getMyEnteredCommunitys } from '@/api/community/communityApi'
import { setCurrentCommunity } from "@/utils/vc"
const DEFAULT_PAGE = 1;
const DEFAULT_ROW = 10;
export default {
name: 'ChooseEnterCommunity',
data() {
return {
dialogVisible: false,
currentPage: DEFAULT_PAGE,
pageSize: DEFAULT_ROW,
total: 0,
communitys: [],
navCommunityInfo: {
_currentCommunity: {},
communityInfos: [],
communityInfo: [],
errorInfo: '',
searchCommunityName: ''
}
}
},
created() {
},
methods: {
open() {
this.dialogVisible = true;
this.navCommunityInfo.searchCommunityName = '';
this.listEnterCommunity(DEFAULT_PAGE, DEFAULT_ROW);
},
handleCurrentChange(val) {
this.currentPage = val;
this.listEnterCommunity(val, DEFAULT_ROW);
},
async listEnterCommunity(_page, _row) {
const { communitys, records } = await getMyEnteredCommunitys({
_uid: '123mlkdinkldldijdhuudjdjkkd',
page: _page,
row: _row,
communityName: this.navCommunityInfo.searchCommunityName
})
this.communitys = communitys
this.total = records;
this.currentPage = _page;
},
_chooseCurrentCommunity(_currentCommunity) {
setCurrentCommunity(_currentCommunity)
this.dialogVisible = false;
window.location.href="/"
},
_queryEnterCommunity() {
this.listEnterCommunity(DEFAULT_PAGE, DEFAULT_ROW);
}
}
}
</script>
<style scoped>
.filter-container {
margin-bottom: 20px;
}
.pagination-container {
margin-top: 20px;
text-align: center;
}
</style>

View File

@ -4,6 +4,15 @@ import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import i18n from './i18n'
import {getCommunityName,getCommunityId} from '@/api/community/communityApi'
Vue.prototype.getCommunityId = function(){
return getCommunityId()
}
Vue.prototype.getCommunityName = function(){
return getCommunityName()
}
Vue.prototype.hasPrivilege = function(_privaleges) {
// 确保 _privaleges 是数组,如果不是则转换为数组

View File

@ -44,7 +44,8 @@ export const messages = {
tip: 'Tip',
fetchError: 'Failed to fetch data',
deleteError: 'Failed to delete',
submitError: 'Failed to submit'
submitError: 'Failed to submit',
moreCommunity:'More Community'
}
},
zh: {
@ -92,7 +93,8 @@ export const messages = {
tip: '提示',
fetchError: '获取数据失败',
deleteError: '删除失败',
submitError: '提交失败'
submitError: '提交失败',
moreCommunity:'更多小区'
}
}
}

View File

@ -11,6 +11,16 @@
</el-menu>
</div>
<div class="header-right">
<el-dropdown @command="changeCommunity" v-if="storeInfo.storeTypeCd == '800900000003'" class="margin-right">
<span class="user-info">
{{ curCommunityName }}
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="c" v-for="(c,index) in communitys" :key="index">{{ c.name }}</el-dropdown-item>
<el-dropdown-item command="moreCommunity" class="moreCommunity">{{ $t('layout.moreCommunity') }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<el-dropdown @command="handleCommand">
<span class="user-info">
{{ username }}
@ -59,11 +69,17 @@
<router-view />
</el-main>
</el-container>
<more-community ref="moreCommunity"/>
</el-container>
</template>
<script>
import { _getMenuCatalog, getMenuTree } from '@/api/user/menuApi'
import { getStoreInfo } from "@/api/user/indexApi"
import { deepCopy,setCurrentCommunity } from "@/utils/vc"
import {getCommunityName,_loadCommunityInfo} from '@/api/community/communityApi'
import moreCommunity from '@/components/community/moreCommunity.vue'
export default {
name: 'Layout',
data() {
@ -71,22 +87,50 @@ export default {
catalogs: [],
menuTree: [],
subMenus: [],
menuWidth:80,
menuWidth: 80,
menuId: '',
curMenuName: '',
activeMenu: '',
activeSubMenu: 'communityList',
searchText: '',
username: '',
curCommunityName:'',
communitys:[],
storeInfo: {
storeTypeCd: '',
storeId: ''
},
}
},
created() {
let _user = JSON.parse(localStorage.getItem('user'));
this.username = _user.name
this._loadStoreInfo()
this.loadCatalogs()
this.curCommunityName = getCommunityName()
this.loadCommunity()
},
components:{
moreCommunity
},
methods: {
async loadCommunity(){
const {communitys} = await _loadCommunityInfo()
this.communitys = communitys
},
async _loadStoreInfo() {
this.loading = true
try {
const res = await getStoreInfo()
deepCopy(res, this.storeInfo);
} catch (error) {
console.error('登录失败:', error)
} finally {
this.loading = false
}
},
async loadCatalogs() {
this.loading = true
try {
@ -95,7 +139,7 @@ export default {
return;
}
this.catalogs = res.data;
if(this.catalogs && this.catalogs.length>0){
if (this.catalogs && this.catalogs.length > 0) {
this._changeMenuCatalog(this.catalogs[0])
}
} catch (error) {
@ -134,6 +178,14 @@ export default {
localStorage.setItem('language', command)
}
},
changeCommunity(community){
if(community == 'moreCommunity'){
this.$refs.moreCommunity.open()
return
}
setCurrentCommunity(community);
this.curCommunityName = getCommunityName()
},
handleMenuSelect(index) {
//
this.$router.push({ name: index })
@ -141,9 +193,9 @@ export default {
loadMenuTree(_catalog) {
getMenuTree(_catalog).then(res => {
let _menus = res.data;
_menus.sort(function(a, b) {
return a.seq - b.seq
});
_menus.sort(function (a, b) {
return a.seq - b.seq
});
this.menuTree = _menus;
})
},
@ -204,19 +256,18 @@ export default {
// } else {
// _href += ("?tab=" + _tabName)
// }
if(_href.indexOf('/#/')>-1){
_href = _href.replace('/#/','/')
if (_href.indexOf('/#/') > -1) {
_href = _href.replace('/#/', '/')
}
console.log(_href,_tabName)
console.log(_href, _tabName)
this.$router.push(_href)
this.$router.push(_href)
},
}
}
</script>
<style lang="scss" scoped>
.app-wrapper {
height: 100vh;
}
@ -369,6 +420,11 @@ export default {
}
}
.moreCommunity{
font-weight: 600;
color: #212529;
font-size: 12px;
}
.vc-menu-main ul li {
height: 45px;
line-height: 45px;