UnisKB/ui/src/views/tool/component/InitParamDrawer.vue

88 lines
2.1 KiB
Vue
Raw Normal View History

2025-05-15 10:21:38 +00:00
<template>
<el-drawer v-model="debugVisible" size="60%" :append-to-body="true">
<template #header>
2025-05-22 10:38:06 +00:00
<h4>{{ $t('common.param.initParam') }}</h4>
2025-05-15 10:21:38 +00:00
</template>
<div>
<div v-if="form.init_field_list?.length > 0">
<DynamicsForm
v-model="form.init_params"
:model="form.init_params"
label-position="top"
require-asterisk-position="right"
:render_data="form.init_field_list"
ref="dynamicsFormRef"
>
</DynamicsForm>
</div>
</div>
<template #footer>
<div>
<el-button type="primary" @click="submit()" :loading="loading">
{{ $t('common.save') }}
</el-button>
</div>
</template>
</el-drawer>
</template>
<script setup lang="ts">
2025-06-06 01:39:01 +00:00
import {ref, watch} from 'vue'
import ToolApi from '@/api/shared/tool'
2025-05-15 10:21:38 +00:00
import DynamicsForm from '@/components/dynamics-form/index.vue'
2025-06-06 01:39:01 +00:00
import {MsgSuccess} from '@/utils/message'
import {t} from '@/locales'
import {cloneDeep} from 'lodash'
2025-05-15 10:21:38 +00:00
const emit = defineEmits(['refresh'])
const dynamicsFormRef = ref()
const loading = ref(false)
const debugVisible = ref(false)
const form = ref<any>({
init_params: {},
})
watch(debugVisible, (bool) => {
if (!bool) {
form.value = {
init_params: {},
is_active: false,
}
}
})
const submit = async () => {
dynamicsFormRef.value.validate().then(() => {
2025-06-06 01:39:01 +00:00
ToolApi.putTool(form.value?.id as string, form.value, loading).then((res) => {
2025-05-15 10:21:38 +00:00
MsgSuccess(t('common.editSuccess'))
emit('refresh')
debugVisible.value = false
})
})
}
const open = (data: any, is_active: boolean) => {
if (data) {
form.value = cloneDeep(data)
form.value.is_active = is_active
}
const init_params = form.value.init_field_list
.map((item: any) => {
if (item.show_default_value === false) {
2025-06-06 01:39:01 +00:00
return {[item.field]: undefined}
2025-05-15 10:21:38 +00:00
}
2025-06-06 01:39:01 +00:00
return {[item.field]: item.default_value}
2025-05-15 10:21:38 +00:00
})
2025-06-06 01:39:01 +00:00
.reduce((x: any, y: any) => ({...x, ...y}), {})
form.value.init_params = {...init_params, ...form.value.init_params}
2025-05-15 10:21:38 +00:00
debugVisible.value = true
}
defineExpose({
open,
})
</script>
<style lang="scss"></style>