Commit 0e3df9ef62d561bb32279c8bf5242cb703ced1ec

Authored by wuxw
1 parent 65dba003

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

src/api/community/communityApi.js
1 -import { setCommunitys,setCurrentCommunity } from "@/utils/vc" 1 +import { setCommunitys,setCurrentCommunity,getCurrentCommunity } from "@/utils/vc"
2 import request from '@/utils/request' 2 import request from '@/utils/request'
3 export function _loadCommunityInfo(_param) { 3 export function _loadCommunityInfo(_param) {
4 return new Promise((resolve, reject) => { 4 return new Promise((resolve, reject) => {
@@ -51,4 +51,32 @@ export function getDict(tableName,tableColumns) { @@ -51,4 +51,32 @@ export function getDict(tableName,tableColumns) {
51 reject(error) 51 reject(error)
52 }) 52 })
53 }) 53 })
  54 +}
  55 +
  56 +export function getCommunityId() {
  57 + return getCurrentCommunity().communityId
  58 +}
  59 +
  60 +
  61 +
  62 +export function getCommunityName() {
  63 + return getCurrentCommunity().name
  64 +}
  65 +
  66 +export function getMyEnteredCommunitys(_param) {
  67 + return new Promise((resolve, reject) => {
  68 + request({
  69 + url: '/community.listMyEnteredCommunitys',
  70 + method: 'get',
  71 + params: {
  72 + ..._param
  73 + }
  74 + }).then(response => {
  75 + const res = response.data
  76 + // 获取验证码成功
  77 + resolve(res)
  78 + }).catch(error => {
  79 + reject(error)
  80 + })
  81 + })
54 } 82 }
55 \ No newline at end of file 83 \ No newline at end of file
src/components/community/moreCommunity.vue 0 → 100644
  1 +<template>
  2 + <div>
  3 + <el-dialog title="切换小区" :visible.sync="dialogVisible" width="70%" :close-on-click-modal="false">
  4 + <div class="filter-container text-right">
  5 + <el-input :placeholder="$t('communityManage.table.name')" v-model="navCommunityInfo.searchCommunityName"
  6 + style="width: 300px;" class="filter-item"></el-input>
  7 + <el-button class="filter-item" type="primary" icon="el-icon-search" @click="_queryEnterCommunity">
  8 + {{ $t('common.search') }}
  9 + </el-button>
  10 + </div>
  11 +
  12 + <el-table :data="communitys" border fit highlight-current-row style="width: 100%; margin-top: 20px;">
  13 + <el-table-column :label="$t('communityManage.table.communityId')" prop="communityId"
  14 + align="center"></el-table-column>
  15 + <el-table-column :label="$t('communityManage.table.name')" prop="name" align="center"></el-table-column>
  16 + <el-table-column :label="$t('common.operation')" align="center">
  17 + <template slot-scope="scope">
  18 + <el-button size="mini" @click="_chooseCurrentCommunity(scope.row)">
  19 + {{ $t('common.select') }}
  20 + </el-button>
  21 + </template>
  22 + </el-table-column>
  23 + </el-table>
  24 +
  25 + <div class="pagination-container">
  26 + <el-pagination @current-change="handleCurrentChange" :current-page="currentPage" :page-size="pageSize"
  27 + layout="total, prev, pager, next" :total="total"></el-pagination>
  28 + </div>
  29 + </el-dialog>
  30 + </div>
  31 +</template>
  32 +
  33 +<script>
  34 +import { getMyEnteredCommunitys } from '@/api/community/communityApi'
  35 +import { setCurrentCommunity } from "@/utils/vc"
  36 +
  37 +const DEFAULT_PAGE = 1;
  38 +const DEFAULT_ROW = 10;
  39 +
  40 +
  41 +export default {
  42 + name: 'ChooseEnterCommunity',
  43 + data() {
  44 + return {
  45 + dialogVisible: false,
  46 + currentPage: DEFAULT_PAGE,
  47 + pageSize: DEFAULT_ROW,
  48 + total: 0,
  49 + communitys: [],
  50 + navCommunityInfo: {
  51 + _currentCommunity: {},
  52 + communityInfos: [],
  53 + communityInfo: [],
  54 + errorInfo: '',
  55 + searchCommunityName: ''
  56 + }
  57 + }
  58 + },
  59 + created() {
  60 + },
  61 + methods: {
  62 + open() {
  63 + this.dialogVisible = true;
  64 + this.navCommunityInfo.searchCommunityName = '';
  65 + this.listEnterCommunity(DEFAULT_PAGE, DEFAULT_ROW);
  66 + },
  67 + handleCurrentChange(val) {
  68 + this.currentPage = val;
  69 + this.listEnterCommunity(val, DEFAULT_ROW);
  70 + },
  71 + async listEnterCommunity(_page, _row) {
  72 +
  73 + const { communitys, records } = await getMyEnteredCommunitys({
  74 + _uid: '123mlkdinkldldijdhuudjdjkkd',
  75 + page: _page,
  76 + row: _row,
  77 + communityName: this.navCommunityInfo.searchCommunityName
  78 + })
  79 + this.communitys = communitys
  80 + this.total = records;
  81 + this.currentPage = _page;
  82 +
  83 + },
  84 + _chooseCurrentCommunity(_currentCommunity) {
  85 + setCurrentCommunity(_currentCommunity)
  86 +
  87 + this.dialogVisible = false;
  88 + window.location.href="/"
  89 + },
  90 + _queryEnterCommunity() {
  91 + this.listEnterCommunity(DEFAULT_PAGE, DEFAULT_ROW);
  92 + }
  93 + }
  94 +}
  95 +</script>
  96 +
  97 +<style scoped>
  98 +.filter-container {
  99 + margin-bottom: 20px;
  100 +}
  101 +
  102 +.pagination-container {
  103 + margin-top: 20px;
  104 + text-align: center;
  105 +}
  106 +</style>
0 \ No newline at end of file 107 \ No newline at end of file
src/main.js
@@ -4,6 +4,15 @@ import router from &#39;./router&#39; @@ -4,6 +4,15 @@ import router from &#39;./router&#39;
4 import ElementUI from 'element-ui' 4 import ElementUI from 'element-ui'
5 import 'element-ui/lib/theme-chalk/index.css' 5 import 'element-ui/lib/theme-chalk/index.css'
6 import i18n from './i18n' 6 import i18n from './i18n'
  7 +import {getCommunityName,getCommunityId} from '@/api/community/communityApi'
  8 +
  9 +Vue.prototype.getCommunityId = function(){
  10 + return getCommunityId()
  11 +}
  12 +Vue.prototype.getCommunityName = function(){
  13 + return getCommunityName()
  14 +}
  15 +
7 16
8 Vue.prototype.hasPrivilege = function(_privaleges) { 17 Vue.prototype.hasPrivilege = function(_privaleges) {
9 // 确保 _privaleges 是数组,如果不是则转换为数组 18 // 确保 _privaleges 是数组,如果不是则转换为数组
src/views/layout/LayoutLang.js
@@ -44,7 +44,8 @@ export const messages = { @@ -44,7 +44,8 @@ export const messages = {
44 tip: 'Tip', 44 tip: 'Tip',
45 fetchError: 'Failed to fetch data', 45 fetchError: 'Failed to fetch data',
46 deleteError: 'Failed to delete', 46 deleteError: 'Failed to delete',
47 - submitError: 'Failed to submit' 47 + submitError: 'Failed to submit',
  48 + moreCommunity:'More Community'
48 } 49 }
49 }, 50 },
50 zh: { 51 zh: {
@@ -92,7 +93,8 @@ export const messages = { @@ -92,7 +93,8 @@ export const messages = {
92 tip: '提示', 93 tip: '提示',
93 fetchError: '获取数据失败', 94 fetchError: '获取数据失败',
94 deleteError: '删除失败', 95 deleteError: '删除失败',
95 - submitError: '提交失败' 96 + submitError: '提交失败',
  97 + moreCommunity:'更多小区'
96 } 98 }
97 } 99 }
98 } 100 }
99 \ No newline at end of file 101 \ No newline at end of file
src/views/layout/layout.vue
@@ -11,6 +11,16 @@ @@ -11,6 +11,16 @@
11 </el-menu> 11 </el-menu>
12 </div> 12 </div>
13 <div class="header-right"> 13 <div class="header-right">
  14 + <el-dropdown @command="changeCommunity" v-if="storeInfo.storeTypeCd == '800900000003'" class="margin-right">
  15 + <span class="user-info">
  16 + {{ curCommunityName }}
  17 + <i class="el-icon-arrow-down el-icon--right"></i>
  18 + </span>
  19 + <el-dropdown-menu slot="dropdown">
  20 + <el-dropdown-item :command="c" v-for="(c,index) in communitys" :key="index">{{ c.name }}</el-dropdown-item>
  21 + <el-dropdown-item command="moreCommunity" class="moreCommunity">{{ $t('layout.moreCommunity') }}</el-dropdown-item>
  22 + </el-dropdown-menu>
  23 + </el-dropdown>
14 <el-dropdown @command="handleCommand"> 24 <el-dropdown @command="handleCommand">
15 <span class="user-info"> 25 <span class="user-info">
16 {{ username }} 26 {{ username }}
@@ -59,11 +69,17 @@ @@ -59,11 +69,17 @@
59 <router-view /> 69 <router-view />
60 </el-main> 70 </el-main>
61 </el-container> 71 </el-container>
  72 + <more-community ref="moreCommunity"/>
62 </el-container> 73 </el-container>
63 </template> 74 </template>
64 75
65 <script> 76 <script>
66 import { _getMenuCatalog, getMenuTree } from '@/api/user/menuApi' 77 import { _getMenuCatalog, getMenuTree } from '@/api/user/menuApi'
  78 +import { getStoreInfo } from "@/api/user/indexApi"
  79 +import { deepCopy,setCurrentCommunity } from "@/utils/vc"
  80 +import {getCommunityName,_loadCommunityInfo} from '@/api/community/communityApi'
  81 +import moreCommunity from '@/components/community/moreCommunity.vue'
  82 +
67 export default { 83 export default {
68 name: 'Layout', 84 name: 'Layout',
69 data() { 85 data() {
@@ -71,22 +87,50 @@ export default { @@ -71,22 +87,50 @@ export default {
71 catalogs: [], 87 catalogs: [],
72 menuTree: [], 88 menuTree: [],
73 subMenus: [], 89 subMenus: [],
74 - menuWidth:80, 90 + menuWidth: 80,
75 menuId: '', 91 menuId: '',
76 curMenuName: '', 92 curMenuName: '',
77 activeMenu: '', 93 activeMenu: '',
78 activeSubMenu: 'communityList', 94 activeSubMenu: 'communityList',
79 searchText: '', 95 searchText: '',
80 username: '', 96 username: '',
  97 + curCommunityName:'',
  98 + communitys:[],
  99 + storeInfo: {
  100 + storeTypeCd: '',
  101 + storeId: ''
  102 + },
81 103
82 } 104 }
83 }, 105 },
84 created() { 106 created() {
85 let _user = JSON.parse(localStorage.getItem('user')); 107 let _user = JSON.parse(localStorage.getItem('user'));
86 this.username = _user.name 108 this.username = _user.name
  109 + this._loadStoreInfo()
87 this.loadCatalogs() 110 this.loadCatalogs()
  111 + this.curCommunityName = getCommunityName()
  112 + this.loadCommunity()
  113 + },
  114 + components:{
  115 + moreCommunity
88 }, 116 },
89 methods: { 117 methods: {
  118 + async loadCommunity(){
  119 + const {communitys} = await _loadCommunityInfo()
  120 + this.communitys = communitys
  121 + },
  122 + async _loadStoreInfo() {
  123 + this.loading = true
  124 + try {
  125 + const res = await getStoreInfo()
  126 + deepCopy(res, this.storeInfo);
  127 + } catch (error) {
  128 + console.error('登录失败:', error)
  129 + } finally {
  130 + this.loading = false
  131 + }
  132 +
  133 + },
90 async loadCatalogs() { 134 async loadCatalogs() {
91 this.loading = true 135 this.loading = true
92 try { 136 try {
@@ -95,7 +139,7 @@ export default { @@ -95,7 +139,7 @@ export default {
95 return; 139 return;
96 } 140 }
97 this.catalogs = res.data; 141 this.catalogs = res.data;
98 - if(this.catalogs && this.catalogs.length>0){ 142 + if (this.catalogs && this.catalogs.length > 0) {
99 this._changeMenuCatalog(this.catalogs[0]) 143 this._changeMenuCatalog(this.catalogs[0])
100 } 144 }
101 } catch (error) { 145 } catch (error) {
@@ -134,6 +178,14 @@ export default { @@ -134,6 +178,14 @@ export default {
134 localStorage.setItem('language', command) 178 localStorage.setItem('language', command)
135 } 179 }
136 }, 180 },
  181 + changeCommunity(community){
  182 + if(community == 'moreCommunity'){
  183 + this.$refs.moreCommunity.open()
  184 + return
  185 + }
  186 + setCurrentCommunity(community);
  187 + this.curCommunityName = getCommunityName()
  188 + },
137 handleMenuSelect(index) { 189 handleMenuSelect(index) {
138 // 处理菜单选择 190 // 处理菜单选择
139 this.$router.push({ name: index }) 191 this.$router.push({ name: index })
@@ -141,9 +193,9 @@ export default { @@ -141,9 +193,9 @@ export default {
141 loadMenuTree(_catalog) { 193 loadMenuTree(_catalog) {
142 getMenuTree(_catalog).then(res => { 194 getMenuTree(_catalog).then(res => {
143 let _menus = res.data; 195 let _menus = res.data;
144 - _menus.sort(function(a, b) {  
145 - return a.seq - b.seq  
146 - }); 196 + _menus.sort(function (a, b) {
  197 + return a.seq - b.seq
  198 + });
147 this.menuTree = _menus; 199 this.menuTree = _menus;
148 }) 200 })
149 }, 201 },
@@ -204,19 +256,18 @@ export default { @@ -204,19 +256,18 @@ export default {
204 // } else { 256 // } else {
205 // _href += ("?tab=" + _tabName) 257 // _href += ("?tab=" + _tabName)
206 // } 258 // }
207 - if(_href.indexOf('/#/')>-1){  
208 - _href = _href.replace('/#/','/') 259 + if (_href.indexOf('/#/') > -1) {
  260 + _href = _href.replace('/#/', '/')
209 } 261 }
210 - console.log(_href,_tabName) 262 + console.log(_href, _tabName)
211 263
212 - this.$router.push(_href) 264 + this.$router.push(_href)
213 }, 265 },
214 } 266 }
215 } 267 }
216 </script> 268 </script>
217 269
218 <style lang="scss" scoped> 270 <style lang="scss" scoped>
219 -  
220 .app-wrapper { 271 .app-wrapper {
221 height: 100vh; 272 height: 100vh;
222 } 273 }
@@ -369,6 +420,11 @@ export default { @@ -369,6 +420,11 @@ export default {
369 } 420 }
370 } 421 }
371 422
  423 +.moreCommunity{
  424 + font-weight: 600;
  425 + color: #212529;
  426 + font-size: 12px;
  427 +}
372 .vc-menu-main ul li { 428 .vc-menu-main ul li {
373 height: 45px; 429 height: 45px;
374 line-height: 45px; 430 line-height: 45px;