|
@@ -3,6 +3,7 @@ import * as api from './api';
|
|
|
import { dictionary } from '/@/utils/dictionary';
|
|
|
import { successMessage } from '../../../utils/message';
|
|
|
import { auth } from '/@/utils/authFunction';
|
|
|
+import { ref, onMounted } from 'vue';
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -25,6 +26,48 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
|
|
|
return await api.AddObj(form);
|
|
|
};
|
|
|
|
|
|
+/* // 修改分类和标签数据获取方式
|
|
|
+ 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();
|
|
|
+ }); */
|
|
|
+
|
|
|
return {
|
|
|
crudOptions: {
|
|
|
request: {
|
|
@@ -150,7 +193,7 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
|
|
|
rules: [{ required: true, message: '题目形式必填' }],
|
|
|
component: {
|
|
|
placeholder: '请选择题目形式',
|
|
|
- onChange: ({ form }) => {
|
|
|
+ onChange: ({ form }: { form: any }) => {
|
|
|
// 重置相关字段
|
|
|
if (form.question_form === 1) {
|
|
|
// 单选题
|
|
@@ -313,7 +356,7 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
|
|
|
component: {
|
|
|
name: 'el-card',
|
|
|
children: {
|
|
|
- default: ({ form }) => {
|
|
|
+ default: ({ form }: { form: any }) => {
|
|
|
// 确保options数组已初始化
|
|
|
if (!form.options) {
|
|
|
form.options = [];
|
|
@@ -325,7 +368,7 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
|
|
|
<span style="flex: 1;">选项内容</span>
|
|
|
<span style="width: 80px; text-align: center;">是否正确</span>
|
|
|
</div>
|
|
|
- {form.options.map((option, index) => (
|
|
|
+ {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}
|
|
@@ -341,7 +384,7 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
|
|
|
onClick={() => {
|
|
|
if (form.question_form === 1) {
|
|
|
// 单选题:只能有一个正确答案
|
|
|
- form.options.forEach((item, idx) => {
|
|
|
+ form.options.forEach((item: any, idx: number) => {
|
|
|
item.is_correct = (idx === index);
|
|
|
});
|
|
|
} else {
|
|
@@ -377,7 +420,7 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
|
|
|
}
|
|
|
// 添加新选项时自动设置排序值
|
|
|
const sort = form.options.length > 0 ?
|
|
|
- Math.max(...form.options.map(o => o.sort || 0)) + 1 : 1;
|
|
|
+ Math.max(...form.options.map((o: any) => o.sort || 0)) + 1 : 1;
|
|
|
form.options.push({ option_text: '', is_correct: false, sort });
|
|
|
}}
|
|
|
>
|
|
@@ -423,7 +466,67 @@ export const createCrudOptions = function ({ crudExpose, context }: CreateCrudOp
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
-
|
|
|
+ category_id: {
|
|
|
+ title: '题目分类',
|
|
|
+ search: { show: true },
|
|
|
+ type: 'dict-select',
|
|
|
+ column: {
|
|
|
+ minWidth: 120,
|
|
|
+ },
|
|
|
+ dict: dict({
|
|
|
+ // 使用API方式获取数据
|
|
|
+ getData: async () => {
|
|
|
+ const res = await api.GetcategoryList({page:1, limit:1000, 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: '选择题目所属的分类'
|
|
|
+ },
|
|
|
+ },
|
|
|
+ tag_ids: {
|
|
|
+ title: '题目标签',
|
|
|
+ search: { show: true },
|
|
|
+ type: 'dict-select',
|
|
|
+ column: {
|
|
|
+ minWidth: 150,
|
|
|
+ component: {
|
|
|
+ name: 'fs-dict-label',
|
|
|
+ props: {
|
|
|
+ multiple: true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ dict: dict({
|
|
|
+ // 使用API方式获取数据
|
|
|
+ getData: async () => {
|
|
|
+ const res = await api.GetTagList({page:1, limit:1000, tenant_id:1});
|
|
|
+ return res.data.items;
|
|
|
+ },
|
|
|
+ label: 'name',
|
|
|
+ value: 'id'
|
|
|
+ }),
|
|
|
+ form: {
|
|
|
+ component: {
|
|
|
+ props: {
|
|
|
+ multiple: true,
|
|
|
+ filterable: true,
|
|
|
+ placeholder: '请选择题目标签'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ helper: '选择题目关联的标签,可多选'
|
|
|
+ }
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
};
|