perf: 优化函数库

This commit is contained in:
wangdan-fit2cloud 2024-08-22 18:16:15 +08:00 committed by wangdan-fit2cloud
parent 2703e73b07
commit e4b17f842d
5 changed files with 79 additions and 33 deletions

View File

@ -711,3 +711,20 @@ h5 {
background: var(--el-color-primary-light-9) !important; background: var(--el-color-primary-light-9) !important;
} }
// Codemirror 编辑器
.function-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;
}
}

View File

@ -39,9 +39,7 @@ import { useRouter, useRoute } from 'vue-router'
import SetRules from './component/SetRules.vue' import SetRules from './component/SetRules.vue'
import ResultSuccess from './component/ResultSuccess.vue' import ResultSuccess from './component/ResultSuccess.vue'
import UploadComponent from './component/UploadComponent.vue' import UploadComponent from './component/UploadComponent.vue'
import datasetApi from '@/api/dataset'
import documentApi from '@/api/document' import documentApi from '@/api/document'
import type { datasetData } from '@/api/type/dataset'
import { MsgConfirm, MsgSuccess } from '@/utils/message' import { MsgConfirm, MsgSuccess } from '@/utils/message'
import useStore from '@/stores' import useStore from '@/stores'

View File

@ -65,7 +65,7 @@ const form = ref<any>({
name: '', name: '',
type: typeOptions[0], type: typeOptions[0],
source: 'reference', source: 'reference',
is_required: false is_required: true
}) })
const rules = reactive({ const rules = reactive({
@ -80,7 +80,7 @@ watch(dialogVisible, (bool) => {
name: '', name: '',
type: typeOptions[0], type: typeOptions[0],
source: 'reference', source: 'reference',
is_required: false is_required: true
} }
isEdit.value = false isEdit.value = false
} }
@ -95,6 +95,7 @@ const open = (row: any) => {
dialogVisible.value = true dialogVisible.value = true
} }
const submit = async (formEl: FormInstance | undefined) => { const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return if (!formEl) return
await formEl.validate((valid) => { await formEl.validate((valid) => {

View File

@ -1,5 +1,5 @@
<template> <template>
<el-drawer v-model="visible" size="60%"> <el-drawer v-model="visible" size="60%" :before-close="close">
<template #header> <template #header>
<h4>{{ title }}</h4> <h4>{{ title }}</h4>
</template> </template>
@ -85,8 +85,13 @@
Python 代码 <el-text type="info" class="color-secondary"> 使用函数时不显示 </el-text> Python 代码 <el-text type="info" class="color-secondary"> 使用函数时不显示 </el-text>
</h4> </h4>
<div class="function-CodemirrorEditor" v-if="showEditor"> <div class="function-CodemirrorEditor mb-8" v-if="showEditor">
<CodemirrorEditor v-model="form.code" /> <CodemirrorEditor v-model="form.code" />
<div class="function-CodemirrorEditor__footer">
<el-button text type="info" @click="openCodemirrorDialog" class="magnify">
<AppIcon iconName="app-magnify" style="font-size: 16px"></AppIcon>
</el-button>
</div>
</div> </div>
<h4 class="title-decoration-1 mb-16 mt-16"> <h4 class="title-decoration-1 mb-16 mt-16">
输出变量 <el-text type="info" class="color-secondary"> 使用函数时显示 </el-text> 输出变量 <el-text type="info" class="color-secondary"> 使用函数时显示 </el-text>
@ -105,6 +110,19 @@
> >
</div> </div>
</template> </template>
<!-- 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>
<FunctionDebugDrawer ref="FunctionDebugDrawerRef" /> <FunctionDebugDrawer ref="FunctionDebugDrawerRef" />
<FieldFormDialog ref="FieldFormDialogRef" @refresh="refreshFieldList" /> <FieldFormDialog ref="FieldFormDialogRef" @refresh="refreshFieldList" />
</el-drawer> </el-drawer>
@ -117,7 +135,7 @@ import FunctionDebugDrawer from './FunctionDebugDrawer.vue'
import type { functionLibData } from '@/api/type/function-lib' import type { functionLibData } from '@/api/type/function-lib'
import functionLibApi from '@/api/function-lib' import functionLibApi from '@/api/function-lib'
import type { FormInstance } from 'element-plus' import type { FormInstance } from 'element-plus'
import { MsgSuccess, MsgError } from '@/utils/message' import { MsgSuccess, MsgConfirm } from '@/utils/message'
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
const props = defineProps({ const props = defineProps({
@ -143,6 +161,9 @@ const form = ref<functionLibData>({
input_field_list: [] input_field_list: []
}) })
const dialogVisible = ref(false)
const cloneContent = ref<any>('')
watch(visible, (bool) => { watch(visible, (bool) => {
if (!bool) { if (!bool) {
isEdit.value = false isEdit.value = false
@ -161,6 +182,39 @@ const rules = reactive({
name: [{ required: true, message: '请输入函数名称', trigger: 'blur' }] name: [{ required: true, message: '请输入函数名称', trigger: 'blur' }]
}) })
function openCodemirrorDialog() {
cloneContent.value = form.value.code
dialogVisible.value = true
}
function submitDialog() {
form.value.code = cloneContent.value
dialogVisible.value = false
}
function close() {
if (!areAllValuesNonEmpty(form.value)) {
visible.value = false
} else {
MsgConfirm(`提示`, `当前的更改尚未保存,确认退出吗?`, {
confirmButtonText: '确认',
type: 'warning'
})
.then(() => {
visible.value = false
})
.catch(() => {})
}
}
function areAllValuesNonEmpty(obj: any) {
return Object.values(obj).some((value) => {
return Array.isArray(value)
? value.length !== 0
: value !== null && value !== undefined && value !== ''
})
}
function openDebug() { function openDebug() {
FunctionDebugDrawerRef.value.open(form.value) FunctionDebugDrawerRef.value.open(form.value)
} }
@ -222,9 +276,4 @@ defineExpose({
open open
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped></style>
.function-CodemirrorEditor {
border: 1px solid #bbbfc4;
border-radius: 4px;
}
</style>

View File

@ -174,10 +174,6 @@ const validate = () => {
}) })
} }
// function changeCode(value: string) {
// set(props.nodeModel.properties.node_data, 'code', value)
// }
const dialogVisible = ref(false) const dialogVisible = ref(false)
const cloneContent = ref('') const cloneContent = ref('')
@ -233,20 +229,5 @@ onMounted(() => {
}) })
</script> </script>
<style lang="scss"> <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> </style>