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
123
124
125
| <script lang="ts" setup>
| import type { FormSchema } from '@jnpf/ui/form';
|
| import { computed, reactive, toRefs } from 'vue';
|
| import { useMessage } from '@jnpf/hooks';
| import { BasicForm, useForm } from '@jnpf/ui/form';
| import { BasicModal, ModalFooter, useModalInner } from '@jnpf/ui/modal';
|
| import { checkAi, create, getInfo, update } from '#/api/system/aiModelConfig';
| import { $t } from '#/locales';
|
| interface State {
| dataForm: any;
| loading: boolean;
| }
|
| const emit = defineEmits(['register', 'reload']);
| const state = reactive<State>({
| dataForm: {},
| loading: false,
| });
| const { loading } = toRefs(state);
| const schemas: FormSchema[] = [
| {
| field: 'fullName',
| label: '模型名称',
| component: 'Input',
| componentProps: { placeholder: '请输入', maxlength: 50 },
| rules: [{ required: true, trigger: 'blur', message: '必填' }],
| },
| {
| field: 'model',
| label: '基础模型',
| component: 'Input',
| componentProps: { placeholder: '请输入', maxlength: 50 },
| rules: [{ required: true, trigger: 'change', message: '必填' }],
| },
| {
| field: 'baseUrl',
| label: ' API 地址',
| component: 'Input',
| rules: [{ required: true, trigger: 'change', message: '必填' }],
| },
| {
| field: 'credential',
| label: 'API Key',
| component: 'Input',
| rules: [{ required: true, trigger: 'change', message: '必填' }],
| },
| {
| field: 'enabledMark',
| label: '状态',
| component: 'Switch',
| defaultValue: 1,
| },
| ];
| const getTitle = computed(() => (state.dataForm.id ? $t('common.editText') : $t('common.addText')));
| const { createMessage } = useMessage();
| const [registerForm, { setFieldsValue, validate, resetFields }] = useForm({ labelWidth: 130, schemas });
| const [registerModal, { closeModal, changeLoading, changeOkLoading }] = useModalInner(init);
|
| function init(data) {
| resetFields();
| state.loading = false;
| state.dataForm.id = data.id;
| if (state.dataForm.id) {
| changeLoading(true);
| getInfo(state.dataForm.id).then((res) => {
| const data = res.data;
| state.dataForm = data;
| setFieldsValue(data);
| changeLoading(false);
| });
| }
| }
| async function handleSubmit() {
| const values = await validate();
| if (!values) return;
| changeOkLoading(true);
| const query = {
| ...values,
| id: state.dataForm.id,
| };
| const formMethod = state.dataForm.id ? update : create;
| formMethod(query)
| .then((res) => {
| createMessage.success(res.msg);
| changeOkLoading(false);
| closeModal();
| emit('reload');
| })
| .catch(() => {
| changeOkLoading(false);
| });
| }
| async function handleCheckAi() {
| const values = await validate();
| if (!values) return;
| state.loading = true;
| changeOkLoading(true);
| checkAi(values)
| .then((res) => {
| createMessage.success(res.msg);
| state.loading = false;
| changeOkLoading(false);
| })
| .catch(() => {
| changeOkLoading(false);
| state.loading = false;
| });
| }
| </script>
| <template>
| <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" show-ok-btn @ok="handleSubmit">
| <BasicForm @register="registerForm" />
| <template #footer>
| <ModalFooter @cancel="closeModal" @ok="handleSubmit">
| <template #insertFooter>
| <a-button :loading="loading" @click="handleCheckAi">测试</a-button>
| </template>
| </ModalFooter>
| </template>
| </BasicModal>
| </template>
|
|