mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-04-12 12:16:38 +08:00
feat(project): 添加vben5前端
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenDrawer } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { cloneDeep } from '@vben/utils';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { clientAdd, clientInfo, clientUpdate } from '#/api/system/client';
|
||||
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
||||
|
||||
import { drawerSchema } from './data';
|
||||
import SecretInput from './secret-input.vue';
|
||||
|
||||
const emit = defineEmits<{ reload: [] }>();
|
||||
|
||||
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',
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
layout: 'vertical',
|
||||
schema: drawerSchema(),
|
||||
showDefaultActions: false,
|
||||
wrapperClass: 'grid-cols-2 gap-x-4',
|
||||
});
|
||||
|
||||
function setupForm(update: boolean) {
|
||||
formApi.updateSchema([
|
||||
{
|
||||
dependencies: {
|
||||
show: () => update,
|
||||
triggerFields: [''],
|
||||
},
|
||||
fieldName: 'clientId',
|
||||
},
|
||||
{
|
||||
componentProps: {
|
||||
disabled: update,
|
||||
},
|
||||
fieldName: 'clientKey',
|
||||
},
|
||||
{
|
||||
componentProps: {
|
||||
disabled: update,
|
||||
},
|
||||
fieldName: 'clientSecret',
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||
{
|
||||
initializedGetter: defaultFormValueGetter(formApi),
|
||||
currentGetter: defaultFormValueGetter(formApi),
|
||||
},
|
||||
);
|
||||
|
||||
// 提取生成状态字段Schema的函数
|
||||
const getStatusSchema = (disabled: boolean) => [
|
||||
{
|
||||
componentProps: { disabled },
|
||||
fieldName: 'status',
|
||||
},
|
||||
];
|
||||
|
||||
const [BasicDrawer, drawerApi] = useVbenDrawer({
|
||||
onBeforeClose,
|
||||
onClosed: handleClosed,
|
||||
onConfirm: handleConfirm,
|
||||
async onOpenChange(isOpen) {
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
}
|
||||
drawerApi.drawerLoading(true);
|
||||
|
||||
const { id } = drawerApi.getData() as { id?: number | string };
|
||||
isUpdate.value = !!id;
|
||||
// 初始化
|
||||
setupForm(isUpdate.value);
|
||||
if (isUpdate.value && id) {
|
||||
const record = await clientInfo(id);
|
||||
// 不能禁用id为1的记录
|
||||
formApi.updateSchema(getStatusSchema(record.id === 1));
|
||||
await formApi.setValues(record);
|
||||
} else {
|
||||
// 新增模式: 确保状态字段可用
|
||||
formApi.updateSchema(getStatusSchema(false));
|
||||
}
|
||||
await markInitialized();
|
||||
|
||||
drawerApi.drawerLoading(false);
|
||||
},
|
||||
});
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
drawerApi.lock(true);
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
const data = cloneDeep(await formApi.getValues());
|
||||
await (isUpdate.value ? clientUpdate(data) : clientAdd(data));
|
||||
resetInitialized();
|
||||
emit('reload');
|
||||
drawerApi.close();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
drawerApi.lock(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleClosed() {
|
||||
await formApi.resetForm();
|
||||
resetInitialized();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BasicDrawer :title="title" class="w-[600px]">
|
||||
<BasicForm>
|
||||
<template #clientSecret="slotProps">
|
||||
<SecretInput v-bind="slotProps" :disabled="isUpdate" />
|
||||
</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>
|
||||
196
Yi.Vben5.Vue3/apps/web-antd/src/views/system/client/data.tsx
Normal file
196
Yi.Vben5.Vue3/apps/web-antd/src/views/system/client/data.tsx
Normal file
@@ -0,0 +1,196 @@
|
||||
import type { FormSchemaGetter } from '#/adapter/form';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { DictEnum } from '@vben/constants';
|
||||
import { getPopupContainer } from '@vben/utils';
|
||||
|
||||
import { getDictOptions } from '#/utils/dict';
|
||||
import { renderDict, renderDictTags } from '#/utils/render';
|
||||
|
||||
export const querySchema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'clientKey',
|
||||
label: '客户端key',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'clientSecret',
|
||||
label: '客户端密钥',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
|
||||
},
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
];
|
||||
|
||||
export const columns: VxeGridProps['columns'] = [
|
||||
{ type: 'checkbox', width: 60 },
|
||||
{
|
||||
title: '客户端ID',
|
||||
field: 'clientId',
|
||||
showOverflow: true,
|
||||
},
|
||||
{
|
||||
title: '客户端key',
|
||||
field: 'clientKey',
|
||||
},
|
||||
{
|
||||
title: '客户端密钥',
|
||||
field: 'clientSecret',
|
||||
},
|
||||
{
|
||||
title: '授权类型',
|
||||
field: 'grantTypeList',
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
if (!row.grantTypeList) {
|
||||
return '无';
|
||||
}
|
||||
return renderDictTags(
|
||||
row.grantTypeList,
|
||||
getDictOptions(DictEnum.SYS_GRANT_TYPE),
|
||||
true,
|
||||
4,
|
||||
);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '设备类型',
|
||||
field: 'deviceType',
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
return renderDict(row.deviceType, DictEnum.SYS_DEVICE_TYPE);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'token活跃时间',
|
||||
field: 'activeTimeout',
|
||||
formatter({ row }) {
|
||||
return `${row.activeTimeout}秒`;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'token超时时间',
|
||||
field: 'timeout',
|
||||
formatter({ row }) {
|
||||
return `${row.timeout}秒`;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
field: 'status',
|
||||
slots: {
|
||||
default: 'status',
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'action',
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
title: '操作',
|
||||
resizable: false,
|
||||
width: 'auto',
|
||||
},
|
||||
];
|
||||
|
||||
export const drawerSchema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
show: () => false,
|
||||
triggerFields: [''],
|
||||
},
|
||||
fieldName: 'id',
|
||||
label: 'id',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
},
|
||||
dependencies: {
|
||||
show: () => false,
|
||||
triggerFields: [''],
|
||||
},
|
||||
fieldName: 'clientId',
|
||||
label: '客户端ID',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'clientKey',
|
||||
label: '客户端key',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'clientSecret',
|
||||
label: '客户端密钥',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
getPopupContainer,
|
||||
mode: 'multiple',
|
||||
optionFilterProp: 'label',
|
||||
options: getDictOptions(DictEnum.SYS_GRANT_TYPE),
|
||||
},
|
||||
fieldName: 'grantTypeList',
|
||||
label: '授权类型',
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: false,
|
||||
getPopupContainer,
|
||||
options: getDictOptions(DictEnum.SYS_DEVICE_TYPE),
|
||||
},
|
||||
fieldName: 'deviceType',
|
||||
label: '设备类型',
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
addonAfter: '秒',
|
||||
placeholder: '请输入',
|
||||
},
|
||||
defaultValue: 1800,
|
||||
fieldName: 'activeTimeout',
|
||||
formItemClass: 'col-span-2 lg:col-span-1',
|
||||
help: '指定时间无操作则过期(单位:秒), 默认30分钟(1800秒)',
|
||||
label: 'Token活跃超时时间',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
addonAfter: '秒',
|
||||
},
|
||||
defaultValue: 604_800,
|
||||
fieldName: 'timeout',
|
||||
formItemClass: 'col-span-2 lg:col-span-1 ',
|
||||
help: '指定时间必定过期(单位:秒),默认七天(604800秒)',
|
||||
label: 'Token固定超时时间',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
buttonStyle: 'solid',
|
||||
options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
|
||||
optionType: 'button',
|
||||
},
|
||||
defaultValue: '0',
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
];
|
||||
182
Yi.Vben5.Vue3/apps/web-antd/src/views/system/client/index.vue
Normal file
182
Yi.Vben5.Vue3/apps/web-antd/src/views/system/client/index.vue
Normal file
@@ -0,0 +1,182 @@
|
||||
<script setup lang="ts">
|
||||
import type { VbenFormProps } from '@vben/common-ui';
|
||||
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { Client } from '#/api/system/client/model';
|
||||
|
||||
import { useAccess } from '@vben/access';
|
||||
import { Page, useVbenDrawer } from '@vben/common-ui';
|
||||
import { getVxePopupContainer } from '@vben/utils';
|
||||
|
||||
import { Modal, Popconfirm, Space } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid, vxeCheckboxChecked } from '#/adapter/vxe-table';
|
||||
import {
|
||||
clientChangeStatus,
|
||||
clientExport,
|
||||
clientList,
|
||||
clientRemove,
|
||||
} from '#/api/system/client';
|
||||
import { TableSwitch } from '#/components/table';
|
||||
import { commonDownloadExcel } from '#/utils/file/download';
|
||||
|
||||
import clientDrawer from './client-drawer.vue';
|
||||
import { columns, querySchema } from './data';
|
||||
|
||||
const formOptions: VbenFormProps = {
|
||||
commonConfig: {
|
||||
labelWidth: 80,
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
schema: querySchema(),
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
||||
};
|
||||
|
||||
const gridOptions: VxeGridProps = {
|
||||
checkboxConfig: {
|
||||
// 高亮
|
||||
highlight: true,
|
||||
// 翻页时保留选中状态
|
||||
reserve: true,
|
||||
// 点击行选中
|
||||
// trigger: 'row',
|
||||
checkMethod: ({ row }) => (row as Client)?.id !== 1,
|
||||
},
|
||||
columns,
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
pagerConfig: {},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues = {}) => {
|
||||
return await clientList({
|
||||
SkipCount: page.currentPage,
|
||||
MaxResultCount: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
id: 'system-client-index',
|
||||
showOverflow: false,
|
||||
};
|
||||
|
||||
const [BasicTable, tableApi] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
});
|
||||
|
||||
const [ClientDrawer, drawerApi] = useVbenDrawer({
|
||||
connectedComponent: clientDrawer,
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
drawerApi.setData({});
|
||||
drawerApi.open();
|
||||
}
|
||||
|
||||
async function handleEdit(record: Client) {
|
||||
drawerApi.setData({ id: record.id });
|
||||
drawerApi.open();
|
||||
}
|
||||
|
||||
async function handleDelete(row: Client) {
|
||||
await clientRemove([row.id]);
|
||||
await tableApi.query();
|
||||
}
|
||||
|
||||
function handleMultiDelete() {
|
||||
const rows = tableApi.grid.getCheckboxRecords();
|
||||
const ids = rows.map((row: Client) => row.id);
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
okType: 'danger',
|
||||
content: `确认删除选中的${ids.length}条记录吗?`,
|
||||
onOk: async () => {
|
||||
await clientRemove(ids);
|
||||
await tableApi.query();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function handleDownloadExcel() {
|
||||
commonDownloadExcel(clientExport, '客户端数据', tableApi.formApi.form.values);
|
||||
}
|
||||
|
||||
const { hasAccessByCodes } = useAccess();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page :auto-content-height="true">
|
||||
<BasicTable table-title="客户端列表">
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<a-button
|
||||
v-access:code="['system:client:export']"
|
||||
@click="handleDownloadExcel"
|
||||
>
|
||||
{{ $t('pages.common.export') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
:disabled="!vxeCheckboxChecked(tableApi)"
|
||||
danger
|
||||
type="primary"
|
||||
v-access:code="['system:client:remove']"
|
||||
@click="handleMultiDelete"
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
type="primary"
|
||||
v-access:code="['system:client:add']"
|
||||
@click="handleAdd"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
</Space>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<!-- pc不允许禁用 禁用了直接登录不了 应该设置disabled -->
|
||||
<!-- 登录提示: 认证权限类型已禁用 -->
|
||||
<TableSwitch
|
||||
v-model:value="row.status"
|
||||
:api="() => clientChangeStatus(row)"
|
||||
:disabled="row.id === 1 || !hasAccessByCodes(['system:client:edit'])"
|
||||
@reload="tableApi.query()"
|
||||
/>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<ghost-button
|
||||
v-access:code="['system:client:edit']"
|
||||
@click.stop="handleEdit(row)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</ghost-button>
|
||||
<Popconfirm
|
||||
:disabled="row.id === 1"
|
||||
:get-popup-container="getVxePopupContainer"
|
||||
placement="left"
|
||||
title="确认删除?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<ghost-button
|
||||
:disabled="row.id === 1"
|
||||
danger
|
||||
v-access:code="['system:client:remove']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</ghost-button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<ClientDrawer @reload="tableApi.query()" />
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script setup lang="ts">
|
||||
import { IconifyIcon } from '@vben/icons';
|
||||
import { buildUUID } from '@vben/utils';
|
||||
|
||||
import { Input } from 'ant-design-vue';
|
||||
|
||||
defineOptions({ name: 'SecretInput' });
|
||||
|
||||
withDefaults(defineProps<{ disabled?: boolean; placeholder?: string }>(), {
|
||||
disabled: false,
|
||||
placeholder: '请输入密钥或随机生成',
|
||||
});
|
||||
|
||||
const value = defineModel<string>('value', {
|
||||
required: false,
|
||||
});
|
||||
|
||||
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]">
|
||||
<IconifyIcon 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>
|
||||
Reference in New Issue
Block a user