create.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <base-dialog :width="900" @cancel="cancelDialog">
  3. <div slot="header">{{ params.type === 'edit' ? $t('table.action.modify') : $t('common.create') }}</div>
  4. <div slot="body">
  5. <a-form-model ref="form" :model="form" :rules="rules" :label-col="{ span: 4 }" :wrapper-col="{ span: 18 }">
  6. <a-form-model-item :label="$t('common.name')" prop="name">
  7. <a-input v-model="form.name" :placeholder="$t('common.tips.input', [$t('common.name')])" :disabled="type === 'edit'" />
  8. </a-form-model-item>
  9. <a-form-model-item :label="$t('aice.llm_type')" prop="llm_type">
  10. <a-radio-group
  11. v-if="type !== 'edit'"
  12. v-model="form.llm_type"
  13. class="llm-type-picker"
  14. button-style="solid">
  15. <a-radio-button v-for="opt in llmTypeOptions" :key="opt.id" :value="opt.id">
  16. {{ opt.name }}
  17. </a-radio-button>
  18. </a-radio-group>
  19. <span v-else>{{ llmTypeName }}</span>
  20. </a-form-model-item>
  21. <a-form-model-item :label="$t('aice.llm_image.name')" prop="image_name">
  22. <a-input v-model="form.image_name" :placeholder="$t('common.tips.input', [$t('aice.llm_image.name')])" />
  23. </a-form-model-item>
  24. <a-form-model-item :label="$t('aice.llm_image.label')" prop="image_label">
  25. <a-input v-model="form.image_label" :placeholder="$t('common.tips.input', [$t('aice.llm_image.label')])" />
  26. </a-form-model-item>
  27. </a-form-model>
  28. </div>
  29. <div slot="footer">
  30. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  31. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  32. </div>
  33. </base-dialog>
  34. </template>
  35. <script>
  36. import DialogMixin from '@/mixins/dialog'
  37. import WindowsMixin from '@/mixins/windows'
  38. import { validateModelForm } from '@/utils/validate'
  39. import { LLM_TYPE_OPTIONS } from '../../llm-sku/llmTypeConfig'
  40. export default {
  41. name: 'DesktopImageCreateDialog',
  42. components: {
  43. },
  44. mixins: [DialogMixin, WindowsMixin],
  45. data () {
  46. const data = this.params.type === 'edit' ? this.params.data[0] : {}
  47. const defaultLlmType = (LLM_TYPE_OPTIONS[0] && LLM_TYPE_OPTIONS[0].id) || 'openclaw'
  48. return {
  49. loading: false,
  50. type: this.params.type,
  51. form: {
  52. name: data.name || undefined,
  53. llm_type: data.llm_type || defaultLlmType,
  54. image_name: data.image_name || undefined,
  55. image_label: data.image_label || undefined,
  56. },
  57. rules: {
  58. name: [{ required: true, validator: this.$validate('imageName') }],
  59. llm_type: [{ required: true, message: this.$t('common.tips.select', [this.$t('aice.llm_type')]) }],
  60. image_name: [{ required: true, message: this.$t('common.tips.input', [this.$t('aice.llm_image.name')]) }],
  61. image_label: [{ required: true, message: this.$t('common.tips.input', [this.$t('aice.llm_image.label')]) }],
  62. },
  63. formItemLayout: {
  64. wrapperCol: {
  65. span: 18,
  66. },
  67. labelCol: {
  68. span: 5,
  69. },
  70. },
  71. }
  72. },
  73. computed: {
  74. llmTypeOptions () {
  75. return LLM_TYPE_OPTIONS.map(opt => ({ id: opt.id, name: this.$t(opt.name) }))
  76. },
  77. llmTypeName () {
  78. const opt = LLM_TYPE_OPTIONS.find(o => o.id === this.form.llm_type)
  79. return opt ? this.$t(opt.name) : this.form.llm_type || '-'
  80. },
  81. desktopModelParams () {
  82. return {
  83. limit: 20,
  84. scope: this.$store.getters.scope,
  85. }
  86. },
  87. },
  88. methods: {
  89. async handleConfirm () {
  90. try {
  91. await validateModelForm(this.$refs.form)
  92. if (this.type === 'edit') {
  93. await this.params.onManager('update', {
  94. id: this.params.data[0].id,
  95. managerArgs: {
  96. data: this.form,
  97. },
  98. })
  99. } else {
  100. await this.params.onManager('create', {
  101. managerArgs: {
  102. data: this.form,
  103. },
  104. })
  105. }
  106. this.loading = false
  107. this.cancelDialog()
  108. this.params.refresh()
  109. } catch (error) {
  110. throw error
  111. } finally {
  112. this.loading = false
  113. }
  114. },
  115. },
  116. }
  117. </script>