feat: 添加同步租户套餐的功能,并更新租户选择器逻辑。
This commit is contained in:
parent
0c40aa32db
commit
d587ce4338
@ -3,10 +3,10 @@ import { computed, onMounted, ref } from 'vue';
|
|||||||
import type { SelectOption } from 'naive-ui';
|
import type { SelectOption } from 'naive-ui';
|
||||||
import { useLoading } from '@sa/hooks';
|
import { useLoading } from '@sa/hooks';
|
||||||
import { fetchTenantList } from '@/service/api';
|
import { fetchTenantList } from '@/service/api';
|
||||||
import { fetchChangeTenant, fetchClearTenant } from '@/service/api/system/tenant';
|
import { fetchClearTenant } from '@/service/api/system/tenant';
|
||||||
import { useAppStore } from '@/store/modules/app';
|
import { useAppStore } from '@/store/modules/app';
|
||||||
import { useTabStore } from '@/store/modules/tab';
|
import { useTabStore } from '@/store/modules/tab';
|
||||||
import { useAuth } from '@/hooks/business/auth';
|
import { useAuthStore } from '@/store/modules/auth';
|
||||||
import { useRouterPush } from '@/hooks/common/router';
|
import { useRouterPush } from '@/hooks/common/router';
|
||||||
|
|
||||||
defineOptions({ name: 'TenantSelect' });
|
defineOptions({ name: 'TenantSelect' });
|
||||||
@ -20,7 +20,7 @@ withDefaults(defineProps<Props>(), {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const { hasRole } = useAuth();
|
const { userInfo } = useAuthStore();
|
||||||
const { clearTabs } = useTabStore();
|
const { clearTabs } = useTabStore();
|
||||||
const { toHome } = useRouterPush();
|
const { toHome } = useRouterPush();
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ const tenantOption = ref<SelectOption[]>([]);
|
|||||||
const { loading, startLoading, endLoading } = useLoading();
|
const { loading, startLoading, endLoading } = useLoading();
|
||||||
|
|
||||||
const showTenantSelect = computed<boolean>(() => {
|
const showTenantSelect = computed<boolean>(() => {
|
||||||
return hasRole('superadmin') && enabled.value;
|
return userInfo.user?.userId === 1 && enabled.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +57,6 @@ async function handleChangeTenant(_tenantId: CommonType.IdType) {
|
|||||||
if (lastSelected.value === _tenantId) {
|
if (lastSelected.value === _tenantId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await fetchChangeTenant(_tenantId);
|
|
||||||
closeAndRefresh('切换租户成功', _tenantId);
|
closeAndRefresh('切换租户成功', _tenantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +81,7 @@ async function handleFetchTenantList() {
|
|||||||
endLoading();
|
endLoading();
|
||||||
}
|
}
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (!hasRole('superadmin')) {
|
if (userInfo.user?.userId !== 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await handleFetchTenantList();
|
await handleFetchTenantList();
|
||||||
|
@ -47,6 +47,15 @@ export function fetchSyncTenantDict() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 同步租户套餐 */
|
||||||
|
export function fetchSyncTenantPackage(params: Api.System.SyncTenantPackageParams) {
|
||||||
|
return request<boolean>({
|
||||||
|
url: '/system/tenant/syncTenantPackage',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** 动态切换租户 */
|
/** 动态切换租户 */
|
||||||
export function fetchChangeTenant(tenantId: CommonType.IdType) {
|
export function fetchChangeTenant(tenantId: CommonType.IdType) {
|
||||||
return request<boolean>({
|
return request<boolean>({
|
||||||
|
3
src/typings/api/system.api.d.ts
vendored
3
src/typings/api/system.api.d.ts
vendored
@ -558,6 +558,9 @@ declare namespace Api {
|
|||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
/** sync tenant package params */
|
||||||
|
type SyncTenantPackageParams = CommonType.RecordNullable<Pick<Api.System.Tenant, 'tenantId' | 'packageId'>>;
|
||||||
|
|
||||||
/** tenant list */
|
/** tenant list */
|
||||||
type TenantList = Api.Common.PaginatingQueryRecord<Tenant>;
|
type TenantList = Api.Common.PaginatingQueryRecord<Tenant>;
|
||||||
|
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
<script setup lang="tsx">
|
<script setup lang="tsx">
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
import { NButton, NDivider } from 'naive-ui';
|
import { NButton, NDivider } from 'naive-ui';
|
||||||
import { fetchBatchDeleteTenant, fetchGetTenantList, fetchSyncTenantDict } from '@/service/api/system/tenant';
|
import {
|
||||||
|
fetchBatchDeleteTenant,
|
||||||
|
fetchGetTenantList,
|
||||||
|
fetchSyncTenantDict,
|
||||||
|
fetchSyncTenantPackage
|
||||||
|
} from '@/service/api/system/tenant';
|
||||||
import { useAppStore } from '@/store/modules/app';
|
import { useAppStore } from '@/store/modules/app';
|
||||||
import { useAuthStore } from '@/store/modules/auth';
|
import { useAuthStore } from '@/store/modules/auth';
|
||||||
import { useAuth } from '@/hooks/business/auth';
|
import { useAuth } from '@/hooks/business/auth';
|
||||||
@ -129,7 +134,7 @@ const {
|
|||||||
icon="material-symbols:sync-outline"
|
icon="material-symbols:sync-outline"
|
||||||
tooltipContent="同步套餐"
|
tooltipContent="同步套餐"
|
||||||
popconfirmContent={`确认同步[${row.companyName}]的套餐吗?`}
|
popconfirmContent={`确认同步[${row.companyName}]的套餐吗?`}
|
||||||
onPositiveClick={() => handleSyncTenantDict()}
|
onPositiveClick={() => handleSyncTenantPackage(row)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -196,6 +201,17 @@ async function handleSyncTenantDict() {
|
|||||||
await getData();
|
await getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleSyncTenantPackage(row: Api.System.Tenant) {
|
||||||
|
const params: Api.System.SyncTenantPackageParams = {
|
||||||
|
tenantId: row.tenantId,
|
||||||
|
packageId: row.packageId
|
||||||
|
};
|
||||||
|
const { error } = await fetchSyncTenantPackage(params);
|
||||||
|
if (error) return;
|
||||||
|
window.$message?.success('同步租户套餐成功');
|
||||||
|
await getData();
|
||||||
|
}
|
||||||
|
|
||||||
async function handleExport() {
|
async function handleExport() {
|
||||||
download('/system/tenant/export', searchParams, `租户列表_${new Date().getTime()}.xlsx`);
|
download('/system/tenant/export', searchParams, `租户列表_${new Date().getTime()}.xlsx`);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user