| | |
| | | const identity = (field: FormationField) => `${field.scope}|${field.key}` |
| | | const fieldName = (field: FormationField) => defaultFormationFields.find(value => value.key === field.key)?.displayName || field.key |
| | | function openSettings() { |
| | | const available: FormationField[] = props.items.flatMap(item => item.businessFields.map(field => ({ key: field.fieldName, displayName: field.fieldName, |
| | | unit: '', kind: 'battery' as const, scope: 'detail' as const, fieldDefinitionId: field.fieldDefinitionId }))) |
| | | const combined = new Map<string, FormationField>() |
| | | for (const field of [...props.fields, ...defaultFormationFields, ...available]) if (!combined.has(identity(field))) combined.set(identity(field), field) |
| | | for (const field of [...props.fields, ...defaultFormationFields].filter(field => field.scope === 'cycle')) if (!combined.has(identity(field))) combined.set(identity(field), field) |
| | | draft.value = [...combined.values()].map(field => ({ ...field, enabled: props.fields.some(selected => identity(selected) === identity(field)) })) |
| | | settingsVisible.value = true |
| | | } |
| | |
| | | const { value } = await ElMessageBox.prompt('请输入字段名称', '添加人工项', { confirmButtonText: '添加', cancelButtonText: '取消', inputValidator: value => Boolean(value?.trim()) || '请输入字段名称' }) |
| | | const key = value.trim() |
| | | if (key.includes('|') || key.length > 100 || draft.value.some(field => field.key === key)) { ElMessage.warning('字段名重复或无效'); return } |
| | | draft.value.push({ key, displayName: key, unit: '', kind: 'manual', scope: 'detail', enabled: true }) |
| | | draft.value.push({ key, displayName: key, unit: '', kind: 'manual', scope: 'cycle', enabled: true }) |
| | | } catch (cause) { if (cause !== 'cancel' && cause !== 'close') ElMessage.error('添加字段失败') } |
| | | } |
| | | async function openTemplates() { |
| | |
| | | function applyTemplate() { |
| | | const template = templates.value.find(item => item.id === selectedTemplate.value) |
| | | if (!template) { ElMessage.warning('请选择字段模板'); return } |
| | | emit('apply', template.fields.map(field => ({ ...field }))) |
| | | const fields = template.fields.filter(field => field.scope === 'cycle') |
| | | if (!fields.length) { ElMessage.warning('模板中没有循环指标'); return } |
| | | emit('apply', fields.map(field => ({ ...field }))) |
| | | templatesVisible.value = false; ElMessage.success('字段模板已应用') |
| | | } |
| | | async function saveTemplate() { |
| | |
| | | <el-dialog v-model="settingsVisible" title="字段设置" width="min(850px, calc(100vw - 28px))"> |
| | | <div class="field-settings-table"><table><thead><tr><th>选择</th><th>字段</th><th>范围</th><th>展示名称</th><th>单位</th><th>顺序</th></tr></thead><tbody> |
| | | <tr v-for="(field, index) in draft" :key="identity(field)"><td><el-checkbox v-model="field.enabled" :aria-label="`选择${fieldName(field)}`" /></td><td>{{ fieldName(field) }}</td> |
| | | <td><el-select v-if="field.kind === 'manual'" v-model="field.scope" aria-label="字段范围"><el-option label="详情" value="detail" /><el-option label="循环" value="cycle" /></el-select><span v-else>{{ field.scope === 'detail' ? '详情' : '循环' }}</span></td> |
| | | <td><span>循环</span></td> |
| | | <td><el-input v-model="field.displayName" aria-label="展示名称" maxlength="100" /></td><td><el-input v-model="field.unit" aria-label="单位" maxlength="30" :disabled="field.kind === 'metric'" /></td> |
| | | <td class="move-buttons"><el-tooltip content="上移"><el-button aria-label="上移" :disabled="index === 0" @click="move(index, -1)"><el-icon><ArrowUp /></el-icon></el-button></el-tooltip><el-tooltip content="下移"><el-button aria-label="下移" :disabled="index === draft.length - 1" @click="move(index, 1)"><el-icon><ArrowDown /></el-icon></el-button></el-tooltip></td> |
| | | </tr></tbody></table></div> |