feat(training): add interview records editor
parent
a5c88c1d8c
commit
d87153795c
@ -0,0 +1,89 @@
|
||||
<template>
|
||||
<el-dialog v-model="visibleProxy" title="编辑访谈记录" width="min(980px, 94vw)" append-to-body destroy-on-close class="interview-records-editor">
|
||||
<div class="editor-tabs" role="tablist" aria-label="访谈记录">
|
||||
<button v-for="(record, index) in draftRecords" :key="record.code || index" type="button" :class="{ active: activeIndex === index }" @click="activeIndex = index">
|
||||
{{ record.code || `U0${index + 1}` }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="activeRecord" class="editor-body">
|
||||
<div class="editor-field">
|
||||
<label>用户编号</label>
|
||||
<el-input :model-value="activeRecord.code" disabled />
|
||||
</div>
|
||||
<div class="editor-field">
|
||||
<label>记录标题</label>
|
||||
<el-input v-model="activeRecord.title" placeholder="例如:访谈记录一" />
|
||||
</div>
|
||||
<div class="editor-field">
|
||||
<label>基本属性</label>
|
||||
<el-input v-model="activeRecord.basicAttributes" type="textarea" :rows="2" placeholder="年龄、性别、城市、职业、收入等" />
|
||||
</div>
|
||||
<div class="content-heading">
|
||||
<strong>访谈内容</strong>
|
||||
<el-button type="primary" link @click="addQuestion">新增问答</el-button>
|
||||
</div>
|
||||
<div v-for="(item, index) in activeRecord.content" :key="index" class="qa-editor-row">
|
||||
<div class="qa-label">Q{{ index + 1 }}</div>
|
||||
<el-input v-model="item.question" placeholder="请输入访谈问题" />
|
||||
<div class="qa-label answer-label">A{{ index + 1 }}</div>
|
||||
<el-input v-model="item.answer" type="textarea" :rows="3" placeholder="请输入访谈回答" />
|
||||
<el-button type="danger" link :disabled="activeRecord.content.length <= 1" @click="removeQuestion(index)">删除</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else description="暂无访谈记录" />
|
||||
<template #footer>
|
||||
<el-button @click="visibleProxy = false">取消</el-button>
|
||||
<el-button type="primary" @click="save">保存访谈记录</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, watch } from "vue"
|
||||
import { cloneInterviewRecords, DEFAULT_INTERVIEW_RECORDS } from "@/utils/interviewRecords"
|
||||
|
||||
const props = defineProps({
|
||||
visible: { type: Boolean, default: false },
|
||||
modelValue: { type: Array, default: () => [] },
|
||||
})
|
||||
const emit = defineEmits(["update:visible", "update:modelValue"])
|
||||
const visibleProxy = computed({ get: () => props.visible, set: (value) => emit("update:visible", value) })
|
||||
const draftRecords = ref([])
|
||||
const activeIndex = ref(0)
|
||||
const activeRecord = computed(() => draftRecords.value[activeIndex.value] || null)
|
||||
|
||||
watch(() => props.visible, (visible) => {
|
||||
if (!visible) return
|
||||
draftRecords.value = cloneInterviewRecords(props.modelValue?.length ? props.modelValue : DEFAULT_INTERVIEW_RECORDS)
|
||||
activeIndex.value = 0
|
||||
}, { immediate: true })
|
||||
|
||||
function addQuestion() {
|
||||
if (!activeRecord.value) return
|
||||
activeRecord.value.content.push({ question: "", answer: "" })
|
||||
}
|
||||
|
||||
function removeQuestion(index) {
|
||||
if (!activeRecord.value || activeRecord.value.content.length <= 1) return
|
||||
activeRecord.value.content.splice(index, 1)
|
||||
}
|
||||
|
||||
function save() {
|
||||
emit("update:modelValue", cloneInterviewRecords(draftRecords.value))
|
||||
visibleProxy.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.editor-tabs { display: flex; gap: 10px; padding-bottom: 14px; border-bottom: 1px solid #e8edf5; }
|
||||
.editor-tabs button { min-width: 66px; padding: 7px 16px; border: 1px solid #d9e1ee; border-radius: 7px; background: #fff; color: #52627a; cursor: pointer; font-weight: 600; }
|
||||
.editor-tabs button.active { border-color: #2563eb; background: #2563eb; color: #fff; }
|
||||
.editor-body { max-height: min(62vh, 650px); overflow: auto; padding: 20px 4px 4px; }
|
||||
.editor-field { margin-bottom: 16px; }
|
||||
.editor-field label { display: block; margin-bottom: 7px; color: #25344d; font-size: 13px; font-weight: 600; }
|
||||
.content-heading { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 10px; color: #25344d; }
|
||||
.qa-editor-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 34px minmax(0, 1.3fr) auto; gap: 8px; align-items: start; margin-bottom: 12px; padding: 12px; border: 1px solid #e8edf5; border-radius: 8px; background: #f8fbff; }
|
||||
.qa-label { padding-top: 8px; color: #2563eb; font-size: 12px; font-weight: 700; }
|
||||
.answer-label { color: #16a36a; }
|
||||
@media (max-width: 760px) { .qa-editor-row { grid-template-columns: 30px minmax(0, 1fr); } .qa-editor-row .answer-label { grid-column: 1; } .qa-editor-row .el-button { grid-column: 2; justify-self: end; } }
|
||||
</style>
|
||||
Loading…
Reference in New Issue