parent
0fc428d58e
commit
dff055951f
@ -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}`);
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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,
|
||||
];
|
||||
@ -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