Browse Source

chore: 表格

master
wangxiang 1 year ago
parent
commit
f9c80939b4
  1. 97
      src/views/system/devtools/genTable/ClientModal.vue
  2. 80
      src/views/system/devtools/genTable/GenTableModal.vue
  3. 154
      src/views/system/devtools/genTable/client.data.ts
  4. 114
      src/views/system/devtools/genTable/genTable.data.ts
  5. 51
      src/views/system/devtools/genTable/index.vue

97
src/views/system/devtools/genTable/ClientModal.vue

@ -1,97 +0,0 @@
<template>
<BasicModal
v-bind="$attrs"
width="720px"
@register="registerModal"
@ok="handleSubmit"
>
<BasicForm @register="registerForm"/>
</BasicModal>
</template>
<script lang="ts" setup>
import { ref, unref } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './client.data';
import { addClient, editClient, getClient, listClient } from '/@/api/platform/system/controller/client';
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
import { isEmpty } from '/@/utils/is';
/** 通用变量统一声明区域 */
const tag = ref<Nullable<string>>('');
/** https://v3.cn.vuejs.org/api/options-data.html#emits */
const emit = defineEmits(['success', 'register']);
const [registerForm, { resetFields, setFieldsValue, validate, clearValidate, updateSchema }] = useForm({
labelWidth: 100,
schemas: formSchema,
showActionButtonGroup: false,
baseColProps: { span: 24 }
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data: BoxPayload = { _tag: '' }) => {
//
await resetFields();
await clearValidate();
//
tag.value = data._tag;
const clientId = data.record?.clientId;
const props: Partial<ModalProps> = { confirmLoading: false };
await updateSchema({
field: 'clientId',
componentProps: {
disabled: unref(tag) != 'add'
},
rules: [
{
required: true,
whitespace: true,
message: '请输入客户端编码'
},
{
validator: async (rule, value) => {
if (!isEmpty(value)) {
const result = await listClient({ clientId: value });
const list = result.data?.filter(item => item.clientId != clientId);
if(list?.length > 0) return Promise.reject('该客户端编码已存在');
}
return Promise.resolve();
},
validateTrigger: 'blur'
}]
});
// tag
switch (unref(tag)) {
case 'add':
props.title = '新增客户端';
break;
case 'edit':
props.title = '编辑客户端';
await setFieldsValue(await getClient(clientId));
break;
}
// :
setModalProps(props);
});
/** 处理弹出框提交 */
async function handleSubmit() {
try {
//
const formData = await validate();
//
setModalProps({ confirmLoading: true });
// tag
switch (unref(tag)) {
case 'add':
await addClient(formData);
break;
case 'edit':
await editClient(formData);
break;
}
//
closeModal();
emit('success');
} finally {
setModalProps({ confirmLoading: false });
}
}
</script>

80
src/views/system/devtools/genTable/GenTableModal.vue

@ -0,0 +1,80 @@
<template>
<BasicModal
v-bind="$attrs"
defaultFullscreen
:canFullscreen="false"
@register="registerModal"
@ok="handleSubmit"
>
<BasicForm @register="registerForm"/>
<AceEditor v-model:value="state.content" @register="registerAceEditor"/>
</BasicModal>
</template>
<script lang="ts" setup>
import { reactive } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './genTable.data';
import { getGenCodeTemplateGroup, saveAndGencodeTemplateObj } from '/@/api/platform/system/controller/gencodeTemplateGroup';
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
import { AceEditor, useAceEditor } from '/@/components/AceEditor';
const state = reactive({
tag: '',
content: ''
});
/** https://v3.cn.vuejs.org/api/options-data.html#emits */
const emit = defineEmits(['success', 'register']);
const [registerForm, { resetFields, setFieldsValue, validate, clearValidate, setProps, updateSchema }] = useForm({
labelWidth: 120,
schemas: formSchema,
showActionButtonGroup: false,
baseColProps: { span: 24 }
});
const [registerAceEditor, { setProps: setAceEditorProps }] = useAceEditor({
lang: 'javascript',
options: {
useWorker: true,
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true,
}
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data: BoxPayload = { _tag: '' }) => {
//
await resetFields();
await clearValidate();
await setProps({ disabled: false });
//
state.tag = data._tag;
const id = data.record?.id;
const props: Partial<ModalProps> = { confirmLoading: false };
// tag
switch (state.tag) {
case 'add':
props.title = '新增模板';
break;
case 'edit':
props.title = '编辑模板';
await setFieldsValue(await getGenCodeTemplateGroup(id));
break;
}
// :
setModalProps(props);
});
/** 处理弹出框提交 */
async function handleSubmit() {
try {
//
const formData = await validate();
//
setModalProps({ confirmLoading: true });
//
closeModal();
emit('success');
} finally {
setModalProps({ confirmLoading: false });
}
}
</script>

154
src/views/system/devtools/genTable/client.data.ts

@ -1,154 +0,0 @@
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
export const columns: BasicColumn[] = [
{
title: '客户端Id',
dataIndex: 'clientId',
width: 100
},
{
title: '客户端密钥',
dataIndex: 'clientSecret',
width: 100
},
{
title: '授权类型',
dataIndex: 'authorizedGrantTypes',
width: 130
},
{
title: '授权范围',
dataIndex: 'scope',
width: 90
},
{
title: '令牌过期秒数',
dataIndex: 'accessTokenValidity',
width: 130
},
{
title: '令牌过期秒数',
dataIndex: 'refreshTokenValidity',
width: 130
},
{
title: '创建时间',
dataIndex: 'createTime',
width: 100
}
];
export const searchFormSchema: FormSchema[] = [
{
field: 'clientId',
label: '客户端编码',
component: 'Input',
componentProps: {
placeholder: '请输入客户端编码',
},
colProps: { span: 8 },
},
{
field: 'dateRange',
label: '创建时间',
component: 'RangePicker',
componentProps: {
style: { width:'100%' },
valueFormat: 'YYYY-MM-DD',
placeholder: ['开始日期','结束日期']
},
colProps: { span: 8 }
}
];
export const formSchema: FormSchema[] = [
{
field: 'id',
label: 'ID',
component: 'Input',
show: false
},
{
field: 'clientId',
label: '客户端Id',
component: 'Input',
required: true,
colProps: {
span: 12
}
},
{
field: 'clientSecret',
label: '客户端密钥',
component: 'Input',
required: true,
colProps: {
span: 12
}
},
{
field: 'authorizedGrantTypes',
label: '授权类型',
component: 'InputTextArea',
required:true,
componentProps: {
rows: 3
},
colProps: {
span: 24
}
},
{
field: 'scope',
label: '授权范围',
component: 'Input',
required:true,
colProps: {
span: 12
}
},
{
field: 'accessTokenValidity',
label: '过期秒数',
component: 'InputNumber',
componentProps: {
style: { width:'100%' },
min: 0
},
colProps: {
span: 12
}
},
{
field: 'refreshTokenValidity',
label: '刷新秒数',
component: 'InputNumber',
componentProps: {
style: { width:'100%' },
min: 0
},
colProps: {
span: 12
}
},
{
field: 'webServerRedirectUri',
label: '回调地址',
component: 'Input',
colProps: {
span: 12
}
},
{
field: 'additionalInformation',
label: '附加说明',
component: 'InputTextArea',
componentProps: {
rows: 6
},
colProps: {
span: 24
}
}
];

114
src/views/system/devtools/genTable/genTable.data.ts

@ -0,0 +1,114 @@
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import {h} from 'vue';
import {Tag} from 'ant-design-vue';
export const columns: BasicColumn[] = [
{
title: '模板名称',
dataIndex: 'name',
},
{
title: '模板分类',
dataIndex: 'type',
customRender: ({record}) => {
const type = record.type;
// 采用二进制~~取反,只要为null或者0等等一些其他的空元素都会转为0
// 第一次取反会运算为-1,在后一次取反会运算为0
const enable = ~~type === 1;
const color = enable ? 'green' : 'warning';
const text = enable ? '单表' : '主附表';
return h(Tag, { color: color }, () => text);
}
},
{
title: '系统模板',
dataIndex: 'isSystem',
customRender: ({ record }) => {
const isSystem = record.isSystem;
// 采用二进制~~取反,只要为null或者0等等一些其他的空元素都会转为0
// 第一次取反会运算为-1,在后一次取反会运算为0
const enable = ~~isSystem === 1;
const color = enable ? 'green' : 'warning';
const text = enable ? '系统内置' : '非系统内置';
return h(Tag, { color: color }, () => text);
}
}
];
export const searchFormSchema: FormSchema[] = [
{
field: 'name',
label: '模板名称',
component: 'Input',
componentProps: {
placeholder: '请输入模板名称',
},
colProps: { span: 6 }
},
{
field: 'type',
label: '模版分类',
component: 'Select',
componentProps: {
options: [
{ label: '单表',value: '1' },
{ label: '主附表',value: '2' }
]
},
colProps: { span: 6 }
}
];
export const formSchema: FormSchema[] = [
{
field: 'id',
label: 'ID',
component: 'Input',
show: false
},
{
field: 'name',
label: '模板名称',
component: 'Input',
required: true,
colProps: { span: 12 },
},
{
field: 'type',
label: '模板分类',
component: 'Select',
required: true,
componentProps: {
options: [
{ label: '单表',value: '1' },
{ label: '主附表',value: '2' }
]
},
colProps: { span: 12 },
},
{
field: 'isSystem',
label: '系统模板',
component: 'Select',
required: true,
componentProps: {
options: [
{ label: '系统内置',value: '1' },
{ label: '非系统内置',value: '0' }
]
},
colProps: { span: 12 },
},
{
label: '备注',
field: 'remarks',
component: 'InputTextArea',
componentProps: {
rows: 2
},
colProps: {
span: 24
}
}
];

51
src/views/system/devtools/genTable/index.vue

@ -6,22 +6,19 @@
> >
<template #toolbar> <template #toolbar>
<a-button <a-button
v-auth="['client_add']"
type="primary" type="primary"
@click="handleAdd()" @click="handleAdd()"
>新增客户端</a-button> >新增</a-button>
<a-button <a-button
v-auth="['client_edit']"
type="primary" type="primary"
:disabled="state.single" :disabled="state.single"
@click="handleEdit()" @click="handleEdit()"
>修改客户端</a-button> >修改</a-button>
<a-button <a-button
v-auth="['client_del']"
type="primary" type="primary"
:disabled="state.multiple" :disabled="state.multiple"
@click="handleDel()" @click="handleDel()"
>删除客户端</a-button> >删除</a-button>
</template> </template>
<template #bodyCell="{ column, record }"> <template #bodyCell="{ column, record }">
<template v-if="column.key === 'action'"> <template v-if="column.key === 'action'">
@ -30,32 +27,34 @@
{ {
label: '编辑', label: '编辑',
icon: 'fa6-regular:pen-to-square', icon: 'fa6-regular:pen-to-square',
auth: ['client_edit'],
onClick: handleEdit.bind(null, record) onClick: handleEdit.bind(null, record)
}, },
{
label: '复制',
icon: 'fa-regular:copy',
onClick: handleCopy.bind(null, record)
},
{ {
label: '删除', label: '删除',
icon: 'ant-design:delete-outlined', icon: 'ant-design:delete-outlined',
color: 'error', color: 'error',
auth: ['client_del'],
onClick: handleDel.bind(null, record) onClick: handleDel.bind(null, record)
}]" }]"
/> />
</template> </template>
</template> </template>
</BasicTable> </BasicTable>
<!--弹出窗体区域--> <GenTableModal @register="registerModal" @success="handleRefreshTable"/>
<ClientModal @register="registerModal" @success="handleRefreshTable"/>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { reactive, toRaw } from 'vue'; import { reactive, toRaw } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table'; import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { listClient, delClient } from '/@/api/platform/system/controller/client'; import { listGenCodeTemplateGroup, delGenCodeTemplateGroup } from '/@/api/platform/system/controller/gencodeTemplateGroup';
import { useModal } from '/@/components/Modal'; import { useModal } from '/@/components/Modal';
import ClientModal from './ClientModal.vue'; import GenTableModal from './GenTableModal.vue';
import { columns, searchFormSchema } from './client.data'; import { columns, searchFormSchema } from './genTable.data';
import { useMessage } from '/@/hooks/web/useMessage'; import { useMessage } from '/@/hooks/web/useMessage';
interface TableState { interface TableState {
@ -73,9 +72,8 @@
const { createConfirm, createMessage } = useMessage(); const { createConfirm, createMessage } = useMessage();
const [registerModal, { openModal }] = useModal(); const [registerModal, { openModal }] = useModal();
const [registerTable, { reload, clearSelectedRowKeys, getSelectRowKeys }] = useTable({ const [registerTable, { reload, clearSelectedRowKeys, getSelectRowKeys }] = useTable({
title: '客户端列表', api: listGenCodeTemplateGroup,
api: listClient, rowKey: 'id',
rowKey: 'clientId',
columns, columns,
formConfig: { formConfig: {
compact: true, compact: true,
@ -83,8 +81,7 @@
schemas: searchFormSchema, schemas: searchFormSchema,
autoSubmitOnEnter: true, autoSubmitOnEnter: true,
showAdvancedButton: true, showAdvancedButton: true,
autoAdvancedLine: 3, autoAdvancedLine: 3
fieldMapToTime: [['dateRange', ['beginTime', 'endTime'], 'YYYY-MM-DD']]
}, },
rowSelection: { type: 'checkbox' }, rowSelection: { type: 'checkbox' },
useSearchForm: true, useSearchForm: true,
@ -96,7 +93,6 @@
width: 220, width: 220,
title: '操作', title: '操作',
dataIndex: 'action', dataIndex: 'action',
//slots: { customRender: 'action' },
fixed: false fixed: false
}, },
handleSearchInfoFn: () => clearSelectedRowKeys() handleSearchInfoFn: () => clearSelectedRowKeys()
@ -109,35 +105,36 @@
state.multiple = !rowSelection.length; state.multiple = !rowSelection.length;
} }
/** 新增按钮操作,行内新增与工具栏局域新增通用 */
function handleAdd() { function handleAdd() {
openModal(true,{ _tag: 'add' }); openModal(true,{ _tag: 'add' });
} }
/** 编辑按钮操作,行内编辑 */ function handleCopy(record?: Recordable) {
record = record || { id: getSelectRowKeys() };
}
function handleEdit(record?: Recordable) { function handleEdit(record?: Recordable) {
record = record || { clientId: getSelectRowKeys() }; record = record || { id: getSelectRowKeys() };
openModal(true, { _tag: 'edit', record }); openModal(true, { _tag: 'edit', record });
} }
/** 删除按钮操作,行内删除 */
async function handleDel(record?: Recordable) { async function handleDel(record?: Recordable) {
const clientIds = record?.clientId || getSelectRowKeys(); const ids = record?.id || getSelectRowKeys();
createConfirm({ createConfirm({
iconType: 'warning', iconType: 'warning',
title: '警告', title: '警告',
content: `是否确认删除客户端编号为${clientIds}客户端吗?`, content: `是否确认删除id编号为${ids}的数据吗?`,
onOk: async () => { onOk: async () => {
await delClient(clientIds); await delGenCodeTemplateGroup(ids);
createMessage.success('删除成功!'); createMessage.success('删除成功!');
handleRefreshTable(); handleRefreshTable();
} }
}); });
} }
/** 处理表格刷新 */
function handleRefreshTable() { function handleRefreshTable() {
clearSelectedRowKeys(); clearSelectedRowKeys();
reload(); reload();
} }
</script> </script>

Loading…
Cancel
Save