|
@@ -1,9 +1,10 @@
|
|
|
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 } from '../../../utils/message';
|
|
|
+import { successMessage, warningMessage } from '../../../utils/message';
|
|
|
import { auth } from '/@/utils/authFunction';
|
|
|
import { ref, onMounted } from 'vue';
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -68,6 +69,24 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
|
|
|
fetchTags();
|
|
|
}); */
|
|
|
|
|
|
+ // 添加批量更新标签的方法
|
|
|
+ const batchUpdateTags = async (questionIds: number[], tagIds: number[]) => {
|
|
|
+ try {
|
|
|
+ const res = await api.BatchUpdateTags({
|
|
|
+ question_ids: questionIds,
|
|
|
+ tag_ids: tagIds,
|
|
|
+ tenant_id: 1
|
|
|
+ });
|
|
|
+ if (res.code === 0) {
|
|
|
+ successMessage('批量更新标签成功');
|
|
|
+ // 刷新列表
|
|
|
+ crudExpose.doRefresh();
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('批量更新标签失败', error);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
return {
|
|
|
crudOptions: {
|
|
|
request: {
|
|
@@ -84,6 +103,25 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
|
|
|
add: {
|
|
|
show: auth('role:Create'),
|
|
|
},
|
|
|
+ // 添加批量绑定标签按钮
|
|
|
+ /* batchBindTags: {
|
|
|
+ text: '批量绑定标签',
|
|
|
+ type: 'primary',
|
|
|
+ show: true,
|
|
|
+ order: 2,
|
|
|
+ click: () => {
|
|
|
+ // 尝试不同的方式获取选中行
|
|
|
+ const selection = crudExpose.getSelection?.() || crudExpose.selectedRows || [];
|
|
|
+ console.log('选中的行:', selection);
|
|
|
+
|
|
|
+ if (!selection || selection.length === 0) {
|
|
|
+ warningMessage('请先选择要操作的题目');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 打开批量绑定标签对话框
|
|
|
+ context.openBatchTagsDialog(selection);
|
|
|
+ },
|
|
|
+ }, */
|
|
|
},
|
|
|
},
|
|
|
rowHandle: {
|
|
@@ -122,16 +160,17 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
|
|
|
},
|
|
|
},
|
|
|
columns: {
|
|
|
- /* _index: {
|
|
|
- title: '序号',
|
|
|
+ _selection: {
|
|
|
+ title: '选择',
|
|
|
form: { show: false },
|
|
|
column: {
|
|
|
- type: 'index',
|
|
|
+ type: 'selection',
|
|
|
align: 'center',
|
|
|
- width: '70px',
|
|
|
- columnSetDisabled: true, //禁止在列设置中选择
|
|
|
+ width: 50,
|
|
|
+ fixed: 'left',
|
|
|
+ columnSetDisabled: true,
|
|
|
},
|
|
|
- }, */
|
|
|
+ },
|
|
|
id: {
|
|
|
title: 'ID',
|
|
|
column: { show: true ,width:80,},
|
|
@@ -528,6 +567,32 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
+ // 确保表格配置正确
|
|
|
+ table: {
|
|
|
+ selection: true,
|
|
|
+ },
|
|
|
},
|
|
|
};
|
|
|
};
|
|
|
+
|
|
|
+// 导出批量更新标签方法,供组件使用
|
|
|
+export const useBatchUpdateTags = (crudExpose: any) => {
|
|
|
+ const batchUpdateTags = async (questionIds: number[], tagIds: number[]) => {
|
|
|
+ try {
|
|
|
+ const res = await api.BatchUpdateTags({
|
|
|
+ question_ids: questionIds,
|
|
|
+ tag_ids: tagIds,
|
|
|
+ tenant_id: 1
|
|
|
+ });
|
|
|
+ if (res.code === 0) {
|
|
|
+ successMessage('批量更新标签成功');
|
|
|
+ // 刷新列表
|
|
|
+ crudExpose.doRefresh();
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('批量更新标签失败', error);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ return { batchUpdateTags };
|
|
|
+};
|