-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathSTTModelParamSettingDialog.vue
More file actions
122 lines (104 loc) · 3.36 KB
/
STTModelParamSettingDialog.vue
File metadata and controls
122 lines (104 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<template>
<el-dialog
align-center
:title="$t('common.paramSetting')"
v-model="dialogVisible"
style="width: 550px"
append-to-body
:close-on-click-modal="false"
:close-on-press-escape="false"
>
<DynamicsForm
v-model="form_data"
:model="form_data"
label-position="top"
require-asterisk-position="right"
:render_data="model_form_field"
ref="dynamicsFormRef"
>
</DynamicsForm>
<template #footer>
<div class="flex-between">
<span class="dialog-footer">
<el-button @click.prevent="dialogVisible = false">
{{ $t('common.cancel') }}
</el-button>
<el-button type="primary" @click="submit" :loading="loading">
{{ $t('common.confirm') }}
</el-button>
</span>
</div>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import type { FormField } from '@/components/dynamics-form/type'
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import DynamicsForm from '@/components/dynamics-form/index.vue'
import { ref, computed } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
const {
params: { id }
} = route as any
const apiType = computed(() => {
if (route.path.includes('resource-management')) {
return 'systemManage'
} else {
return 'workspace'
}
})
const dialogVisible = ref<boolean>(false)
const form_data = ref<any>({})
const dynamicsFormRef = ref<InstanceType<typeof DynamicsForm>>()
const stt_model_id = ref<string>('')
const loading = ref<boolean>(false)
const model_form_field = ref<Array<FormField>>([])
const emit = defineEmits(['refresh'])
const open = (model_id: string, application_id?: string, model_setting_data?: any) => {
form_data.value = {}
stt_model_id.value = model_id
loadSharedApi({ type: 'model', systemType: apiType.value })
.getModelParamsForm(model_id, loading)
.then(( ok: any ) => {
model_form_field.value = ok.data
const resp = ok.data
.map((item: any) => ({
[item.field]: item.show_default_value !== false ? item.default_value : undefined,
}))
.reduce((x: any, y: any) => ({ ...x, ...y }), {})
if (model_setting_data) {
Object.keys(model_setting_data).forEach((key) => {
if (!(key in resp)) {
delete model_setting_data[key]
}
})
}
model_setting_data = { ...resp, ...model_setting_data }
// 渲染动态表单
dynamicsFormRef.value?.render(model_form_field.value, model_setting_data)
})
dialogVisible.value = true
}
const submit = async () => {
dynamicsFormRef.value?.validate().then(() => {
emit('refresh', form_data.value)
dialogVisible.value = false
})
}
const reset_default = (model_id: string, application_id?: string) => {
loadSharedApi({ type: 'model', systemType: apiType.value })
.getModelParamsForm(model_id, loading)
.then((ok: any) => {
model_form_field.value = ok.data
const model_setting_data = ok.data
.map((item: any) => ({
[item.field]: item.show_default_value !== false ? item.default_value : undefined,
}))
.reduce((x: any, y: any) => (({ ...x, ...y })), {})
emit('refresh', model_setting_data)
})
}
defineExpose({ open, reset_default })
</script>
<style lang="scss" scoped></style>