crud.tsx 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544
  1. import { CreateCrudOptionsProps, CreateCrudOptionsRet, AddReq, DelReq, EditReq, dict, compute } from '@fast-crud/fast-crud';
  2. import * as api from './api';
  3. import { dictionary } from '/@/utils/dictionary';
  4. import { successMessage, warningMessage } from '../../../utils/message';
  5. import { auth } from '/@/utils/authFunction';
  6. import { ref, onMounted, watch } from 'vue';
  7. import { ElMessage } from 'element-plus';
  8. // 在文件顶部添加全局接口声明
  9. declare global {
  10. interface Window {
  11. competencyTagsOptions?: any[];
  12. }
  13. }
  14. /**
  15. *
  16. * @param crudExpose:index传递过来的示例
  17. * @param context:index传递过来的自定义参数
  18. * @returns
  19. */
  20. export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  21. const pageRequest = async (query: any) => {
  22. // 如果存在 question 搜索值,将其赋值给 keyword
  23. if (query.question) {
  24. query.keyword = query.question;
  25. delete query.question; // 删除原有的 question 参数
  26. }
  27. return await api.GetList(query);
  28. };
  29. const editRequest = async ({ form, row }: EditReq) => {
  30. form.id = row.id;
  31. // 处理胜任力标签配置
  32. if (form.competency_tags && form.competency_tags.length > 0 && form.competency_tags_config) {
  33. form.competency_tags = form.competency_tags_config.map((config: any) => ({
  34. id: config.id,
  35. weight: config.weight || 100,
  36. importance: config.importance || 1,
  37. remark: config.remark || ''
  38. }));
  39. } else {
  40. form.competency_tags_config = [];
  41. }
  42. // 调用更新题目的接口
  43. const editResult = await api.UpdateObj(form);
  44. // 如果更新成功且题目形式为0(开放题)或5,异步触发视频生成
  45. if (editResult.code === 2000 && (form.question_form === 0 || form.question_form === 5)) {
  46. // 使用 setTimeout 将视频生成请求放入下一个事件循环
  47. setTimeout(async () => {
  48. try {
  49. // 构造视频生成请求参数
  50. const videoParams = {
  51. video_url: "http://data.qicai321.com/minlong/32ae7e1f-042f-4ee5-b234-be34d98d70e6.mp4",
  52. text: form.question,
  53. question_id: form.id,
  54. guidance_scale: 2.0,
  55. inference_steps: 20,
  56. seed: 1247
  57. };
  58. // 调用视频生成接口
  59. const videoResult = await fetch(`${import.meta.env.VITE_API_URL_MINLONG}/queue/process/text/`, {
  60. method: 'POST',
  61. headers: {
  62. 'Content-Type': 'application/json'
  63. },
  64. body: JSON.stringify(videoParams)
  65. });
  66. if (!videoResult.ok) {
  67. console.warn('数字人视频生成请求失败:', await videoResult.text());
  68. ElMessage({
  69. type: 'warning',
  70. message: '数字人视频生成请求失败,但不影响题目的更新'
  71. });
  72. } else {
  73. ElMessage({
  74. type: 'success',
  75. message: '题目已更新,数字人视频正在重新生成中,请稍后查看'
  76. });
  77. }
  78. } catch (error) {
  79. console.error('调用数字人视频生成接口失败:', error);
  80. ElMessage({
  81. type: 'warning',
  82. message: '数字人视频生成失败,但题目已成功更新'
  83. });
  84. }
  85. }, 0);
  86. }
  87. return editResult;
  88. };
  89. const delRequest = async ({ row }: DelReq) => {
  90. return await api.DelObj(row.id);
  91. };
  92. const addRequest = async ({ form }: AddReq) => {
  93. // 处理胜任力标签配置
  94. if (form.competency_tags && form.competency_tags.length > 0 && form.competency_tags_config) {
  95. form.competency_tags = form.competency_tags_config.map((config: any) => ({
  96. id: config.id,
  97. weight: config.weight || 100,
  98. importance: config.importance || 1,
  99. remark: config.remark || ''
  100. }));
  101. } else {
  102. form.competency_tags_config = [];
  103. }
  104. // 根据题目类型调用不同的接口
  105. let addResult;
  106. if (form.question_form === 6) { // 填空题
  107. addResult = await api.AddFillQuestion(form);
  108. } else {
  109. addResult = await api.AddObj(form);
  110. }
  111. // 如果添加成功且题目形式为0(开放题)或5,异步触发视频生成
  112. if (addResult.code === 2000 && (form.question_form === 0 || form.question_form === 5)) {
  113. // 使用 setTimeout 将视频生成请求放入下一个事件循环
  114. setTimeout(async () => {
  115. try {
  116. // 构造视频生成请求参数
  117. const videoParams = {
  118. video_url: "http://data.qicai321.com/minlong/32ae7e1f-042f-4ee5-b234-be34d98d70e6.mp4",
  119. text: form.question,
  120. question_id: addResult.data.id,
  121. guidance_scale: 2.0,
  122. inference_steps: 20,
  123. seed: 1247
  124. };
  125. // 调用视频生成接口http://192.168.66.101:7861
  126. const videoResult = await fetch(`${import.meta.env.VITE_API_URL_MINLONG}/queue/process/text/`, {
  127. method: 'POST',
  128. headers: {
  129. 'Content-Type': 'application/json'
  130. },
  131. body: JSON.stringify(videoParams)
  132. });
  133. if (!videoResult.ok) {
  134. console.warn('数字人视频生成请求失败:', await videoResult.text());
  135. ElMessage({
  136. type: 'warning',
  137. message: '数字人视频生成请求失败,但不影响题目的保存'
  138. });
  139. } else {
  140. ElMessage({
  141. type: 'success',
  142. message: '题目已保存,数字人视频正在生成中,请稍后查看'
  143. });
  144. }
  145. } catch (error) {
  146. console.error('调用数字人视频生成接口失败:', error);
  147. ElMessage({
  148. type: 'warning',
  149. message: '数字人视频生成失败,但题目已成功保存'
  150. });
  151. }
  152. }, 0);
  153. }
  154. return addResult;
  155. };
  156. /* // 修改分类和标签数据获取方式
  157. const categoryOptions = ref<Array<{value: number, label: string}>>([]);
  158. const tagOptions = ref<Array<{value: number, label: string}>>([]);
  159. // 获取分类数据
  160. const fetchCategories = async () => {
  161. try {
  162. const res = await api.GetcategoryList({page:1, limit:1000, tenant_id:1});
  163. if (res.code === 0 && res.data && res.data.items) {
  164. categoryOptions.value = res.data.items;
  165. }
  166. } catch (error) {
  167. console.error('获取分类数据失败', error);
  168. }
  169. };
  170. // 获取标签数据
  171. const fetchTags = async (categoryId?: number) => {
  172. try {
  173. const params = {
  174. page: 1,
  175. limit: 1000,
  176. tenant_id: 1
  177. };
  178. if (categoryId) {
  179. params.category_id = categoryId;
  180. }
  181. const res = await api.GetTagList(params);
  182. if (res.code === 0 && res.data && res.data.items) {
  183. tagOptions.value = res.data.items;
  184. }
  185. } catch (error) {
  186. console.error('获取标签数据失败', error);
  187. }
  188. }; */
  189. // 初始化时获取分类数据
  190. /* onMounted(() => {
  191. fetchCategories();
  192. fetchTags();
  193. }); */
  194. // 添加批量更新标签的方法
  195. const batchUpdateTags = async (questionIds: number[], tagIds: number[]) => {
  196. try {
  197. const res = await api.BatchUpdateTags({
  198. question_ids: questionIds,
  199. tags: tagIds,
  200. tenant_id: 1
  201. });
  202. if (res.code === 0) {
  203. successMessage('批量更新标签成功');
  204. // 刷新列表
  205. crudExpose.doRefresh();
  206. }
  207. } catch (error) {
  208. console.error('批量更新标签失败', error);
  209. }
  210. };
  211. // 添加批量更新分类的方法
  212. const batchUpdateCategory = async (questionIds: number[], categoryId: number) => {
  213. try {
  214. const res = await api.BatchUpdateCategory({
  215. question_ids: questionIds,
  216. category_id: categoryId,
  217. tenant_id: "1"
  218. });
  219. if (res.code === 0) {
  220. successMessage('批量更新分类成功');
  221. // 刷新列表
  222. crudExpose.doRefresh();
  223. }
  224. } catch (error) {
  225. console.error('批量更新分类失败', error);
  226. }
  227. };
  228. return {
  229. crudOptions: {
  230. toolbar:{
  231. buttons:{
  232. search:{show:false},
  233. // 刷新按钮
  234. refresh:{show:false},
  235. // 紧凑模式
  236. compact:{show:false},
  237. // 导出按钮
  238. export:{
  239. text: '导出',
  240. type: 'primary',
  241. size: 'small',
  242. icon: 'upload',
  243. circle: false,
  244. display: true
  245. },
  246. // 列设置按钮
  247. columns:{
  248. show:false
  249. },
  250. }
  251. },
  252. request: {
  253. pageRequest,
  254. addRequest,
  255. editRequest,
  256. delRequest,
  257. },
  258. pagination: {
  259. show: true,
  260. },
  261. // 添加搜索表单配置
  262. search: {
  263. show: true,
  264. buttons: {
  265. search: {
  266. size: 'small', // 设置查询按钮大小为small
  267. },
  268. reset: {
  269. size: 'small', // 设置重置按钮大小为small
  270. }
  271. }
  272. },
  273. actionbar: {
  274. buttons: {
  275. add: {
  276. size: 'small',
  277. show: auth('role:Create'),
  278. },
  279. // 添加批量绑定标签按钮
  280. batchBindTags: {
  281. text: '批量绑定标签',
  282. type: 'primary',
  283. size: 'small',
  284. show: true,
  285. order: 2,
  286. click: () => {
  287. // 使用存储的选中行
  288. const selection = context.selectedRows || [];
  289. console.log('选中的行:', selection);
  290. if (!selection || selection.length === 0) {
  291. warningMessage('请先选择要操作的题目');
  292. return;
  293. }
  294. // 打开批量绑定标签对话框
  295. context.openBatchTagsDialog(selection);
  296. },
  297. },
  298. // 添加批量设置分类按钮
  299. batchSetCategory: {
  300. text: '批量设置分类',
  301. type: 'primary',
  302. show: true,
  303. size: 'small',
  304. order: 3,
  305. click: () => {
  306. // 使用存储的选中行
  307. const selection = context.selectedRows || [];
  308. console.log('选中的行:', selection);
  309. if (!selection || selection.length === 0) {
  310. warningMessage('请先选择要操作的题目');
  311. return;
  312. }
  313. // 打开批量设置分类对话框
  314. context.openBatchCategoryDialog(selection);
  315. },
  316. },
  317. batchBindCompetencyTags: {
  318. text: '批量绑定胜任力标签',
  319. type: 'primary',
  320. size: 'small',
  321. show: true,
  322. order: 4,
  323. click: () => {
  324. const selection = context.selectedRows || [];
  325. if (!selection || selection.length === 0) {
  326. warningMessage('请先选择要操作的题目');
  327. return;
  328. }
  329. // 打开批量绑定胜任力标签对话框
  330. context.openBatchCompetencyTagsDialog(selection);
  331. },
  332. },
  333. },
  334. },
  335. rowHandle: {
  336. //固定右侧
  337. fixed: 'right',
  338. width: 259,
  339. buttons: {
  340. view: {
  341. show: true,
  342. size: 'small',
  343. icon:"View",
  344. type: 'text',
  345. },
  346. edit: {
  347. show: auth('role:Update'),
  348. size: 'small',
  349. icon:"Edit",
  350. type: 'text',
  351. },
  352. remove: {
  353. show: auth('role:Delete'),
  354. size: 'small',
  355. type: 'text',
  356. icon:"Delete",
  357. },
  358. // 添加生成数字人视频按钮
  359. /* generateVideo: {
  360. text: '生成视频',
  361. type: 'text',
  362. size: 'small',
  363. show: ({ row }) => {
  364. // 只在题目形式为开放题(0)或追加型开放题(5)时显示
  365. return row.question_form === 0 || row.question_form === 5;
  366. },
  367. click: async ({ row }) => {
  368. try {
  369. // 构造视频生成请求参数
  370. const videoParams = {
  371. video_url: "http://data.qicai321.com/minlong/32ae7e1f-042f-4ee5-b234-be34d98d70e6.mp4",
  372. text: row.question,
  373. question_id: row.id,
  374. guidance_scale: 2.0,
  375. inference_steps: 20,
  376. seed: 1247
  377. };
  378. // 调用视频生成接口
  379. const videoResult = await fetch('http://192.168.66.101:7861/queue/process/text/', {
  380. method: 'POST',
  381. headers: {
  382. 'Content-Type': 'application/json'
  383. },
  384. body: JSON.stringify(videoParams)
  385. });
  386. if (!videoResult.ok) {
  387. console.warn('数字人视频生成请求失败:', await videoResult.text());
  388. ElMessage({
  389. type: 'error',
  390. message: '视频生成请求失败'
  391. });
  392. } else {
  393. ElMessage({
  394. type: 'info',
  395. message: '数字人视频正在生成中...'
  396. });
  397. }
  398. } catch (error) {
  399. console.error('调用数字人视频生成接口失败:', error);
  400. ElMessage({
  401. type: 'error',
  402. message: '视频生成请求失败'
  403. });
  404. }
  405. }
  406. } */
  407. },
  408. },
  409. form: {
  410. col: { span: 24 },
  411. labelWidth: '100px',
  412. wrapper: {
  413. is: 'el-dialog',
  414. width: '600px',
  415. },
  416. },
  417. columns: {
  418. _selection: {
  419. title: '选择',
  420. form: { show: false },
  421. column: {
  422. type: 'selection',
  423. align: 'center',
  424. width: 50,
  425. fixed: 'left',
  426. columnSetDisabled: true,
  427. },
  428. },
  429. id: {
  430. title: 'ID',
  431. column: { show: true ,width:80,},
  432. search: { show: false },
  433. form: { show: false },
  434. },
  435. question: {
  436. title: '题目内容',
  437. search: {
  438. show: true,
  439. size: 'small',
  440. col: { span: 3 },
  441. component: {
  442. name: 'el-input',
  443. props: {
  444. placeholder: '请输入题目内容搜索',
  445. clearable: true
  446. }
  447. }
  448. },
  449. column: {
  450. showOverflowTooltip: true,
  451. width: 300,
  452. sortable: 'custom',
  453. },
  454. form: {
  455. rules: [{ required: true, message: '题目内容必填' }],
  456. component: {
  457. placeholder: '请输入题目内容',
  458. },
  459. },
  460. },
  461. competency_tags:{
  462. title: '胜任力标签',
  463. search: {
  464. show: true,
  465. size: 'small',
  466. component: {
  467. props: {
  468. multiple: false,
  469. filterable: true,
  470. }
  471. },
  472. col:{ span:3 },
  473. },
  474. type: 'dict-select',
  475. column: {
  476. minWidth: 230,
  477. component: {
  478. name: 'fs-component',
  479. render: ({ row }: { row: any }) => {
  480. if (!row.competency_tags || row.competency_tags.length === 0) return <span>-</span>;
  481. const displayTags = row.competency_tags.slice(0, 2);
  482. const remainingCount = row.competency_tags.length - 2;
  483. return (
  484. <div style="display: flex; gap: 4px; align-items: center;">
  485. {displayTags.map((tag: any) => (
  486. <el-tag
  487. key={tag.id}
  488. type="warning"
  489. effect="plain"
  490. size="mini"
  491. style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"
  492. title={tag.name}
  493. >
  494. {tag.name.length > 4 ? tag.name.slice(0, 4) + '...' : tag.name}
  495. </el-tag>
  496. ))}
  497. {remainingCount > 0 && (
  498. <el-tooltip
  499. placement="top"
  500. effect="light"
  501. popper-class="tag-tooltip"
  502. >
  503. {{
  504. default: () => (
  505. <el-tag
  506. type="info"
  507. effect="plain"
  508. size="mini"
  509. >
  510. +{remainingCount}
  511. </el-tag>
  512. ),
  513. content: () => (
  514. <div>
  515. <div style="font-weight: bold; margin-bottom: 5px">剩余{remainingCount}个标签:</div>
  516. {row.competency_tags.slice(2).map((tag: any) => (
  517. <div key={tag.id} style="margin: 3px 0">{tag.name}</div>
  518. ))}
  519. </div>
  520. )
  521. }}
  522. </el-tooltip>
  523. )}
  524. </div>
  525. );
  526. }
  527. }
  528. },
  529. dict: dict({
  530. getData: async () => {
  531. const res = await api.GetCompetencyList({page:1, limit:100, tenant_id:1});
  532. window.competencyTagsOptions = res.data.items || [];
  533. return res.data.items;
  534. },
  535. label: 'name',
  536. value: 'id'
  537. }),
  538. form: {
  539. component: {
  540. props: {
  541. multiple: true,
  542. filterable: true,
  543. placeholder: '请选择胜任力标签'
  544. },
  545. value: compute(({ form }) => {
  546. if (!form.competency_tags) return [];
  547. console.log('form.competency_tags', form.competency_tags);
  548. // 如果是数组但元素是对象,提取id
  549. if (Array.isArray(form.competency_tags)) {
  550. const ids = form.competency_tags.map((tag: any) => {
  551. if (typeof tag === 'object' && tag !== null) {
  552. // 同时更新 competency_tags_config
  553. if (!form.competency_tags_config) {
  554. form.competency_tags_config = [];
  555. form.competency_tags = [];
  556. }
  557. // 检查配置是否已存在
  558. const existingConfig = form.competency_tags_config.find(
  559. (config: any) => config.id === tag.id
  560. );
  561. if (!existingConfig) {
  562. form.competency_tags_config.push({
  563. id: tag.id,
  564. competency_name: tag.name,
  565. weight: tag.weight || 100,
  566. importance: tag.importance || 1,
  567. remark: ''
  568. });
  569. form.competency_tags.push(tag.id);
  570. }
  571. return tag.id;
  572. }
  573. return tag;
  574. });
  575. return ids;
  576. }
  577. return form.competency_tags;
  578. }),
  579. onValueChange: ({ value, form }: { value: any[], form: any }) => {
  580. // 保存选中的ID数组
  581. form.competency_tags = value;
  582. // 同步更新competency_tags_config
  583. if (!form.competency_tags_config) {
  584. form.competency_tags_config = [];
  585. }
  586. // 获取当前已有的配置ID
  587. const existingConfigIds = form.competency_tags_config.map((config: any) => config.id);
  588. // 从全局变量获取胜任力标签选项数据
  589. const competencyOptions = window.competencyTagsOptions || [];
  590. // 添加新选择的标签配置
  591. value.forEach((tagId: number) => {
  592. if (!existingConfigIds.includes(tagId)) {
  593. // 查找标签信息
  594. const tagInfo = competencyOptions.find((tag: any) => tag.id === tagId);
  595. if (tagInfo) {
  596. form.competency_tags_config.push({
  597. id: tagId,
  598. competency_name: tagInfo.name,
  599. weight: tagInfo.weight || 100,
  600. importance: tagInfo.importance || 1,
  601. remark: ''
  602. });
  603. }
  604. }
  605. });
  606. // 移除已不存在的标签配置
  607. form.competency_tags_config = form.competency_tags_config.filter(
  608. (config: any) => value.includes(config.id)
  609. );
  610. }
  611. },
  612. helper: '选择题目关联的胜任力标签,可多选'
  613. }
  614. },
  615. competency_tags_config: {
  616. title: '胜任力配置',
  617. search: { show: false },
  618. column: { show: false },
  619. form: {
  620. show: compute(({ form }) => {
  621. // 只有当选择了胜任力标签时才显示配置
  622. return form && form.competency_tags && form.competency_tags.length > 0;
  623. }),
  624. component: {
  625. name: 'el-card',
  626. children: {
  627. default: ({ form }: { form: any }) => {
  628. // 确保competency_tags_config数组已初始化
  629. if (!form.competency_tags_config) {
  630. form.competency_tags_config = [];
  631. }
  632. // 使用ref标记是否已经处理过,避免重复处理
  633. const processed = ref(false);
  634. // 使用onMounted确保只在组件挂载时执行一次
  635. onMounted(() => {
  636. if (!processed.value && form.competency_tags && form.competency_tags.length > 0) {
  637. updateCompetencyConfig();
  638. processed.value = true;
  639. }
  640. });
  641. // 监听competency_tags变化,但避免无限循环
  642. watch(() => [...(form.competency_tags || [])], (newTags, oldTags) => {
  643. // 只有当标签真正变化时才更新配置
  644. if (JSON.stringify(newTags) !== JSON.stringify(oldTags)) {
  645. updateCompetencyConfig();
  646. }
  647. });
  648. // 抽取更新配置的逻辑到单独的函数
  649. const updateCompetencyConfig = () => {
  650. // 获取当前已有的配置ID
  651. const existingConfigIds = form.competency_tags_config.map((config: any) => config.id);
  652. // 创建新的配置数组
  653. const newConfigs = [...form.competency_tags_config];
  654. // 从全局变量获取胜任力标签选项数据
  655. const competencyOptions = window.competencyTagsOptions || [];
  656. // 添加新选择的标签配置
  657. form.competency_tags.forEach((tagId: number) => {
  658. if (!existingConfigIds.includes(tagId)) {
  659. // 查找标签名称
  660. const tagName = competencyOptions.find((tag: any) => tag.id === tagId)?.name || '未知标签';
  661. // 添加新配置
  662. newConfigs.push({
  663. id: tagId,
  664. competency_name: tagName,
  665. weight: 100, // 默认权重为100%
  666. importance: 1, // 默认重要性为1
  667. remark: '' // 默认备注为空
  668. });
  669. }
  670. });
  671. // 移除已不存在的标签配置
  672. const filteredConfigs = newConfigs.filter(
  673. (config: any) => form.competency_tags.includes(config.id)
  674. );
  675. // 一次性更新配置数组
  676. form.competency_tags_config = filteredConfigs;
  677. };
  678. // 渲染表格
  679. return (
  680. <div>
  681. <el-table border style="width: 100%" data={form.competency_tags_config}>
  682. <el-table-column label="标签" width="200">
  683. {{
  684. default: ({ row }: { row: any }) => (
  685. <span>{row.competency_name}</span>
  686. )
  687. }}
  688. </el-table-column>
  689. <el-table-column label="权重" width="100">
  690. {{
  691. default: ({ row }: { row: any }) => (
  692. <div class="weight-input" style="display: flex; align-items: center;">
  693. <el-input-number
  694. v-model={row.weight}
  695. min={0}
  696. max={100}
  697. step={1}
  698. precision={0}
  699. controls={false}
  700. style="width: calc(100% - 20px)"
  701. />
  702. <span style="margin-left: 4px;">%</span>
  703. </div>
  704. )
  705. }}
  706. </el-table-column>
  707. <el-table-column label="级别" width="100">
  708. {{
  709. default: ({ row }: { row: any }) => (
  710. <el-input-number
  711. v-model={row.importance}
  712. min={1}
  713. controls={false}
  714. style="width: 100%"
  715. />
  716. )
  717. }}
  718. </el-table-column>
  719. {/* <el-table-column label="备注">
  720. {{
  721. default: ({ row }: { row: any }) => (
  722. <el-input
  723. v-model={row.remark}
  724. placeholder="请输入备注"
  725. />
  726. )
  727. }}
  728. </el-table-column> */}
  729. </el-table>
  730. </div>
  731. );
  732. }
  733. }
  734. },
  735. helper: '配置每个胜任力标签的权重、重要性和备注'
  736. }
  737. },
  738. /* question_type: {
  739. title: '问题类型',
  740. search: { show: true },
  741. type: 'dict-select',
  742. column: {
  743. minWidth: 100,
  744. },
  745. dict: dict({
  746. data: [
  747. { value: 1, label: '专业技能' },
  748. { value: 2, label: '通用能力' },
  749. { value: 3, label: '个人特质' }
  750. ]
  751. }),
  752. form: {
  753. rules: [{ required: true, message: '问题类型必填' }],
  754. component: {
  755. placeholder: '请选择问题类型',
  756. },
  757. helper: '选择问题的类型分类',
  758. },
  759. }, */
  760. question_form: {
  761. title: '题目形式',
  762. search: { show: true,
  763. size: 'small',
  764. col:{ span:3},
  765. },
  766. type: 'dict-select',
  767. column: {
  768. minWidth: 120,
  769. },
  770. dict: dict({
  771. // 使用API方式获取数据
  772. getData: async () => {
  773. const res = await api.GetQuestionTypeList();
  774. // 返回question_forms数组
  775. return res.data.question_forms || [];
  776. },
  777. label: 'label',
  778. value: 'value'
  779. }),
  780. form: {
  781. rules: [{ required: true, message: '题目形式必填' }],
  782. component: {
  783. placeholder: '请选择题目形式',
  784. onChange: ({ form }: { form: any }) => {
  785. // 重置相关字段
  786. if (form.question_form === 1) {
  787. // 单选题
  788. form.options = [{ option_text: '', is_correct: false, sort: 1 }, { option_text: '', is_correct: false, sort: 2 }];
  789. } else if (form.question_form === 2) {
  790. // 多选题
  791. form.options = [{ option_text: '', is_correct: false, sort: 1 }, { option_text: '', is_correct: false, sort: 2 }];
  792. } else if (form.question_form === 4) {
  793. // 得分题 - 初始化五个评分选项
  794. form.options = [
  795. { option_text: '无', score: 0, sort: 1 },
  796. { option_text: '轻度', score: 1, sort: 2 },
  797. { option_text: '中度', score: 2, sort: 3 },
  798. { option_text: '偏重', score: 3, sort: 4 },
  799. { option_text: '严重', score: 4, sort: 5 }
  800. ];
  801. // 初始化评分说明
  802. if (!form.scoring_reference) {
  803. form.scoring_reference = '该评分反映了症状表现的频率与严重程度。';
  804. }
  805. } else if (form.question_form === 6) {
  806. // 填空题
  807. form.blank_answer_template = [
  808. { blank_index: 1, correct_answer: '', score: 5 }
  809. ];
  810. // 初始化评分说明
  811. if (!form.scoring_reference) {
  812. form.scoring_reference = '根据答案的准确性评分';
  813. }
  814. } else {
  815. // 开放问题
  816. form.options = [];
  817. }
  818. }
  819. },
  820. helper: '选择题目的形式:开放问题、单选题、多选题、填空题、色盲题或追加型开放问题',
  821. },
  822. },
  823. position_types: {
  824. title: '适用职位',
  825. search: { show: true,
  826. size: 'small',
  827. col:{ span:3}, },
  828. type: 'dict-select',
  829. column: {
  830. minWidth: 120,
  831. maxTagCount: 1
  832. },
  833. dict: dict({
  834. getData: async () => {
  835. const res = await api.GetPositionList({page:1,limit:1000,tenant_id:1});
  836. console.log(res.data);
  837. return res.data || [];
  838. },
  839. label: 'title',
  840. value: 'id'
  841. }),
  842. form: {
  843. component: {
  844. /* name: 'el-select', */
  845. props: {
  846. multiple: true,
  847. filterable: true,
  848. placeholder: '请选择适用职位类型',
  849. /* options: [
  850. { value: '0', label: '技术' },
  851. { value: '1', label: '管理' },
  852. ] */
  853. }
  854. },
  855. helper: '选择题目适用的职位类型,可多选'
  856. }
  857. },
  858. category_id: {
  859. title: '分类',
  860. search: { show: true,
  861. size: 'small',
  862. col:{ span:2}, },
  863. type: 'dict-select',
  864. column: {
  865. minWidth: 120,
  866. component: {
  867. // 自定义渲染组件,显示彩色标签
  868. // name: 'fs-component',
  869. render: ({ row }: { row: any }) => {
  870. if (!row.category || row.category.length === 0) return <span>-</span>;
  871. return (
  872. <el-tag
  873. key={row.category.id}
  874. type="warning"
  875. effect="plain"
  876. size="mini"
  877. style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"
  878. >
  879. {row.category.name.length > 4 ? row.category.name.slice(0, 4) + '...' : row.category.name}
  880. </el-tag>
  881. );
  882. }
  883. }
  884. },
  885. dict: dict({
  886. // 使用API方式获取数据
  887. getData: async () => {
  888. const res = await api.GetcategoryList({page:1, limit:1000, tenant_id:1});
  889. return res.data.items;
  890. },
  891. label: 'name',
  892. value: 'id'
  893. }),
  894. form: {
  895. // rules: [{ required: true, message: '题目分类必填' }],
  896. component: {
  897. placeholder: '请选择题目分类',
  898. /* onChange: ({ value }: { value: number }) => {
  899. // 当分类变化时,重新获取对应的标签
  900. fetchTags(value);
  901. } */
  902. },
  903. helper: '选择所属的分类'
  904. },
  905. },
  906. tags:{
  907. title: '标签',
  908. search: {
  909. show: true,
  910. size: 'small',
  911. col:{ span:3},
  912. component: {
  913. props: {
  914. multiple: false, // 在搜索表单中使用单选模式
  915. filterable: true,
  916. placeholder: '请选择标签搜索'
  917. }
  918. }
  919. },
  920. type: 'dict-select',
  921. column: {
  922. minWidth: 220,
  923. component: {
  924. name: 'fs-component',
  925. render: ({ row }: { row: any }) => {
  926. if (!row.tags || row.tags.length === 0) return <span>-</span>;
  927. const displayTags = row.tags.slice(0, 2); // 只取前两个标签
  928. const remainingCount = row.tags.length - 2; // 计算剩余标签数量
  929. return (
  930. <div style="display: flex; gap: 4px; align-items: center;">
  931. {displayTags.map((tag: any) => (
  932. <el-tag
  933. key={tag.id}
  934. type="warning"
  935. effect="plain"
  936. size="mini"
  937. style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"
  938. title={tag.name}
  939. >
  940. {tag.name.length > 4 ? tag.name.slice(0, 4) + '...' : tag.name}
  941. </el-tag>
  942. ))}
  943. {remainingCount > 0 && (
  944. <el-tooltip
  945. placement="top"
  946. effect="light"
  947. popper-class="tag-tooltip"
  948. >
  949. {{
  950. default: () => (
  951. <el-tag
  952. type="info"
  953. effect="plain"
  954. size="mini"
  955. >
  956. +{remainingCount}
  957. </el-tag>
  958. ),
  959. content: () => (
  960. <div>
  961. <div style="font-weight: bold; margin-bottom: 5px">剩余{remainingCount}个标签:</div>
  962. {row.tags.slice(2).map((tag: any) => (
  963. <div key={tag.id} style="margin: 3px 0">{tag.name}</div>
  964. ))}
  965. </div>
  966. )
  967. }}
  968. </el-tooltip>
  969. )}
  970. </div>
  971. );
  972. }
  973. }
  974. },
  975. dict: dict({
  976. // 使用API方式获取数据
  977. getData: async () => {
  978. const res = await api.GetTagList({page:1, limit:1000, tenant_id:1});
  979. return res.data.items;
  980. },
  981. label: 'name',
  982. value: 'id'
  983. }),
  984. form: {
  985. component: {
  986. props: {
  987. multiple: true, // 在编辑表单中保持多选
  988. filterable: true,
  989. placeholder: '请选择标签'
  990. }
  991. },
  992. helper: '选择题目关联的标签,可多选'
  993. }
  994. },
  995. recommended_duration: {
  996. title: '建议时长(秒)',
  997. search: { show: false },
  998. column: {
  999. minWidth: 100,
  1000. },
  1001. form: {
  1002. value: 60,
  1003. component: {
  1004. name: 'el-input-number',
  1005. props: {
  1006. min: 10,
  1007. max: 600,
  1008. step: 10
  1009. }
  1010. },
  1011. helper: '建议回答此题目的时长,单位为秒'
  1012. }
  1013. },
  1014. /* difficulty: {
  1015. title: '难度等级',
  1016. search: { show: true },
  1017. type: 'dict-select',
  1018. column: {
  1019. minWidth: 80,
  1020. },
  1021. dict: dict({
  1022. data: [
  1023. { value: 1, label: '初级' },
  1024. { value: 2, label: '中级' },
  1025. { value: 3, label: '高级' }
  1026. ]
  1027. }),
  1028. form: {
  1029. rules: [{ required: true, message: '难度等级必填' }],
  1030. helper: '选择题目的难度级别'
  1031. },
  1032. }, */
  1033. is_system: {
  1034. title: '系统题目',
  1035. search: { show: false },
  1036. type: 'dict-select',
  1037. column: {
  1038. width: 100,
  1039. /* component: {
  1040. name: 'fs-component',
  1041. render: ({ row }: { row: any }) => {
  1042. return row.is_system ?
  1043. <el-tag type="success" size="small">是</el-tag> :
  1044. <el-tag type="info" size="small">否</el-tag>;
  1045. }
  1046. } */
  1047. },
  1048. dict: dict({
  1049. data: [
  1050. { value: true, label: '是' },
  1051. { value: false, label: '否' }
  1052. ]
  1053. }),
  1054. form: {
  1055. value: false,
  1056. component: {
  1057. placeholder: '请选择是否为系统题目'
  1058. },
  1059. helper: '是否为系统预设题目'
  1060. }
  1061. },
  1062. status: {
  1063. title: '状态',
  1064. search: { show: true,
  1065. size: 'small',
  1066. col:{ span:2},},
  1067. type: 'dict-select',
  1068. column: {
  1069. width: 80,
  1070. },
  1071. dict: dict({
  1072. data: [
  1073. { value: 0, label: '停用' },
  1074. { value: 1, label: '启用' }
  1075. ]
  1076. }),
  1077. form: {
  1078. value: 1,
  1079. rules: [{ required: true, message: '状态必填' }],
  1080. component: {
  1081. placeholder: '请选择状态',
  1082. },
  1083. helper: '题目的启用状态'
  1084. },
  1085. },
  1086. // 添加红线问题字段
  1087. is_required_correct: {
  1088. title: '红线问题',
  1089. search: { show: true,
  1090. size: 'small',
  1091. col:{ span:2}, },
  1092. type: 'dict-select',
  1093. column: {
  1094. width: 100,
  1095. component: {
  1096. name: 'fs-component',
  1097. render: ({ row }: { row: any }) => {
  1098. // 只有单选题和多选题才显示红线问题状态
  1099. if (row.question_form !== 1 && row.question_form !== 2) {
  1100. return <span>-</span>;
  1101. }
  1102. return row.is_required_correct ?
  1103. <el-tag type="danger" size="small">是</el-tag> :
  1104. <el-tag type="info" size="small">否</el-tag>;
  1105. }
  1106. }
  1107. },
  1108. dict: dict({
  1109. data: [
  1110. { value: true, label: '是' },
  1111. { value: false, label: '否' }
  1112. ]
  1113. }),
  1114. form: {
  1115. value: false,
  1116. show: compute(({ form }) => {
  1117. // 只有单选题和多选题才显示红线问题选项
  1118. return form && (form.question_form === 1 || form.question_form === 2);
  1119. }),
  1120. component: {
  1121. placeholder: '请选择是否为红线问题'
  1122. },
  1123. helper: '红线问题是指必须回答正确的题目,否则可能导致面试失败'
  1124. }
  1125. },
  1126. sort: {
  1127. title: '排序',
  1128. search: { show: false },
  1129. column: {
  1130. width: 80,
  1131. },
  1132. form: {
  1133. component: {
  1134. name: 'el-input-number',
  1135. props: {
  1136. min: 1,
  1137. max: 999
  1138. }
  1139. },
  1140. helper: '题目的排序值,值越小排序越靠前'
  1141. }
  1142. },
  1143. option_items: {
  1144. title: '选项列表',
  1145. search: { show: false },
  1146. column: { show: false },
  1147. form: {
  1148. show: compute(({ form }) => {
  1149. return form && (form.question_form === 1 || form.question_form === 2 || form.question_form === 4);
  1150. }),
  1151. component: {
  1152. name: 'el-card',
  1153. children: {
  1154. default: ({ form }: { form: any }) => {
  1155. // 确保options数组已初始化
  1156. if (!form.options) {
  1157. form.options = [];
  1158. }
  1159. // 心理评估题的选项渲染
  1160. if (form.question_form === 4) {
  1161. return (
  1162. <div>
  1163. <div class="option-header" style="display: flex; margin-bottom: 10px; font-weight: bold;">
  1164. <span style="flex: 1;">选项内容</span>
  1165. <span style="width: 120px; text-align: center;">分值</span>
  1166. </div>
  1167. {form.options.map((option: any, index: number) => (
  1168. <div class="option-item" key={index} style="display: flex; align-items: center; margin-bottom: 10px;">
  1169. <el-input
  1170. v-model={option.option_text}
  1171. placeholder="请输入选项内容"
  1172. style="flex: 1; margin-right: 10px;"
  1173. />
  1174. <el-input-number
  1175. v-model={option.score}
  1176. min={0}
  1177. max={10}
  1178. style="width: 120px;"
  1179. placeholder="分值"
  1180. />
  1181. </div>
  1182. ))}
  1183. <div style="display: flex; justify-content: space-between; margin-top: 10px;">
  1184. <el-button
  1185. type="primary"
  1186. onClick={() => {
  1187. if (!form.options) {
  1188. form.options = [];
  1189. }
  1190. const sort = form.options.length > 0 ?
  1191. Math.max(...form.options.map((o: any) => o.sort || 0)) + 1 : 1;
  1192. form.options.push({ option_text: '', score: 0, sort });
  1193. }}
  1194. >
  1195. 添加选项
  1196. </el-button>
  1197. {form.options.length > 2 && (
  1198. <el-button
  1199. type="danger"
  1200. onClick={() => {
  1201. form.options.pop();
  1202. }}
  1203. >
  1204. 删除最后一项
  1205. </el-button>
  1206. )}
  1207. </div>
  1208. </div>
  1209. );
  1210. }
  1211. // 单选题和多选题的选项渲染(原有逻辑)
  1212. return (
  1213. <div>
  1214. <div class="option-header" style="display: flex; margin-bottom: 10px; font-weight: bold;">
  1215. <span style="flex: 1;">选项内容</span>
  1216. <span style="width: 80px; text-align: center;">是否正确</span>
  1217. </div>
  1218. {form.options.map((option: any, index: number) => (
  1219. <div class="option-item" key={index} style="display: flex; align-items: center; margin-bottom: 10px;">
  1220. <el-input
  1221. v-model={option.option_text}
  1222. placeholder="请输入选项内容"
  1223. style="flex: 1; margin-right: 10px;"
  1224. />
  1225. <el-tooltip
  1226. content="设置为正确答案"
  1227. placement="top"
  1228. effect="light"
  1229. >
  1230. <div
  1231. onClick={() => {
  1232. if (form.question_form === 1) {
  1233. // 单选题:只能有一个正确答案
  1234. form.options.forEach((item: any, idx: number) => {
  1235. item.is_correct = (idx === index);
  1236. });
  1237. } else {
  1238. // 多选题:可以有多个正确答案
  1239. option.is_correct = !option.is_correct;
  1240. }
  1241. }}
  1242. style="cursor: pointer; width: 80px; text-align: center;"
  1243. >
  1244. {form.question_form === 1 ? (
  1245. // 单选题使用单选按钮
  1246. <el-radio
  1247. modelValue={option.is_correct}
  1248. label={true}
  1249. />
  1250. ) : (
  1251. // 多选题使用复选框
  1252. <el-checkbox
  1253. modelValue={option.is_correct}
  1254. />
  1255. )}
  1256. </div>
  1257. </el-tooltip>
  1258. </div>
  1259. ))}
  1260. <div style="display: flex; justify-content: space-between; margin-top: 10px;">
  1261. <el-button
  1262. type="primary"
  1263. onClick={() => {
  1264. // 确保options数组已初始化
  1265. if (!form.options) {
  1266. form.options = [];
  1267. }
  1268. // 添加新选项时自动设置排序值
  1269. const sort = form.options.length > 0 ?
  1270. Math.max(...form.options.map((o: any) => o.sort || 0)) + 1 : 1;
  1271. form.options.push({ option_text: '', is_correct: false, sort });
  1272. }}
  1273. >
  1274. 添加选项
  1275. </el-button>
  1276. {form.options.length > 2 && (
  1277. <el-button
  1278. type="danger"
  1279. onClick={() => {
  1280. form.options.pop();
  1281. }}
  1282. >
  1283. 删除最后一项
  1284. </el-button>
  1285. )}
  1286. </div>
  1287. </div>
  1288. )
  1289. }
  1290. }
  1291. },
  1292. helper: compute(({ form }) => {
  1293. if (form.question_form === 1) {
  1294. return '添加单选题的选项,并标记正确答案(只能有一个正确答案)';
  1295. } else if (form.question_form === 2) {
  1296. return '添加多选题的选项,并标记正确答案(可以有多个正确答案)';
  1297. } else if (form.question_form === 4) {
  1298. return '添加心理评估题的选项,并设置每个选项的分值';
  1299. }
  1300. return '';
  1301. })
  1302. }
  1303. },
  1304. scoring_reference: {
  1305. title: '评分标准',
  1306. search: { show: false },
  1307. column: { show: false },
  1308. form: {
  1309. component: {
  1310. name: 'el-input',
  1311. type: 'textarea',
  1312. rows: 4,
  1313. placeholder: compute(({ form }) => {
  1314. if (form && form.question_form === 4) {
  1315. return '请输入评分标准说明';
  1316. }
  1317. return '请输入评分标准说明';
  1318. })
  1319. },
  1320. helper: compute(({ form }) => {
  1321. if (form && form.question_form === 4) {
  1322. return '评分标准说明,例如:该评分反映了症状表现的频率与严重程度。';
  1323. }
  1324. return '题目的评分标准';
  1325. })
  1326. },
  1327. },
  1328. digital_human_video_url:{
  1329. title: '视频是否生成',
  1330. search: { show: false },
  1331. column: {
  1332. width: 120,
  1333. component: {
  1334. name: 'fs-component',
  1335. render: ({ row }: { row: any }) => {
  1336. return row.digital_human_video_url ?
  1337. <el-tag type="success" size="small">是</el-tag> :
  1338. <el-tag type="info" size="small">否</el-tag>;
  1339. }
  1340. }
  1341. },
  1342. form: {
  1343. show: false // 在表单中不显示此字段,通常由系统自动生成
  1344. }
  1345. },
  1346. blank_answer_template: {
  1347. title: '填空答案模板',
  1348. search: { show: false },
  1349. column: { show: false },
  1350. form: {
  1351. show: compute(({ form }) => {
  1352. return form && form.question_form === 6;
  1353. }),
  1354. component: {
  1355. name: 'el-card',
  1356. children: {
  1357. default: ({ form }: { form: any }) => {
  1358. // 确保blank_answer_template数组已初始化
  1359. if (!form.blank_answer_template) {
  1360. form.blank_answer_template = [{ blank_index: 1, correct_answer: '', score: 5 }];
  1361. }
  1362. // 计算题目中的填空数量
  1363. const blankCount = (form.question || '').split('___').length - 1;
  1364. // 如果填空数量变化,更新模板
  1365. if (blankCount > 0 && form.blank_answer_template.length !== blankCount) {
  1366. form.blank_answer_template = Array.from({ length: blankCount }, (_, i) => ({
  1367. blank_index: i + 1,
  1368. correct_answer: '',
  1369. score: 5
  1370. }));
  1371. }
  1372. return (
  1373. <div>
  1374. <div class="blank-header" style="display: flex; margin-bottom: 10px; font-weight: bold;">
  1375. <span style="width: 80px;">填空序号</span>
  1376. <span style="flex: 1;">正确答案</span>
  1377. <span style="width: 120px; text-align: center;">分值</span>
  1378. </div>
  1379. {form.blank_answer_template.map((blank: any, index: number) => (
  1380. <div class="blank-item" key={index} style="display: flex; align-items: center; margin-bottom: 10px;">
  1381. <span style="width: 80px;">{blank.blank_index}</span>
  1382. <el-input
  1383. v-model={blank.correct_answer}
  1384. placeholder="请输入正确答案"
  1385. style="flex: 1; margin: 0 10px;"
  1386. />
  1387. <el-input-number
  1388. v-model={blank.score}
  1389. min={0}
  1390. max={100}
  1391. style="width: 120px;"
  1392. placeholder="分值"
  1393. />
  1394. </div>
  1395. ))}
  1396. <div style="color: #666; font-size: 12px; margin-top: 10px;">
  1397. 提示:在题目中使用"___"(三个下划线)表示填空位置,系统会自动识别填空数量
  1398. </div>
  1399. </div>
  1400. );
  1401. }
  1402. }
  1403. },
  1404. helper: '设置每个填空的正确答案和分值'
  1405. }
  1406. }
  1407. },
  1408. // 确保表格配置正确
  1409. table: {
  1410. selection: true,
  1411. onSelectionChange: (selection: any[]) => {
  1412. // 存储选中的行到一个全局变量中
  1413. context.selectedRows = selection;
  1414. },
  1415. },
  1416. },
  1417. };
  1418. };
  1419. // 导出批量更新标签方法,供组件使用
  1420. export const useBatchUpdateTags = (crudExpose: any) => {
  1421. const batchUpdateTags = async (questionIds: number[], tagIds: number[]) => {
  1422. try {
  1423. const res = await api.BatchUpdateTags({
  1424. question_ids: questionIds,
  1425. tags: tagIds,
  1426. tenant_id: 1
  1427. });
  1428. if (res.code === 0) {
  1429. successMessage('批量更新标签成功');
  1430. // 刷新列表
  1431. crudExpose.doRefresh();
  1432. }
  1433. } catch (error) {
  1434. console.error('批量更新标签失败', error);
  1435. }
  1436. };
  1437. return { batchUpdateTags };
  1438. };
  1439. // 导出批量更新分类方法,供组件使用
  1440. export const useBatchUpdateCategory = (crudExpose: any) => {
  1441. const batchUpdateCategory = async (questionIds: number[], categoryId: number) => {
  1442. try {
  1443. const res = await api.BatchUpdateCategory({
  1444. question_ids: questionIds,
  1445. category_id: categoryId,
  1446. tenant_id: "1"
  1447. });
  1448. if (res.code === 0) {
  1449. successMessage('批量更新分类成功');
  1450. // 刷新列表
  1451. crudExpose.doRefresh();
  1452. }
  1453. } catch (error) {
  1454. console.error('批量更新分类失败', error);
  1455. }
  1456. };
  1457. return { batchUpdateCategory };
  1458. };
  1459. // 导出批量更新胜任力标签方法,供组件使用
  1460. export const useBatchUpdateCompetencyTags = (crudExpose: any) => {
  1461. const batchUpdateCompetencyTags = async (questionIds: number[], competencyTags: any[]) => {
  1462. try {
  1463. const res = await api.BatchUpdateCompetencyTags({
  1464. question_ids: questionIds,
  1465. competency_tags: competencyTags,
  1466. tenant_id: 1
  1467. });
  1468. if (res.code === 0) {
  1469. successMessage('批量更新胜任力标签成功');
  1470. // 刷新列表
  1471. crudExpose.doRefresh();
  1472. }
  1473. } catch (error) {
  1474. console.error('批量更新胜任力标签失败', error);
  1475. }
  1476. };
  1477. return { batchUpdateCompetencyTags };
  1478. };