|
| 1 | +<!-- |
| 2 | + GPU 型号 + 数量编辑,用于推理模板创建/编辑(每行可选型号与张数,支持多行)。 |
| 3 | +--> |
| 4 | +<template> |
| 5 | + <div class="llm-gpu-devices-editor"> |
| 6 | + <div |
| 7 | + v-for="(row, index) in innerRows" |
| 8 | + :key="rowKeys[index]" |
| 9 | + class="llm-gpu-devices-editor__row"> |
| 10 | + <base-select |
| 11 | + :value="row.model" |
| 12 | + :options="specList" |
| 13 | + :select-props="modelSelectProps" |
| 14 | + class="llm-gpu-devices-editor__model" |
| 15 | + @change="val => onModelChange(index, val)" /> |
| 16 | + <a-input-number |
| 17 | + :value="row.count" |
| 18 | + :min="1" |
| 19 | + :max="maxCount" |
| 20 | + :precision="0" |
| 21 | + class="llm-gpu-devices-editor__count" |
| 22 | + @change="val => onCountChange(index, val)" /> |
| 23 | + <span class="llm-gpu-devices-editor__unit">{{ $t('aice.devices.count_unit') }}</span> |
| 24 | + <a-button |
| 25 | + v-if="innerRows.length > 1" |
| 26 | + shape="circle" |
| 27 | + icon="minus" |
| 28 | + size="small" |
| 29 | + class="llm-gpu-devices-editor__remove" |
| 30 | + @click="removeRow(index)" /> |
| 31 | + </div> |
| 32 | + <a-button type="link" icon="plus" class="pl-0" @click="addRow"> |
| 33 | + {{ $t('aice.devices.add') }} |
| 34 | + </a-button> |
| 35 | + </div> |
| 36 | +</template> |
| 37 | + |
| 38 | +<script> |
| 39 | +import { uuid } from '@/utils/utils' |
| 40 | +import { createEmptyDeviceRow, normalizeDeviceRows } from '@Ai/utils/deviceFormUtils' |
| 41 | +
|
| 42 | +export default { |
| 43 | + name: 'LlmGpuDevicesEditor', |
| 44 | + props: { |
| 45 | + value: { |
| 46 | + type: Array, |
| 47 | + default: () => [], |
| 48 | + }, |
| 49 | + maxCount: { |
| 50 | + type: Number, |
| 51 | + default: 16, |
| 52 | + }, |
| 53 | + }, |
| 54 | + data () { |
| 55 | + return { |
| 56 | + rowKeys: [uuid()], |
| 57 | + } |
| 58 | + }, |
| 59 | + computed: { |
| 60 | + specList () { |
| 61 | + const list = Object.values(this.$store.getters.capability?.pci_model_types || {}) |
| 62 | + .filter(item => item.hypervisor === 'pod') |
| 63 | + return list.map(item => ({ key: item.model, label: item.model })) |
| 64 | + }, |
| 65 | + modelSelectProps () { |
| 66 | + return { |
| 67 | + placeholder: this.$t('common.tips.select', [this.$t('aice.devices')]), |
| 68 | + allowClear: true, |
| 69 | + } |
| 70 | + }, |
| 71 | + innerRows () { |
| 72 | + return normalizeDeviceRows(this.value) |
| 73 | + }, |
| 74 | + }, |
| 75 | + watch: { |
| 76 | + value: { |
| 77 | + immediate: true, |
| 78 | + handler (val) { |
| 79 | + const rows = normalizeDeviceRows(val) |
| 80 | + while (this.rowKeys.length < rows.length) { |
| 81 | + this.rowKeys.push(uuid()) |
| 82 | + } |
| 83 | + while (this.rowKeys.length > rows.length) { |
| 84 | + this.rowKeys.pop() |
| 85 | + } |
| 86 | + }, |
| 87 | + }, |
| 88 | + }, |
| 89 | + methods: { |
| 90 | + emitRows (rows) { |
| 91 | + const normalized = normalizeDeviceRows(rows) |
| 92 | + this.$emit('input', normalized) |
| 93 | + this.$emit('change', normalized) |
| 94 | + }, |
| 95 | + onModelChange (index, model) { |
| 96 | + const rows = this.innerRows.map((row, i) => ( |
| 97 | + i === index ? { ...row, model } : { ...row } |
| 98 | + )) |
| 99 | + this.emitRows(rows) |
| 100 | + }, |
| 101 | + onCountChange (index, count) { |
| 102 | + const rows = this.innerRows.map((row, i) => ( |
| 103 | + i === index ? { ...row, count: count ?? 1 } : { ...row } |
| 104 | + )) |
| 105 | + this.emitRows(rows) |
| 106 | + }, |
| 107 | + addRow () { |
| 108 | + this.rowKeys.push(uuid()) |
| 109 | + this.emitRows([...this.innerRows, createEmptyDeviceRow()]) |
| 110 | + }, |
| 111 | + removeRow (index) { |
| 112 | + if (this.innerRows.length <= 1) return |
| 113 | + this.rowKeys.splice(index, 1) |
| 114 | + const rows = this.innerRows.filter((_, i) => i !== index) |
| 115 | + this.emitRows(rows.length ? rows : [createEmptyDeviceRow()]) |
| 116 | + }, |
| 117 | + }, |
| 118 | +} |
| 119 | +</script> |
| 120 | +
|
| 121 | +<style lang="less" scoped> |
| 122 | +.llm-gpu-devices-editor__row { |
| 123 | + display: flex; |
| 124 | + align-items: center; |
| 125 | + gap: 8px; |
| 126 | + margin-bottom: 8px; |
| 127 | +} |
| 128 | +.llm-gpu-devices-editor__model { |
| 129 | + flex: 1; |
| 130 | + min-width: 0; |
| 131 | +} |
| 132 | +.llm-gpu-devices-editor__count { |
| 133 | + width: 88px; |
| 134 | +} |
| 135 | +.llm-gpu-devices-editor__unit { |
| 136 | + color: rgba(0, 0, 0, 0.45); |
| 137 | + white-space: nowrap; |
| 138 | +} |
| 139 | +.llm-gpu-devices-editor__remove { |
| 140 | + flex-shrink: 0; |
| 141 | +} |
| 142 | +</style> |
0 commit comments