|
@@ -57,7 +57,7 @@
|
|
:max="100"
|
|
:max="100"
|
|
:step="1"
|
|
:step="1"
|
|
controls-position="right"
|
|
controls-position="right"
|
|
- @change="(value) => handleWeightChange(index, value)"
|
|
|
|
|
|
+ @change="(value: number) => handleWeightChange(index, value)"
|
|
/> %
|
|
/> %
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -123,7 +123,7 @@
|
|
style="display: flex; align-items: center; margin-bottom: 10px;"
|
|
style="display: flex; align-items: center; margin-bottom: 10px;"
|
|
>
|
|
>
|
|
<el-input
|
|
<el-input
|
|
- v-model="option.option_text"
|
|
|
|
|
|
+ v-model="option.text"
|
|
placeholder="请输入选项内容"
|
|
placeholder="请输入选项内容"
|
|
style="flex: 1; margin-right: 10px;"
|
|
style="flex: 1; margin-right: 10px;"
|
|
/>
|
|
/>
|
|
@@ -308,14 +308,15 @@ const fetchQuestionDetail = async (id: string | number) => {
|
|
questionForm.position = questionData.positions || [];
|
|
questionForm.position = questionData.positions || [];
|
|
questionForm.category = questionData.category_id || '';
|
|
questionForm.category = questionData.category_id || '';
|
|
questionForm.tags = questionData.tags || [];
|
|
questionForm.tags = questionData.tags || [];
|
|
- questionForm.competency_tags = questionData.competency_tags || [];
|
|
|
|
|
|
+ const competencyTags = questionData.competency_tags || [];
|
|
|
|
+ questionForm.competency_tags = competencyTags;
|
|
questionForm.options = questionData.options || [];
|
|
questionForm.options = questionData.options || [];
|
|
questionForm.question_form = questionData.question_form;
|
|
questionForm.question_form = questionData.question_form;
|
|
questionForm.suggestedDuration = questionData.duration || 0;
|
|
questionForm.suggestedDuration = questionData.duration || 0;
|
|
questionForm.scoring_reference = questionData.scoring_reference || '';
|
|
questionForm.scoring_reference = questionData.scoring_reference || '';
|
|
|
|
|
|
// 更新胜任力标签选择
|
|
// 更新胜任力标签选择
|
|
- competencyTagsValue.value = questionData.competency_tags?.map((tag: any) => tag.id) || [];
|
|
|
|
|
|
+ competencyTagsValue.value = competencyTags.map((tag: any) => tag.id);
|
|
} else {
|
|
} else {
|
|
ElMessage.warning('未找到问题详情数据');
|
|
ElMessage.warning('未找到问题详情数据');
|
|
}
|
|
}
|
|
@@ -331,6 +332,8 @@ watch(() => props.questionId, (newVal) => {
|
|
fetchQuestionDetail(newVal);
|
|
fetchQuestionDetail(newVal);
|
|
}, { immediate: true });
|
|
}, { immediate: true });
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
// 加载初始数据
|
|
// 加载初始数据
|
|
onMounted(async () => {
|
|
onMounted(async () => {
|
|
try {
|
|
try {
|
|
@@ -398,6 +401,31 @@ const questionForm = reactive<QuestionForm>({
|
|
const competencyTagsValue = ref<number[]>([])
|
|
const competencyTagsValue = ref<number[]>([])
|
|
const competencyTagOptions = ref<CompetencyTag[]>([])
|
|
const competencyTagOptions = ref<CompetencyTag[]>([])
|
|
|
|
|
|
|
|
+// 监听胜任力标签选择变化
|
|
|
|
+watch(() => competencyTagsValue.value, (newVal) => {
|
|
|
|
+ if (!newVal) return;
|
|
|
|
+
|
|
|
|
+ // 根据选中的ID更新competency_tags
|
|
|
|
+ questionForm.competency_tags = newVal.map(id => {
|
|
|
|
+ const tag = competencyTagOptions.value.find(t => t.id === id);
|
|
|
|
+ return {
|
|
|
|
+ id: tag?.id || 0,
|
|
|
|
+ name: tag?.name || '',
|
|
|
|
+ weight: tag?.weight || 0
|
|
|
|
+ };
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 如果有标签,自动平均分配权重
|
|
|
|
+ if (questionForm.competency_tags.length > 0) {
|
|
|
|
+ const averageWeight = Math.floor(100 / questionForm.competency_tags.length);
|
|
|
|
+ const remainder = 100 - (averageWeight * questionForm.competency_tags.length);
|
|
|
|
+
|
|
|
|
+ questionForm.competency_tags.forEach((tag, index) => {
|
|
|
|
+ tag.weight = averageWeight + (index === 0 ? remainder : 0);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
// 职位选项
|
|
// 职位选项
|
|
interface PositionOption {
|
|
interface PositionOption {
|
|
value: string
|
|
value: string
|
|
@@ -425,7 +453,38 @@ const getTotalWeight = () => {
|
|
}
|
|
}
|
|
|
|
|
|
const handleWeightChange = (index: number, value: number): void => {
|
|
const handleWeightChange = (index: number, value: number): void => {
|
|
- // 实现权重调整逻辑
|
|
|
|
|
|
+ const tags = questionForm.competency_tags;
|
|
|
|
+ if (!tags || tags.length <= 1) return;
|
|
|
|
+
|
|
|
|
+ const oldWeight = tags[index].weight;
|
|
|
|
+ const weightDiff = value - oldWeight;
|
|
|
|
+
|
|
|
|
+ // 如果权重差为0,不需要调整
|
|
|
|
+ if (weightDiff === 0) return;
|
|
|
|
+
|
|
|
|
+ // 计算其他标签的总权重
|
|
|
|
+ const otherTotalWeight = tags.reduce((sum, tag, i) => i !== index ? sum + tag.weight : sum, 0);
|
|
|
|
+
|
|
|
|
+ // 如果其他标签总权重为0,平均分配剩余权重
|
|
|
|
+ if (otherTotalWeight === 0) {
|
|
|
|
+ const remainingWeight = 100 - value;
|
|
|
|
+ const averageWeight = Math.floor(remainingWeight / (tags.length - 1));
|
|
|
|
+ const remainder = remainingWeight - (averageWeight * (tags.length - 1));
|
|
|
|
+
|
|
|
|
+ tags.forEach((tag, i) => {
|
|
|
|
+ if (i !== index) {
|
|
|
|
+ tag.weight = averageWeight + (i === 0 ? remainder : 0);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ // 按比例调整其他标签的权重
|
|
|
|
+ tags.forEach((tag, i) => {
|
|
|
|
+ if (i !== index) {
|
|
|
|
+ const proportion = tag.weight / otherTotalWeight;
|
|
|
|
+ tag.weight = Math.max(0, Math.round(tag.weight - (weightDiff * proportion)));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
const handleQuestionTypeChange = (value: string) => {
|
|
const handleQuestionTypeChange = (value: string) => {
|
|
@@ -494,12 +553,13 @@ const confirmAddQuestion = async () => {
|
|
positions: questionForm.position,
|
|
positions: questionForm.position,
|
|
category_id: questionForm.category,
|
|
category_id: questionForm.category,
|
|
tags: questionForm.tags,
|
|
tags: questionForm.tags,
|
|
- competency_tags: questionForm.competency_tags,
|
|
|
|
|
|
+ competency_tag_info: questionForm.competency_tags,
|
|
options: questionForm.options,
|
|
options: questionForm.options,
|
|
- duration: questionForm.suggestedDuration,
|
|
|
|
|
|
+ recommended_duration: questionForm.suggestedDuration,
|
|
scoring_reference: questionForm.scoring_reference
|
|
scoring_reference: questionForm.scoring_reference
|
|
};
|
|
};
|
|
-
|
|
|
|
|
|
+/* console.log(questionForm)
|
|
|
|
+return */
|
|
// 发送请求
|
|
// 发送请求
|
|
try {
|
|
try {
|
|
const response = await api.UpdateObj(requestData);
|
|
const response = await api.UpdateObj(requestData);
|