123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596 |
- import { CreateCrudOptionsProps, CreateCrudOptionsRet, AddReq, DelReq, EditReq, dict, compute } from '@fast-crud/fast-crud';
- import * as api from './api';
- import { dictionary } from '/@/utils/dictionary';
- import { successMessage, warningMessage } from '../../../utils/message';
- import { auth } from '/@/utils/authFunction';
- import { ref, onMounted, watch } from 'vue';
- import { ElMessage } from 'element-plus';
- // 在文件顶部添加全局接口声明
- declare global {
- interface Window {
- competencyTagsOptions?: any[];
- }
- }
- /**
- *
- * @param crudExpose:index传递过来的示例
- * @param context:index传递过来的自定义参数
- * @returns
- */
- export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
- const pageRequest = async (query: any) => {
- // 如果存在 question 搜索值,将其赋值给 keyword
- console.log('query', query);
- if (query.question) {
- query.keyword = query.question;
- delete query.question_tag;
- delete query.question; // 删除原有的 question 参数
- }
- const params = {
- ...query,
- question_category: query.category||query.question_category,
- /* question_tag: query.tag, */
- tenant_id: 1
- }
- console.log('params', params);
- return await api.GetList(params);
- };
- const editRequest = async ({ form, row }: EditReq) => {
- form.id = row.id;
-
- // 处理胜任力标签配置
- if (form.competency_tags && form.competency_tags.length > 0 && form.competency_tags_config) {
- form.competency_tags = form.competency_tags_config.map((config: any) => ({
- id: config.id,
- weight: config.weight || 100,
- importance: config.importance || 1,
- remark: config.remark || ''
- }));
- } else {
- form.competency_tags_config = [];
- }
-
- // 调用更新题目的接口
- const editResult = await api.UpdateObj(form);
-
- // 如果更新成功且题目形式为0(开放题)或5,异步触发视频生成
- if (editResult.code === 2000 && (form.question_form === 0 || form.question_form === 5)) {
- // 使用 setTimeout 将视频生成请求放入下一个事件循环
- /* setTimeout(async () => {
- try {
- // 构造视频生成请求参数
- const videoParams = {
- video_url: "http://data.qicai321.com/minlong/32ae7e1f-042f-4ee5-b234-be34d98d70e6.mp4",
- text: form.question,
- question_id: form.id,
- guidance_scale: 2.0,
- inference_steps: 20,
- seed: 1247
- };
- // 调用视频生成接口
- const videoResult = await fetch(`${import.meta.env.VITE_API_URL_MINLONG}/queue/process/text/`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(videoParams)
- });
- if (!videoResult.ok) {
- console.warn('数字人视频生成请求失败:', await videoResult.text());
- ElMessage({
- type: 'warning',
- message: '数字人视频生成请求失败,但不影响题目的更新'
- });
- } else {
- ElMessage({
- type: 'success',
- message: '题目已更新,数字人视频正在重新生成中,请稍后查看'
- });
- }
- } catch (error) {
- console.error('调用数字人视频生成接口失败:', error);
- ElMessage({
- type: 'warning',
- message: '数字人视频生成失败,但题目已成功更新'
- });
- }
- }, 0); */
- }
- return editResult;
- };
- const delRequest = async ({ row }: DelReq) => {
- return await api.DelObj(row.id);
- };
- const addRequest = async ({ form }: AddReq) => {
- // 处理胜任力标签配置
- if (form.competency_tags && form.competency_tags.length > 0 && form.competency_tags_config) {
- form.competency_tags = form.competency_tags_config.map((config: any) => ({
- id: config.id,
- weight: config.weight || 100,
- importance: config.importance || 1,
- remark: config.remark || ''
- }));
- } else {
- form.competency_tags_config = [];
- }
-
- // 根据题目类型调用不同的接口
- let addResult;
- if (form.question_form === 6) { // 填空题
- addResult = await api.AddFillQuestion(form);
- } else {
- addResult = await api.AddObj(form);
- }
-
- // 如果添加成功且题目形式为0(开放题)或5,异步触发视频生成
- if (addResult.code === 2000 && (form.question_form === 0 || form.question_form === 5)) {
- // 使用 setTimeout 将视频生成请求放入下一个事件循环
- /* setTimeout(async () => {
- try {
- // 构造视频生成请求参数
- const videoParams = {
- video_url: "http://data.qicai321.com/minlong/32ae7e1f-042f-4ee5-b234-be34d98d70e6.mp4",
- text: form.question,
- question_id: addResult.data.id,
- guidance_scale: 2.0,
- inference_steps: 20,
- seed: 1247
- };
- // 调用视频生成接口http://192.168.66.101:7861
- const videoResult = await fetch(`${import.meta.env.VITE_API_URL_MINLONG}/queue/process/text/`, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(videoParams)
- });
- if (!videoResult.ok) {
- console.warn('数字人视频生成请求失败:', await videoResult.text());
- ElMessage({
- type: 'warning',
- message: '数字人视频生成请求失败,但不影响题目的保存'
- });
- } else {
- ElMessage({
- type: 'success',
- message: '题目已保存,数字人视频正在生成中,请稍后查看'
- });
- }
- } catch (error) {
- console.error('调用数字人视频生成接口失败:', error);
- ElMessage({
- type: 'warning',
- message: '数字人视频生成失败,但题目已成功保存'
- });
- }
- }, 0); */
- }
- return addResult;
- };
- /* // 修改分类和标签数据获取方式
- const categoryOptions = ref<Array<{value: number, label: string}>>([]);
- const tagOptions = ref<Array<{value: number, label: string}>>([]);
-
- // 获取分类数据
- const fetchCategories = async () => {
- try {
- const res = await api.GetcategoryList({page:1, limit:1000, tenant_id:1});
- if (res.code === 0 && res.data && res.data.items) {
- categoryOptions.value = res.data.items;
- }
- } catch (error) {
- console.error('获取分类数据失败', error);
- }
- };
-
- // 获取标签数据
- const fetchTags = async (categoryId?: number) => {
- try {
- const params = {
- page: 1,
- limit: 1000,
- tenant_id: 1
- };
- if (categoryId) {
- params.category_id = categoryId;
- }
- const res = await api.GetTagList(params);
- if (res.code === 0 && res.data && res.data.items) {
- tagOptions.value = res.data.items;
- }
- } catch (error) {
- console.error('获取标签数据失败', error);
- }
- }; */
-
- // 初始化时获取分类数据
- /* onMounted(() => {
- fetchCategories();
- fetchTags();
- }); */
- // 添加批量更新标签的方法
- const batchUpdateTags = async (questionIds: number[], tagIds: number[]) => {
- try {
- const res = await api.BatchUpdateTags({
- question_ids: questionIds,
- tags: tagIds,
- tenant_id: 1
- });
- if (res.code === 0) {
- successMessage('批量更新标签成功');
- // 刷新列表
- crudExpose.doRefresh();
- }
- } catch (error) {
- console.error('批量更新标签失败', error);
- }
- };
- // 添加批量更新分类的方法
- const batchUpdateCategory = async (questionIds: number[], categoryId: number) => {
- try {
- const res = await api.BatchUpdateCategory({
- question_ids: questionIds,
- category_id: categoryId,
- tenant_id: "1"
- });
- if (res.code === 0) {
- successMessage('批量更新分类成功');
- // 刷新列表
- crudExpose.doRefresh();
- }
- } catch (error) {
- console.error('批量更新分类失败', error);
- }
- };
- return {
- crudOptions: {
- toolbar:{
- buttons:{
- search:{show:false},
- // 刷新按钮
- refresh:{show:false},
- // 紧凑模式
- compact:{show:false},
- // 导出按钮
- export:{
- text: '导出',
- type: 'primary',
- size: 'small',
- icon: 'upload',
- circle: false,
- display: true,
- show:false
- },
- // 列设置按钮
- columns:{
- show:false
- },
- }
- },
- request: {
- pageRequest,
- addRequest,
- editRequest,
- delRequest,
- },
- pagination: {
- show: true,
- },
- // 添加搜索表单配置
- search: {
- col: { span: 3 },
- show: true,
- autoSearch:false,
- buttons: {
- search: {
- size: 'small', // 设置查询按钮大小为small
- },
- reset: {
- size: 'small', // 设置重置按钮大小为small
- }
- }
- },
- actionbar: {
- buttons: {
- add: {
- size: 'small',
- show: auth('role:Create'),
- },
- // 添加批量绑定标签按钮
- batchBindTags: {
- text: '批量绑定标签',
- type: 'primary',
- size: 'small',
- show: true,
- order: 2,
- click: () => {
- // 使用存储的选中行
- const selection = context.selectedRows || [];
- console.log('选中的行:', selection);
-
- if (!selection || selection.length === 0) {
- warningMessage('请先选择要操作的题目');
- return;
- }
- // 打开批量绑定标签对话框
- context.openBatchTagsDialog(selection);
- },
- },
- // 添加批量设置分类按钮
- batchSetCategory: {
- text: '批量设置分类',
- type: 'primary',
- show: true,
- size: 'small',
- order: 3,
- click: () => {
- // 使用存储的选中行
- const selection = context.selectedRows || [];
- console.log('选中的行:', selection);
-
- if (!selection || selection.length === 0) {
- warningMessage('请先选择要操作的题目');
- return;
- }
- // 打开批量设置分类对话框
- context.openBatchCategoryDialog(selection);
- },
- },
- batchBindCompetencyTags: {
- text: '批量绑定胜任力标签',
- type: 'primary',
- size: 'small',
- show: true,
- order: 4,
- click: () => {
- const selection = context.selectedRows || [];
-
- if (!selection || selection.length === 0) {
- warningMessage('请先选择要操作的题目');
- return;
- }
- // 打开批量绑定胜任力标签对话框
- context.openBatchCompetencyTagsDialog(selection);
- },
- },
- },
- },
- rowHandle: {
- //固定右侧
- fixed: 'right',
- width: 259,
- buttons: {
- view: {
- show: true,
- size: 'small',
- icon:"View",
- type: 'text',
- },
- edit: {
- show: auth('role:Update'),
- size: 'small',
- icon:"Edit",
- type: 'text',
- },
- remove: {
- show: auth('role:Delete'),
- size: 'small',
- type: 'text',
- icon:"Delete",
- },
- // 添加生成数字人视频按钮
- /* generateVideo: {
- text: '生成视频',
- type: 'text',
- size: 'small',
- show: ({ row }) => {
- // 只在题目形式为开放题(0)或追加型开放题(5)时显示
- return row.question_form === 0 || row.question_form === 5;
- },
- click: async ({ row }) => {
- try {
- // 构造视频生成请求参数
- const videoParams = {
- video_url: "http://data.qicai321.com/minlong/32ae7e1f-042f-4ee5-b234-be34d98d70e6.mp4",
- text: row.question,
- question_id: row.id,
- guidance_scale: 2.0,
- inference_steps: 20,
- seed: 1247
- };
- // 调用视频生成接口
- const videoResult = await fetch('http://192.168.66.101:7861/queue/process/text/', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(videoParams)
- });
- if (!videoResult.ok) {
- console.warn('数字人视频生成请求失败:', await videoResult.text());
- ElMessage({
- type: 'error',
- message: '视频生成请求失败'
- });
- } else {
- ElMessage({
- type: 'info',
- message: '数字人视频正在生成中...'
- });
- }
- } catch (error) {
- console.error('调用数字人视频生成接口失败:', error);
- ElMessage({
- type: 'error',
- message: '视频生成请求失败'
- });
- }
- }
- } */
- },
- },
- form: {
- col: { span: 24 },
- labelWidth: '100px',
- wrapper: {
- is: 'el-dialog',
- width: '600px',
- },
- },
- columns: {
- _selection: {
- title: '选择',
- form: { show: false },
- column: {
- type: 'selection',
- align: 'center',
- width: 50,
- fixed: 'left',
- columnSetDisabled: true,
- },
- },
- id: {
- title: 'ID',
- column: { show: true ,width:80,},
- search: { show: false },
- form: { show: false },
- },
- question: {
- title: '题目内容',
- search: {
- show: true,
- size: 'small',
- col: { span: 3 },
- component: {
- name: 'el-input',
- props: {
- placeholder: '请输入题目内容搜索',
- clearable: true
- }
- }
- },
- column: {
- showOverflowTooltip: true,
- width: 300,
- sortable: 'custom',
- },
- form: {
- rules: [{ required: true, message: '题目内容必填' }],
- component: {
- placeholder: '请输入题目内容',
- },
- },
- },
- competency_tags:{
- title: '胜任力标签',
- search: {
- show: true,
- size: 'small',
- component: {
- props: {
- multiple: false,
- filterable: true,
- }
- },
- col:{ span:3 },
- },
- type: 'dict-select',
- column: {
- minWidth: 230,
- component: {
- name: 'fs-component',
- render: ({ row }: { row: any }) => {
- if (!row.competency_tags || row.competency_tags.length === 0) return <span>-</span>;
-
- const displayTags = row.competency_tags.slice(0, 2);
- const remainingCount = row.competency_tags.length - 2;
-
- return (
- <div style="display: flex; gap: 4px; align-items: center;">
- {displayTags.map((tag: any) => (
- <el-tag
- key={tag.id}
- type="warning"
- effect="plain"
- size="mini"
- style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"
- title={tag.name}
- >
- {tag.name.length > 4 ? tag.name.slice(0, 4) + '...' : tag.name}
- </el-tag>
- ))}
- {remainingCount > 0 && (
- <el-tooltip
- placement="top"
- effect="light"
- popper-class="tag-tooltip"
- >
- {{
- default: () => (
- <el-tag
- type="info"
- effect="plain"
- size="mini"
- >
- +{remainingCount}
- </el-tag>
- ),
- content: () => (
- <div>
- <div style="font-weight: bold; margin-bottom: 5px">剩余{remainingCount}个标签:</div>
- {row.competency_tags.slice(2).map((tag: any) => (
- <div key={tag.id} style="margin: 3px 0">{tag.name}</div>
- ))}
- </div>
- )
- }}
- </el-tooltip>
- )}
- </div>
- );
- }
- }
- },
- dict: dict({
- getData: async () => {
- const res = await api.GetCompetencyList({page:1, limit:100, tenant_id:1});
- window.competencyTagsOptions = res.data.items || [];
- return res.data.items;
- },
- label: 'name',
- value: 'id'
- }),
- form: {
- component: {
- props: {
- multiple: true,
- filterable: true,
- placeholder: '请选择胜任力标签'
- },
- value: compute(({ form }) => {
- if (!form.competency_tags) return [];
- console.log('form.competency_tags', form.competency_tags);
- // 如果是数组但元素是对象,提取id
- if (Array.isArray(form.competency_tags)) {
- const ids = form.competency_tags.map((tag: any) => {
- if (typeof tag === 'object' && tag !== null) {
- // 同时更新 competency_tags_config
- if (!form.competency_tags_config) {
- form.competency_tags_config = [];
- form.competency_tags = [];
- }
-
- // 检查配置是否已存在
- const existingConfig = form.competency_tags_config.find(
- (config: any) => config.id === tag.id
- );
-
- if (!existingConfig) {
- form.competency_tags_config.push({
- id: tag.id,
- competency_name: tag.name,
- weight: tag.weight || 100,
- importance: tag.importance || 1,
- remark: ''
- });
-
- form.competency_tags.push(tag.id);
- }
-
- return tag.id;
- }
- return tag;
- });
- return ids;
- }
-
- return form.competency_tags;
- }),
- onValueChange: ({ value, form }: { value: any[], form: any }) => {
- // 保存选中的ID数组
- form.competency_tags = value;
-
- // 同步更新competency_tags_config
- if (!form.competency_tags_config) {
- form.competency_tags_config = [];
- }
-
- // 获取当前已有的配置ID
- const existingConfigIds = form.competency_tags_config.map((config: any) => config.id);
-
- // 从全局变量获取胜任力标签选项数据
- const competencyOptions = window.competencyTagsOptions || [];
-
- // 添加新选择的标签配置
- value.forEach((tagId: number) => {
- if (!existingConfigIds.includes(tagId)) {
- // 查找标签信息
- const tagInfo = competencyOptions.find((tag: any) => tag.id === tagId);
- if (tagInfo) {
- form.competency_tags_config.push({
- id: tagId,
- competency_name: tagInfo.name,
- weight: tagInfo.weight || 100,
- importance: tagInfo.importance || 1,
- remark: ''
- });
- }
- }
- });
-
- // 移除已不存在的标签配置
- form.competency_tags_config = form.competency_tags_config.filter(
- (config: any) => value.includes(config.id)
- );
- }
- },
- helper: '选择题目关联的胜任力标签,可多选'
- }
- },
- competency_tags_config: {
- title: '胜任力配置',
- search: { show: false },
- column: { show: false },
- form: {
- show: compute(({ form }) => {
- // 只有当选择了胜任力标签时才显示配置
- return form && form.competency_tags && form.competency_tags.length > 0;
- }),
- component: {
- name: 'el-card',
- children: {
- default: ({ form }: { form: any }) => {
- // 确保competency_tags_config数组已初始化
- if (!form.competency_tags_config) {
- form.competency_tags_config = [];
- }
-
- // 使用ref标记是否已经处理过,避免重复处理
- const processed = ref(false);
-
- // 使用onMounted确保只在组件挂载时执行一次
- onMounted(() => {
- if (!processed.value && form.competency_tags && form.competency_tags.length > 0) {
- updateCompetencyConfig();
- processed.value = true;
- }
- });
-
- // 监听competency_tags变化,但避免无限循环
- watch(() => [...(form.competency_tags || [])], (newTags, oldTags) => {
- // 只有当标签真正变化时才更新配置
- if (JSON.stringify(newTags) !== JSON.stringify(oldTags)) {
- updateCompetencyConfig();
- }
- });
-
- // 抽取更新配置的逻辑到单独的函数
- const updateCompetencyConfig = () => {
- // 获取当前已有的配置ID
- const existingConfigIds = form.competency_tags_config.map((config: any) => config.id);
-
- // 创建新的配置数组
- const newConfigs = [...form.competency_tags_config];
-
- // 从全局变量获取胜任力标签选项数据
- const competencyOptions = window.competencyTagsOptions || [];
-
- // 添加新选择的标签配置
- form.competency_tags.forEach((tagId: number) => {
- if (!existingConfigIds.includes(tagId)) {
- // 查找标签名称
- const tagName = competencyOptions.find((tag: any) => tag.id === tagId)?.name || '未知标签';
-
- // 添加新配置
- newConfigs.push({
- id: tagId,
- competency_name: tagName,
- weight: 100, // 默认权重为100%
- importance: 1, // 默认重要性为1
- remark: '' // 默认备注为空
- });
- }
- });
-
- // 移除已不存在的标签配置
- const filteredConfigs = newConfigs.filter(
- (config: any) => form.competency_tags.includes(config.id)
- );
-
- // 一次性更新配置数组
- form.competency_tags_config = filteredConfigs;
- };
-
- // 渲染表格
- return (
- <div>
- <el-table border style="width: 100%" data={form.competency_tags_config}>
- <el-table-column label="标签" width="200">
- {{
- default: ({ row }: { row: any }) => (
- <span>{row.competency_name}</span>
- )
- }}
- </el-table-column>
- <el-table-column label="权重" width="100">
- {{
- default: ({ row }: { row: any }) => (
- <div class="weight-input" style="display: flex; align-items: center;">
- <el-input-number
- v-model={row.weight}
- min={0}
- max={100}
- step={1}
- precision={0}
- controls={false}
- style="width: calc(100% - 20px)"
- />
- <span style="margin-left: 4px;">%</span>
- </div>
- )
- }}
- </el-table-column>
- <el-table-column label="级别" width="100">
- {{
- default: ({ row }: { row: any }) => (
- <el-input-number
- v-model={row.importance}
- min={1}
- controls={false}
- style="width: 100%"
- />
- )
- }}
- </el-table-column>
- {/* <el-table-column label="备注">
- {{
- default: ({ row }: { row: any }) => (
- <el-input
- v-model={row.remark}
- placeholder="请输入备注"
- />
- )
- }}
- </el-table-column> */}
- </el-table>
- </div>
- );
- }
- }
- },
- helper: '配置每个胜任力标签的权重、重要性和备注'
- }
- },
-
- /* question_type: {
- title: '问题类型',
- search: { show: true },
- type: 'dict-select',
- column: {
- minWidth: 100,
- },
- dict: dict({
- data: [
- { value: 1, label: '专业技能' },
- { value: 2, label: '通用能力' },
- { value: 3, label: '个人特质' }
- ]
- }),
- form: {
- rules: [{ required: true, message: '问题类型必填' }],
- component: {
- placeholder: '请选择问题类型',
- },
- helper: '选择问题的类型分类',
- },
- }, */
- question_form: {
- title: '题目形式',
- search: { show: true,
- size: 'small',
- col:{ span:3},
- },
- type: 'dict-select',
- column: {
- minWidth: 120,
- },
- dict: dict({
- // 使用API方式获取数据
- getData: async () => {
- const res = await api.GetQuestionTypeList();
- // 返回question_forms数组
- return res.data.question_forms || [];
- },
- label: 'label',
- value: 'value'
- }),
- form: {
- rules: [{ required: true, message: '题目形式必填' }],
- component: {
- placeholder: '请选择题目形式',
- onChange: ({ form }: { form: any }) => {
- // 重置相关字段
- if (form.question_form === 1) {
- // 单选题
- form.options = [{ option_text: '', is_correct: false, sort: 1 }, { option_text: '', is_correct: false, sort: 2 }];
- } else if (form.question_form === 2) {
- // 多选题
- form.options = [{ option_text: '', is_correct: false, sort: 1 }, { option_text: '', is_correct: false, sort: 2 }];
- } else if (form.question_form === 4) {
- // 得分题 - 初始化五个评分选项
- form.options = [
- { option_text: '无', score: 0, sort: 1 },
- { option_text: '轻度', score: 1, sort: 2 },
- { option_text: '中度', score: 2, sort: 3 },
- { option_text: '偏重', score: 3, sort: 4 },
- { option_text: '严重', score: 4, sort: 5 }
- ];
- // 初始化评分说明
- if (!form.scoring_reference) {
- form.scoring_reference = '该评分反映了症状表现的频率与严重程度。';
- }
- } else if (form.question_form === 6) {
- // 填空题
- form.blank_answer_template = [
- { blank_index: 1, correct_answer: '', score: 5 }
- ];
- // 初始化评分说明
- if (!form.scoring_reference) {
- form.scoring_reference = '根据答案的准确性评分';
- }
- } else {
- // 开放问题
- form.options = [];
- }
- }
- },
- helper: '选择题目的形式:开放问题、单选题、多选题、填空题、色盲题或追加型开放问题',
- },
- },
- position_types: {
- title: '适用职位',
- search: { show: true,
- size: 'small',
- col:{ span:3}, },
- type: 'dict-select',
- column: {
- minWidth: 120,
- maxTagCount: 1
- },
- dict: dict({
- getData: async () => {
- const res = await api.GetPositionList({page:1,limit:50,tenant_id:1});
- console.log(res.data);
- return res.data || [];
- },
- label: 'title',
- value: 'id'
- }),
- form: {
- component: {
- /* name: 'el-select', */
- props: {
- multiple: true,
- filterable: true,
- placeholder: '请选择适用职位类型',
- /* options: [
- { value: '0', label: '技术' },
- { value: '1', label: '管理' },
- ] */
- }
- },
- helper: '选择题目适用的职位类型,可多选'
- }
- },
- category_id: {
- title: '分类',
- search: { show: true,
- size: 'small',
- col:{ span:2}, },
- type: 'dict-select',
- column: {
- minWidth: 120,
- component: {
- // 自定义渲染组件,显示彩色标签
- // name: 'fs-component',
- render: ({ row }: { row: any }) => {
- if (!row.category || row.category.length === 0) return <span>-</span>;
-
- return (
- <el-tag
- key={row.category.id}
- type="warning"
- effect="plain"
- size="mini"
- style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"
- >
- {row.category.name.length > 4 ? row.category.name.slice(0, 4) + '...' : row.category.name}
- </el-tag>
- );
- }
- }
- },
- dict: dict({
- // 使用API方式获取数据
- getData: async () => {
- const res = await api.GetcategoryList({page:1, limit:50, tenant_id:1});
- return res.data.items;
- },
- label: 'name',
- value: 'id'
- }),
- form: {
- // rules: [{ required: true, message: '题目分类必填' }],
- component: {
- placeholder: '请选择题目分类',
- /* onChange: ({ value }: { value: number }) => {
- // 当分类变化时,重新获取对应的标签
- fetchTags(value);
- } */
- },
- helper: '选择所属的分类'
- },
- },
- question_tags:{
- title: '标签',
- search: {
- show: true,
- size: 'small',
- col:{ span:3 },
- component: {
- props: {
- multiple: false, // 在搜索表单中使用单选模式
- filterable: true,
- placeholder: '请选择标签搜索'
- }
- }
- },
- type: 'dict-select',
- column: {
- show: false,
- minWidth: 220,
- },
- dict: dict({
- // 使用API方式获取数据
- getData: async () => {
- const res = await api.GetTagList({page:1, limit:50, tenant_id:1});
- return res.data.items;
- },
- label: 'name',
- value: 'id'
- }),
- form: {
- component: {
- props: {
- multiple: true, // 在编辑表单中保持多选
- filterable: true,
- placeholder: '请选择标签'
- }
- },
- helper: '选择题目关联的标签,可多选'
- }
- },
- tags:{
- title: '标签',
- search: {
- show: false,
- size: 'small',
- col:{ span:3},
- component: {
- props: {
- multiple: false, // 在搜索表单中使用单选模式
- filterable: true,
- placeholder: '请选择标签搜索'
- }
- }
- },
- type: 'dict-select',
- column: {
- minWidth: 220,
- component: {
- name: 'fs-component',
- render: ({ row }: { row: any }) => {
- if (!row.tags || row.tags.length === 0) return <span>-</span>;
-
- const displayTags = row.tags.slice(0, 2); // 只取前两个标签
- const remainingCount = row.tags.length - 2; // 计算剩余标签数量
-
- return (
- <div style="display: flex; gap: 4px; align-items: center;">
- {displayTags.map((tag: any) => (
- <el-tag
- key={tag.id}
- type="warning"
- effect="plain"
- size="mini"
- style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"
- title={tag.name}
- >
- {tag.name.length > 4 ? tag.name.slice(0, 4) + '...' : tag.name}
- </el-tag>
- ))}
- {remainingCount > 0 && (
- <el-tooltip
- placement="top"
- effect="light"
- popper-class="tag-tooltip"
- >
- {{
- default: () => (
- <el-tag
- type="info"
- effect="plain"
- size="mini"
- >
- +{remainingCount}
- </el-tag>
- ),
- content: () => (
- <div>
- <div style="font-weight: bold; margin-bottom: 5px">剩余{remainingCount}个标签:</div>
- {row.tags.slice(2).map((tag: any) => (
- <div key={tag.id} style="margin: 3px 0">{tag.name}</div>
- ))}
- </div>
- )
- }}
- </el-tooltip>
- )}
- </div>
- );
- }
- }
- },
- dict: dict({
- // 使用API方式获取数据
- getData: async () => {
- const res = await api.GetTagList({page:1, limit:50, tenant_id:1});
- return res.data.items;
- },
- label: 'name',
- value: 'id'
- }),
- form: {
- component: {
- props: {
- multiple: true, // 在编辑表单中保持多选
- filterable: true,
- placeholder: '请选择标签'
- }
- },
- helper: '选择题目关联的标签,可多选'
- }
- },
- recommended_duration: {
- title: '建议时长(秒)',
- search: { show: false },
- column: {
- minWidth: 100,
- },
- form: {
- value: 60,
- component: {
- name: 'el-input-number',
- props: {
- min: 10,
- max: 600,
- step: 10
- }
- },
- helper: '建议回答此题目的时长,单位为秒'
- }
- },
- /* difficulty: {
- title: '难度等级',
- search: { show: true },
- type: 'dict-select',
- column: {
- minWidth: 80,
- },
- dict: dict({
- data: [
- { value: 1, label: '初级' },
- { value: 2, label: '中级' },
- { value: 3, label: '高级' }
- ]
- }),
- form: {
- rules: [{ required: true, message: '难度等级必填' }],
- helper: '选择题目的难度级别'
- },
- }, */
- is_system: {
- title: '系统题目',
- search: { show: false },
- type: 'dict-select',
- column: {
- width: 100,
- /* component: {
- name: 'fs-component',
- render: ({ row }: { row: any }) => {
- return row.is_system ?
- <el-tag type="success" size="small">是</el-tag> :
- <el-tag type="info" size="small">否</el-tag>;
- }
- } */
- },
- dict: dict({
- data: [
- { value: true, label: '是' },
- { value: false, label: '否' }
- ]
- }),
- form: {
- value: false,
- component: {
- placeholder: '请选择是否为系统题目'
- },
- helper: '是否为系统预设题目'
- }
- },
- status: {
- title: '状态',
- search: { show: true,
- size: 'small',
- col:{ span:2},},
- type: 'dict-select',
- column: {
- width: 80,
- },
- dict: dict({
- data: [
- { value: 0, label: '停用' },
- { value: 1, label: '启用' }
- ]
- }),
- form: {
- value: 1,
- rules: [{ required: true, message: '状态必填' }],
- component: {
- placeholder: '请选择状态',
- },
- helper: '题目的启用状态'
- },
- },
- // 添加红线问题字段
- is_required_correct: {
- title: '红线问题',
- search: { show: false,
- size: 'small',
- col:{ span:2}, },
- type: 'dict-select',
- column: {
- width: 100,
- component: {
- name: 'fs-component',
- render: ({ row }: { row: any }) => {
- // 只有单选题和多选题才显示红线问题状态
- if (row.question_form !== 1 && row.question_form !== 2) {
- return <span>-</span>;
- }
- return row.is_required_correct ?
- <el-tag type="danger" size="small">是</el-tag> :
- <el-tag type="info" size="small">否</el-tag>;
- }
- }
- },
- dict: dict({
- data: [
- { value: true, label: '是' },
- { value: false, label: '否' }
- ]
- }),
- form: {
- value: false,
- show: compute(({ form }) => {
- // 只有单选题和多选题才显示红线问题选项
- return form && (form.question_form === 1 || form.question_form === 2);
- }),
- component: {
- placeholder: '请选择是否为红线问题'
- },
- helper: '红线问题是指必须回答正确的题目,否则可能导致面试失败'
- }
- },
- sort: {
- title: '排序',
- search: { show: false },
- column: {
- width: 80,
- },
- form: {
- component: {
- name: 'el-input-number',
- props: {
- min: 1,
- max: 999
- }
- },
- helper: '题目的排序值,值越小排序越靠前'
- }
- },
- option_items: {
- title: '选项列表',
- search: { show: false },
- column: { show: false },
- form: {
- show: compute(({ form }) => {
- return form && (form.question_form === 1 || form.question_form === 2 || form.question_form === 4);
- }),
- component: {
- name: 'el-card',
- children: {
- default: ({ form }: { form: any }) => {
- // 确保options数组已初始化
- if (!form.options) {
- form.options = [];
- }
-
- // 心理评估题的选项渲染
- if (form.question_form === 4) {
- return (
- <div>
- <div class="option-header" style="display: flex; margin-bottom: 10px; font-weight: bold;">
- <span style="flex: 1;">选项内容</span>
- <span style="width: 120px; text-align: center;">分值</span>
- </div>
- {form.options.map((option: any, index: number) => (
- <div class="option-item" key={index} style="display: flex; align-items: center; margin-bottom: 10px;">
- <el-input
- v-model={option.option_text}
- placeholder="请输入选项内容"
- style="flex: 1; margin-right: 10px;"
- />
- <el-input-number
- v-model={option.score}
- min={0}
- max={10}
- style="width: 120px;"
- placeholder="分值"
- />
- </div>
- ))}
- <div style="display: flex; justify-content: space-between; margin-top: 10px;">
- <el-button
- type="primary"
- onClick={() => {
- if (!form.options) {
- form.options = [];
- }
- const sort = form.options.length > 0 ?
- Math.max(...form.options.map((o: any) => o.sort || 0)) + 1 : 1;
- form.options.push({ option_text: '', score: 0, sort });
- }}
- >
- 添加选项
- </el-button>
-
- {form.options.length > 2 && (
- <el-button
- type="danger"
- onClick={() => {
- form.options.pop();
- }}
- >
- 删除最后一项
- </el-button>
- )}
- </div>
- </div>
- );
- }
-
- // 单选题和多选题的选项渲染(原有逻辑)
- return (
- <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>
- {form.options.map((option: any, index: number) => (
- <div class="option-item" key={index} style="display: flex; align-items: center; margin-bottom: 10px;">
- <el-input
- v-model={option.option_text}
- placeholder="请输入选项内容"
- style="flex: 1; margin-right: 10px;"
- />
- <el-tooltip
- content="设置为正确答案"
- placement="top"
- effect="light"
- >
- <div
- onClick={() => {
- if (form.question_form === 1) {
- // 单选题:只能有一个正确答案
- form.options.forEach((item: any, idx: number) => {
- item.is_correct = (idx === index);
- });
- } else {
- // 多选题:可以有多个正确答案
- option.is_correct = !option.is_correct;
- }
- }}
- style="cursor: pointer; width: 80px; text-align: center;"
- >
- {form.question_form === 1 ? (
- // 单选题使用单选按钮
- <el-radio
- modelValue={option.is_correct}
- label={true}
- />
- ) : (
- // 多选题使用复选框
- <el-checkbox
- modelValue={option.is_correct}
- />
- )}
- </div>
- </el-tooltip>
- </div>
- ))}
- <div style="display: flex; justify-content: space-between; margin-top: 10px;">
- <el-button
- type="primary"
- onClick={() => {
- // 确保options数组已初始化
- if (!form.options) {
- form.options = [];
- }
- // 添加新选项时自动设置排序值
- const sort = form.options.length > 0 ?
- Math.max(...form.options.map((o: any) => o.sort || 0)) + 1 : 1;
- form.options.push({ option_text: '', is_correct: false, sort });
- }}
- >
- 添加选项
- </el-button>
-
- {form.options.length > 2 && (
- <el-button
- type="danger"
- onClick={() => {
- form.options.pop();
- }}
- >
- 删除最后一项
- </el-button>
- )}
- </div>
- </div>
- )
- }
- }
- },
- helper: compute(({ form }) => {
- if (form.question_form === 1) {
- return '添加单选题的选项,并标记正确答案(只能有一个正确答案)';
- } else if (form.question_form === 2) {
- return '添加多选题的选项,并标记正确答案(可以有多个正确答案)';
- } else if (form.question_form === 4) {
- return '添加心理评估题的选项,并设置每个选项的分值';
- }
- return '';
- })
- }
- },
- scoring_reference: {
- title: '评分标准',
- search: { show: false },
- column: { show: false },
- form: {
- component: {
- name: 'el-input',
- type: 'textarea',
- rows: 4,
- placeholder: compute(({ form }) => {
- if (form && form.question_form === 4) {
- return '请输入评分标准说明';
- }
- return '请输入评分标准说明';
- })
- },
- helper: compute(({ form }) => {
- if (form && form.question_form === 4) {
- return '评分标准说明,例如:【团队协作能力】1.优秀:xxxxxx。2.xxxx。3.一般:xxxxx。';
- }
- return '评分标准说明,例如:【团队协作能力】1.优秀:xxxxxx。2.xxxx。3.一般:xxxxx。';
- })
- },
- },
- digital_human_video_url:{
- title: '视频是否生成',
- search: { show: false },
- column: {
- width: 120,
- component: {
- name: 'fs-component',
- render: ({ row }: { row: any }) => {
- return row.digital_human_video_url ?
- <el-tag type="success" size="small">是</el-tag> :
- <el-tag type="info" size="small">否</el-tag>;
- }
- }
- },
- form: {
- show: false // 在表单中不显示此字段,通常由系统自动生成
- }
- },
- blank_answer_template: {
- title: '填空答案模板',
- search: { show: false },
- column: { show: false },
- form: {
- show: compute(({ form }) => {
- return form && form.question_form === 6;
- }),
- component: {
- name: 'el-card',
- children: {
- default: ({ form }: { form: any }) => {
- // 确保blank_answer_template数组已初始化
- if (!form.blank_answer_template) {
- form.blank_answer_template = [{ blank_index: 1, correct_answer: '', score: 5 }];
- }
- // 计算题目中的填空数量
- const blankCount = (form.question || '').split('___').length - 1;
- // 如果填空数量变化,更新模板
- if (blankCount > 0 && form.blank_answer_template.length !== blankCount) {
- form.blank_answer_template = Array.from({ length: blankCount }, (_, i) => ({
- blank_index: i + 1,
- correct_answer: '',
- score: 5
- }));
- }
- return (
- <div>
- <div class="blank-header" style="display: flex; margin-bottom: 10px; font-weight: bold;">
- <span style="width: 80px;">填空序号</span>
- <span style="flex: 1;">正确答案</span>
- <span style="width: 120px; text-align: center;">分值</span>
- </div>
- {form.blank_answer_template.map((blank: any, index: number) => (
- <div class="blank-item" key={index} style="display: flex; align-items: center; margin-bottom: 10px;">
- <span style="width: 80px;">{blank.blank_index}</span>
- <el-input
- v-model={blank.correct_answer}
- placeholder="请输入正确答案"
- style="flex: 1; margin: 0 10px;"
- />
- <el-input-number
- v-model={blank.score}
- min={0}
- max={100}
- style="width: 120px;"
- placeholder="分值"
- />
- </div>
- ))}
- <div style="color: #666; font-size: 12px; margin-top: 10px;">
- 提示:在题目中使用"___"(三个下划线)表示填空位置,系统会自动识别填空数量
- </div>
- </div>
- );
- }
- }
- },
- helper: '设置每个填空的正确答案和分值'
- }
- }
-
- },
- // 确保表格配置正确
- table: {
- selection: true,
- onSelectionChange: (selection: any[]) => {
- // 存储选中的行到一个全局变量中
- context.selectedRows = selection;
- },
- },
- },
- };
- };
- // 导出批量更新标签方法,供组件使用
- export const useBatchUpdateTags = (crudExpose: any) => {
- const batchUpdateTags = async (questionIds: number[], tagIds: number[]) => {
- try {
- const res = await api.BatchUpdateTags({
- question_ids: questionIds,
- tags: tagIds,
- tenant_id: 1
- });
- if (res.code === 0) {
- successMessage('批量更新标签成功');
- // 刷新列表
- crudExpose.doRefresh();
- }
- } catch (error) {
- console.error('批量更新标签失败', error);
- }
- };
-
- return { batchUpdateTags };
- };
- // 导出批量更新分类方法,供组件使用
- export const useBatchUpdateCategory = (crudExpose: any) => {
- const batchUpdateCategory = async (questionIds: number[], categoryId: number) => {
- try {
- const res = await api.BatchUpdateCategory({
- question_ids: questionIds,
- category_id: categoryId,
- tenant_id: "1"
- });
- if (res.code === 0) {
- successMessage('批量更新分类成功');
- // 刷新列表
- crudExpose.doRefresh();
- }
- } catch (error) {
- console.error('批量更新分类失败', error);
- }
- };
-
- return { batchUpdateCategory };
- };
- // 导出批量更新胜任力标签方法,供组件使用
- export const useBatchUpdateCompetencyTags = (crudExpose: any) => {
- const batchUpdateCompetencyTags = async (questionIds: number[], competencyTags: any[]) => {
- try {
- const res = await api.BatchUpdateCompetencyTags({
- question_ids: questionIds,
- competency_tags: competencyTags,
- tenant_id: 1
- });
- if (res.code === 0) {
- successMessage('批量更新胜任力标签成功');
- // 刷新列表
- crudExpose.doRefresh();
- }
- } catch (error) {
- console.error('批量更新胜任力标签失败', error);
- }
- };
-
- return { batchUpdateCompetencyTags };
- };
|