北斗启航科技教育平台管理系统
This commit is contained in:
538
src/components/mainPage/contest/choiceTopic.vue
Normal file
538
src/components/mainPage/contest/choiceTopic.vue
Normal file
@@ -0,0 +1,538 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- 表格 -->
|
||||
<el-card>
|
||||
<div class="flex justify-center flex-wrap">
|
||||
<TabelTools @showTools="showTools" :dialogObj="choiceTopicMsgActive" />
|
||||
<AddNewData newDataLabel="新增单选题" @showAddForm="showAddForm" />
|
||||
<el-table
|
||||
ref="tableRef"
|
||||
:data="tableData"
|
||||
style="width: 100%"
|
||||
max-height="50rem"
|
||||
table-layout="auto"
|
||||
scrollbar-always-on
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<el-table-column
|
||||
v-if="dialogOperationVisible"
|
||||
fixed="left"
|
||||
type="selection"
|
||||
width="40"
|
||||
column-key="selection"
|
||||
/>
|
||||
<TabelSelect
|
||||
v-if="dialogOperationVisible"
|
||||
ref="EditSelectRef"
|
||||
:holderText="editSelectHold"
|
||||
singleColor="primary"
|
||||
multipleColor="warning"
|
||||
allColor="danger"
|
||||
singleSize="small"
|
||||
multipleSize="small"
|
||||
allSize="small"
|
||||
:singlePlain="true"
|
||||
:multiplePlain="false"
|
||||
:allPlain="false"
|
||||
operateType="edit"
|
||||
singleType="single"
|
||||
@showComfirmDialog="showComfirmDialog"
|
||||
/>
|
||||
<TabelSelect
|
||||
v-if="dialogOperationVisible"
|
||||
ref="DelSelectRef"
|
||||
:holderText="delSelectHold"
|
||||
singleColor="danger"
|
||||
multipleColor="warning"
|
||||
allColor="danger"
|
||||
singleSize="small"
|
||||
multipleSize="small"
|
||||
allSize="small"
|
||||
:singlePlain="true"
|
||||
:multiplePlain="false"
|
||||
:allPlain="false"
|
||||
operateType="del"
|
||||
@showComfirmDialog="showComfirmDialog"
|
||||
/>
|
||||
<el-table-column min-width="200" column-key="topic">
|
||||
<template #header>
|
||||
<div>
|
||||
<SearchKey
|
||||
v-if="dialogSearchVisible"
|
||||
ref="SearchTopicKeyRef"
|
||||
holderText="输入题目以搜索相关数据"
|
||||
@search="choiceTopicMsg"
|
||||
/>
|
||||
<div>
|
||||
<el-text class="mx-1"> 题目 </el-text>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<div class="flex justify-start items-center text-base">
|
||||
{{ scope.row.topic }}
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column min-width="200" column-key="options_a">
|
||||
<template #header>
|
||||
<div>
|
||||
<SearchKey
|
||||
v-if="dialogSearchVisible"
|
||||
ref="SearchOptionsAKeyRef"
|
||||
holderText="输入选项A以搜索相关数据"
|
||||
@search="choiceTopicMsg"
|
||||
/>
|
||||
<div>
|
||||
<el-text class="mx-1"> 选项A </el-text>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<div class="flex justify-start items-center text-base">
|
||||
{{ scope.row.options_a }}
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column min-width="200" column-key="options_b">
|
||||
<template #header>
|
||||
<div>
|
||||
<SearchKey
|
||||
v-if="dialogSearchVisible"
|
||||
ref="SearchOptionsBKeyRef"
|
||||
holderText="输入选项B以搜索相关数据"
|
||||
@search="choiceTopicMsg"
|
||||
/>
|
||||
<div>
|
||||
<el-text class="mx-1"> 选项B </el-text>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<div class="flex justify-start items-center text-base">
|
||||
{{ scope.row.options_b }}
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column min-width="200" column-key="options_c">
|
||||
<template #header>
|
||||
<div>
|
||||
<SearchKey
|
||||
v-if="dialogSearchVisible"
|
||||
ref="SearchOptionsCKeyRef"
|
||||
holderText="输入选项C以搜索相关数据"
|
||||
@search="choiceTopicMsg"
|
||||
/>
|
||||
<div>
|
||||
<el-text class="mx-1"> 选项C </el-text>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<div class="flex justify-start items-center text-base">
|
||||
{{ scope.row.options_c }}
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column min-width="200" column-key="options_d">
|
||||
<template #header>
|
||||
<div>
|
||||
<SearchKey
|
||||
v-if="dialogSearchVisible"
|
||||
ref="SearchOptionsDKeyRef"
|
||||
holderText="输入选项D以搜索相关数据"
|
||||
@search="choiceTopicMsg"
|
||||
/>
|
||||
<div>
|
||||
<el-text class="mx-1"> 选项D </el-text>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<div class="flex justify-start items-center text-base">
|
||||
{{ scope.row.options_d }}
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column min-width="100" column-key="answer">
|
||||
<template #header>
|
||||
<div>
|
||||
<SearchKey
|
||||
v-if="dialogSearchVisible"
|
||||
ref="SearchAnswerKeyRef"
|
||||
holderText="输入答案以搜索相关数据"
|
||||
@search="choiceTopicMsg"
|
||||
/>
|
||||
<div>
|
||||
<el-text class="mx-1"> 答案 </el-text>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #default="scope">
|
||||
<div class="flex justify-start items-center text-base">
|
||||
{{ scope.row.answer }}
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<!-- 表格 -->
|
||||
<Pagination
|
||||
ref="PaginationRef"
|
||||
:active="choiceTopicMsgActive"
|
||||
@sizeChangeBack="changePage"
|
||||
@search="choiceTopicMsg"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
<AddChoiceTopicForm
|
||||
ref="addChoiceTopicFormRef"
|
||||
title="新增单选题"
|
||||
@reloadData="choiceTopicMsg"
|
||||
/>
|
||||
<EditChoiceTopicForm
|
||||
ref="editChoiceTopicFormRef"
|
||||
operateLabel="编辑单选题"
|
||||
:editData="editData"
|
||||
@requestOperate="requestOperate"
|
||||
/>
|
||||
<PasswordOauth
|
||||
ref="delPasswordOauthRef"
|
||||
operateLabel="删除单选题"
|
||||
@requestOperate="requestOperate"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, watch, onMounted, nextTick } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
|
||||
import TabelTools from "../../operate/tabelTools.vue";
|
||||
import AddNewData from "../../operate/addNewData.vue";
|
||||
import TabelSelect from "../../operate/tabelSelect.vue";
|
||||
import SearchKey from "../../search/searchKey.vue";
|
||||
import Pagination from "../../search/pagination.vue";
|
||||
import AddChoiceTopicForm from "../../addNewData/contest/choiceTopicForm/choiceTopicForm.vue";
|
||||
import EditChoiceTopicForm from "../../editData/contest/choiceTopicForm.vue";
|
||||
import PasswordOauth from "../../operate/passwordOauth.vue";
|
||||
|
||||
import choiceTopicActiveStore from "../../../stores/contest/choiceTopic";
|
||||
|
||||
import moment from "moment";
|
||||
|
||||
import $http from "../../../api/index";
|
||||
import $url from "../../../api/url";
|
||||
|
||||
import { encrypt } from "../../../utils/aes";
|
||||
import { judgment } from "../../../utils/judgment.js";
|
||||
import { hasNullOrEmptyPropertyWithTypeof } from "../../../utils/hasNullOrEmptyPropertyWithTypeof.js";
|
||||
|
||||
const choiceTopicMsgActive = choiceTopicActiveStore();
|
||||
|
||||
const editSelectHold = {
|
||||
single: "编辑",
|
||||
multiple: "编辑选中",
|
||||
all: "编辑所有",
|
||||
label: "编辑单选题",
|
||||
};
|
||||
|
||||
const delSelectHold = {
|
||||
single: "删除",
|
||||
multiple: "删除选中",
|
||||
all: "删除所有",
|
||||
label: "删除单选题",
|
||||
};
|
||||
const EditSelectRef = ref(null);
|
||||
const DelSelectRef = ref(null);
|
||||
const SearchTopicKeyRef = ref(null);
|
||||
const SearchOptionsAKeyRef = ref(null);
|
||||
const SearchOptionsBKeyRef = ref(null);
|
||||
const SearchOptionsCKeyRef = ref(null);
|
||||
const SearchOptionsDKeyRef = ref(null);
|
||||
const SearchAnswerKeyRef = ref(null);
|
||||
const PaginationRef = ref(null);
|
||||
const addChoiceTopicFormRef = ref(null);
|
||||
const editChoiceTopicFormRef = ref(null);
|
||||
const delPasswordOauthRef = ref(null);
|
||||
const dialogSearchVisible = ref(false);
|
||||
const dialogSortVisible = ref(false);
|
||||
const dialogOperationVisible = ref(false);
|
||||
const tableRef = ref();
|
||||
const offsetOff = ref(true);
|
||||
const pageCount = ref(0);
|
||||
const operate = ref("edit");
|
||||
const searchOptions = reactive({
|
||||
topic: "",
|
||||
options_a: "",
|
||||
options_b: "",
|
||||
options_c: "",
|
||||
options_d: "",
|
||||
answer: "",
|
||||
});
|
||||
const sortOptions = reactive({});
|
||||
const tableData = ref([]);
|
||||
let singleData = reactive({});
|
||||
let operateData = reactive({});
|
||||
let operateDataClone = reactive({});
|
||||
const editData = reactive({});
|
||||
|
||||
const showAddForm = () => {
|
||||
addChoiceTopicFormRef.value.dialogVisible = true;
|
||||
};
|
||||
|
||||
const styleShunt = (options, data) => {
|
||||
let nowStyle;
|
||||
options.forEach((item) => {
|
||||
if (data == item.value) {
|
||||
nowStyle = item.style;
|
||||
}
|
||||
});
|
||||
return nowStyle;
|
||||
};
|
||||
|
||||
const labelShunt = (options, data) => {
|
||||
let nowLabel;
|
||||
options.forEach((item) => {
|
||||
if (data == item.value) {
|
||||
nowLabel = item.label;
|
||||
}
|
||||
});
|
||||
return nowLabel;
|
||||
};
|
||||
|
||||
const showTools = (operateType) => {
|
||||
switch (operateType) {
|
||||
case "search":
|
||||
dialogSearchVisible.value = !dialogSearchVisible.value;
|
||||
choiceTopicMsgActive.dialogSearchVisible = dialogSearchVisible.value;
|
||||
break;
|
||||
case "sort":
|
||||
dialogSortVisible.value = !dialogSortVisible.value;
|
||||
choiceTopicMsgActive.dialogSortVisible = dialogSortVisible.value;
|
||||
break;
|
||||
case "operation":
|
||||
dialogOperationVisible.value = !dialogOperationVisible.value;
|
||||
choiceTopicMsgActive.dialogOperationVisible = dialogOperationVisible.value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
const resetOffset = () => {
|
||||
if (hasNullOrEmptyPropertyWithTypeof(searchOptions)) {
|
||||
if (PaginationRef.value.offset !== 1 && offsetOff.value) {
|
||||
PaginationRef.value.handleCurrentChange(1);
|
||||
offsetOff.value = false;
|
||||
}
|
||||
} else {
|
||||
offsetOff.value = true;
|
||||
}
|
||||
};
|
||||
|
||||
const choiceTopicMsg = () => {
|
||||
judgment(searchOptions, "topic", SearchTopicKeyRef.value, "searchMsg");
|
||||
judgment(searchOptions, "options_a", SearchOptionsAKeyRef.value, "searchMsg");
|
||||
judgment(searchOptions, "options_b", SearchOptionsBKeyRef.value, "searchMsg");
|
||||
judgment(searchOptions, "options_c", SearchOptionsCKeyRef.value, "searchMsg");
|
||||
judgment(searchOptions, "options_d", SearchOptionsDKeyRef.value, "searchMsg");
|
||||
judgment(searchOptions, "answer", SearchAnswerKeyRef.value, "searchMsg");
|
||||
resetOffset();
|
||||
const data = {
|
||||
offset: PaginationRef.value == null ? 1 : PaginationRef.value.offset,
|
||||
limit: PaginationRef.value == null ? 10 : PaginationRef.value.limit,
|
||||
searchOptions: searchOptions,
|
||||
sortOptions: sortOptions,
|
||||
};
|
||||
$http.post($url.showChoiceTopic, data).then((res) => {
|
||||
if (res.data.code === 200) {
|
||||
tableData.value = res.data.choiceTopicMsg;
|
||||
tableData.value.forEach((item) => {
|
||||
item.origin_createdAt = item.created_at;
|
||||
item.created_at = moment
|
||||
.utc(item.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY-MM-DD-HH:mm:ss");
|
||||
item.origin_updatedAt = item.updated_at;
|
||||
item.updated_at = moment
|
||||
.utc(item.updated_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY-MM-DD-HH:mm:ss");
|
||||
});
|
||||
PaginationRef.value.dataCount = res.data.count;
|
||||
choiceTopicMsgActive.dataCount = PaginationRef.value.dataCount;
|
||||
pageCount.value = Math.ceil(
|
||||
PaginationRef.value.dataCount / PaginationRef.value.limit
|
||||
);
|
||||
choiceTopicMsgActive.pageCount = pageCount.value;
|
||||
if (!operateData[PaginationRef.value.offset]) return;
|
||||
operateData[PaginationRef.value.offset].forEach((element) => {
|
||||
tableData.value.forEach((item) => {
|
||||
if (item.created_at == element.created_at) {
|
||||
nextTick(() => {
|
||||
tableRef.value.toggleRowSelection(item, true);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
tableData.value = [];
|
||||
ElMessage.error("未查找到相关数据!");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const changePage = (val) => {
|
||||
pageCount.value = Math.ceil(PaginationRef.value.dataCount / val);
|
||||
operateData = {};
|
||||
for (let i = 0; i < pageCount.value; i++) {
|
||||
operateData[i + 1] = [];
|
||||
for (const key in operateDataClone) {
|
||||
operateDataClone[key].forEach((element) => {
|
||||
// 判断数据在第几页
|
||||
if (Math.ceil(element.location / PaginationRef.value.limit) == i + 1) {
|
||||
operateData[i + 1].push(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelectionChange = (val) => {
|
||||
operateData[PaginationRef.value.offset] = val;
|
||||
tableData.value.forEach((item, index) => {
|
||||
operateData[PaginationRef.value.offset].forEach((element) => {
|
||||
if (item.created_at == element.created_at) {
|
||||
// 数据在表格中的位置
|
||||
element.location =
|
||||
(PaginationRef.value.offset - 1) * PaginationRef.value.limit + (index + 1);
|
||||
}
|
||||
});
|
||||
});
|
||||
operateDataClone = JSON.parse(JSON.stringify(operateData));
|
||||
for (const key in operateDataClone) {
|
||||
operateDataClone[key].forEach((item) => {
|
||||
if (item.origin_createdAt) {
|
||||
item.created_at = item.origin_createdAt;
|
||||
}
|
||||
if (item.origin_updatedAt) {
|
||||
item.created_at = item.origin_updatedAt;
|
||||
}
|
||||
delete item.origin_createdAt;
|
||||
delete item.origin_updatedAt;
|
||||
delete item.location;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const showComfirmDialog = (singleMsg) => {
|
||||
singleData = { ...singleMsg.data };
|
||||
singleData.created_at = singleData.origin_createdAt;
|
||||
singleData.updated_at = singleData.origin_updatedAt;
|
||||
delete singleData.origin_createdAt;
|
||||
delete singleData.origin_updatedAt;
|
||||
operate.value = singleMsg.operateType;
|
||||
if (singleMsg.operateType == "edit") {
|
||||
editChoiceTopicFormRef.value.choiceTopicForm({ ...singleMsg.data });
|
||||
editChoiceTopicFormRef.value.operateDialogVisible = true;
|
||||
editChoiceTopicFormRef.value.model = EditSelectRef.value.model;
|
||||
}
|
||||
if (singleMsg.operateType == "del") {
|
||||
delPasswordOauthRef.value.operateDialogVisible = true;
|
||||
}
|
||||
};
|
||||
|
||||
const requestOperate = () => {
|
||||
let operateType, url, model, password;
|
||||
if (operate.value == "edit") {
|
||||
operateType = "编辑";
|
||||
url = $url.editChoiceTopic;
|
||||
model = EditSelectRef.value.model;
|
||||
password = editChoiceTopicFormRef.value.password;
|
||||
} else if (operate.value == "del") {
|
||||
operateType = "删除";
|
||||
url = $url.delChoiceTopic;
|
||||
model = DelSelectRef.value.model;
|
||||
password = delPasswordOauthRef.value.ruleForm.password;
|
||||
}
|
||||
const data = {
|
||||
uid: localStorage.data,
|
||||
model: encrypt(model),
|
||||
password: encrypt(password),
|
||||
requestMsg:
|
||||
model == "single" ? singleData : model == "multiple" ? operateDataClone : "",
|
||||
};
|
||||
if (operate.value == "edit") {
|
||||
data.updateMsg = { ...editChoiceTopicFormRef.value.ruleForm };
|
||||
}
|
||||
$http.post(url, data).then((res) => {
|
||||
if (res.data.code === 200) {
|
||||
tableRef.value.clearSelection();
|
||||
operateData = {};
|
||||
operateDataClone = {};
|
||||
ElMessage({
|
||||
message: `${operateType}成功!`,
|
||||
type: "success",
|
||||
});
|
||||
choiceTopicMsg();
|
||||
} else {
|
||||
ElMessage.error(`${operateType}失败!`);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
defineExpose({ choiceTopicMsg });
|
||||
|
||||
watch(searchOptions, (value) => {
|
||||
choiceTopicMsgActive.searchOptions = value;
|
||||
});
|
||||
|
||||
watch(sortOptions, (value) => {
|
||||
choiceTopicMsgActive.sortOptions = value;
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
pageCount.value = choiceTopicMsgActive.pageCount;
|
||||
dialogSearchVisible.value = choiceTopicMsgActive.dialogSearchVisible;
|
||||
dialogSortVisible.value = choiceTopicMsgActive.dialogSortVisible;
|
||||
dialogOperationVisible.value = choiceTopicMsgActive.dialogOperationVisible;
|
||||
|
||||
if (dialogSearchVisible.value) {
|
||||
searchOptions.topic = choiceTopicMsgActive.searchOptions.topic;
|
||||
searchOptions.options_a = choiceTopicMsgActive.searchOptions.options_a;
|
||||
searchOptions.options_b = choiceTopicMsgActive.searchOptions.options_b;
|
||||
searchOptions.options_c = choiceTopicMsgActive.searchOptions.options_c;
|
||||
searchOptions.options_d = choiceTopicMsgActive.searchOptions.options_d;
|
||||
searchOptions.answer = choiceTopicMsgActive.searchOptions.answer;
|
||||
}
|
||||
|
||||
if (dialogSortVisible.value) {
|
||||
}
|
||||
|
||||
if (dialogOperationVisible.value) {
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
choiceTopicMsg();
|
||||
}, 200);
|
||||
|
||||
setTimeout(() => {
|
||||
if (dialogSearchVisible.value) {
|
||||
SearchTopicKeyRef.value.searchMsg = choiceTopicMsgActive.searchOptions.topic;
|
||||
SearchOptionsAKeyRef.value.searchMsg = choiceTopicMsgActive.searchOptions.options_a;
|
||||
SearchOptionsBKeyRef.value.searchMsg = choiceTopicMsgActive.searchOptions.options_b;
|
||||
SearchOptionsCKeyRef.value.searchMsg = choiceTopicMsgActive.searchOptions.options_c;
|
||||
SearchOptionsDKeyRef.value.searchMsg = choiceTopicMsgActive.searchOptions.options_d;
|
||||
SearchAnswerKeyRef.value.searchMsg = choiceTopicMsgActive.searchOptions.answer;
|
||||
}
|
||||
|
||||
if (dialogSortVisible.value) {
|
||||
}
|
||||
|
||||
if (dialogOperationVisible.value) {
|
||||
}
|
||||
}, 0);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
Reference in New Issue
Block a user