chore: 租户套餐demo
This commit is contained in:
parent
0fc428d58e
commit
dff055951f
47
apps/web-antd/src/api/system/tenant-package/index.ts
Normal file
47
apps/web-antd/src/api/system/tenant-package/index.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import type { TenantPackage } from './model';
|
||||
|
||||
import type { ID, IDS, PageQuery } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
enum Api {
|
||||
packageChangeStatus = '/system/tenant/package/changeStatus',
|
||||
packageExport = '/system/tenant/package/export',
|
||||
packageList = '/system/tenant/package/list',
|
||||
packageSelectList = '/system/tenant/package/selectList',
|
||||
root = '/system/tenant/package',
|
||||
}
|
||||
|
||||
export function packageList(params?: PageQuery) {
|
||||
return requestClient.get<TenantPackage[]>(Api.packageList, { params });
|
||||
}
|
||||
|
||||
// 下拉框
|
||||
export function packageSelectList() {
|
||||
return requestClient.get<TenantPackage[]>(Api.packageSelectList);
|
||||
}
|
||||
|
||||
export function packageExport(data: any) {
|
||||
return commonExport(Api.packageExport, data);
|
||||
}
|
||||
|
||||
export function packageInfo(id: ID) {
|
||||
return requestClient.get<TenantPackage>(`${Api.root}/${id}`);
|
||||
}
|
||||
|
||||
export function packageAdd(data: any) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
export function packageUpdate(data: any) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
export function packageChangeStatus(data: any) {
|
||||
return requestClient.putWithMsg(Api.packageChangeStatus, data);
|
||||
}
|
||||
|
||||
export function packageRemove(ids: IDS) {
|
||||
return requestClient.deleteWithMsg(`${Api.root}/${ids}`);
|
||||
}
|
17
apps/web-antd/src/api/system/tenant-package/model.d.ts
vendored
Normal file
17
apps/web-antd/src/api/system/tenant-package/model.d.ts
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @description 租户套餐
|
||||
* @param packageId id
|
||||
* @param packageName 名称
|
||||
* @param menuIds 菜单id 格式为[1,2,3] 返回为string 提交为数组
|
||||
* @param remark 备注
|
||||
* @param menuCheckStrictly 是否关联父节点
|
||||
* @param status 状态
|
||||
*/
|
||||
export interface TenantPackage {
|
||||
packageId: string;
|
||||
packageName: string;
|
||||
menuIds: number[] | string;
|
||||
remark: string;
|
||||
menuCheckStrictly: boolean;
|
||||
status: string;
|
||||
}
|
59
apps/web-antd/src/views/system/tenantPackage/data.ts
Normal file
59
apps/web-antd/src/views/system/tenantPackage/data.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import type { FormSchemaGetter } from '#/adapter';
|
||||
|
||||
export const schema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入',
|
||||
},
|
||||
fieldName: 'packageName',
|
||||
label: '套餐名称',
|
||||
},
|
||||
];
|
||||
|
||||
export const drawerSchema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
show: () => false,
|
||||
triggerFields: [''],
|
||||
},
|
||||
fieldName: 'packageId',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
show: () => false,
|
||||
triggerFields: [''],
|
||||
},
|
||||
fieldName: 'menuCheckStrictly',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入',
|
||||
},
|
||||
fieldName: 'packageName',
|
||||
label: '套餐名称',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'menuIds',
|
||||
defaultValue: [],
|
||||
fieldName: 'menuIds',
|
||||
label: '关联菜单',
|
||||
},
|
||||
{
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入',
|
||||
},
|
||||
fieldName: 'remark',
|
||||
formItemClass: 'items-baseline',
|
||||
},
|
||||
];
|
||||
|
||||
// 租户管理 不可分配 只有superadmin有权限操作 分配了也没用
|
||||
export const excludeIds = [
|
||||
6, 121, 122, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615,
|
||||
];
|
@ -1,9 +1,104 @@
|
||||
<script setup lang="ts">
|
||||
import CommonSkeleton from '#/views/common';
|
||||
import type { DataNode } from 'ant-design-vue/es/tree';
|
||||
import type { CheckInfo } from 'ant-design-vue/es/vc-tree/props';
|
||||
|
||||
import type { Menu } from '#/api/system/menu/model';
|
||||
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { Page, useVbenDrawer } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { filter, listToTree } from '@vben/utils';
|
||||
|
||||
import { Card, Tree } from 'ant-design-vue';
|
||||
|
||||
import { menuList } from '#/api/system/menu';
|
||||
|
||||
import { excludeIds } from './data';
|
||||
import tenantPackageDrawer from './tenant-package-drawer.vue';
|
||||
|
||||
const [TenantPackageDrawer, drawerApi] = useVbenDrawer({
|
||||
connectedComponent: tenantPackageDrawer,
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
drawerApi.setData({ update: false });
|
||||
drawerApi.open();
|
||||
}
|
||||
|
||||
const menuTree = ref<DataNode[]>([]);
|
||||
// checkable 状态下节点选择完全受控(父子节点选中状态不再关联)
|
||||
const menuCheckStrictly = ref<boolean>(false);
|
||||
const checkedKeys = ref<string[]>([]);
|
||||
|
||||
/** 已经选择的所有节点 包括子/父节点 */
|
||||
const checkedMenuKeys = ref<(number | string)[]>([]);
|
||||
/**
|
||||
*
|
||||
* @param checkedKeys 已经选中的子节点的ID
|
||||
* @param info info.halfCheckedKeys为父节点的ID
|
||||
*/
|
||||
type CheckedState<T = number | string> =
|
||||
| { checked: T[]; halfChecked: T[] }
|
||||
| T[];
|
||||
function handleChecked(checkedKeys: CheckedState, info: CheckInfo) {
|
||||
// 数组的话为节点关联
|
||||
if (Array.isArray(checkedKeys)) {
|
||||
const halfCheckedKeys: number[] = (info.halfCheckedKeys || []) as number[];
|
||||
checkedMenuKeys.value = [...halfCheckedKeys, ...checkedKeys];
|
||||
} else {
|
||||
checkedMenuKeys.value = [...checkedKeys.checked];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 不显示租户相关菜单 分配了也没法使用
|
||||
* @param menuTree menus
|
||||
*/
|
||||
function transformMenu(menuTree: Menu[]) {
|
||||
return filter(
|
||||
menuTree,
|
||||
(item) => {
|
||||
if (excludeIds.includes(item.menuId)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
{ id: 'menuId', pid: 'parentId', children: 'children' },
|
||||
);
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const resp = await menuList();
|
||||
// 去除租户相关菜单(分配了也无权限)
|
||||
const afterTransform = transformMenu(resp);
|
||||
const tree = listToTree(afterTransform, { id: 'menuId' });
|
||||
menuTree.value = tree;
|
||||
});
|
||||
|
||||
function test() {
|
||||
console.log(checkedMenuKeys.value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<CommonSkeleton />
|
||||
</div>
|
||||
<Page>
|
||||
<a-button type="primary" @click="handleAdd">
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
<a-button @click="test">获取</a-button>
|
||||
<Card>
|
||||
<Tree
|
||||
v-if="menuTree.length > 0"
|
||||
v-model:check-strictly="menuCheckStrictly"
|
||||
v-model:checked-keys="checkedKeys"
|
||||
:checkable="true"
|
||||
:field-names="{ title: 'menuName', key: 'menuId' }"
|
||||
:selectable="false"
|
||||
:tree-data="menuTree"
|
||||
@check="handleChecked"
|
||||
/>
|
||||
</Card>
|
||||
<TenantPackageDrawer />
|
||||
</Page>
|
||||
</template>
|
||||
|
@ -0,0 +1,136 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenDrawer } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { Card, Tree } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter';
|
||||
import { clientAdd, clientInfo, clientUpdate } from '#/api/system/client';
|
||||
|
||||
import { drawerSchema } from './data';
|
||||
|
||||
const emit = defineEmits<{ reload: [] }>();
|
||||
|
||||
interface DrawerProps {
|
||||
update: boolean;
|
||||
id?: number | string;
|
||||
}
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const title = computed(() => {
|
||||
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
||||
});
|
||||
|
||||
const [BasicForm, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
formItemClass: 'col-span-2',
|
||||
},
|
||||
layout: 'vertical',
|
||||
schema: drawerSchema(),
|
||||
showDefaultActions: false,
|
||||
wrapperClass: 'grid-cols-2',
|
||||
});
|
||||
|
||||
function setupForm(update: boolean) {
|
||||
formApi.updateSchema([
|
||||
{
|
||||
dependencies: {
|
||||
show: () => update,
|
||||
triggerFields: [''],
|
||||
},
|
||||
fieldName: 'clientId',
|
||||
},
|
||||
{
|
||||
componentProps: {
|
||||
disabled: update,
|
||||
},
|
||||
fieldName: 'clientKey',
|
||||
},
|
||||
{
|
||||
componentProps: {
|
||||
disabled: update,
|
||||
},
|
||||
fieldName: 'clientSecret',
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
const [BasicDrawer, drawerApi] = useVbenDrawer({
|
||||
onCancel: handleCancel,
|
||||
onConfirm: handleConfirm,
|
||||
async onOpenChange(isOpen) {
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
}
|
||||
drawerApi.drawerLoading(true);
|
||||
const { id, update } = drawerApi.getData() as DrawerProps;
|
||||
isUpdate.value = update;
|
||||
// 初始化
|
||||
setupForm(update);
|
||||
if (update && id) {
|
||||
const record = await clientInfo(id);
|
||||
// 不能禁用id为1的记录
|
||||
formApi.updateSchema([
|
||||
{
|
||||
componentProps: {
|
||||
disabled: record.id === 1,
|
||||
},
|
||||
fieldName: 'status',
|
||||
},
|
||||
]);
|
||||
|
||||
for (const key in record) {
|
||||
await formApi.setFieldValue(key, record[key as keyof typeof record]);
|
||||
}
|
||||
}
|
||||
drawerApi.drawerLoading(false);
|
||||
},
|
||||
});
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
drawerApi.drawerLoading(true);
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
const data = await formApi.getValues();
|
||||
await (isUpdate.value ? clientUpdate(data) : clientAdd(data));
|
||||
emit('reload');
|
||||
await handleCancel();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
drawerApi.drawerLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCancel() {
|
||||
drawerApi.close();
|
||||
await formApi.resetForm();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BasicDrawer :close-on-click-modal="false" :title="title" class="w-[600px]">
|
||||
<BasicForm>
|
||||
<template #menuIds="slotProps">
|
||||
<Card class="w-full">
|
||||
<Tree v-bind="slotProps" />
|
||||
</Card>
|
||||
</template>
|
||||
</BasicForm>
|
||||
</BasicDrawer>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
/**
|
||||
自定义组件校验失败样式
|
||||
*/
|
||||
:deep(.form-valid-error .ant-input[name='clientSecret']) {
|
||||
border-color: hsl(var(--destructive));
|
||||
box-shadow: 0 0 0 2px rgb(255 38 5 / 6%);
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user