fix:Tenant selection problem (#1512)

Co-authored-by: 吹泡泡的团子 <baoxinyi_i@didiglobal.com>
pull/1513/merge
GRL-bxy 8 months ago committed by GitHub
parent bb6dbc7e5f
commit a03f7e9f16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,12 +18,8 @@
<!-- </el-tooltip>-->
</template>
<el-select class="select-tenant" v-model="tenant.index" filterable @change="changeTenant">
<el-option
v-for="(item, index) in tenantList"
:key="index"
:label="item.resource"
:value="item.index">
<el-select v-model="currentTenant" class="select-tenant" @change="changeTenant">
<el-option v-for="item in tenantList" :key="item.tenantId" :label="item.resource" :value="item.tenantId">
</el-option>
</el-select>
<langChange />
@ -33,9 +29,6 @@
<i class="el-icon-caret-bottom" />
</div>
<el-dropdown-menu slot="dropdown">
<!--<router-link to="/profile/index">
<el-dropdown-item>Profile</el-dropdown-item>
</router-link>-->
<router-link to="/">
<el-dropdown-item>{{ this.$t('menu.dashboard') }}</el-dropdown-item>
</router-link>
@ -49,16 +42,18 @@
</template>
<script>
import * as jobProjectApi from '@/api/hippo4j-tenant';
import * as user from '@/api/hippo4j-user';
import { mapGetters, mapState } from 'vuex'
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import ErrorLog from '@/components/ErrorLog'
import langChange from '@/locale/langChange'
import { i18nConfig } from '@/locale/config'
export default {
components: {
Breadcrumb,
Hamburger,
langChange
},
data() {
return {
tenant: {
@ -66,14 +61,9 @@
resource: '',
username: ''
},
currentTenant: undefined
}
},
components: {
Breadcrumb,
Hamburger,
ErrorLog,
langChange
},
computed: {
...mapGetters([
'sidebar',
@ -83,13 +73,10 @@
'tenantInfo'
])
},
watch: {
tenantInfo(newVal) {
this.tenant.tenantId = newVal.tenantId
this.tenant.resource = newVal.resource
console.log("ischangLang", newVal, this.tenantList)
}
mounted() {
this.getTenantList()
},
methods: {
toggleSideBar() {
this.$store.dispatch('app/toggleSideBar')
@ -106,59 +93,38 @@
.getCurrentUser(userName)
.then((response) => {
const { resources } = response;
console.log("isTenList1", resources, this.tenantList)
if (response.role == 'ROLE_ADMIN') {
resources.unshift({
action: "rw",
resource: this.$t('common.allTenant'),
username: userName,
tenantId: this.$t('common.allTenant'),
index: 0,
})
}
console.log("isTenList1111111", this.$t('common.allTenant'), resources, this.tenantList)
const resourcesRes = resources.map((item, index) => {
let resourcesRes = resources.map((item) => {
let query = {
...item,
tenantId: item.resource,
index: index,
}
console.log("=============", index, query, item)
return query
})
console.log("isTenList22222", resourcesRes, this.tenantList)
if (response.role == 'ROLE_ADMIN') {
resourcesRes = [{
action: "rw",
resource: this.$t('common.allTenant'),
username: userName,
tenantId: this.$t('common.allTenant'),
}, ...resourcesRes]
}
this.$store.dispatch('tenant/setTenantList', resourcesRes)
this.tenant = JSON.parse(this.$cookie.get('tenantInfo')) || resourcesRes[0]
this.$store.dispatch('tenant/setTenantInfo', this.tenant || resourcesRes[0])
this.$store.dispatch('tenant/setTenantInfo', resourcesRes[0])
this.$cookie.set('tenantInfo', JSON.stringify(this.tenant));
console.log("isTenList2", this.tenantList)
this.currentTenant = resourcesRes[0]?.tenantId
// console.log('resourceRes:::', this.tenantInfo, this.tenantList)
})
.catch(() => { });
},
async changeTenant(index) {
console.log("isTenList", this.tenantList)
let tenant = {
tenantId: this.tenantList[index].resource,
resource: this.tenantList[index].resource,
index: this.tenantList[index].index,
current: 1,
desc: true,
size: 10,
}
changeTenant(id) {
const tenant = this.tenantList.find(item => item.tenantId === id)
this.currentTenant = id
this.$store.dispatch('tenant/setTenantInfo', tenant)
this.$cookie.set('tenantInfo', JSON.stringify(tenant));
let isAllTenant = tenant.tenantId == i18nConfig.messages.zh.common.allTenant || tenant.tenantId == i18nConfig.messages.en.common.allTenant
tenant.tenantId = isAllTenant ? '' : tenant.tenantId
await jobProjectApi.list(tenant).then((response) => {
console.log("isRes", response)
// this.$store.dispatch('tenant/setTenantList', resources)
});
}
},
async mounted() {
this.getTenantList()
},
}
</script>
@ -197,6 +163,7 @@
height: 100%;
line-height: 50px;
display: flex;
&:focus {
outline: none;
}

Loading…
Cancel
Save