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

Loading…
Cancel
Save