mirror of
https://gitee.com/JavaLionLi/plus-ui.git
synced 2026-09-15 16:28:33 +08:00
feat(biz): 新增接口平台和接口定义管理功能
- 添加平台管理API接口,支持平台的增删改查和状态切换 - 添加接口定义管理API接口,支持接口的增删改查和完整URL构建 - 实现平台管理页面,包含表单验证、数据列表展示和操作功能 - 实现接口定义管理页面,支持平台选择、URI拼接和积分配置 - 创建平台和定义相关的数据类型定义文件 - 集成权限控制和字典数据绑定功能
This commit is contained in:
parent
9fd2b6f137
commit
df5765a461
41
src/api/biz/definition/index.ts
Normal file
41
src/api/biz/definition/index.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import request from '@/utils/request';
|
||||||
|
import { AxiosPromise } from 'axios';
|
||||||
|
import { DefinitionForm, DefinitionQuery, DefinitionVO } from '@/api/biz/definition/types';
|
||||||
|
|
||||||
|
export function listDefinition(query?: DefinitionQuery): AxiosPromise<DefinitionVO[]> {
|
||||||
|
return request({
|
||||||
|
url: '/biz/definition/list',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDefinition(apiId: string | number): AxiosPromise<DefinitionVO> {
|
||||||
|
return request({
|
||||||
|
url: '/biz/definition/' + apiId,
|
||||||
|
method: 'get'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addDefinition(data: DefinitionForm) {
|
||||||
|
return request({
|
||||||
|
url: '/biz/definition',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateDefinition(data: DefinitionForm) {
|
||||||
|
return request({
|
||||||
|
url: '/biz/definition',
|
||||||
|
method: 'put',
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function delDefinition(apiId: string | number | Array<string | number>) {
|
||||||
|
return request({
|
||||||
|
url: '/biz/definition/' + apiId,
|
||||||
|
method: 'delete'
|
||||||
|
});
|
||||||
|
}
|
||||||
39
src/api/biz/definition/types.ts
Normal file
39
src/api/biz/definition/types.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
export interface DefinitionVO {
|
||||||
|
apiId: string | number;
|
||||||
|
platformId: string | number;
|
||||||
|
platformName: string;
|
||||||
|
baseUrl: string;
|
||||||
|
apiCode: string;
|
||||||
|
apiName: string;
|
||||||
|
apiUri: string;
|
||||||
|
fullUrl: string;
|
||||||
|
requestMethod: string;
|
||||||
|
pointsCost: number;
|
||||||
|
timeout: number;
|
||||||
|
contentType: string;
|
||||||
|
status: string;
|
||||||
|
remark: string;
|
||||||
|
createTime: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DefinitionForm extends BaseEntity {
|
||||||
|
apiId?: string | number;
|
||||||
|
platformId?: string | number;
|
||||||
|
apiCode?: string;
|
||||||
|
apiName?: string;
|
||||||
|
apiUri?: string;
|
||||||
|
requestMethod?: string;
|
||||||
|
pointsCost?: number;
|
||||||
|
timeout?: number;
|
||||||
|
contentType?: string;
|
||||||
|
status?: string;
|
||||||
|
remark?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DefinitionQuery extends PageQuery {
|
||||||
|
platformId?: string | number;
|
||||||
|
apiCode?: string;
|
||||||
|
apiName?: string;
|
||||||
|
requestMethod?: string;
|
||||||
|
status?: string;
|
||||||
|
}
|
||||||
63
src/api/biz/platform/index.ts
Normal file
63
src/api/biz/platform/index.ts
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import request from '@/utils/request';
|
||||||
|
import { AxiosPromise } from 'axios';
|
||||||
|
import { PlatformForm, PlatformOptionVO, PlatformQuery, PlatformVO } from '@/api/biz/platform/types';
|
||||||
|
|
||||||
|
export function listPlatform(query?: PlatformQuery): AxiosPromise<PlatformVO[]> {
|
||||||
|
return request({
|
||||||
|
url: '/biz/platform/list',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPlatform(platformId: string | number): AxiosPromise<PlatformVO> {
|
||||||
|
return request({
|
||||||
|
url: '/biz/platform/' + platformId,
|
||||||
|
method: 'get'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function optionselectPlatform(): AxiosPromise<PlatformOptionVO[]> {
|
||||||
|
return request({
|
||||||
|
url: '/biz/platform/optionselect',
|
||||||
|
method: 'get'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addPlatform(data: PlatformForm) {
|
||||||
|
return request({
|
||||||
|
url: '/biz/platform',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updatePlatform(data: PlatformForm) {
|
||||||
|
return request({
|
||||||
|
url: '/biz/platform',
|
||||||
|
method: 'put',
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function delPlatform(platformId: string | number | Array<string | number>) {
|
||||||
|
return request({
|
||||||
|
url: '/biz/platform/' + platformId,
|
||||||
|
method: 'delete'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function changePlatformStatus(platformId: string | number, status: string) {
|
||||||
|
return request({
|
||||||
|
url: '/biz/platform/changeStatus',
|
||||||
|
method: 'put',
|
||||||
|
data: { platformId, status }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resetPlatformSecret(platformId: string | number) {
|
||||||
|
return request({
|
||||||
|
url: '/biz/platform/resetSecret/' + platformId,
|
||||||
|
method: 'put'
|
||||||
|
});
|
||||||
|
}
|
||||||
42
src/api/biz/platform/types.ts
Normal file
42
src/api/biz/platform/types.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
export interface PlatformVO {
|
||||||
|
platformId: string | number;
|
||||||
|
platformCode: string;
|
||||||
|
platformName: string;
|
||||||
|
baseUrl: string;
|
||||||
|
appKey: string;
|
||||||
|
appSecret: string;
|
||||||
|
token: string;
|
||||||
|
tokenExpireTime: string;
|
||||||
|
authType: string;
|
||||||
|
status: string;
|
||||||
|
remark: string;
|
||||||
|
createTime: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlatformOptionVO {
|
||||||
|
platformId: string | number;
|
||||||
|
platformCode: string;
|
||||||
|
platformName: string;
|
||||||
|
baseUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlatformForm extends BaseEntity {
|
||||||
|
platformId?: string | number;
|
||||||
|
platformCode?: string;
|
||||||
|
platformName?: string;
|
||||||
|
baseUrl?: string;
|
||||||
|
appKey?: string;
|
||||||
|
appSecret?: string;
|
||||||
|
token?: string;
|
||||||
|
tokenExpireTime?: string;
|
||||||
|
authType?: string;
|
||||||
|
status?: string;
|
||||||
|
remark?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlatformQuery extends PageQuery {
|
||||||
|
platformCode?: string;
|
||||||
|
platformName?: string;
|
||||||
|
authType?: string;
|
||||||
|
status?: string;
|
||||||
|
}
|
||||||
332
src/views/biz/apiDefinition/index.vue
Normal file
332
src/views/biz/apiDefinition/index.vue
Normal file
@ -0,0 +1,332 @@
|
|||||||
|
<template>
|
||||||
|
<div class="p-2">
|
||||||
|
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||||
|
<div v-show="showSearch" class="search">
|
||||||
|
<el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="85px">
|
||||||
|
<el-form-item label="接口名称" prop="apiName">
|
||||||
|
<el-input v-model="queryParams.apiName" placeholder="请输入接口名称" clearable @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="所属平台" prop="platformId">
|
||||||
|
<el-select v-model="queryParams.platformId" placeholder="请选择平台" clearable>
|
||||||
|
<el-option
|
||||||
|
v-for="item in platformOptions"
|
||||||
|
:key="item.platformId"
|
||||||
|
:label="item.platformName + ' (' + item.platformCode + ')'"
|
||||||
|
:value="item.platformId"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="请求方式" prop="requestMethod">
|
||||||
|
<el-select v-model="queryParams.requestMethod" placeholder="请求方式" clearable>
|
||||||
|
<el-option v-for="dict in biz_request_method" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-select v-model="queryParams.status" placeholder="状态" clearable>
|
||||||
|
<el-option v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||||
|
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</transition>
|
||||||
|
|
||||||
|
<el-card shadow="never">
|
||||||
|
<template #header>
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button v-hasPermi="['biz:definition:add']" type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button v-hasPermi="['biz:definition:edit']" type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()">修改</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button v-hasPermi="['biz:definition:remove']" type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()">删除</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button v-hasPermi="['biz:definition:export']" type="warning" plain icon="Download" @click="handleExport">导出</el-button>
|
||||||
|
</el-col>
|
||||||
|
<right-toolbar v-model:show-search="showSearch" @query-table="getList"></right-toolbar>
|
||||||
|
</el-row>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<el-table v-loading="loading" :data="definitionList" border @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
|
<el-table-column label="接口编码" align="center" prop="apiCode" min-width="120" />
|
||||||
|
<el-table-column label="接口名称" align="center" prop="apiName" min-width="120" />
|
||||||
|
<el-table-column label="平台名称" align="center" prop="platformName" min-width="120" />
|
||||||
|
<el-table-column label="完整地址" align="center" prop="fullUrl" min-width="240" show-overflow-tooltip />
|
||||||
|
<el-table-column label="请求方式" align="center" prop="requestMethod" width="100">
|
||||||
|
<template #default="scope">
|
||||||
|
<dict-tag :options="biz_request_method" :value="scope.row.requestMethod" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="消耗积分" align="center" prop="pointsCost" width="90" />
|
||||||
|
<el-table-column label="状态" align="center" prop="status" width="80">
|
||||||
|
<template #default="scope">
|
||||||
|
<dict-tag :options="sys_normal_disable" :value="scope.row.status" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tooltip content="修改" placement="top">
|
||||||
|
<el-button v-hasPermi="['biz:definition:edit']" link type="primary" icon="Edit" @click="handleUpdate(scope.row)"></el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip content="删除" placement="top">
|
||||||
|
<el-button v-hasPermi="['biz:definition:remove']" link type="primary" icon="Delete" @click="handleDelete(scope.row)"></el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
|
||||||
|
</el-card>
|
||||||
|
|
||||||
|
<el-dialog v-model="dialog.visible" :title="dialog.title" width="650px" append-to-body>
|
||||||
|
<el-form ref="definitionFormRef" :model="form" :rules="rules" label-width="110px">
|
||||||
|
<el-form-item label="所属平台" prop="platformId">
|
||||||
|
<el-select v-model="form.platformId" placeholder="请选择平台" @change="handlePlatformChange">
|
||||||
|
<el-option
|
||||||
|
v-for="item in platformOptions"
|
||||||
|
:key="item.platformId"
|
||||||
|
:label="item.platformName + ' (' + item.platformCode + ')'"
|
||||||
|
:value="item.platformId"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="接口编码" prop="apiCode">
|
||||||
|
<el-input v-model="form.apiCode" :disabled="!!form.apiId" placeholder="请输入接口编码" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="接口名称" prop="apiName">
|
||||||
|
<el-input v-model="form.apiName" placeholder="请输入接口名称" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="访问URI" prop="apiUri">
|
||||||
|
<el-input v-model="form.apiUri" placeholder="/v1/user/query" @input="updateFullUrlPreview" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="完整地址预览">
|
||||||
|
<el-input :model-value="fullUrlPreview" readonly placeholder="选择平台并填写URI后自动生成" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="请求方式" prop="requestMethod">
|
||||||
|
<el-select v-model="form.requestMethod" placeholder="请选择请求方式">
|
||||||
|
<el-option v-for="dict in biz_request_method" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="消耗积分" prop="pointsCost">
|
||||||
|
<el-input-number v-model="form.pointsCost" :min="0" controls-position="right" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="超时(秒)" prop="timeout">
|
||||||
|
<el-input-number v-model="form.timeout" :min="1" controls-position="right" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="Content-Type" prop="contentType">
|
||||||
|
<el-select v-model="form.contentType" placeholder="请选择Content-Type" allow-create filterable default-first-option>
|
||||||
|
<el-option label="application/json" value="application/json" />
|
||||||
|
<el-option label="application/x-www-form-urlencoded" value="application/x-www-form-urlencoded" />
|
||||||
|
<el-option label="multipart/form-data" value="multipart/form-data" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-radio-group v-model="form.status">
|
||||||
|
<el-radio v-for="dict in sys_normal_disable" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注" prop="remark">
|
||||||
|
<el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||||
|
<el-button @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="BizApiDefinition" lang="ts">
|
||||||
|
import { optionselectPlatform } from '@/api/biz/platform';
|
||||||
|
import { PlatformOptionVO } from '@/api/biz/platform/types';
|
||||||
|
import { addDefinition, delDefinition, getDefinition, listDefinition, updateDefinition } from '@/api/biz/definition';
|
||||||
|
import { DefinitionForm, DefinitionQuery, DefinitionVO } from '@/api/biz/definition/types';
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||||
|
const dictData = proxy?.useDict('sys_normal_disable', 'biz_request_method') ?? {};
|
||||||
|
const { sys_normal_disable, biz_request_method } = toRefs<any>(reactive(dictData));
|
||||||
|
|
||||||
|
const definitionList = ref<DefinitionVO[]>([]);
|
||||||
|
const platformOptions = ref<PlatformOptionVO[]>([]);
|
||||||
|
const fullUrlPreview = ref('');
|
||||||
|
const buttonLoading = ref(false);
|
||||||
|
const loading = ref(true);
|
||||||
|
const showSearch = ref(true);
|
||||||
|
const ids = ref<Array<string | number>>([]);
|
||||||
|
const single = ref(true);
|
||||||
|
const multiple = ref(true);
|
||||||
|
const total = ref(0);
|
||||||
|
|
||||||
|
const queryFormRef = ref<ElFormInstance>();
|
||||||
|
const definitionFormRef = ref<ElFormInstance>();
|
||||||
|
|
||||||
|
const dialog = reactive<DialogOption>({
|
||||||
|
visible: false,
|
||||||
|
title: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const initFormData: DefinitionForm = {
|
||||||
|
apiId: undefined,
|
||||||
|
platformId: undefined,
|
||||||
|
apiCode: undefined,
|
||||||
|
apiName: undefined,
|
||||||
|
apiUri: undefined,
|
||||||
|
requestMethod: 'GET',
|
||||||
|
pointsCost: 0,
|
||||||
|
timeout: 30,
|
||||||
|
contentType: 'application/json',
|
||||||
|
status: '0',
|
||||||
|
remark: undefined
|
||||||
|
};
|
||||||
|
|
||||||
|
const data = reactive<PageData<DefinitionForm, DefinitionQuery>>({
|
||||||
|
form: { ...initFormData },
|
||||||
|
queryParams: {
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
platformId: undefined,
|
||||||
|
apiName: undefined,
|
||||||
|
requestMethod: undefined,
|
||||||
|
status: undefined
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
platformId: [{ required: true, message: '所属平台不能为空', trigger: 'change' }],
|
||||||
|
apiCode: [{ required: true, message: '接口编码不能为空', trigger: 'blur' }],
|
||||||
|
apiName: [{ required: true, message: '接口名称不能为空', trigger: 'blur' }],
|
||||||
|
apiUri: [{ required: true, message: '访问URI不能为空', trigger: 'blur' }],
|
||||||
|
requestMethod: [{ required: true, message: '请求方式不能为空', trigger: 'change' }],
|
||||||
|
pointsCost: [{ required: true, message: '消耗积分不能为空', trigger: 'blur' }]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const { queryParams, form, rules } = toRefs(data);
|
||||||
|
|
||||||
|
const buildFullUrl = (baseUrl?: string, apiUri?: string) => {
|
||||||
|
if (!baseUrl || !apiUri) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
const base = baseUrl.trim().replace(/\/+$/, '');
|
||||||
|
let uri = apiUri.trim();
|
||||||
|
if (!uri.startsWith('/')) {
|
||||||
|
uri = '/' + uri;
|
||||||
|
}
|
||||||
|
return base + uri;
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateFullUrlPreview = () => {
|
||||||
|
const platform = platformOptions.value.find((item) => item.platformId === form.value.platformId);
|
||||||
|
fullUrlPreview.value = buildFullUrl(platform?.baseUrl, form.value.apiUri);
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadPlatformOptions = async () => {
|
||||||
|
try {
|
||||||
|
const res = await optionselectPlatform();
|
||||||
|
platformOptions.value = res.data ?? [];
|
||||||
|
} catch {
|
||||||
|
platformOptions.value = [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const res = await listDefinition(queryParams.value);
|
||||||
|
definitionList.value = res.rows ?? [];
|
||||||
|
total.value = res.total ?? 0;
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const cancel = () => {
|
||||||
|
reset();
|
||||||
|
dialog.visible = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const reset = () => {
|
||||||
|
form.value = { ...initFormData };
|
||||||
|
fullUrlPreview.value = '';
|
||||||
|
definitionFormRef.value?.resetFields();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.value.pageNum = 1;
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value?.resetFields();
|
||||||
|
handleQuery();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSelectionChange = (selection: DefinitionVO[]) => {
|
||||||
|
ids.value = selection.map((item) => item.apiId);
|
||||||
|
single.value = selection.length != 1;
|
||||||
|
multiple.value = !selection.length;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePlatformChange = () => {
|
||||||
|
updateFullUrlPreview();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAdd = async () => {
|
||||||
|
reset();
|
||||||
|
await loadPlatformOptions();
|
||||||
|
dialog.visible = true;
|
||||||
|
dialog.title = '新增接口定义';
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUpdate = async (row?: DefinitionVO) => {
|
||||||
|
reset();
|
||||||
|
await loadPlatformOptions();
|
||||||
|
const apiId = row?.apiId || ids.value[0];
|
||||||
|
const res = await getDefinition(apiId);
|
||||||
|
Object.assign(form.value, res.data);
|
||||||
|
updateFullUrlPreview();
|
||||||
|
dialog.visible = true;
|
||||||
|
dialog.title = '修改接口定义';
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitForm = () => {
|
||||||
|
definitionFormRef.value?.validate(async (valid: boolean) => {
|
||||||
|
if (valid) {
|
||||||
|
buttonLoading.value = true;
|
||||||
|
if (form.value.apiId) {
|
||||||
|
await updateDefinition(form.value).finally(() => (buttonLoading.value = false));
|
||||||
|
} else {
|
||||||
|
await addDefinition(form.value).finally(() => (buttonLoading.value = false));
|
||||||
|
}
|
||||||
|
proxy?.$modal.msgSuccess('操作成功');
|
||||||
|
dialog.visible = false;
|
||||||
|
await getList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = async (row?: DefinitionVO) => {
|
||||||
|
const apiIds = row?.apiId || ids.value;
|
||||||
|
await proxy?.$modal.confirm('是否确认删除接口编号为"' + apiIds + '"的数据项?');
|
||||||
|
await delDefinition(apiIds);
|
||||||
|
proxy?.$modal.msgSuccess('删除成功');
|
||||||
|
await getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleExport = () => {
|
||||||
|
proxy?.download('biz/definition/export', { ...queryParams.value }, `definition_${new Date().getTime()}.xlsx`);
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await loadPlatformOptions();
|
||||||
|
await getList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
291
src/views/biz/platform/index.vue
Normal file
291
src/views/biz/platform/index.vue
Normal file
@ -0,0 +1,291 @@
|
|||||||
|
<template>
|
||||||
|
<div class="p-2">
|
||||||
|
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||||
|
<div v-show="showSearch" class="search">
|
||||||
|
<el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="85px">
|
||||||
|
<el-form-item label="平台名称" prop="platformName">
|
||||||
|
<el-input v-model="queryParams.platformName" placeholder="请输入平台名称" clearable @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="平台编码" prop="platformCode">
|
||||||
|
<el-input v-model="queryParams.platformCode" placeholder="请输入平台编码" clearable @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-select v-model="queryParams.status" placeholder="状态" clearable>
|
||||||
|
<el-option v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||||
|
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</transition>
|
||||||
|
|
||||||
|
<el-card shadow="never">
|
||||||
|
<template #header>
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button v-hasPermi="['biz:platform:add']" type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button v-hasPermi="['biz:platform:edit']" type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()">修改</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button v-hasPermi="['biz:platform:remove']" type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()">删除</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button v-hasPermi="['biz:platform:export']" type="warning" plain icon="Download" @click="handleExport">导出</el-button>
|
||||||
|
</el-col>
|
||||||
|
<right-toolbar v-model:show-search="showSearch" @query-table="getList"></right-toolbar>
|
||||||
|
</el-row>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<el-table v-loading="loading" :data="platformList" border @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
|
<el-table-column label="平台编码" align="center" prop="platformCode" min-width="100" />
|
||||||
|
<el-table-column label="平台名称" align="center" prop="platformName" min-width="120" />
|
||||||
|
<el-table-column label="请求地址" align="center" prop="baseUrl" min-width="200" show-overflow-tooltip />
|
||||||
|
<el-table-column label="AppKey" align="center" prop="appKey" min-width="120" show-overflow-tooltip />
|
||||||
|
<el-table-column label="AppSecret" align="center" prop="appSecret" min-width="120" show-overflow-tooltip />
|
||||||
|
<el-table-column label="Token" align="center" prop="token" min-width="120" show-overflow-tooltip />
|
||||||
|
<el-table-column label="认证方式" align="center" prop="authType" width="120">
|
||||||
|
<template #default="scope">
|
||||||
|
<dict-tag :options="biz_auth_type" :value="scope.row.authType" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="状态" align="center" width="80">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-switch v-model="scope.row.status" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tooltip content="修改" placement="top">
|
||||||
|
<el-button v-hasPermi="['biz:platform:edit']" link type="primary" icon="Edit" @click="handleUpdate(scope.row)"></el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip content="删除" placement="top">
|
||||||
|
<el-button v-hasPermi="['biz:platform:remove']" link type="primary" icon="Delete" @click="handleDelete(scope.row)"></el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
|
||||||
|
</el-card>
|
||||||
|
|
||||||
|
<el-dialog v-model="dialog.visible" :title="dialog.title" width="600px" append-to-body>
|
||||||
|
<el-form ref="platformFormRef" :model="form" :rules="rules" label-width="110px">
|
||||||
|
<el-form-item label="平台编码" prop="platformCode">
|
||||||
|
<el-input v-model="form.platformCode" :disabled="!!form.platformId" placeholder="请输入平台编码" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="平台名称" prop="platformName">
|
||||||
|
<el-input v-model="form.platformName" placeholder="请输入平台名称" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="请求地址" prop="baseUrl">
|
||||||
|
<el-input v-model="form.baseUrl" placeholder="https://api.example.com" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="认证方式" prop="authType">
|
||||||
|
<el-radio-group v-model="form.authType">
|
||||||
|
<el-radio v-for="dict in biz_auth_type" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="AppKey" prop="appKey">
|
||||||
|
<el-input v-model="form.appKey" placeholder="请输入AppKey" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="AppSecret" prop="appSecret">
|
||||||
|
<el-input v-model="form.appSecret" type="password" show-password placeholder="请输入AppSecret" />
|
||||||
|
<el-button v-if="form.platformId" class="ml-2" type="warning" plain @click="handleResetSecret">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="Token" prop="token">
|
||||||
|
<el-input v-model="form.token" type="password" show-password placeholder="请输入Token" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="Token过期时间" prop="tokenExpireTime">
|
||||||
|
<el-date-picker v-model="form.tokenExpireTime" type="datetime" value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择Token过期时间" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-radio-group v-model="form.status">
|
||||||
|
<el-radio v-for="dict in sys_normal_disable" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注" prop="remark">
|
||||||
|
<el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||||
|
<el-button @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="BizPlatform" lang="ts">
|
||||||
|
import {
|
||||||
|
addPlatform,
|
||||||
|
changePlatformStatus,
|
||||||
|
delPlatform,
|
||||||
|
getPlatform,
|
||||||
|
listPlatform,
|
||||||
|
resetPlatformSecret,
|
||||||
|
updatePlatform
|
||||||
|
} from '@/api/biz/platform';
|
||||||
|
import { PlatformForm, PlatformQuery, PlatformVO } from '@/api/biz/platform/types';
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||||
|
const { sys_normal_disable, biz_auth_type } = toRefs<any>(proxy?.useDict('sys_normal_disable', 'biz_auth_type'));
|
||||||
|
|
||||||
|
const platformList = ref<PlatformVO[]>([]);
|
||||||
|
const buttonLoading = ref(false);
|
||||||
|
const loading = ref(true);
|
||||||
|
const showSearch = ref(true);
|
||||||
|
const ids = ref<Array<string | number>>([]);
|
||||||
|
const single = ref(true);
|
||||||
|
const multiple = ref(true);
|
||||||
|
const total = ref(0);
|
||||||
|
|
||||||
|
const queryFormRef = ref<ElFormInstance>();
|
||||||
|
const platformFormRef = ref<ElFormInstance>();
|
||||||
|
|
||||||
|
const dialog = reactive<DialogOption>({
|
||||||
|
visible: false,
|
||||||
|
title: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const initFormData: PlatformForm = {
|
||||||
|
platformId: undefined,
|
||||||
|
platformCode: undefined,
|
||||||
|
platformName: undefined,
|
||||||
|
baseUrl: undefined,
|
||||||
|
appKey: undefined,
|
||||||
|
appSecret: undefined,
|
||||||
|
token: undefined,
|
||||||
|
tokenExpireTime: undefined,
|
||||||
|
authType: '0',
|
||||||
|
status: '0',
|
||||||
|
remark: undefined
|
||||||
|
};
|
||||||
|
|
||||||
|
const data = reactive<PageData<PlatformForm, PlatformQuery>>({
|
||||||
|
form: { ...initFormData },
|
||||||
|
queryParams: {
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
platformCode: undefined,
|
||||||
|
platformName: undefined,
|
||||||
|
status: undefined
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
platformCode: [{ required: true, message: '平台编码不能为空', trigger: 'blur' }],
|
||||||
|
platformName: [{ required: true, message: '平台名称不能为空', trigger: 'blur' }],
|
||||||
|
baseUrl: [{ required: true, message: '请求地址不能为空', trigger: 'blur' }],
|
||||||
|
authType: [{ required: true, message: '认证方式不能为空', trigger: 'change' }]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const { queryParams, form, rules } = toRefs(data);
|
||||||
|
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
const res = await listPlatform(queryParams.value);
|
||||||
|
platformList.value = res.rows;
|
||||||
|
total.value = res.total;
|
||||||
|
loading.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const cancel = () => {
|
||||||
|
reset();
|
||||||
|
dialog.visible = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const reset = () => {
|
||||||
|
form.value = { ...initFormData };
|
||||||
|
platformFormRef.value?.resetFields();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.value.pageNum = 1;
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetQuery = () => {
|
||||||
|
queryFormRef.value?.resetFields();
|
||||||
|
handleQuery();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSelectionChange = (selection: PlatformVO[]) => {
|
||||||
|
ids.value = selection.map((item) => item.platformId);
|
||||||
|
single.value = selection.length != 1;
|
||||||
|
multiple.value = !selection.length;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAdd = () => {
|
||||||
|
reset();
|
||||||
|
dialog.visible = true;
|
||||||
|
dialog.title = '新增接口平台';
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUpdate = async (row?: PlatformVO) => {
|
||||||
|
reset();
|
||||||
|
const platformId = row?.platformId || ids.value[0];
|
||||||
|
const res = await getPlatform(platformId);
|
||||||
|
Object.assign(form.value, res.data);
|
||||||
|
dialog.visible = true;
|
||||||
|
dialog.title = '修改接口平台';
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitForm = () => {
|
||||||
|
platformFormRef.value?.validate(async (valid: boolean) => {
|
||||||
|
if (valid) {
|
||||||
|
buttonLoading.value = true;
|
||||||
|
if (form.value.platformId) {
|
||||||
|
await updatePlatform(form.value).finally(() => (buttonLoading.value = false));
|
||||||
|
} else {
|
||||||
|
await addPlatform(form.value).finally(() => (buttonLoading.value = false));
|
||||||
|
}
|
||||||
|
proxy?.$modal.msgSuccess('操作成功');
|
||||||
|
dialog.visible = false;
|
||||||
|
await getList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = async (row?: PlatformVO) => {
|
||||||
|
const platformIds = row?.platformId || ids.value;
|
||||||
|
await proxy?.$modal.confirm('是否确认删除平台编号为"' + platformIds + '"的数据项?');
|
||||||
|
await delPlatform(platformIds);
|
||||||
|
proxy?.$modal.msgSuccess('删除成功');
|
||||||
|
await getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleExport = () => {
|
||||||
|
proxy?.download('biz/platform/export', { ...queryParams.value }, `platform_${new Date().getTime()}.xlsx`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleStatusChange = async (row: PlatformVO) => {
|
||||||
|
const text = row.status === '0' ? '启用' : '停用';
|
||||||
|
try {
|
||||||
|
await proxy?.$modal.confirm('确认要"' + text + '""' + row.platformName + '"平台吗?');
|
||||||
|
await changePlatformStatus(row.platformId, row.status);
|
||||||
|
proxy?.$modal.msgSuccess(text + '成功');
|
||||||
|
} catch {
|
||||||
|
row.status = row.status === '0' ? '1' : '0';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleResetSecret = async () => {
|
||||||
|
if (!form.value.platformId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await proxy?.$modal.confirm('确认要重置该平台的AppSecret吗?');
|
||||||
|
const res = await resetPlatformSecret(form.value.platformId);
|
||||||
|
form.value.appSecret = res.data;
|
||||||
|
proxy?.$modal.msgSuccess('重置成功');
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user