|
@@ -5,6 +5,7 @@
|
|
width="500px"
|
|
width="500px"
|
|
:close-on-click-modal="false"
|
|
:close-on-click-modal="false"
|
|
class="question-dialog"
|
|
class="question-dialog"
|
|
|
|
+ @close="resetForm"
|
|
>
|
|
>
|
|
<div class="question-form">
|
|
<div class="question-form">
|
|
<div class="form-item">
|
|
<div class="form-item">
|
|
@@ -284,37 +285,51 @@ interface QuestionForm {
|
|
// 对话框显示状态
|
|
// 对话框显示状态
|
|
const showQuestionDialog = ref(false)
|
|
const showQuestionDialog = ref(false)
|
|
|
|
|
|
-// 监听 questionId 变化
|
|
|
|
-watch(() => props.questionId, async (newVal) => {
|
|
|
|
- if (newVal) {
|
|
|
|
- // 获取问题详情
|
|
|
|
- try {
|
|
|
|
- const response = await api.GetObj({question_id:newVal});
|
|
|
|
|
|
+// 监听对话框显示状态
|
|
|
|
+watch(() => showQuestionDialog.value, (newVal) => {
|
|
|
|
+ if (newVal && props.questionId) {
|
|
|
|
+ fetchQuestionDetail(props.questionId);
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+// 获取问题详情的函数
|
|
|
|
+const fetchQuestionDetail = async (id: string | number) => {
|
|
|
|
+ if (!id) return;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ const response = await api.GetObj({ question_id: id });
|
|
|
|
+
|
|
|
|
+ if (response?.code === 2000 && response.data) {
|
|
|
|
+ const questionData = response.data;
|
|
|
|
+ // 更新表单数据
|
|
|
|
+ questionForm.content = questionData.question || '';
|
|
|
|
+ questionForm.type = questionData.question_form === 1 ? 'single' :
|
|
|
|
+ questionData.question_form === 2 ? 'multiple' : 'open';
|
|
|
|
+ questionForm.position = questionData.positions || [];
|
|
|
|
+ questionForm.category = questionData.category_id || '';
|
|
|
|
+ questionForm.tags = questionData.tags || [];
|
|
|
|
+ questionForm.competency_tags = questionData.competency_tags || [];
|
|
|
|
+ questionForm.options = questionData.options || [];
|
|
|
|
+ questionForm.question_form = questionData.question_form;
|
|
|
|
+ questionForm.suggestedDuration = questionData.duration || 0;
|
|
|
|
+ questionForm.scoring_reference = questionData.scoring_reference || '';
|
|
|
|
|
|
- if (response && response.code === 2000 && response.data) {
|
|
|
|
- const questionData = response.data;
|
|
|
|
- // 更新表单数据
|
|
|
|
- questionForm.content = questionData.question || '';
|
|
|
|
- questionForm.type = questionData.question_form === 1 ? 'single' :
|
|
|
|
- questionData.question_form === 2 ? 'multiple' : 'open';
|
|
|
|
- questionForm.position = questionData.positions || [];
|
|
|
|
- questionForm.category = questionData.category_id || '';
|
|
|
|
- questionForm.tags = questionData.tags || [];
|
|
|
|
- questionForm.competency_tags = questionData.competency_tags || [];
|
|
|
|
- questionForm.options = questionData.options || [];
|
|
|
|
- questionForm.question_form = questionData.question_form;
|
|
|
|
- questionForm.suggestedDuration = questionData.duration || 0;
|
|
|
|
- questionForm.scoring_reference = questionData.scoring_reference || '';
|
|
|
|
-
|
|
|
|
- // 更新胜任力标签选择
|
|
|
|
- competencyTagsValue.value = questionData.competency_tags?.map((tag: any) => tag.id) || [];
|
|
|
|
- }
|
|
|
|
- } catch (error: any) {
|
|
|
|
- console.error('获取问题详情失败:', error);
|
|
|
|
- ElMessage.error(error.message || '获取问题详情失败');
|
|
|
|
|
|
+ // 更新胜任力标签选择
|
|
|
|
+ competencyTagsValue.value = questionData.competency_tags?.map((tag: any) => tag.id) || [];
|
|
|
|
+ } else {
|
|
|
|
+ ElMessage.warning('未找到问题详情数据');
|
|
}
|
|
}
|
|
|
|
+ } catch (error: any) {
|
|
|
|
+ console.error('获取问题详情失败:', error);
|
|
|
|
+ ElMessage.error(error.message || '获取问题详情失败');
|
|
}
|
|
}
|
|
-}, { immediate: false });
|
|
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// 监听 questionId 变化
|
|
|
|
+watch(() => props.questionId, (newVal) => {
|
|
|
|
+ console.log(newVal)
|
|
|
|
+ fetchQuestionDetail(newVal);
|
|
|
|
+}, { immediate: true });
|
|
|
|
|
|
// 加载初始数据
|
|
// 加载初始数据
|
|
onMounted(async () => {
|
|
onMounted(async () => {
|
|
@@ -449,7 +464,22 @@ const removeLastOption = () => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 重置表单数据
|
|
|
|
+const resetForm = () => {
|
|
|
|
+ questionForm.content = ''
|
|
|
|
+ questionForm.type = 'open'
|
|
|
|
+ questionForm.position = []
|
|
|
|
+ questionForm.category = ''
|
|
|
|
+ questionForm.tags = []
|
|
|
|
+ questionForm.competency_tags = []
|
|
|
|
+ questionForm.options = []
|
|
|
|
+ questionForm.suggestedDuration = 0
|
|
|
|
+ questionForm.scoring_reference = ''
|
|
|
|
+ competencyTagsValue.value = []
|
|
|
|
+}
|
|
|
|
+
|
|
const cancelAddQuestion = () => {
|
|
const cancelAddQuestion = () => {
|
|
|
|
+ resetForm()
|
|
showQuestionDialog.value = false
|
|
showQuestionDialog.value = false
|
|
}
|
|
}
|
|
|
|
|
|
@@ -539,6 +569,7 @@ defineExpose({
|
|
.config-row {
|
|
.config-row {
|
|
display: flex;
|
|
display: flex;
|
|
align-items: center;
|
|
align-items: center;
|
|
|
|
+ justify-content: space-between;
|
|
margin-bottom: 10px;
|
|
margin-bottom: 10px;
|
|
|
|
|
|
&:last-child {
|
|
&:last-child {
|
|
@@ -547,7 +578,7 @@ defineExpose({
|
|
}
|
|
}
|
|
|
|
|
|
.config-label {
|
|
.config-label {
|
|
- width: 80px;
|
|
|
|
|
|
+ width: 105px;
|
|
margin-right: 10px;
|
|
margin-right: 10px;
|
|
}
|
|
}
|
|
|
|
|