feat: 高级编排Python代码编辑框增加一个放大按钮

This commit is contained in:
wangdan-fit2cloud 2024-08-19 17:00:24 +08:00
parent 7799163651
commit 9afdb50cc4
8 changed files with 122 additions and 60 deletions

View File

@ -18,7 +18,7 @@
"@logicflow/extension": "^1.2.27",
"@vueuse/core": "^10.9.0",
"axios": "^0.28.0",
"codemirror-editor-vue3": "^2.7.0",
"codemirror": "^6.0.1",
"cropperjs": "^1.6.2",
"echarts": "^5.5.0",
"element-plus": "^2.5.6",
@ -41,6 +41,7 @@
"use-element-plus-theme": "^0.0.5",
"vue": "^3.3.4",
"vue-clipboard3": "^2.0.0",
"vue-codemirror": "^6.1.1",
"vue-i18n": "^9.13.1",
"vue-router": "^4.2.4"
},

View File

@ -125,7 +125,7 @@
<el-input
ref="quickInputRef"
v-model="inputValue"
placeholder="请输入"
placeholder="请输入问题Ctrl+Enter 换行Enter发送"
:autosize="{ minRows: 1, maxRows: isMobile ? 4 : 10 }"
type="textarea"
:maxlength="100000"

View File

@ -1,23 +1,27 @@
<template>
<Codemirror v-bind="$attrs" border :height="200" :option="cmOptions" />
<Codemirror v-bind="$attrs" border :options="cmOption" ref="cmRef" :style="codemirrorStyle" />
</template>
<script setup lang="ts">
import Codemirror from 'codemirror-editor-vue3'
import { ref, onMounted, onUnmounted } from 'vue'
import { Codemirror } from 'vue-codemirror'
defineOptions({ name: 'CodemirrorEditor' })
const cmOptions = {
mode: 'text/x-python',
autoRefresh: true
const cmOption = {
tabSize: 4,
lineWrapping: true,
lineNumbers: true,
line: true
}
const codemirrorStyle = {
height: '210px!important'
}
const cmRef = ref()
onMounted(() => {})
onUnmounted(() => {
cmRef.value?.destroy()
})
</script>
<style lang="scss" scoped>
.codemirror-container.bordered {
border: 1px solid #bbbfc4;
border-radius: 4px;
}
.CodeMirror-gutters {
left: 0 !important;
}
</style>
<style lang="scss"></style>

View File

@ -710,3 +710,4 @@ h5 {
.custom-header {
background: var(--el-color-primary-light-9) !important;
}

View File

@ -47,27 +47,11 @@
</template>
</el-tab-pane>
<el-tab-pane label="函数库" name="function">
<div
class="workflow-dropdown-item cursor flex p-8-12"
@click="clickNodes(functionNode)"
@mousedown="onmousedown(functionNode)"
>
<component
:is="iconComponent(`function-lib-node-icon`)"
class="mr-8 mt-4"
:size="32"
/>
<div class="pre-wrap">
<div class="lighter">{{ functionNode.label }}</div>
<el-text type="info" size="small">{{ functionNode.text }}</el-text>
</div>
</div>
<template v-for="(item, index) in functionLibList" :key="index">
<el-scrollbar max-height="300">
<div
class="workflow-dropdown-item cursor flex p-8-12"
@click="clickNodes(functionLibNode, item)"
@mousedown="onmousedown(functionLibNode, item)"
@click="clickNodes(functionNode)"
@mousedown="onmousedown(functionNode)"
>
<component
:is="iconComponent(`function-lib-node-icon`)"
@ -75,11 +59,29 @@
:size="32"
/>
<div class="pre-wrap">
<div class="lighter">{{ item.name }}</div>
<el-text type="info" size="small">{{ item.desc }}</el-text>
<div class="lighter">{{ functionNode.label }}</div>
<el-text type="info" size="small">{{ functionNode.text }}</el-text>
</div>
</div>
</template>
<template v-for="(item, index) in functionLibList" :key="index">
<div
class="workflow-dropdown-item cursor flex p-8-12"
@click="clickNodes(functionLibNode, item)"
@mousedown="onmousedown(functionLibNode, item)"
>
<component
:is="iconComponent(`function-lib-node-icon`)"
class="mr-8 mt-4"
:size="32"
/>
<div class="pre-wrap">
<div class="lighter">{{ item.name }}</div>
<el-text type="info" size="small">{{ item.desc }}</el-text>
</div>
</div>
</template>
</el-scrollbar>
</el-tab-pane>
</el-tabs>
</div>

View File

@ -45,19 +45,18 @@
</template>
<script setup lang="ts">
import { ref, watch, reactive } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { cloneDeep } from 'lodash'
import type { ApplicationFormType } from '@/api/type/application'
import type { FormInstance, FormRules } from 'element-plus'
import applicationApi from '@/api/application'
import { MsgSuccess, MsgAlert } from '@/utils/message'
import { isWorkFlow } from '@/utils/application'
import { t } from '@/locales'
import useStore from '@/stores'
import { ValidType, ValidCount } from '@/enums/common'
const { common, user } = useStore()
const router = useRouter()
const emit = defineEmits(['refresh'])
// @ts-ignore
@ -69,7 +68,7 @@ const applicationFormRef = ref()
const loading = ref(false)
const dialogVisible = ref<boolean>(false)
// @ts-ignore
const applicationForm = ref<ApplicationFormType>({
name: '',
desc: '',

View File

@ -85,8 +85,9 @@
Python 代码 <el-text type="info" class="color-secondary"> 使用函数时不显示 </el-text>
</h4>
<CodemirrorEditor v-model:value="form.code" v-if="showEditor" @change="changeCode" />
<div class="function-CodemirrorEditor" v-if="showEditor">
<CodemirrorEditor v-model="form.code" />
</div>
<h4 class="title-decoration-1 mb-16 mt-16">
输出变量 <el-text type="info" class="color-secondary"> 使用函数时显示 </el-text>
</h4>
@ -181,9 +182,9 @@ function refreshFieldList(data: any) {
currentIndex.value = null
}
function changeCode(value: string) {
form.value.code = value
}
// function changeCode(value: string) {
// form.value.code = value
// }
const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return
@ -221,4 +222,9 @@ defineExpose({
open
})
</script>
<style lang="scss"></style>
<style lang="scss" scoped>
.function-CodemirrorEditor {
border: 1px solid #bbbfc4;
border-radius: 4px;
}
</style>

View File

@ -58,6 +58,7 @@
class="w-full"
placeholder="请选择变量"
v-model="item.value"
:width="100"
/>
<el-input v-else v-model="item.value" placeholder="请输入变量值" />
</el-form-item>
@ -68,15 +69,21 @@
</el-card>
<h5 class="lighter mb-8">Python 代码</h5>
<CodemirrorEditor
v-model:value="chat_data.code"
@change="changeCode"
@wheel="wheel"
@keydown="isKeyDown = true"
@keyup="isKeyDown = false"
class="mb-8"
v-if="showEditor"
/>
<div class="workflow-CodemirrorEditor mb-8" v-if="showEditor">
<CodemirrorEditor
v-model="chat_data.code"
@wheel="wheel"
@keydown="isKeyDown = true"
@keyup="isKeyDown = false"
style="height: 130px !important"
/>
<div class="workflow-CodemirrorEditor__footer">
<el-button text type="info" @click="openCodemirrorDialog" class="magnify">
<AppIcon iconName="app-magnify" style="font-size: 16px"></AppIcon>
</el-button>
</div>
</div>
<el-form-item label="返回内容" @click.prevent>
<template #label>
<div class="flex align-center">
@ -95,6 +102,18 @@
</el-form-item>
</el-form>
<FieldFormDialog ref="FieldFormDialogRef" @refresh="refreshFieldList" />
<!-- Codemirror 弹出层 -->
<el-dialog v-model="dialogVisible" title="Python 代码" append-to-body>
<CodemirrorEditor
v-model="cloneContent"
style="height: 300px !important; border: 1px solid #bbbfc4; border-radius: 4px"
/>
<template #footer>
<div class="dialog-footer mt-24">
<el-button type="primary" @click="submitDialog"> 确认</el-button>
</div>
</template>
</el-dialog>
</NodeContainer>
</template>
<script setup lang="ts">
@ -152,8 +171,21 @@ const validate = () => {
})
}
function changeCode(value: string) {
set(props.nodeModel.properties.node_data, 'code', value)
// function changeCode(value: string) {
// set(props.nodeModel.properties.node_data, 'code', value)
// }
const dialogVisible = ref(false)
const cloneContent = ref('')
function openCodemirrorDialog() {
cloneContent.value = chat_data.value.code
dialogVisible.value = true
}
function submitDialog() {
set(props.nodeModel.properties.node_data, 'code', cloneContent.value)
dialogVisible.value = false
}
function openAddDialog(data?: any, index?: any) {
@ -197,4 +229,21 @@ onMounted(() => {
}, 100)
})
</script>
<style lang="scss" scoped></style>
<style lang="scss">
.workflow-CodemirrorEditor {
border: 1px solid #bbbfc4;
border-radius: 4px;
position: relative;
padding-bottom: 20px;
&__footer {
.magnify {
position: absolute;
bottom: 5px;
right: 5px;
}
}
.cm-gutters {
display: none !important;
}
}
</style>