|
|
@@ -0,0 +1,289 @@
|
|
|
+<template>
|
|
|
+ <el-space :fill="true" direction="vertical" class="qr-wrapper" alignment="flex-start" :size="30">
|
|
|
+ <h1>Question Search</h1>
|
|
|
+ <el-input placeholder="请输入内容" v-model="searchContent" @keydown.enter="clickSearch">
|
|
|
+ <template #append>
|
|
|
+ <el-button icon="el-icon-search" @click="clickSearch"></el-button>
|
|
|
+ </template>
|
|
|
+ </el-input>
|
|
|
+ <el-collapse @change="closeCollapse" v-model="isCollapsed">
|
|
|
+ <el-collapse-item :title="collapseItemTitle" name="1">
|
|
|
+ <el-space direction="vertical" alignment="flex-start">
|
|
|
+ <button-filter :title="typeFilter.title" :checkboxOption="typeFilter.option" ref="typeFilter"
|
|
|
+ @filterChange="handleTypeFilter"/>
|
|
|
+ <button-filter :title="levelFilter.title" :checkboxOption="levelFilter.option" ref="levelFilter"
|
|
|
+ @filterChange="handleLevelFilter"/>
|
|
|
+ <search-filter :title="tagFilter.title" :keyword="tagFilter.keyword" ref="tagFilter"
|
|
|
+ @filterChange="handleTagFilter"/>
|
|
|
+ <search-filter :title="knowledgeFilter.title" :keyword="knowledgeFilter.keyword"
|
|
|
+ ref="knowledgeFilter"
|
|
|
+ @filterChange="handleKnowledgeFilter"/>
|
|
|
+ <qr-sorter :option="sorter.option" @dirChange="handleSortDirChange" @stdChange="handleSortStdChange"
|
|
|
+ ref="sorter"/>
|
|
|
+ </el-space>
|
|
|
+ </el-collapse-item>
|
|
|
+ </el-collapse>
|
|
|
+ <!-- 注释-->
|
|
|
+ <el-space direction="vertical">
|
|
|
+ <brief-question-card v-for="(item, index) in currentQuestions" :questionvo="item"
|
|
|
+ :total-num="requiredQuestions.length"
|
|
|
+ :cur-num="index+pagination.size*(pagination.current-1)"/>
|
|
|
+ <el-pagination v-if="requiredQuestions.length!==0" @size-change="handleSizeChange"
|
|
|
+ @current-change="handleCurrentChange"
|
|
|
+ v-model:current-page="pagination.current" :page-sizes="pagination.sizes"
|
|
|
+ v-model:page-size="pagination.size" :layout="pagination.layout"
|
|
|
+ :total="requiredQuestions.length"/>
|
|
|
+ </el-space>
|
|
|
+ </el-space>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import QuestionList from "@/components/QuestionItem/ListItem";
|
|
|
+import ButtonFilter from "@/components/tool/ButtonFilter";
|
|
|
+import Sorter from "@/components/tool/Sorter";
|
|
|
+import BriefQuestionCard from "@/components/card/BriefQuestionCard";
|
|
|
+import SearchFilter from "@/components/tool/SearchFilter";
|
|
|
+import axios from "axios";
|
|
|
+import src from "./srcData"
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: "Search",
|
|
|
+ components: {
|
|
|
+ QuestionList,
|
|
|
+ ButtonFilter,
|
|
|
+ SearchFilter,
|
|
|
+ "qr-sorter": Sorter,
|
|
|
+ BriefQuestionCard
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ searchContent: "",
|
|
|
+
|
|
|
+ // 筛选条件
|
|
|
+ isCollapsed: [],
|
|
|
+ //
|
|
|
+ typeFilter: {
|
|
|
+ title: "题型",
|
|
|
+ group: [],
|
|
|
+ option: src.typeOption,
|
|
|
+ },
|
|
|
+ levelFilter: {
|
|
|
+ title: "难度",
|
|
|
+ group: [],
|
|
|
+ option: src.levelOption,
|
|
|
+ },
|
|
|
+ tagFilter: {
|
|
|
+ title: "Tags",
|
|
|
+ keyword: src.tagKeyword,
|
|
|
+ },
|
|
|
+ knowledgeFilter: {
|
|
|
+ title: "知识点",
|
|
|
+ keyword: src.knowledgeKeyword,
|
|
|
+ },
|
|
|
+ sorter: {
|
|
|
+ option: src.sortOption,
|
|
|
+ },
|
|
|
+
|
|
|
+ // 根据关键词搜索的结果
|
|
|
+ resultQuestions: [],
|
|
|
+ // 经过筛选后的结果
|
|
|
+ requiredQuestions: [],
|
|
|
+
|
|
|
+ // 分页信息
|
|
|
+ pagination: {
|
|
|
+ current: 1,
|
|
|
+ size: 10,
|
|
|
+ layout: "total, sizes, prev, pager, next, jumper",
|
|
|
+ sizes: [5, 10, 20]
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ // 筛选和排序折叠栏的标题
|
|
|
+ collapseItemTitle() {
|
|
|
+ let res = "筛选和排序"
|
|
|
+ if (this.isCollapsed.length) {
|
|
|
+ return res + "(点击收起)"
|
|
|
+ } else {
|
|
|
+ return res + "(点击展开)"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 当前页面展示的问题
|
|
|
+ currentQuestions() {
|
|
|
+ // todo
|
|
|
+ const _this = this
|
|
|
+ let pageIndex = _this.pagination.current - 1
|
|
|
+ let pageSize = _this.pagination.size
|
|
|
+ let start = pageIndex * pageSize
|
|
|
+ let end = Math.min(start + pageSize, _this.requiredQuestions.length)
|
|
|
+ let res = _this.requiredQuestions.slice(start, end)
|
|
|
+ return res
|
|
|
+ },
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ // 展开和收起
|
|
|
+ closeCollapse(val) {
|
|
|
+ if (!val.length) {
|
|
|
+ // this.resetAll()
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 清空筛选条件
|
|
|
+ resetAll() {
|
|
|
+ const _this = this
|
|
|
+ _this.$refs.typeFilter.clearFilter();
|
|
|
+ _this.$refs.levelFilter.clearFilter();
|
|
|
+ _this.$refs.tagFilter.clearFilter();
|
|
|
+ _this.$refs.knowledgeFilter.clearFilter();
|
|
|
+ _this.$refs.sorter.reset();
|
|
|
+ },
|
|
|
+
|
|
|
+ // 处理题型的筛选
|
|
|
+ handleTypeFilter(checkboxGroup) {
|
|
|
+ // todo
|
|
|
+ if (this.resultQuestions.length === 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ console.log(checkboxGroup)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 处理知识点的筛选
|
|
|
+ handleKnowledgeFilter(group) {
|
|
|
+ // todo
|
|
|
+ if (this.resultQuestions.length === 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ console.log(group)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 处理难度的筛选
|
|
|
+ handleLevelFilter(checkboxGroup) {
|
|
|
+ // todo
|
|
|
+ if (this.resultQuestions.length === 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ console.log(checkboxGroup)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 处理排序标准的筛选
|
|
|
+ handleSortStdChange(std) {
|
|
|
+ // todo
|
|
|
+ if (this.resultQuestions.length === 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ console.log(std)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 处理排序顺序的筛选
|
|
|
+ handleSortDirChange(dir) {
|
|
|
+ // todo
|
|
|
+ if (this.resultQuestions.length === 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ console.log(dir)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 处理Tag的筛选
|
|
|
+ handleTagFilter(group) {
|
|
|
+ // todo
|
|
|
+ if (this.resultQuestions.length === 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ console.log(group)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 进行关键词搜索
|
|
|
+ clickSearch() {
|
|
|
+ const _this = this
|
|
|
+ if (_this.searchContent === "") {
|
|
|
+ alert("请输入关键词");
|
|
|
+ } else {
|
|
|
+ this.requestQuestion(this.searchContent, [], [], [], [])
|
|
|
+
|
|
|
+ // todo
|
|
|
+ let typeArray = _this.$refs.typeFilter.checkboxGroup;
|
|
|
+ let levelArray = _this.$refs.levelFilter.checkboxGroup;
|
|
|
+ let tagArray = _this.$refs.tagFilter.checkGroup;
|
|
|
+ let knowledgeArray = _this.$refs.knowledgeFilter.checkGroup;
|
|
|
+ let sortStd = _this.$refs.sorter.standard;
|
|
|
+ let sortDir = _this.$refs.sorter.direction;
|
|
|
+ console.log(typeArray, levelArray, tagArray, knowledgeArray, sortStd, sortDir)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // todo 注释
|
|
|
+ requestQuestion(stem, ...items) {
|
|
|
+ axios.get("/api/api/question", {
|
|
|
+ params: {
|
|
|
+ stem: stem,
|
|
|
+ tags: items[0],
|
|
|
+ type: items[1],
|
|
|
+ weights: items[2],
|
|
|
+ knowledgeId: items[3]
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res);
|
|
|
+ this.resultQuestions = res.data.questions
|
|
|
+ this.$notify({
|
|
|
+ title: '成功',
|
|
|
+ message: '搜索成功',
|
|
|
+ type: 'success'
|
|
|
+ });
|
|
|
+
|
|
|
+ // todo 经过初始筛选条件的处理
|
|
|
+ this.requiredQuestions = this.resultQuestions.map(function (item) {
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ }).catch(err => {
|
|
|
+ console.log(err);
|
|
|
+ this.$notify.error({
|
|
|
+ title: '错误',
|
|
|
+ message: '搜索失败'
|
|
|
+ });
|
|
|
+ }).finally(() => {
|
|
|
+ console.log("search completed!")
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ //
|
|
|
+ handleSizeChange(val) {
|
|
|
+ },
|
|
|
+
|
|
|
+ //
|
|
|
+ handleCurrentChange(val) {
|
|
|
+ },
|
|
|
+ },
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+.el-collapse {
|
|
|
+ border: 1px solid var(--el-collapse-border-color);
|
|
|
+}
|
|
|
+
|
|
|
+.collapse-title {
|
|
|
+ display: flex;
|
|
|
+
|
|
|
+&
|
|
|
+-length {
|
|
|
+ margin-left: auto;
|
|
|
+ margin-right: 14px;
|
|
|
+}
|
|
|
+
|
|
|
+}
|
|
|
+::v-deep .el-collapse-item__content {
|
|
|
+ padding: 0;
|
|
|
+}
|
|
|
+
|
|
|
+::v-deep .el-collapse-item__arrow {
|
|
|
+ margin: 4px 12px 4px 12px;
|
|
|
+}
|
|
|
+
|
|
|
+::v-deep .el-collapse-item__header {
|
|
|
+ /*color: $blue;*/
|
|
|
+ /*height: 40px;*/
|
|
|
+ display: flex;
|
|
|
+ flex-direction: row-reverse;
|
|
|
+ justify-content: flex-end;
|
|
|
+}
|
|
|
+</style>
|