|
@@ -1,7 +1,7 @@
|
|
|
<script setup lang="ts">
|
|
|
import {useVModel} from "@vueuse/core";
|
|
|
import {nextTick, onMounted, onUnmounted, ref, Ref, unref} from 'vue'
|
|
|
-import {TDataBaseSqlApi} from "@/ts-type/data-base-type";
|
|
|
+import type {TDataBaseSqlApi} from "@/ts-type/data-base-type";
|
|
|
import * as monaco from "monaco-editor";
|
|
|
import JsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'
|
|
|
import CssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker'
|
|
@@ -15,6 +15,7 @@ import {FormInstance} from "element-plus";
|
|
|
import {xcMessage} from "@/utils/xiaochan-element-plus";
|
|
|
import {copyStrFunc, isDev} from "@/utils/public";
|
|
|
import {windowSizeStore} from "@/utils/store-public";
|
|
|
+import GenericTokenParser from "@/utils/genergic-token-parser";
|
|
|
|
|
|
// 代码提示
|
|
|
self.MonacoEnvironment = {
|
|
@@ -46,7 +47,7 @@ const props = defineProps({
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-const urlPrefix = isDev ? `http://172.16.30.61:8706/dataBase/api/data` : `http://172.16.32.160:8077/dataBase/api/data`;
|
|
|
+const urlPrefix = isDev ? `http://172.16.30.61:8706/dataBase/api` : `http://172.16.32.160:8077/dataBase/api`;
|
|
|
|
|
|
const emits = defineEmits(['update:modelValue'])
|
|
|
const modelValue: Ref<TDataBaseSqlApi> = useVModel(props, 'modelValue', emits) as Ref<TDataBaseSqlApi>
|
|
@@ -110,6 +111,7 @@ async function handleTest() {
|
|
|
|
|
|
const data = prepareData()
|
|
|
data.params = unref(testParams)
|
|
|
+ data.currentDataSource = dataSource.value
|
|
|
|
|
|
testSqlApi(data).then(res => {
|
|
|
console.log(res)
|
|
@@ -174,19 +176,21 @@ function copyUrl(url: string) {
|
|
|
}
|
|
|
|
|
|
function fillingFunc() {
|
|
|
- const str = modelValue.value.sql;
|
|
|
- const regex = /\{(.*?)\}/g;
|
|
|
- const matches = str.match(regex);
|
|
|
- if (!matches) {
|
|
|
- return
|
|
|
- }
|
|
|
+ const addKeys = new Set()
|
|
|
+
|
|
|
+ new GenericTokenParser('#{', "}", (content) => {
|
|
|
+ addKeys.add(content)
|
|
|
+ return ""
|
|
|
+ }).parse(modelValue.value.sql)
|
|
|
+
|
|
|
+ new GenericTokenParser('${', "}", (content) => {
|
|
|
+ addKeys.add(content)
|
|
|
+ return ""
|
|
|
+ }).parse(modelValue.value.sql)
|
|
|
+
|
|
|
|
|
|
const keys = new Set()
|
|
|
- const addKeys = new Set()
|
|
|
|
|
|
- matches.forEach(item => {
|
|
|
- addKeys.add(item.slice(1, -1).trim())
|
|
|
- })
|
|
|
|
|
|
modelValue.value.configJson.params.forEach(item => {
|
|
|
keys.add(item.key)
|
|
@@ -200,9 +204,11 @@ function fillingFunc() {
|
|
|
})
|
|
|
|
|
|
result1.forEach(item => {
|
|
|
+ const index = modelValue.value.sql.indexOf(`test="${item}`)
|
|
|
+
|
|
|
modelValue.value.configJson.params.push({
|
|
|
key: item,
|
|
|
- required: false,
|
|
|
+ required: index === -1,
|
|
|
describe: '',
|
|
|
defaultValue: null
|
|
|
})
|
|
@@ -215,6 +221,8 @@ function processingOpenProperties() {
|
|
|
drawerDialog.value = true
|
|
|
}
|
|
|
|
|
|
+const dataSource = ref('')
|
|
|
+
|
|
|
onUnmounted(() => {
|
|
|
monacoEditor.dispose()
|
|
|
})
|
|
@@ -242,12 +250,25 @@ onMounted(async () => {
|
|
|
monacoEditor.onDidChangeModelContent((val) => {
|
|
|
modelValue.value.sql = monacoEditor.getValue();
|
|
|
})
|
|
|
+ dataSource.value = modelValue.value.configJson.dataSources[0]
|
|
|
})
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
<div class="api_pane-container">
|
|
|
<div class="api_pane-header">
|
|
|
+ <span style="font-size: 12px;margin: 0">
|
|
|
+ 数据库:
|
|
|
+ </span>
|
|
|
+ <el-select v-model="modelValue.configJson.dataSources"
|
|
|
+ placeholder="请选择"
|
|
|
+ size="small"
|
|
|
+ multiple
|
|
|
+ collapse-tags
|
|
|
+ style="width: 160px">
|
|
|
+ <el-option v-for="item in props.dataBase" :label="item.name" :value="item.alias"/>
|
|
|
+ </el-select>
|
|
|
+ <el-divider direction="vertical"/>
|
|
|
<span class="iconfont icon-baocun" @click="handleSave" title="保存"/>
|
|
|
<span class="iconfont icon-ceshi" title="测试" @click="handleDialogOpen"></span>
|
|
|
<el-button
|
|
@@ -256,18 +277,6 @@ onMounted(async () => {
|
|
|
{{ modelValue.enable ? '停用' : '启用' }}
|
|
|
</el-button>
|
|
|
<el-divider direction="vertical"/>
|
|
|
- <span style="font-size: 12px;margin: 0">
|
|
|
- 数据库:
|
|
|
- </span>
|
|
|
-
|
|
|
- <!-- multiple -->
|
|
|
- <el-select v-model="modelValue.dataBaseId"
|
|
|
- placeholder="请选择"
|
|
|
- size="small"
|
|
|
- style="width: 120px">
|
|
|
- <el-option v-for="item in props.dataBase" :label="item.name" :value="item.id"/>
|
|
|
- </el-select>
|
|
|
- <el-divider direction="vertical"/>
|
|
|
<el-button @click="processingOpenProperties" type="primary">属性</el-button>
|
|
|
</div>
|
|
|
|
|
@@ -355,7 +364,7 @@ onMounted(async () => {
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="24" v-if="modelValue.configJson.pageInfo.page">
|
|
|
- <el-form-item label="页大写">
|
|
|
+ <el-form-item label="页大小">
|
|
|
<el-select v-model="modelValue.configJson.pageInfo.pageSize">
|
|
|
<xc-el-option :data="pageSizeList"/>
|
|
|
</el-select>
|
|
@@ -378,9 +387,18 @@ onMounted(async () => {
|
|
|
:column="3"
|
|
|
size="small">
|
|
|
<el-descriptions-item label="地址" :span="3">
|
|
|
- {{ `${urlPrefix}/${modelValue.id}` }}
|
|
|
+ <el-select v-model="dataSource"
|
|
|
+ placeholder="请选择"
|
|
|
+ size="small"
|
|
|
+ style="width: 120px">
|
|
|
+ <el-option v-for="item in props.dataBase"
|
|
|
+ :label="item.name"
|
|
|
+ :disabled="!modelValue.configJson.dataSources.includes(item.alias)"
|
|
|
+ :value="item.alias"/>
|
|
|
+ </el-select>
|
|
|
+ {{ `${urlPrefix}/${dataSource}/${modelValue.id}` }}
|
|
|
<el-button icon="CopyDocument" circle
|
|
|
- @click="copyUrl(`${urlPrefix}/${modelValue.id}`)"/>
|
|
|
+ @click="copyUrl(`${urlPrefix}/${dataSource}/${modelValue.id}`)"/>
|
|
|
</el-descriptions-item>
|
|
|
<el-descriptions-item label="请求方式">
|
|
|
{{ modelValue.requestMapping }}
|