feat: 客户端管理 表单
This commit is contained in:
parent
1a8eeb2abe
commit
aca098640a
41
apps/web-antd/src/api/system/client/index.ts
Normal file
41
apps/web-antd/src/api/system/client/index.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import type { Client } from './model';
|
||||
|
||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
enum Api {
|
||||
clientChangeStatus = '/system/client/changeStatus',
|
||||
clientExport = '/system/client/export',
|
||||
clientList = '/system/client/list',
|
||||
root = '/system/client',
|
||||
}
|
||||
|
||||
export function clientList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<Client>>(Api.clientList, { params });
|
||||
}
|
||||
|
||||
export function clientExport(data: any) {
|
||||
return commonExport(Api.clientExport, data);
|
||||
}
|
||||
|
||||
export function clientInfo(id: ID) {
|
||||
return requestClient.get<Client>(`${Api.root}/${id}`);
|
||||
}
|
||||
|
||||
export function clientAdd(data: any) {
|
||||
return requestClient.postWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
export function clientUpdate(data: any) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
export function clientChangeStatus(data: any) {
|
||||
return requestClient.putWithMsg<void>(Api.root, data);
|
||||
}
|
||||
|
||||
export function clientRemove(ids: IDS) {
|
||||
return requestClient.deleteWithMsg(`${Api.root}/${ids.join(',')}`);
|
||||
}
|
12
apps/web-antd/src/api/system/client/model.d.ts
vendored
Normal file
12
apps/web-antd/src/api/system/client/model.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
export interface Client {
|
||||
id: number;
|
||||
clientId: string;
|
||||
clientKey: string;
|
||||
clientSecret: string;
|
||||
grantTypeList: string[];
|
||||
grantType: string;
|
||||
deviceType: string;
|
||||
activeTimeout: number;
|
||||
timeout: number;
|
||||
status: string;
|
||||
}
|
126
apps/web-antd/src/views/system/client/client-drawer.vue
Normal file
126
apps/web-antd/src/views/system/client/client-drawer.vue
Normal file
@ -0,0 +1,126 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenDrawer } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { useVbenForm } from '#/adapter';
|
||||
import { clientAdd, clientUpdate } from '#/api/system/client';
|
||||
|
||||
import { drawerSchema } from './data';
|
||||
import SecretInput from './secret-input.vue';
|
||||
|
||||
const emit = defineEmits<{ reload: [] }>();
|
||||
|
||||
interface DrawerProps {
|
||||
update: boolean;
|
||||
record?: any;
|
||||
}
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const title = computed(() => {
|
||||
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
||||
});
|
||||
|
||||
const [BasicForm, formApi] = useVbenForm({
|
||||
layout: 'vertical',
|
||||
schema: drawerSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
function setupForm(update: boolean, record?: any) {
|
||||
formApi.setState((prev) => {
|
||||
return {
|
||||
...prev,
|
||||
schema: prev.schema?.map((item) => {
|
||||
if (item.fieldName === 'clientId') {
|
||||
return {
|
||||
...item,
|
||||
dependencies: {
|
||||
show: () => update,
|
||||
triggerFields: [''],
|
||||
},
|
||||
};
|
||||
}
|
||||
if (
|
||||
item.fieldName === 'clientKey' ||
|
||||
item.fieldName === 'clientSecret'
|
||||
) {
|
||||
return {
|
||||
...item,
|
||||
componentProps: {
|
||||
...item.componentProps,
|
||||
disabled: update,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (item.fieldName === 'status') {
|
||||
return {
|
||||
...item,
|
||||
componentProps: {
|
||||
...item.componentProps,
|
||||
disabled: record?.id === 1,
|
||||
},
|
||||
};
|
||||
}
|
||||
return item;
|
||||
}),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const [BasicDrawer, drawerApi] = useVbenDrawer({
|
||||
onCancel: handleCancel,
|
||||
onConfirm: handleConfirm,
|
||||
async onOpenChange(isOpen) {
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
}
|
||||
drawerApi.drawerLoading(true);
|
||||
const { record, update } = drawerApi.getData() as DrawerProps;
|
||||
isUpdate.value = update;
|
||||
// 初始化
|
||||
setupForm(update, record);
|
||||
if (update && record) {
|
||||
for (const key in record) {
|
||||
await formApi.setFieldValue(key, record[key]);
|
||||
}
|
||||
}
|
||||
drawerApi.drawerLoading(false);
|
||||
},
|
||||
});
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
drawerApi.drawerLoading(true);
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
const data = await formApi.getValues();
|
||||
console.log(data);
|
||||
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 :title="title" class="w-[600px]">
|
||||
<BasicForm>
|
||||
<template #clientSecret="slotProps">
|
||||
<SecretInput v-bind="slotProps" :disabled="isUpdate" />
|
||||
</template>
|
||||
</BasicForm>
|
||||
</BasicDrawer>
|
||||
</template>
|
106
apps/web-antd/src/views/system/client/data.tsx
Normal file
106
apps/web-antd/src/views/system/client/data.tsx
Normal file
@ -0,0 +1,106 @@
|
||||
import type { FormSchemaGetter } from '#/adapter';
|
||||
|
||||
import { DictEnum } from '@vben/constants';
|
||||
import { getPopupContainer } from '@vben/utils';
|
||||
|
||||
import { getDictOptions } from '#/utils/dict';
|
||||
|
||||
export const drawerSchema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
show: () => false,
|
||||
triggerFields: [''],
|
||||
},
|
||||
fieldName: 'id',
|
||||
label: 'id',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
placeholder: '请输入',
|
||||
},
|
||||
dependencies: {
|
||||
show: () => false,
|
||||
triggerFields: [''],
|
||||
},
|
||||
fieldName: 'clientId',
|
||||
label: '客户端ID',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入',
|
||||
},
|
||||
fieldName: 'clientKey',
|
||||
label: '客户端key',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'clientSecret',
|
||||
label: '客户端密钥',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
getPopupContainer,
|
||||
mode: 'multiple',
|
||||
optionFilterProp: 'label',
|
||||
options: getDictOptions(DictEnum.SYS_GRANT_TYPE),
|
||||
placeholder: '请选择',
|
||||
},
|
||||
fieldName: 'grantTypeList',
|
||||
label: '授权类型',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: false,
|
||||
class: 'w-full',
|
||||
getPopupContainer,
|
||||
options: getDictOptions(DictEnum.SYS_DEVICE_TYPE),
|
||||
placeholder: '请选择',
|
||||
},
|
||||
fieldName: 'deviceType',
|
||||
label: '设备类型',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
addonAfter: '秒',
|
||||
placeholder: '请输入',
|
||||
},
|
||||
defaultValue: 1800,
|
||||
fieldName: 'activeTimeout',
|
||||
label: 'Token活跃超时时间',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
addonAfter: '秒',
|
||||
placeholder: '请输入',
|
||||
},
|
||||
defaultValue: 604_800,
|
||||
fieldName: 'timeout',
|
||||
label: 'Token固定超时时间',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
buttonStyle: 'solid',
|
||||
options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
|
||||
optionType: 'button',
|
||||
},
|
||||
defaultValue: '0',
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
];
|
@ -1,9 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import CommonSkeleton from '#/views/common';
|
||||
import { Page, useVbenDrawer } from '@vben/common-ui';
|
||||
|
||||
import clientDrawer from './client-drawer.vue';
|
||||
|
||||
const [ClientDrawer, drawerApi] = useVbenDrawer({
|
||||
connectedComponent: clientDrawer,
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
drawerApi.setData({ update: false });
|
||||
drawerApi.open();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<CommonSkeleton />
|
||||
</div>
|
||||
<Page>
|
||||
<a-button type="primary" @click="handleAdd">add</a-button>
|
||||
<ClientDrawer />
|
||||
</Page>
|
||||
</template>
|
||||
|
60
apps/web-antd/src/views/system/client/secret-input.vue
Normal file
60
apps/web-antd/src/views/system/client/secret-input.vue
Normal file
@ -0,0 +1,60 @@
|
||||
<script setup lang="ts">
|
||||
import { Icon } from '@vben/icons';
|
||||
|
||||
import { Input } from 'ant-design-vue';
|
||||
|
||||
import { buildUUID } from '#/utils/uuid';
|
||||
|
||||
defineOptions({ name: 'SecretInput' });
|
||||
|
||||
defineProps({
|
||||
disabled: {
|
||||
default: false,
|
||||
type: Boolean,
|
||||
},
|
||||
placeholder: {
|
||||
default: '请输入密钥或随机生成',
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
const value = defineModel<string>('value', {
|
||||
required: false,
|
||||
type: String,
|
||||
});
|
||||
|
||||
function refreshSecret() {
|
||||
value.value = buildUUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* 万一要在每次新增时打开Drawer刷新
|
||||
* 需要调用实例方法
|
||||
*/
|
||||
defineExpose({ refreshSecret });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Input v-model:value="value" :disabled="disabled" :placeholder="placeholder">
|
||||
<template v-if="!disabled" #addonAfter>
|
||||
<a-button type="primary" @click="refreshSecret">
|
||||
<div class="flex items-center gap-[4px]">
|
||||
<Icon icon="charm:refresh" />
|
||||
<span>随机生成</span>
|
||||
</div>
|
||||
</a-button>
|
||||
</template>
|
||||
</Input>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
:deep(.ant-input-group-addon) {
|
||||
padding: 0;
|
||||
border: none;
|
||||
}
|
||||
|
||||
:deep(.ant-btn-primary) {
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user