<template>
|
<div class="h-full flex flex-col">
|
<div class="grid grid-cols-2 gap-2 h-full flex-0">
|
<div class="h-full overflow-auto">
|
<el-table
|
:data="configList"
|
row-class-name="cursor-pointer"
|
class="h-full"
|
highlight-current-row
|
@current-change="dockRowChange"
|
>
|
<el-table-column prop="path" label="配置路径" />
|
<el-table-column prop="recordId" label="SQL记录id" />
|
<el-table-column prop="queryId" label="查询id" />
|
<el-table-column prop="url" label="请求地址" />
|
</el-table>
|
<!-- <codemirror
|
v-model="dockCode"
|
:style="{ height: '100%' }"
|
:autofocus="true"
|
:indent-with-tab="true"
|
:tab-size="2"
|
:extensions="dockEditorExtensions"
|
@change="log('change', $event)"
|
@focus="log('focus', $event)"
|
@blur="log('blur', $event)"
|
/> -->
|
</div>
|
<div class="h-full overflow-auto">
|
<codemirror
|
class="h-full overflow-auto"
|
v-model="sqlCode"
|
:style="{ height: '100%' }"
|
:autofocus="true"
|
:indent-with-tab="true"
|
:tab-size="2"
|
:extensions="sqlEditorExtensions"
|
@change="log('change', $event)"
|
@focus="log('focus', $event)"
|
@blur="log('blur', $event)"
|
/>
|
</div>
|
</div>
|
<!-- <div class="flex-auto overflow-auto mt-3">
|
<codemirror
|
disabled
|
class="h-full overflow-auto"
|
v-model="jsonCode"
|
:style="{ height: '100%' }"
|
:autofocus="true"
|
:indent-with-tab="true"
|
:tab-size="2"
|
:extensions="jsonEditorExtensions"
|
@change="log('change', $event)"
|
@focus="log('focus', $event)"
|
@blur="log('blur', $event)"
|
/>
|
</div> -->
|
</div>
|
</template>
|
|
<script setup lang="ts">
|
import { json } from '@codemirror/lang-json';
|
import { sql } from '@codemirror/lang-sql';
|
import { xml } from '@codemirror/lang-xml';
|
import { vscodeDark } from '@uiw/codemirror-theme-vscode';
|
import { ref } from 'vue';
|
import { Codemirror } from 'vue-codemirror';
|
import * as codeExample from './testData';
|
import _, { uniqueId } from 'lodash';
|
import {v4 as uuid} from 'uuid'
|
const log = console.log;
|
const jsonCode = ref(codeExample.jsonCode);
|
const dockCode = ref(codeExample.dockCode);
|
const sqlCode = ref(codeExample.sqlCode);
|
|
const jsonEditorExtensions = [json(), vscodeDark];
|
const sqlEditorExtensions = [sql(), vscodeDark];
|
const dockEditorExtensions = [xml(), vscodeDark];
|
|
const dockRowChange = (row) => {};
|
/** @description 路径分隔符 */
|
const PATH_SEPARATOR = '/';
|
/** @description 1 退出所有循环 -1退出当次循环 0或其他值继续 */
|
const travelObj = (obj, callBack?: (key?: string, value?: any, path?: string) => 1 | -1 | undefined | void | 0, path = '') => {
|
let entry = Object.entries(obj);
|
|
let res;
|
|
iterate: for (const item of entry) {
|
const [key, value] = item;
|
const currentPath = path ? path + PATH_SEPARATOR + key : key;
|
res = callBack?.(key, value, currentPath);
|
switch (res) {
|
case 1:
|
break iterate;
|
case -1:
|
continue iterate;
|
default:
|
break;
|
}
|
if (!value) {
|
continue;
|
}
|
if (_.isObjectLike(value)) {
|
res = travelObj(value, callBack, currentPath);
|
switch (res) {
|
case 1:
|
break iterate;
|
case -1:
|
continue iterate;
|
default:
|
break;
|
}
|
}
|
}
|
return res;
|
};
|
|
const enum AmisDockType {
|
Api,
|
}
|
type AmisDockApi = string;
|
type AmisDockValue = AmisDockApi;
|
type AmisDockConfig = {
|
type: AmisDockType;
|
path: string;
|
value: AmisDockValue;
|
};
|
|
type AmisDockSQLConfig = AmisDockConfig&{
|
queryId:string;
|
recordId:string;
|
}
|
|
const configList = ref<AmisDockConfig[]>([]);
|
const parseJSONData = (json: string) => {
|
if (!json) return;
|
const obj = JSON.parse(json);
|
travelObj(obj, (key, value, path) => {
|
if (key === 'api') {
|
const url = value.url;
|
const urlPath = path + PATH_SEPARATOR + 'url';
|
const queryId ='query_'+uuid().slice(0,12);
|
|
// const recordId = uniqueId()
|
configList.value.push({
|
queryId:queryId,
|
recordId:queryId,
|
type: AmisDockType.Api,
|
path: urlPath,
|
value: url,
|
url:url,
|
} as any);
|
}
|
});
|
};
|
|
parseJSONData(codeExample.jsonCode);
|
</script>
|