Browse Source

chore: 编写代码模板接口

master
wangxiang 1 year ago
parent
commit
3c3d69bd6c
  1. 26
      src/api/platform/system/controller/gencodeTemplateGroup.ts
  2. 20
      src/api/platform/system/controller/gencodeTemplateObj.ts
  3. 15
      src/api/platform/system/entity/gencodeTemplateGroup.ts
  4. 17
      src/api/platform/system/entity/gencodeTemplateObj.ts
  5. 51
      src/views/system/devtools/template/TemplateModal.vue
  6. 154
      src/views/system/devtools/template/client.data.ts
  7. 52
      src/views/system/devtools/template/index.vue
  8. 72
      src/views/system/devtools/template/template.data.ts

26
src/api/platform/system/controller/gencodeTemplateGroup.ts

@ -0,0 +1,26 @@
import type { GencodeTemplateGroup, GencodeTemplateGroupParams, GencodeTemplateGroupResult } from '/@/api/platform/system/entity/gencodeTemplateGroup';
import { defHttp } from '/@/utils/http/axios';
enum Api {
list = '/system_proxy/system/devtools/genCodeTemplateGroup/list',
add = '/system_proxy/system/devtools/genCodeTemplateGroup/save',
get = '/system_proxy/system/devtools/genCodeTemplateGroup',
edit = '/system_proxy/system/devtools/genCodeTemplateGroup/update',
del = '/system_proxy/system/devtools/genCodeTemplateGroup/remove',
saveAndGencodeTemplateObj = '/system_proxy/system/devtools/genCodeTemplateGroup/saveAndGencodeTemplateObj',
copy = '/system_proxy/system/devtools/genCodeTemplateGroup/copy'
}
export const listGenCodeTemplateGroup = (params?: Partial<GencodeTemplateGroupParams>) => defHttp.get<GencodeTemplateGroupResult>({ url: Api.list, params }, { isReturnResultResponse: true });
export const addGenCodeTemplateGroup = (params: Partial<GencodeTemplateGroup>) => defHttp.post({ url: Api.add, data: params });
export const editGenCodeTemplateGroup = (params: Partial<GencodeTemplateGroup>) => defHttp.put({ url: Api.edit, data: params });
export const saveAndGencodeTemplateObj = (params: Partial<GencodeTemplateGroup>) => defHttp.put({ url: Api.saveAndGencodeTemplateObj, data: params });
export const copyGenCodeTemplateGroup = (params: Partial<GencodeTemplateGroup>) => defHttp.put({ url: Api.copy, data: params });
export const getGenCodeTemplateGroup = (id: string) => defHttp.get<GencodeTemplateGroup>({ url: `${Api.get}/${id}` });
export const delGenCodeTemplateGroup = (ids: string) => defHttp.delete({ url: `${Api.del}/${ids}` });

20
src/api/platform/system/controller/gencodeTemplateObj.ts

@ -0,0 +1,20 @@
import type { GencodeTemplateObj, GencodeTemplateObjParams, GencodeTemplateObjResult } from '/@/api/platform/system/entity/gencodeTemplateObj';
import { defHttp } from '/@/utils/http/axios';
enum Api {
list = '/system_proxy/system/devtools/gencodeTemplateObj/list',
add = '/system_proxy/system/devtools/gencodeTemplateObj/save',
get = '/system_proxy/system/devtools/gencodeTemplateObj',
edit = '/system_proxy/system/devtools/gencodeTemplateObj/update',
del = '/system_proxy/system/devtools/gencodeTemplateObj/remove'
}
export const listGencodeTemplateObj = (params?: Partial<GencodeTemplateObjParams>) => defHttp.get<GencodeTemplateObjResult>({ url: Api.list, params }, { isReturnResultResponse: true });
export const addGencodeTemplateObj = (params: Partial<GencodeTemplateObj>) => defHttp.post({ url: Api.add, data: params });
export const editGencodeTemplateObj = (params: Partial<GencodeTemplateObj>) => defHttp.put({ url: Api.edit, data: params });
export const getGencodeTemplateObj = (id: string) => defHttp.get<GencodeTemplateObj>({ url: `${Api.get}/${id}` });
export const delGencodeTemplateObj = (ids: string) => defHttp.delete({ url: `${Api.del}/${ids}` });

15
src/api/platform/system/entity/gencodeTemplateGroup.ts

@ -0,0 +1,15 @@
import type { R } from '/#/axios';
import type { Page, CommonEntity } from '/@/api/common/data/entity';
import type { GencodeTemplateObj } from './gencodeTemplateObj';
export type GencodeTemplateGroupParams = Page & GencodeTemplateGroup;
export interface GencodeTemplateGroup extends CommonEntity {
id: string;
name: string;
type: string;
isSystem: string;
genCodeTemplateObjList: GencodeTemplateObj[];
[key: string]: any;
}
export type GencodeTemplateGroupResult = R<GencodeTemplateGroup[]>;

17
src/api/platform/system/entity/gencodeTemplateObj.ts

@ -0,0 +1,17 @@
import type { R } from '/#/axios';
import type { Page, CommonEntity } from '/@/api/common/data/entity';
export type GencodeTemplateObjParams = Page & GencodeTemplateObj;
export interface GencodeTemplateObj extends CommonEntity {
id: string;
name: string;
groupId: string;
contents: string;
defaultContents: string;
sort: string;
isChild: string;
[key: string]: any;
}
export type GencodeTemplateObjResult = R<GencodeTemplateObj[]>;

51
src/views/system/devtools/template/ClientModal.vue → src/views/system/devtools/template/TemplateModal.vue

@ -11,16 +11,15 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ref, unref } from 'vue'; import { ref, unref } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index'; import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './client.data'; import { formSchema } from './template.data';
import { addClient, editClient, getClient, listClient } from '/@/api/platform/system/controller/client'; import { addGenQueryType, editGenQueryType, getGenQueryType } from '/@/api/platform/system/controller/genQueryType';
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal'; import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
import { isEmpty } from '/@/utils/is';
/** 通用变量统一声明区域 */ /** 通用变量统一声明区域 */
const tag = ref<Nullable<string>>(''); const tag = ref<Nullable<string>>('');
/** https://v3.cn.vuejs.org/api/options-data.html#emits */ /** https://v3.cn.vuejs.org/api/options-data.html#emits */
const emit = defineEmits(['success', 'register']); const emit = defineEmits(['success', 'register']);
const [registerForm, { resetFields, setFieldsValue, validate, clearValidate, updateSchema }] = useForm({ const [registerForm, { resetFields, setFieldsValue, validate, clearValidate, setProps, updateSchema }] = useForm({
labelWidth: 100, labelWidth: 100,
schemas: formSchema, schemas: formSchema,
showActionButtonGroup: false, showActionButtonGroup: false,
@ -30,41 +29,25 @@
// //
await resetFields(); await resetFields();
await clearValidate(); await clearValidate();
await setProps({ disabled: false });
// //
tag.value = data._tag; tag.value = data._tag;
const clientId = data.record?.clientId; const id = data.record?.id;
const props: Partial<ModalProps> = { confirmLoading: false }; const props: Partial<ModalProps> = { confirmLoading: false, showOkBtn: true };
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 // tag
switch (unref(tag)) { switch (unref(tag)) {
case 'add': case 'add':
props.title = '新增客户端'; props.title = '新增查询类型';
break;
case 'view':
props.title = '查看查询类型';
props.showOkBtn = false;
await setProps({ disabled: true });
await setFieldsValue(await getGenQueryType(id));
break; break;
case 'edit': case 'edit':
props.title = '编辑客户端'; props.title = '编辑查询类型';
await setFieldsValue(await getClient(clientId)); await setFieldsValue(await getGenQueryType(id));
break; break;
} }
// : // :
@ -81,10 +64,10 @@
// tag // tag
switch (unref(tag)) { switch (unref(tag)) {
case 'add': case 'add':
await addClient(formData); await addGenQueryType(formData);
break; break;
case 'edit': case 'edit':
await editClient(formData); await editGenQueryType(formData);
break; break;
} }
// //

154
src/views/system/devtools/template/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
}
}
];

52
src/views/system/devtools/template/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: handleViewEdit.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>
<!--弹出窗体区域--> <TemplateModal @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 { listGenQueryType, delGenQueryType } from '/@/api/platform/system/controller/genQueryType';
import { useModal } from '/@/components/Modal'; import { useModal } from '/@/components/Modal';
import ClientModal from './ClientModal.vue'; import TemplateModal from './TemplateModal.vue';
import { columns, searchFormSchema } from './client.data'; import { columns, searchFormSchema } from './template.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: listGenQueryType,
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,37 @@
state.multiple = !rowSelection.length; state.multiple = !rowSelection.length;
} }
/** 新增按钮操作,行内新增与工具栏局域新增通用 */
function handleAdd() { function handleAdd() {
openModal(true,{ _tag: 'add' }); openModal(true,{ _tag: 'add' });
} }
/** 编辑按钮操作,行内编辑 */ function handleViewEdit(record?: Recordable) {
record = record || { id: getSelectRowKeys() };
openModal(true, { _tag: 'view', record });
}
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 delGenQueryType(ids);
createMessage.success('删除成功!'); createMessage.success('删除成功!');
handleRefreshTable(); handleRefreshTable();
} }
}); });
} }
/** 处理表格刷新 */
function handleRefreshTable() { function handleRefreshTable() {
clearSelectedRowKeys(); clearSelectedRowKeys();
reload(); reload();
} }
</script> </script>

72
src/views/system/devtools/template/template.data.ts

@ -0,0 +1,72 @@
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
export const columns: BasicColumn[] = [
{
title: '标签',
dataIndex: 'label',
width: 100
},
{
title: '值',
dataIndex: 'value',
width: 100
},
{
title: '排序',
dataIndex: 'sort',
width: 130
}
];
export const searchFormSchema: FormSchema[] = [
{
field: 'label',
label: '标签',
component: 'Input',
componentProps: {
placeholder: '请输入标签',
},
colProps: { span: 6 }
},
{
field: 'value',
label: '值',
component: 'Input',
componentProps: {
placeholder: '请输入值',
},
colProps: { span: 6 }
}
];
export const formSchema: FormSchema[] = [
{
field: 'id',
label: 'ID',
component: 'Input',
show: false
},
{
field: 'label',
label: '标签',
component: 'Input',
required: true
},
{
field: 'value',
label: '值',
component: 'Input',
required: true
},
{
field: 'sort',
label: '排序',
component: 'InputNumber',
componentProps: {
style: { width:'100%' },
min: 0
},
required: true
}
];
Loading…
Cancel
Save