Skip to content

Commit

Permalink
feat: delete select tenent and Inject globalTenant (#1487)
Browse files Browse the repository at this point in the history
Co-authored-by: 吹泡泡的团子 <[email protected]>
  • Loading branch information
GRL-bxy and 吹泡泡的团子 authored Sep 29, 2023
1 parent 19b465f commit ef73f25
Show file tree
Hide file tree
Showing 26 changed files with 378 additions and 236 deletions.
9 changes: 7 additions & 2 deletions threadpool/console/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ export default {
.getCurrentUser(userName)
.then((response) => {
const { resources } = response;
resources.map((item) => ({
...item,
tenantId: item.resource
}))
if (response.role == 'ROLE_ADMIN') {
resources.unshift({
action: "rw",
resource: "所有租户",
username: userName
resource: this.$t('common.allTenant'),
username: userName,
tenantId: this.$t('common.allTenant'),
})
}
this.$store.dispatch('tenant/setTenantList', resources)
Expand Down
23 changes: 20 additions & 3 deletions threadpool/console/src/layout/components/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import Hamburger from '@/components/Hamburger'
import ErrorLog from '@/components/ErrorLog'
import langChange from '@/locale/langChange'
import { i18nConfig } from '@/locale/config'
export default {
data() {
Expand All @@ -82,6 +83,13 @@
'tenantInfo'
])
},
watch: {
tenantInfo(newVal) {
this.tenant.tenantId = newVal.tenantId
this.tenant.resource = newVal.resource
console.log("ischangLang", newVal)
}
},
methods: {
toggleSideBar() {
this.$store.dispatch('app/toggleSideBar')
Expand All @@ -97,29 +105,38 @@
.getCurrentUser(userName)
.then((response) => {
const { resources } = response;
resources.map((item) => ({
...item,
tenantId: item.resource
}))
if (response.role == 'ROLE_ADMIN') {
resources.unshift({
action: "rw",
resource: "所有租户",
username: userName
resource: this.$t('common.allTenant'),
username: userName,
tenantId: this.$t('common.allTenant'),
})
}
this.$store.dispatch('tenant/setTenantList', resources)
this.$store.dispatch('tenant/setTenantInfo', this.tenantInfo || resources[0])
this.tenant = this.tenantInfo || resources[0]
console.log("isResour", resources[0], this.tenant)
})
.catch(() => {});
},
async changeTenant(index) {
console.log("isTenList", this.tenantList)
let tenant = {
tenantId: this.tenantList[index].resource,
resource: this.tenantList[index].resource,
current: 1,
desc: true,
size: 10,
}
this.$store.dispatch('tenant/setTenantInfo', tenant)
tenant.tenantId = tenant.tenantId == '所有租户' ? '' : tenant.tenantId
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)
Expand Down
1 change: 1 addition & 0 deletions threadpool/console/src/locale/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default {
audit: 'Audit',
yes: 'Yes',
no: 'No',
allTenant: 'ALL TENANT'
},

// 运行报表
Expand Down
1 change: 1 addition & 0 deletions threadpool/console/src/locale/lang/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default {
audit: '审核',
yes: '是',
no: '否',
allTenant: '所有租户'
},

// 运行报表
Expand Down
41 changes: 40 additions & 1 deletion threadpool/console/src/locale/langChange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
</div>
</template>
<script>
import { langSelectList } from './config'
import { langSelectList, i18nConfig } from './config'
import * as user from '@/api/hippo4j-user';
import { mapGetters } from 'vuex';
export default {
data() {
return {
Expand All @@ -31,6 +33,7 @@ export default {
this.currentLang = lang || null
},
computed: {
...mapGetters(['tenantInfo', 'tenantList']),
currentLangName() {
const langItem = this.langSelectList.find(item => item.lang === this.currentLang)
return langItem?.name || '选择语言'
Expand All @@ -42,6 +45,42 @@ export default {
this.currentLang = value
this.$i18n.locale = value
localStorage.setItem('locale_lang', value)
this.changeTenant()
},
changeTenant() {
const userName = this.$cookie.get('userName');
user.getCurrentUser(userName)
.then((response) => {
const { resources } = response;
resources.map((item) => ({
...item,
tenantId: item.resource
}))
//change lang =》 change global tenantInfo
if (response.role == 'ROLE_ADMIN') {
//判断tenantInfo是否为所有租户选项
let tenantId = this.tenantInfo.resource
let isAllTenant = tenantId == i18nConfig.messages.zh.common.allTenant || tenantId == i18nConfig.messages.en.common.allTenant
let alreadyHasAll = resources[0] == i18nConfig.messages.zh.common.allTenant || resources[0] == i18nConfig.messages.en.common.allTenant
if (alreadyHasAll) {
this.$set(resources[0], 'resource', this.$t('common.allTenant'))
this.$store.dispatch('tenant/setTenantList', resources)
} else {
resources.unshift({
action: "rw",
resource: this.$t('common.allTenant'),
username: userName,
tenantId: this.$t('common.allTenant'),
})
this.$store.dispatch('tenant/setTenantList', resources)
}
if (isAllTenant) {
this.$store.dispatch('tenant/setTenantInfo', resources[0])
}
}
})
}
}
}
Expand Down
29 changes: 14 additions & 15 deletions threadpool/console/src/views/hippo4j/instance/index.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
<template>
<div class="app-container">
<div class="filter-container">
<el-select
v-model="listQuery.tenantId"
:placeholder="$t('tenantManage.tenantRequired')"
style="width: 220px"
filterable
class="filter-item"
@change="tenantSelectList()"
>
<el-option
v-for="item in tenantOptions"
:key="item.key"
:label="item.display_name"
:value="item.key"
/>
</el-select>
<el-select
v-model="listQuery.itemId"
:placeholder="$t('projectManage.itemRequired')"
Expand Down Expand Up @@ -443,6 +428,8 @@ import * as instanceApi from '@/api/hippo4j-instance';
import waves from '@/directive/waves';
import Pagination from '@/components/Pagination';
import axios from 'axios';
import { mapGetters } from 'vuex';
import { i18nConfig } from '@/locale/config'
export default {
components: { Pagination },
Expand Down Expand Up @@ -567,6 +554,9 @@ export default {
};
},
computed:{
...mapGetters([
'tenantInfo'
]),
rules(){
return{
tenantId: [{ required: true, message: this.$t('message.requiredError'), trigger: 'blur' }],
Expand All @@ -585,6 +575,12 @@ export default {
}
},
},
watch: {
tenantInfo(newVal, oldVal) {
this.listQuery.tenantId = newVal.tenantId;
this.fetchData()
}
},
created() {
// this.fetchData()
// 初始化项目
Expand All @@ -595,6 +591,9 @@ export default {
this.$forceUpdate();
},
fetchData() {
this.listQuery.tenantId = this?.tenantInfo?.tenantId || this.listQuery.tenantId
let isAllTenant = this.listQuery.tenantId == i18nConfig.messages.zh.common.allTenant || this.listQuery.tenantId == i18nConfig.messages.en.common.allTenant
this.listQuery.tenantId = isAllTenant ? '' : this.listQuery.tenantId
if (!this.listQuery.tenantId) {
this.$message.warning(this.$t('message.emptyWarning', { name: this.$t('tenantManage.tenant') }));
return;
Expand Down
14 changes: 14 additions & 0 deletions threadpool/console/src/views/hippo4j/item/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ import * as jobProjectApi from '@/api/hippo4j-item';
import * as tenantApi from '@/api/hippo4j-tenant';
import waves from '@/directive/waves';
import Pagination from '@/components/Pagination';
import { mapGetters } from 'vuex';
import { i18nConfig } from '@/locale/config'
export default {
name: 'JobProject',
Expand Down Expand Up @@ -218,6 +220,9 @@ export default {
};
},
computed:{
...mapGetters([
'tenantInfo'
]),
rules(){
return{
tenantId: [{ required: true, message: this.$t('message.requiredError'), trigger: 'blur' }],
Expand All @@ -228,6 +233,12 @@ export default {
}
},
},
watch: {
tenantInfo(newVal, oldVal) {
this.listQuery.tenantId = newVal.tenantId;
this.fetchData()
}
},
created() {
this.fetchData();
// 初始化租户
Expand All @@ -238,6 +249,9 @@ export default {
},
methods: {
fetchData() {
this.listQuery.tenantId = this?.tenantInfo?.tenantId || this.listQuery.tenantId
let isAllTenant = this.listQuery.tenantId == i18nConfig.messages.zh.common.allTenant || this.listQuery.tenantId == i18nConfig.messages.en.common.allTenant
this.listQuery.tenantId = isAllTenant ? '' : this.listQuery.tenantId
this.listLoading = true;
jobProjectApi.list(this.listQuery).then((response) => {
const { records } = response;
Expand Down
5 changes: 5 additions & 0 deletions threadpool/console/src/views/hippo4j/log/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@
import * as logApi from '@/api/hippo4j-log';
import waves from '@/directive/waves';
import Pagination from '@/components/Pagination';
import { mapGetters } from 'vuex';
import { i18nConfig } from '@/locale/config'
export default {
name: 'JobProject',
Expand Down Expand Up @@ -198,6 +200,9 @@ export default {
},
methods: {
fetchData() {
// this.listQuery.tenantId = this?.tenantInfo?.tenantId || this.listQuery.tenantId
// let isAllTenant = this.listQuery.tenantId == i18nConfig.messages.zh.common.allTenant || this.listQuery.tenantId == i18nConfig.messages.en.common.allTenant
// this.listQuery.tenantId = isAllTenant ? '' : this.listQuery.tenantId
this.listLoading = true;
logApi.list(this.listQuery).then((response) => {
const { records } = response;
Expand Down
31 changes: 16 additions & 15 deletions threadpool/console/src/views/hippo4j/monitor/index.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
<template>
<div class="dashboard-editor-container">
<div class="filter-container">
<el-select
v-model="listQuery.tenantId"
:placeholder="$t('tenantManage.tenantRequired')"
style="width: 220px"
filterable
class="filter-item"
@change="tenantSelectList()"
>
<el-option
v-for="item in tenantOptions"
:key="item.key"
:label="item.display_name"
:value="item.key"
/>
</el-select>
<el-select
v-model="listQuery.itemId"
:placeholder="$t('projectManage.itemRequired')"
Expand Down Expand Up @@ -156,6 +141,8 @@ import * as tenantApi from '@/api/hippo4j-tenant';
import * as threadPoolApi from '@/api/hippo4j-threadPool';
import * as instanceApi from '@/api/hippo4j-instance';
import * as monitorApi from '@/api/hippo4j-monitor';
import { mapGetters } from 'vuex';
import { i18nConfig } from '@/locale/config'
export default {
name: 'Monitor',
Expand Down Expand Up @@ -261,11 +248,25 @@ export default {
lastTaskCount: null,
};
},
computed: {
...mapGetters([
'tenantInfo'
]),
},
watch: {
tenantInfo(newVal, oldVal) {
this.listQuery.tenantId = newVal.tenantId;
this.fetchData()
}
},
async created() {
this.initSelect();
},
methods: {
fetchData() {
this.listQuery.tenantId = this?.tenantInfo?.tenantId || this.listQuery.tenantId
let isAllTenant = this.listQuery.tenantId == i18nConfig.messages.zh.common.allTenant || this.listQuery.tenantId == i18nConfig.messages.en.common.allTenant
this.listQuery.tenantId = isAllTenant ? '' : this.listQuery.tenantId
if (!this.listQuery.tenantId) {
this.$message.warning(this.$t('message.emptyWarning', { name: this.$t('tenantManage.tenant') }));
return;
Expand Down
Loading

0 comments on commit ef73f25

Please sign in to comment.