fix: api配置、应用管理

This commit is contained in:
easy 2023-03-14 16:04:23 +08:00
parent 0103cba6f7
commit 557c41afb6
8 changed files with 124 additions and 47 deletions

View File

@ -23,4 +23,13 @@ export const addOperations_api = (data:object) => server.patch(`/application/ope
/** /**
* ID * ID
*/ */
export const delOperations_api = (data:object) => server.remove(`/application/operations/_batch`,{},{data}); export const delOperations_api = (data:object) => server.remove(`/application/operations/_batch`,{},{data});
/**
* -/api
* @param id
* @param type
* @param data
* @returns
*/
export const updateOperations_api = (code:string,type:'_add'| '_delete', data: object) => server.post(`/application/${code}/grant/${type}`, data);

View File

@ -1738,7 +1738,6 @@ function changeBackUpload(info: UploadChangeParam<UploadFile<any>>) {
if (info.file.status === 'uploading') { if (info.file.status === 'uploading') {
form.uploadLoading = true; form.uploadLoading = true;
} else if (info.file.status === 'done') { } else if (info.file.status === 'done') {
console.log(info);
info.file.url = info.file.response?.result; info.file.url = info.file.response?.result;
form.uploadLoading = false; form.uploadLoading = false;
@ -1749,9 +1748,6 @@ function changeBackUpload(info: UploadChangeParam<UploadFile<any>>) {
message.error('logo上传失败请稍后再试'); message.error('logo上传失败请稍后再试');
} }
} }
function test(...args: any[]) {
console.log('test:', args);
}
function clearNullProp(obj: object) { function clearNullProp(obj: object) {
if (typeof obj !== 'object') return; if (typeof obj !== 'object') return;
for (const prop in obj) { for (const prop in obj) {
@ -1799,6 +1795,17 @@ function clearNullProp(obj: object) {
padding: 0 15px; padding: 0 15px;
box-sizing: content-box; box-sizing: content-box;
margin-right: 20px; margin-right: 20px;
color: #000;
&.ant-radio-button-wrapper-disabled {
opacity: .5;
}
&.ant-radio-button-wrapper-checked {
background-color: #fff;
border: 1px solid #1d39c4;
opacity: 1;
}
> :last-child { > :last-child {
width: 100%; width: 100%;

View File

@ -271,6 +271,8 @@ const columns = [
dataIndex: 'action', dataIndex: 'action',
key: 'action', key: 'action',
scopedSlots: true, scopedSlots: true,
width:'200px',
fixed:'right'
}, },
]; ];
const queryParams = ref({}); const queryParams = ref({});

View File

@ -148,7 +148,9 @@ const requestCard = reactive<tableCardType>({
return (requestCard.tableData = props.selectApi.parameters); return (requestCard.tableData = props.selectApi.parameters);
const schema = const schema =
props.selectApi.requestBody.content['application/json'].schema; props.selectApi.requestBody.content['application/json'].schema;
const schemaName = (schema.$ref || schema.items.$ref)?.split('/').pop(); const _ref = schema.$ref || schema?.items?.$ref;
if(!_ref) return; // schemaJava
const schemaName = _ref?.split('/').pop();
const type = schema.type || ''; const type = schema.type || '';
const tableData = findData(schemaName); const tableData = findData(schemaName);
if (type === 'array') { if (type === 'array') {

View File

@ -95,6 +95,7 @@
</j-button> </j-button>
</div> </div>
<MonacoEditor <MonacoEditor
v-if="refStr"
v-model:modelValue="requestBody.code" v-model:modelValue="requestBody.code"
style="height: 300px; width: 100%" style="height: 300px; width: 100%"
theme="vs" theme="vs"
@ -125,6 +126,8 @@ const props = defineProps<{
selectApi: apiDetailsType; selectApi: apiDetailsType;
schemas: any; schemas: any;
}>(); }>();
const responsesContent = ref({});
const editorRef = ref();
const formRef = ref<FormInstance>(); const formRef = ref<FormInstance>();
const requestBody = reactive({ const requestBody = reactive({
tableColumns: [ tableColumns: [
@ -178,8 +181,16 @@ const paramsTable = computed(() => {
return requestBody.params.paramsTable.slice(startIndex, endIndex); return requestBody.params.paramsTable.slice(startIndex, endIndex);
}); });
const responsesContent = ref({}); let schema: any = {};
const editorRef = ref() const refStr = ref('');
const init = () => {
if (!props.selectApi.requestBody) return;
schema = props.selectApi.requestBody.content['application/json'].schema;
refStr.value = schema.$ref || schema?.items?.$ref;
};
init();
const send = () => { const send = () => {
if (paramsTable.value.length) if (paramsTable.value.length)
formRef.value && formRef.value &&
@ -210,10 +221,10 @@ const _send = () => {
...urlParams, ...urlParams,
}; };
server[methodObj[methodName]](url, params).then((resp: any) => { server[methodObj[methodName]](url, params).then((resp: any) => {
if (Object.keys(params).length === 0){ // body
if (Object.keys(params).length === 0 && refStr.value) {
requestBody.code = JSON.stringify(getDefaultParams()); requestBody.code = JSON.stringify(getDefaultParams());
editorRef.value?.editorFormat() editorRef.value?.editorFormat();
} }
responsesContent.value = resp; responsesContent.value = resp;
}); });
@ -224,9 +235,8 @@ const _send = () => {
*/ */
function getDefaultParams() { function getDefaultParams() {
if (!props.selectApi.requestBody) return {}; if (!props.selectApi.requestBody) return {};
const schema = if (!refStr.value) return ''; // schemaJava
props.selectApi.requestBody.content['application/json'].schema; const schemaName = refStr.value?.split('/').pop() as string;
const schemaName = (schema.$ref || schema.items.$ref)?.split('/').pop();
const type = schema.type || ''; const type = schema.type || '';
const tableData = findData(schemaName); const tableData = findData(schemaName);
if (type === 'array') { if (type === 'array') {

View File

@ -11,7 +11,7 @@
<template #url="slotProps"> <template #url="slotProps">
<span <span
style="color: #1d39c4; cursor: pointer" style="color: #1d39c4; cursor: pointer"
@click="jump(slotProps)" @click="emits('update:clickApi', slotProps)"
>{{ slotProps.url }}</span >{{ slotProps.url }}</span
> >
</template> </template>
@ -25,18 +25,28 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { addOperations_api, delOperations_api } from '@/api/system/apiPage'; import {
addOperations_api,
delOperations_api,
updateOperations_api,
} from '@/api/system/apiPage';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
import { modeType } from '../typing'; import { modeType } from '../typing';
const emits = defineEmits(['update:clickApi', 'update:selectedRowKeys']); const emits = defineEmits([
'refresh',
'update:clickApi',
'update:selectedRowKeys',
'update:changedApis',
]);
const props = defineProps<{ const props = defineProps<{
tableData: any[]; tableData: any[];
clickApi: any; clickApi: any;
selectedRowKeys: string[]; selectedRowKeys: string[];
sourceKeys: string[]; sourceKeys: string[];
mode: modeType; mode: modeType;
changedApis: any; // api
}>(); }>();
const code = useRoute().query.code as string;
const columns = [ const columns = [
{ {
title: 'API', title: 'API',
@ -52,13 +62,20 @@ const columns = [
]; ];
const rowSelection = { const rowSelection = {
onSelect: (record: any) => { onSelect: (record: any) => {
const targetId = record.id;
let newKeys = [...props.selectedRowKeys]; let newKeys = [...props.selectedRowKeys];
if (props.selectedRowKeys.includes(record.id)) { if (props.selectedRowKeys.includes(targetId)) {
newKeys = newKeys.filter((id) => id !== record.id); newKeys = newKeys.filter((id) => id !== targetId);
} else newKeys.push(record.id); } else newKeys.push(targetId);
emits('update:selectedRowKeys', newKeys); emits('update:selectedRowKeys', newKeys);
if (props.mode === 'appManger') {
emits('update:changedApis', {
...props.changedApis,
[record.id]: record,
});
}
}, },
selectedRowKeys: ref<string[]>([]), selectedRowKeys: ref<string[]>([]),
}; };
@ -73,13 +90,30 @@ const save = () => {
removeKeys.length && removeKeys.length &&
delOperations_api(removeKeys) delOperations_api(removeKeys)
.finally(() => addOperations_api(addKeys)) .finally(() => addOperations_api(addKeys))
.then(() => message.success('操作成功')); .then(() => {
message.success('操作成功');
emits('refresh')
});
} else if (props.mode === 'appManger') {
const removeItems = removeKeys.map((key) => ({
id: key,
permissions: props.changedApis[key]?.security,
}));
const addItems = addKeys.map((key) => ({
id: key,
permissions: props.changedApis[key]?.security,
}));
Promise.all([
updateOperations_api(code, '_delete', { operations: removeItems }),
updateOperations_api(code, '_add', { operations: addItems }),
]).then((resps) => {
if (resps[0].status === 200 && resps[1].status === 200) {
message.success('操作成功');
emits('refresh');
}
});
} }
}; };
const jump = (row: any) => {
emits('update:clickApi', row);
};
watch( watch(
() => props.selectedRowKeys, () => props.selectedRowKeys,
(n) => { (n) => {

View File

@ -16,7 +16,6 @@
@select="treeSelect" @select="treeSelect"
:mode="props.mode" :mode="props.mode"
:has-home="props.hasHome" :has-home="props.hasHome"
:filter-array="treeFilter"
:code="props.code" :code="props.code"
/> />
</j-col> </j-col>
@ -26,10 +25,12 @@
<ChooseApi <ChooseApi
v-show="!selectedApi.url" v-show="!selectedApi.url"
v-model:click-api="selectedApi" v-model:click-api="selectedApi"
:table-data="tableData"
v-model:selectedRowKeys="selectedKeys" v-model:selectedRowKeys="selectedKeys"
v-model:changedApis="changedApis"
:table-data="tableData"
:source-keys="selectSourceKeys" :source-keys="selectSourceKeys"
:mode="props.mode" :mode="props.mode"
@refresh="getSelectKeys"
/> />
<div <div
@ -82,9 +83,8 @@ const props = defineProps<{
hasHome?: boolean; hasHome?: boolean;
code?: string; code?: string;
}>(); }>();
const showHome = ref<boolean>(Boolean(props.hasHome)); const showHome = ref<boolean>(Boolean(props.hasHome)); // home
const tableData = ref([]); const tableData = ref([]);
const treeFilter = ref([]);
const treeSelect = (node: treeNodeTpye, nodeSchemas: object = {}) => { const treeSelect = (node: treeNodeTpye, nodeSchemas: object = {}) => {
if (node.key === 'home') return (showHome.value = true); if (node.key === 'home') return (showHome.value = true);
schemas.value = nodeSchemas; schemas.value = nodeSchemas;
@ -109,8 +109,8 @@ const treeSelect = (node: treeNodeTpye, nodeSchemas: object = {}) => {
tableData.value = table; tableData.value = table;
}; };
const activeKey = ref<'does' | 'test'>('does'); const activeKey = ref<'does' | 'test'>('does');
const schemas = ref({}); const schemas = ref({}); // api
const initSelectedApi: apiDetailsType = { const initSelectedApi: apiDetailsType = {
url: '', url: '',
method: '', method: '',
@ -121,23 +121,14 @@ const initSelectedApi: apiDetailsType = {
}; };
const selectedApi = ref<apiDetailsType>(initSelectedApi); const selectedApi = ref<apiDetailsType>(initSelectedApi);
const selectedKeys = ref<string[]>([]); // const selectedKeys = ref<string[]>([]); //
let selectSourceKeys = ref<string[]>([]); const selectSourceKeys = ref<string[]>([]); //
const changedApis = ref({}); // idkey
init(); init();
function init() { function init() {
// getSelectKeys();
if (props.mode === 'appManger') {
getApiGranted_api(props.code as string).then((resp) => {
selectedKeys.value = resp.result as string[];
selectSourceKeys.value = [...(resp.result as string[])];
});
} else if (props.mode === 'api') {
apiOperations_api().then((resp) => {
selectedKeys.value = resp.result as string[];
selectSourceKeys.value = [...(resp.result as string[])];
});
}
watch(tableData, () => { watch(tableData, () => {
activeKey.value = 'does'; activeKey.value = 'does';
selectedApi.value = initSelectedApi; selectedApi.value = initSelectedApi;
@ -147,6 +138,24 @@ function init() {
() => (activeKey.value = 'does'), () => (activeKey.value = 'does'),
); );
} }
/**
* 右侧api选中项
*/
function getSelectKeys() {
if (props.mode === 'appManger') {
getApiGranted_api(props.code as string).then((resp) => {
selectedKeys.value = resp.result as string[];
selectSourceKeys.value = [...(resp.result as string[])];
changedApis.value = {};
});
} else if (props.mode === 'api') {
apiOperations_api().then((resp) => {
selectedKeys.value = resp.result as string[];
selectSourceKeys.value = [...(resp.result as string[])];
});
}
}
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@ -24,5 +24,9 @@ export type apiDetailsType = {
responses:object; responses:object;
description?:string; description?:string;
} }
/**
* api: api配置
* appManger -
* home-
*/
export type modeType = 'api'| 'appManger' | 'home' export type modeType = 'api'| 'appManger' | 'home'