edit.vue 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!--
  2. - Copyright (c) 2024 LangChat. TyCoding All Rights Reserved.
  3. -
  4. - Licensed under the GNU Affero General Public License, Version 3 (the "License");
  5. - you may not use this file except in compliance with the License.
  6. - You may obtain a copy of the License at
  7. -
  8. - https://www.gnu.org/licenses/agpl-3.0.html
  9. -
  10. - Unless required by applicable law or agreed to in writing, software
  11. - distributed under the License is distributed on an "AS IS" BASIS,
  12. - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. - See the License for the specific language governing permissions and
  14. - limitations under the License.
  15. -->
  16. <script lang="ts" setup>
  17. import { computed, nextTick } from 'vue';
  18. import { add, getById, update } from '@/api/aigc/embed-store';
  19. import { useMessage } from 'naive-ui';
  20. import { getProviderLabel, getSchemas } from './columns';
  21. import { basicModal, useModal } from '@/components/Modal';
  22. import { BasicForm, useForm } from '@/components/Form';
  23. import { isNullOrWhitespace } from '@/utils/is';
  24. const props = defineProps<{
  25. provider: string;
  26. }>();
  27. const emit = defineEmits(['reload']);
  28. const message = useMessage();
  29. const [
  30. modalRegister,
  31. { openModal: openModal, closeModal: closeModal, setSubLoading: setSubLoading },
  32. ] = useModal({
  33. title: getProviderLabel(props.provider) + ' 新增/编辑',
  34. closable: true,
  35. maskClosable: false,
  36. showCloseBtn: false,
  37. showSubBtn: false,
  38. });
  39. const [register, { setFieldsValue }] = useForm({
  40. gridProps: { cols: 2 },
  41. labelWidth: 120,
  42. layout: 'horizontal',
  43. submitButtonText: '提交',
  44. });
  45. const schemas = computed(() => {
  46. nextTick();
  47. return getSchemas(props.provider);
  48. });
  49. async function show(id: string) {
  50. openModal();
  51. await nextTick();
  52. if (id) {
  53. setFieldsValue(await getById(id));
  54. } else {
  55. setFieldsValue({ isPerms: true, provider: props.provider });
  56. }
  57. }
  58. async function handleSubmit(values: any) {
  59. if (values !== false) {
  60. if (isNullOrWhitespace(values.id)) {
  61. await add(values);
  62. closeModal();
  63. emit('reload');
  64. message.success('新增成功');
  65. } else {
  66. await update(values);
  67. closeModal();
  68. emit('reload');
  69. message.success('修改成功');
  70. }
  71. } else {
  72. setSubLoading(false);
  73. message.error('请完善表单');
  74. }
  75. }
  76. defineExpose({ show });
  77. </script>
  78. <template>
  79. <basicModal style="width: 45%" @register="modalRegister">
  80. <template #default>
  81. <n-alert
  82. class="w-full mb-4 mt-2 min-alert"
  83. title="注意:请慎重修改模型的向量纬度参数(Dimension),此参数需要和向量库匹配(错误修改可能将影响已有的向量数据)"
  84. type="info"
  85. />
  86. <BasicForm :schemas="schemas" class="mt-5" @register="register" @submit="handleSubmit" />
  87. </template>
  88. </basicModal>
  89. </template>
  90. <style lang="less" scoped></style>