133 lines
2.6 KiB
Vue
133 lines
2.6 KiB
Vue
<template>
|
|
<UploadFile
|
|
ref="uploadFileRef"
|
|
:options="options"
|
|
:relatedRules="relatedRules"
|
|
:relatedOptions="relatedOptions"
|
|
/>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref } from "vue";
|
|
import { ElMessage } from "element-plus";
|
|
|
|
import UploadFile from "../../../operate/uploadFile.vue";
|
|
|
|
const uploadFileRef = ref(null);
|
|
const formClone = ref([]);
|
|
|
|
const options = {
|
|
limit: 1,
|
|
accept: ".xlsx",
|
|
action: "",
|
|
multiple: false,
|
|
listType: "text",
|
|
autoUpload: false,
|
|
};
|
|
|
|
const relatedRules = {
|
|
topic: {
|
|
value: "",
|
|
label: "题目",
|
|
},
|
|
options_a: {
|
|
value: "",
|
|
label: "选项A",
|
|
},
|
|
options_b: {
|
|
value: "",
|
|
label: "选项B",
|
|
},
|
|
options_c: {
|
|
value: "",
|
|
label: "选项C",
|
|
},
|
|
options_d: {
|
|
value: "",
|
|
label: "选项D",
|
|
},
|
|
answer: {
|
|
value: "",
|
|
label: "答案",
|
|
},
|
|
};
|
|
|
|
const relatedOptions = [
|
|
{
|
|
value: "0",
|
|
label: "题目",
|
|
disabled: false,
|
|
},
|
|
{
|
|
value: "1",
|
|
label: "选项A",
|
|
disabled: false,
|
|
},
|
|
{
|
|
value: "1",
|
|
label: "选项B",
|
|
disabled: false,
|
|
},
|
|
{
|
|
value: "1",
|
|
label: "选项C",
|
|
disabled: false,
|
|
},
|
|
{
|
|
value: "1",
|
|
label: "选项D",
|
|
disabled: false,
|
|
},
|
|
{
|
|
value: "1",
|
|
label: "答案",
|
|
disabled: false,
|
|
},
|
|
];
|
|
|
|
const emit = defineEmits(["addChoiceTopic"]);
|
|
|
|
const resetCheckForm = () => {
|
|
if (!uploadFileRef) return;
|
|
uploadFileRef.value.handleExceed();
|
|
};
|
|
|
|
const confirm = async () => {
|
|
if (!uploadFileRef) return;
|
|
formClone.value = [];
|
|
const length = uploadFileRef.value.loadData.length;
|
|
if (length == 0) return ElMessage.error("请先上传文件!");
|
|
const flag = await uploadFileRef.value.confirm();
|
|
if (!flag) return ElMessage.error("请先选择表格关联项!");
|
|
ElMessage({
|
|
message: `正在上传数据中,请稍等...`,
|
|
type: "success",
|
|
});
|
|
setTimeout(() => {
|
|
uploadFileRef.value.loadData.forEach((ExcleForm) => {
|
|
ExcleForm.forEach((worksheet) => {
|
|
let context = [...worksheet];
|
|
context.shift();
|
|
context.forEach((item) => {
|
|
if (item.length != 0) {
|
|
formClone.value.push({
|
|
topic: item[relatedRules.topic.value],
|
|
options_a: item[relatedRules.options_a.value],
|
|
options_b: item[relatedRules.options_b.value],
|
|
options_c: item[relatedRules.options_c.value],
|
|
options_d: item[relatedRules.options_d.value],
|
|
answer: item[relatedRules.answer.value],
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
emit("addChoiceTopic", formClone.value);
|
|
}, 3000);
|
|
};
|
|
|
|
defineExpose({ resetCheckForm, confirm, formClone });
|
|
</script>
|
|
|
|
<style scoped></style>
|