yangg 1 долоо хоног өмнө
parent
commit
916ad0fcf2

+ 8 - 0
src/views/position/detail/api.ts

@@ -165,6 +165,14 @@ export function GetPositionTags(obj: AddReq) {
 		params: {...obj,tenant_id:"1"},
 	});
 }
+/* 修改问题 */
+export function UpdateQuestion(obj: AddReq) {
+	return request({
+		url: '/api/system/interview_question/update',
+		method: 'put',
+		data: {...obj,tenant_id:1},
+	});
+}
 
 export function GetcategoryList(query: UserPageQuery) {
 	return request({

+ 156 - 64
src/views/position/detail/index.vue

@@ -287,10 +287,9 @@
               filterable
               placeholder="请选择能力标签"
               style="width: 100%"
-            
             >
               <el-option
-                v-for="tag in competencyTags"
+                v-for="tag in competencyTagOptions"
                 :key="tag.id"
                 :label="tag.name"
                 :value="tag.id"
@@ -1094,7 +1093,7 @@
         <div class="form-item">
           <div class="form-label">胜任力标签</div>
           <el-select
-            v-model="questionForm.competencyTags"
+            v-model="questionForm.competency_tags"
             placeholder="请选择胜任力标签"
             class="full-width"
             multiple
@@ -1102,9 +1101,9 @@
           >
             <el-option 
               v-for="tag in competencyTagOptions" 
-              :key="tag.value"
-              :label="tag.label"
-              :value="tag.value"
+              :key="tag.id"
+              :label="tag.name"
+              :value="tag.id"
             />
           </el-select>
           <div class="form-tip">选择胜任力标签和胜任力标签,可多选</div>
@@ -1120,10 +1119,10 @@
               <span class="config-label">权重</span>
               <span class="config-label">级别</span>
             </div>
-            <div class="config-row">
-              <span class="tag-name">时间管理</span>
-              <el-input-number v-model="questionForm.weight" :min="0" :max="100" :step="1" controls-position="right" /> %
-              <el-input-number v-model="questionForm.level" :min="1" :max="5" :step="1" controls-position="right" />
+            <div class="config-row" v-for="tag in questionForm.competency_tags" :key="tag.id">
+              <span class="tag-name">{{ tag.name }}</span>
+              <el-input-number v-model="tag.weight" :min="0" :max="100" :step="1" controls-position="right" /> %
+              <el-input-number v-model="tag.importance" :min="1" :max="5" :step="1" controls-position="right" />
             </div>
           </div>
           <div class="form-tip">配置各个胜任力标签的权重,总和需要100%</div>
@@ -1163,6 +1162,89 @@
           </el-select>
           <div class="form-tip">选择题目适用的职位类型,可多选</div>
         </div>
+        <div class="form-item" v-if="questionForm.question_form === 1 || questionForm.question_form === 2">
+          <div class="form-label">选项</div>
+          <div>
+            <div class="option-header" style="display: flex; margin-bottom: 10px; font-weight: bold;">
+              <span style="flex: 1;">选项内容</span>
+              <span style="width: 80px; text-align: center;">是否正确</span>
+            </div>
+            <div 
+              v-for="(option, index) in questionForm.options" 
+              :key="index" 
+              class="option-item" 
+              style="display: flex; align-items: center; margin-bottom: 10px;"
+            >
+              <el-input 
+                v-model="option.text" 
+                placeholder="请输入选项内容" 
+                style="flex: 1; margin-right: 10px;"
+              />
+              <el-tooltip 
+                content="设置为正确答案" 
+                placement="top" 
+                effect="light"
+              >
+                <div 
+                  @click="() => {
+                    if (questionForm.question_form === 1) {
+                      // 单选题:只能有一个正确答案
+                      questionForm.options.forEach((item, idx) => {
+                        item.is_correct = (idx === index);
+                      });
+                    } else {
+                      // 多选题:可以有多个正确答案
+                      option.is_correct = !option.is_correct;
+                    }
+                  }"
+                  style="cursor: pointer; width: 80px; text-align: center;"
+                >
+                  <template v-if="questionForm.question_form === 1">
+                    <!-- 单选题使用单选按钮 -->
+                    <el-radio 
+                      v-model="option.is_correct"
+                      :label="true"
+                    />
+                  </template>
+                  <template v-else>
+                    <!-- 多选题使用复选框 -->
+                    <el-checkbox 
+                      v-model="option.is_correct"
+                    />
+                  </template>
+                </div>
+              </el-tooltip>
+            </div>
+            <div style="display: flex; justify-content: space-between; margin-top: 10px;">
+              <el-button 
+                type="primary" 
+                @click="() => {
+                  // 确保options数组已初始化
+                  if (!questionForm.options) {
+                    questionForm.options = [];
+                  }
+                  // 添加新选项时自动设置排序值
+                  const sort = questionForm.options.length > 0 ? 
+                    Math.max(...questionForm.options.map(o => o.sort || 0)) + 1 : 1;
+                  questionForm.options.push({ option_text: '', is_correct: false, sort });
+                }"
+              >
+                添加选项
+              </el-button>
+              
+              <el-button 
+                v-if="questionForm.options && questionForm.options.length > 2"
+                type="danger" 
+                @click="() => {
+                  questionForm.options.pop();
+                }"
+              >
+                删除最后一项
+              </el-button>
+            </div>
+          </div>
+          <div class="form-tip">添加选项并设置正确答案,单选题只能有一个正确答案,多选题可以有多个正确答案</div>
+        </div>
 
         <div class="form-item">
           <div class="form-label">分类</div>
@@ -1213,7 +1295,8 @@
         </div>
         <div class="form-item">
           <div class="form-label">评价标准</div>
-          <el-input v-model="questionForm.scoring_reference" placeholder="请输入评价标准" class="full-width" />
+          <el-input v-model="questionForm.scoring_reference"  type="textarea"
+          rows="4" placeholder="请输入评价标准" class="full-width" />
           <div class="form-tip">评价标准,用于评价应聘者的表现</div>
         </div>
       </div>
@@ -1870,7 +1953,8 @@ import { GetList } from '../../questionBank/classList/api';
 import { GetCompetencyList,GetQuestionList,GenerateQuestions,
   GetDraftList,SaveDraft,GetDigitalList,
   CreateConfig,GetConfig,UpdateConfig,AddDocument,
-  GetOpeningSpeech,GetVideo,BatchBind,BatchUnbind,UpdateObj,GenerateCompetency,SaveCompetency,GetPositionTags } from './api';
+  GetOpeningSpeech,GetVideo,BatchBind,BatchUnbind,UpdateObj,GenerateCompetency,SaveCompetency,GetPositionTags,
+  UpdateQuestion } from './api';
 import draggable from 'vuedraggable';
 import { updateFieldConfig } from './utils';
 import type { ProfileFieldsConfig } from './types';
@@ -1906,6 +1990,7 @@ interface ChatQuestion {
   scoring_reference?: string;
   competency_tags?: CompetencyTag[];
   enable_follow_up?: boolean;
+  options?: any[];
 }
 
 // 添加 Paper 接口定义
@@ -1950,6 +2035,7 @@ const positionData = reactive({
   work_experience_required: '',
   education_required: '',
   competency_tags: [],
+  options: [],
   status: 0
 });
 
@@ -2168,11 +2254,14 @@ const maxQuestions = ref(5); // 默认5个问题
 // 在 script setup 部分添加以下响应式变量
 const showQuestionDialog = ref(false); // 控制添加问题弹框显示
 const questionForm = reactive({
+  id: '',
   content: '', // 题目内容
-  competencyTags: [], // 胜任力标签
+  competency_tags: [], // 胜任力标签
   weight: 100, // 权重占比,默认100%
   level: 1, // 胜任力级别,默认1级
   type: 'open', // 题目形式:开放问题/单选题/多选题/填空题/自言语
+  question_form: 0, // 题目类型:0-开放问题,1-单选题,2-多选题
+  options: [], // 选项列表
   position: [], // 适用职位
   category: '', // 分类
   tags: [], // 标签
@@ -2181,13 +2270,7 @@ const questionForm = reactive({
 });
 
 // 胜任力标签选项
-const competencyTagOptions = ref([
-  { label: '时间管理', value: 'time_management' },
-  { label: '沟通能力', value: 'communication' },
-  { label: '团队协作', value: 'teamwork' },
-  { label: '问题解决', value: 'problem_solving' },
-  { label: '抗压能力', value: 'pressure_resistance' }
-]);
+const competencyTagOptions = ref<CompetencyTag[]>([]);
 
 // 职位类型选项
 const positionOptions = ref([
@@ -2219,15 +2302,19 @@ const tagOptions = ref([
 // 重置问题表单
 const resetQuestionForm = () => {
   Object.assign(questionForm, {
+    id: '',
     content: '',
-    competencyTags: [],
+    competency_tags: [],
     weight: 100,
     level: 1,
     type: 'open',
+    question_form: 0,
+    options: [],
     position: [],
     category: '',
     tags: [],
-    suggestedDuration: 60
+    suggestedDuration: 60,
+    scoring_reference: ''
   });
 };
 
@@ -2237,7 +2324,7 @@ const cancelAddQuestion = () => {
   resetQuestionForm();
 };
 
-// 确认添加问题
+// 确认修改问题
 const confirmAddQuestion = async () => {
   // 表单验证
   if (!questionForm.content) {
@@ -2250,44 +2337,31 @@ const confirmAddQuestion = async () => {
     return;
   }
 
-  // 验证其他必填项
-  if (!questionForm.type) {
-    ElMessage.error('请选择题目形式');
-    return;
-  }
-
-  if (questionForm.position.length === 0) {
-    ElMessage.error('请选择适用职位');
-    return;
-  }
-
-  if (!questionForm.category) {
-    ElMessage.error('请选择题目分类');
-    return;
-  }
-
-  if (questionForm.suggestedDuration <= 0) {
-    ElMessage.error('请设置有效的建议时长');
-    return;
-  }
-
   try {
     // 创建新的问题对象
     const newQuestion = {
+      id: questionForm.id,
       content: questionForm.content,
-      competencyTags: questionForm.competencyTags,
+      competency_tags: questionForm.competency_tags,
+      options: questionForm.options,
       weight: questionForm.weight,
       level: questionForm.level,
-      type: questionForm.type,
+      question_form: questionForm.question_form,
       position: questionForm.position,
       category: questionForm.category,
-      tags: questionForm.tags,
-      suggestedDuration: questionForm.suggestedDuration
+      suggestedDuration: questionForm.suggestedDuration,
+      scoring_reference: questionForm.scoring_reference,
     };
+    console.log(newQuestion);
 
     // TODO: 调用API保存问题
-    // const response = await api.saveQuestion(newQuestion);
-
+ /*     const response = await UpdateQuestion(newQuestion);
+     console.log(response);
+    if(response.code === 200){
+      ElMessage.success('问题修改成功');
+    }else{
+      ElMessage.error('问题修改失败');
+    } */
     // 关闭弹窗
     showQuestionDialog.value = false;
     
@@ -2295,7 +2369,7 @@ const confirmAddQuestion = async () => {
     resetQuestionForm();
     
     // 提示成功
-    ElMessage.success('问题添加成功');
+   /*  ElMessage.success('问题修改成功'); */
     
     // 刷新问题列表
     // await loadQuestions();
@@ -2415,9 +2489,11 @@ const getPositionDetail = async () => {
     const response = await api.GetObj(id); // 使用 infoReq 而不是 id
     if (response && response.data) {
       Object.assign(positionData, response.data);
+      competencyTagOptions.value=response.data.competency_tags
       const config = await GetConfig(id);
       if (config && config.data) {
         getConfigId.value=config.data.id;
+        
         // 根据配置状态初始化得分题和色盲题开关
         if (config.data.enable_psychological_test !== undefined) {
           questionSettings.enableScoreQuestions = config.data.enable_psychological_test;
@@ -3018,6 +3094,7 @@ const handleImportQuestion = () => {
 const editQuestion = (index: number) => {
   // 编辑问题的逻辑
   const question = chatQuestions.value[index];
+  console.log(question);
   Object.assign(questionForm, question);
   showQuestionDialog.value = true;
 };
@@ -3645,9 +3722,9 @@ const getCompetencyList = async () => {
   try {
     const response = await GetCompetencyList({page:1,pageSize:1000});
     if (response && response.data) {
-      // 为每个标签添加选中状态属性
-     /*  competencyTags.value = response.data.items.map((item:any) => ({
-        ...item,
+    /*   competencyTagOptions.value = response.data.items.map((item: any) => ({
+        id: item.id,
+        name: item.name,
         selected: false
       })); */
     }
@@ -3658,8 +3735,18 @@ const getCompetencyList = async () => {
 };
 
 // 开始编辑能力标签
-const startEditCompetency = () => {
-  selectedCompetencies.value = positionData.competency_tags?.map((tag:any) => tag.id) || [];
+const startEditCompetency = async () => {
+  // 先获取所有可用的胜任力标签
+  await getCompetencyList();
+  
+  // 设置已选中的标签
+  selectedCompetencies.value = positionData.competency_tags?.map((tag: any) => tag.id) || [];
+  
+  // 标记已选中的标签
+  competencyTagOptions.value.forEach(tag => {
+    tag.selected = selectedCompetencies.value.includes(tag.id);
+  });
+  
   isEditingCompetency.value = true;
 };
 
@@ -3678,9 +3765,13 @@ const saveCompetency = async () => {
     });
     
     // 更新本地数据
-    positionData.competency_tags = competencyTags.value.filter(tag => 
-      selectedCompetencies.value.includes(tag.id)
-    );
+    positionData.competency_tags = competencyTagOptions.value
+      .filter(tag => selectedCompetencies.value.includes(tag.id))
+      .map(tag => ({
+        id: tag.id,
+        name: tag.name
+      }));
+      
     isEditingCompetency.value = false;
     ElMessage.success('能力标签已更新');
   } catch (error) {
@@ -4416,7 +4507,10 @@ console.log(selectedQuestions.value);
     is_required_correct: question.is_required_correct,
     weight: 100, // 默认权重
     maxAnswers: 1, // 默认最多回答次数
+    enable_follow_up:true,
+    options: question.options || [],
     source: 'custom_selected' as const // 标识为自定义选择的题目
+
   }));
   
   chatQuestions.value.push(...formattedQuestions);
@@ -4911,6 +5005,8 @@ const handleAutoGenerate = async () => {
           is_required_correct: question.is_required_correct,
           weight: 100,
           maxAnswers: 1,
+          enable_follow_up:true,
+          options: question.options || [],
           source: 'ai_generated' as const // 标识为AI生成的题目
         }));
         
@@ -4941,7 +5037,7 @@ const handleCompetencyTagsChange = (value: string[]) => {
 
 // 验证胜任力配置
 const validateCompetencyConfig = () => {
-  if (questionForm.competencyTags.length === 0) {
+  if (questionForm.competency_tags.length === 0) {
     ElMessage.warning('请至少选择一个胜任力标签');
     return false;
   }
@@ -4951,10 +5047,6 @@ const validateCompetencyConfig = () => {
     return false;
   }
   
-  if (questionForm.level < 1 || questionForm.level > 5) {
-    ElMessage.warning('级别必须在1-5之间');
-    return false;
-  }
   
   return true;
 };