-
Xuaua
+
-
-
-
- {{ useSotr.username }}
+ {{ user.nickname || "用户" }}
+
+
diff --git a/src/main.js b/src/main.js
index bff492a..3817ef1 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,21 +1,26 @@
-import './assets/main.css'
+import { createApp } from 'vue';
+import { createPinia } from 'pinia';
+import ElementPlus from 'element-plus';
+import 'element-plus/dist/index.css';
+import * as ElementPlusIconsVue from '@element-plus/icons-vue';
+import App from './App.vue';
+import router from './router';
+import './assets/main.css';
+import 'swiper/css';
+const app = createApp(App);
-import { createApp } from 'vue'
-import { createPinia } from 'pinia'
-import ElementPlus from 'element-plus'
-import 'element-plus/dist/index.css'
-import App from './App.vue'
-import router from './router'
-// 如果您正在使用CDN引入,请删除下面一行。
-import * as ElementPlusIconsVue from '@element-plus/icons-vue'
+import VueAwesomeSwiper from 'vue-awesome-swiper'
+import 'swiper/swiper-bundle.css'
-const app = createApp(App)
+// import 'swiper/swiper-bundle.css'
+app.use(VueAwesomeSwiper)
+app.use(createPinia());
+app.use(router);
+app.use(ElementPlus);
-app.use(createPinia())
-app.use(router)
-app.use(ElementPlus)
-for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
- app.component(key, component)
-}
+// Register Element Plus icons globally
+Object.entries(ElementPlusIconsVue).forEach(([key, component]) => {
+ app.component(key, component);
+});
-app.mount('#app')
+app.mount('#app');
diff --git a/src/router/index.js b/src/router/index.js
index 22a9963..b05bd9d 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -2,7 +2,7 @@ import { createRouter, createWebHistory,createWebHashHistory } from 'vue-router'
import TokenService from '@/utils/token'
const router = createRouter({
- history: createWebHashHistory(import.meta.env.BASE_URL),
+ history: createWebHashHistory(),
routes: [
{
path: '/',
@@ -18,6 +18,10 @@ const router = createRouter({
path: '/user',
name: 'USER',
component: () => import('@/views/user/index.vue')
+ },
+ {
+ path:"/search",
+ component:()=>import('@/views/search/index.vue')
}
]
})
diff --git a/src/stores/topic.js b/src/stores/topic.js
index 316a6c0..7337049 100644
--- a/src/stores/topic.js
+++ b/src/stores/topic.js
@@ -1,176 +1,261 @@
-import { ref, computed, onMounted } from 'vue'
-import { defineStore } from 'pinia'
-import { getQuestionByTagName ,validationAnswer} from '@/api/question/question'
-import {collect, cancelCollect ,getCollectList} from '@/api/collect/collect'
+import { ref, computed, onMounted } from "vue";
+import { defineStore } from "pinia";
+import {
+ getQuestionByTagName,
+ validationAnswer,
+ getQuestion,
+ answered,
+} from "@/api/question/question";
+import { collect, cancelCollect, getCollectList } from "@/api/collect/collect";
import { ElMessage } from "element-plus";
import "element-plus/theme-chalk/el-message.css";
+import router from "@/router";
+import { ElLoading } from 'element-plus'
// import { fa } from 'element-plus/es/locale';
-export const useTopicStore = defineStore('useTopicStore', () => {
- //当前标签
- const tagName = ref('');
- //当前索引
- const index = ref(1);
- //题目列表
- const Topics=ref([]);
- //当前题目
- const Topic=computed(()=>{
- return Topics.value[index.value-1];
+export const useTopicStore = defineStore("useTopicStore", () => {
+ //当前标签
+ const tagName = ref("");
+ //当前索引
+ const index = ref(0);
+ //题目列表
+ const Topics = ref([]);
+ //当前题目
+ const Topic = computed(() => {
+ return Topics.value[index.value - 1];
+ });
+ //收藏列表
+ const collectTopics = ref([]);
+ //收藏列表id
+ const collectTopicIds = computed(() => {
+ return collectTopics.value.map((item) => item.id);
+ });
+ const count = computed(() => Topics.value.length);
+ const init = () => {
+ index.value = 0;
+ if (Topics.value.length == 0) {
+ CollectList();
+ getData();
+ console.log("刷新数据");
+ } else {
+ console.log("已存在");
+ }
+ };
+
+ const setQuestion = (question) => {
+ CollectList();
+ Topics.value = [];
+ Topic.value = question;
+ Topics.value.push({
+ ...question,
+ isCollect: collectTopicIds.value.includes(question.id),
});
- //收藏列表
- const collectTopics=ref([]);
- //收藏列表id
- const collectTopicIds=computed(()=>{
- return collectTopics.value.map(item=>item.id);
- })
- const count = computed(()=>Topics.value.length);
- const init=()=>{
- if(Topics.value.length==0){
- CollectList();
- getData();
- console.log("刷新数据");
- }else{
- console.log("已存在");
- }
-
- }
- //设置标签
- const setTagName=(name)=>{
- tagName.value=name;
- }
- //根据传入标签情况判断是刷新还是加载
- const loadData=async(name)=>{
- if(name===tagName.value){
- await getData();
- }else{
- setTagName(name)
- await refresh();
- }
- }
- //刷新
- const refresh=async()=>{
- clear();
- let res=await getQuestionByTagName(tagName.value);
- if(res.code==200){
- res.data=res.data.map(e=>{
- return {
- ...e,
- isCollect:collectTopicIds.value.includes(e.id),
+ };
- }})
- Topics.value=res.data;
- index.value=Topics.value.length>0?1:0;
- }
+ const setQuestions = (questions,item) => {
+ CollectList();
+ index.value =0
+ Topics.value = [];
+ Topic.value = item;
+ questions.forEach(e => {
+ Topics.value.push({
+ ...e,
+ isCollect: collectTopicIds.value.includes(e.id),
+ });
+ });
+
+ };
+ //获取题目
+ //设置标签
+ const setTagName = (name) => {
+ tagName.value = name;
+ };
+ //根据传入标签情况判断是刷新还是加载
+ const loadData = async (name) => {
+ if (name === tagName.value) {
+ await getData();
+ } else {
+ setTagName(name);
+ await refresh();
}
- //加载数据
- const getData=async()=>{
- let res=await getQuestionByTagName(tagName.value);
- if(res.code==200){
- res.data=res.data.map(e=>{
- return {
- ...e,
- isCollect:collectTopicIds.value.includes(e.id),
-
- }})
- Topics.value=[...Topics.value,...res.data];
- }
+ };
+ //刷新
+ const refresh = async () => {
+ clear();
+ let res = await getQuestion("refresh");
+ if (res.code == 200) {
+ if (res.data.length == 0) {
+ ElMessage({ message: "题库为空你已经打完所有题目", type: "warning" });
+ return;
+ }
+ res.data = res.data.map((e) => {
+ return {
+ ...e,
+ // isCollect: collectTopicIds.value.includes(e.id),
+ };
+ });
+ Topics.value = res.data;
+ index.value = Topics.value.length > 0 ? 1 : 0;
}
- //清空数据
- const clear=()=>{
- index.value=0;
- Topics.value=[];
- collectTopics.value=[];
-
- }
- //提交答案
- const submitAnswer=async(answer)=>{
- //先判断是否已经答过
- // if(Topic.value.isAnswer){
- // ElMessage({ message: "已经做过了", type: "warning" });
- // return;
- // }
- console.log(Topic.value)
- let res=await validationAnswer({questionId:Topic.value.id,answer});
- console.log(res);
- if(res.code==200){
- setAnswer({
- isAnswer:true,
- analysis:res.data.analysis,
- correctAnswer:res.data.correctAnswer?res.data.correctAnswer:answer,
- correct:res.data.correct,
- userAnswer:answer
- });
- }
+ };
+ //加载数据
+ const getData = async () => {
+ const loadingInstance = ElLoading.service()
+ let res = await getQuestion();
+ if (res.code == 200) {
+ if (res.data.length == 0) {
+ ElMessage({ message: "题库为空你已经打完所有题目", type: "warning" });
+ res.data = [
+ {
+ id: 0,
+ question: "没有题目了",
+ analysis: "没有题目了",
+ correctAnswer: "没有题目了",
+ correct: false,
+ userAnswer: "没有题目了",
+ isAnswer: false,
+ isCollect: false,
+ },
+ ];
+ }
+ res.data = res.data.map((e) => {
+ return {
+ ...e,
+ // isCollect: collectTopicIds.value.includes(e.id),
+ };
+ });
+ Topics.value = [...Topics.value, ...res.data];
+ loadingInstance.close()
}
- //设置答题情况
- const setAnswer=({isAnswer,analysis,userAnswer,correctAnswer,correct})=>{
- Topics.value[index.value-1]={
- ...Topic.value,
- isAnswer,
- analysis,
- correctAnswer,
- correct,
- userAnswer
- }
+ };
+ //清空数据
+ const clear = () => {
+ index.value = 0;
+ Topics.value = [];
+ collectTopics.value = [];
+ };
+ //提交答案
+ const submitAnswer = async (answer) => {
+ //先判断是否已经答过
+ // if(Topic.value.isAnswer){
+ // ElMessage({ message: "已经做过了", type: "warning" });
+ // return;
+ // }
+ // console.log(Topic.value);
+ // let res = await validationAnswer({ questionId: Topic.value.id, answer });
+ // console.log(res);
+ // if (res.code == 200) {
+ // setAnswer({
+ // isAnswer: true,
+ // analysis: res.data.analysis,
+ // correctAnswer: res.data.correctAnswer ? res.data.correctAnswer : answer,
+ // correct: res.data.correct,
+ // userAnswer: answer,
+ // });
+ // }
+ let res = await answered(Topic.value.id);
+ ElMessage({ message: res.msg, type: "info" });
+ refresh();
+ };
+ //设置答题情况
+ const setAnswer = ({
+ isAnswer,
+ analysis,
+ userAnswer,
+ correctAnswer,
+ correct,
+ }) => {
+ Topics.value[index.value - 1] = {
+ ...Topic.value,
+ isAnswer,
+ analysis,
+ correctAnswer,
+ correct,
+ userAnswer,
+ };
+ };
+ //收藏题目
+ const Collect = async () => {
+ console.log("执行");
+ let res;
+ if (isCollect()) {
+ res = await cancelCollect(Topic.value.id);
+ if (res.code == 200) {
+ ElMessage({ message: "取消收藏", type: "info" });
+ Topics.value[index.value - 1].isCollect = false;
+ }
+ } else {
+ res = await collect(Topic.value.id);
+ if (res.code == 200) {
+ ElMessage({ message: "收藏成功", type: "info" });
+ Topics.value[index.value - 1].isCollect = true;
+ }
}
- //收藏题目
- const Collect=async()=>{
- console.log("执行")
- let res;
- if(isCollect()){
- res=await cancelCollect(Topic.value.id);
- if(res.code==200){
- ElMessage({ message: "取消收藏", type: "info" });
- Topics.value[index.value-1].isCollect=false;
- }
- }else{
- res= await collect(Topic.value.id);
- if(res.code==200){
- ElMessage({ message: "收藏成功", type: "info" });
- Topics.value[index.value-1].isCollect=true;
- }
- }
- await CollectList();
+ await CollectList();
+ };
+ //上一题
+ const prev = () => {
+ if (index.value >= 1) {
+ index.value--;
+ return true;
}
- //上一题
- const prev=()=>{
- if(index.value>=1){
- index.value--;
- return true;
- }
- return false;
+ return false;
+ };
+ //下一题
+ const next = () => {
+ index.value++;
+ if (index.value > count.value) {
+ index.value = count.value;
+ return false;
}
- //下一题
- const next=()=>{
- index.value++;
- if(index.value>count.value){
- index.value=count.value;
- return false;
- }
- if(index.value==count.value){
- getData();
- }
- return true;
+ const type = router.currentRoute.value.query.type;
+ if (type == "view") {
+ return true;
}
- //获取收藏题目列表
- const CollectList=async()=>{
- let res=await getCollectList();
- if(res.code==200){
- collectTopics.value=res.data.map(item=>item.questionVo);
- }
+ if (index.value == count.value) {
+ getData();
}
- //判断是否收藏
- const isCollect=()=>{
- if(count.value==0){
- return false;
- }
- console.log("123",Topic.value,index.value)
- return collectTopicIds.value.includes(Topic.value.id);
+ return true;
+ };
+ //获取收藏题目列表
+ const CollectList = async () => {
+ let res = await getCollectList();
+ if (res.code == 200) {
+ collectTopics.value = res.data.map((item) => item.questionVo);
}
- onMounted(()=>{
- init();
- })
- return { index, Topics, count,collectTopics ,collectTopicIds,Topic,
- setAnswer,loadData,setTagName,refresh,submitAnswer,Collect,isCollect,clear,getData,
- prev,next,CollectList,init}
-})
+ };
+ //判断是否收藏
+ const isCollect = () => {
+ if (count.value == 0) {
+ return false;
+ }
+ console.log("123", Topic.value, index.value);
+ return collectTopicIds.value.includes(Topic.value.id);
+ };
+ // onMounted(() => {
+ // init();
+ // });
+ return {
+ index,
+ Topics,
+ count,
+ collectTopics,
+ collectTopicIds,
+ Topic,
+ setAnswer,
+ loadData,
+ setTagName,
+ refresh,
+ submitAnswer,
+ Collect,
+ isCollect,
+ clear,
+ getData,
+ prev,
+ next,
+ CollectList,
+ init,
+ setQuestion,
+ setQuestions
+ };
+});
diff --git a/src/stores/user.js b/src/stores/user.js
index be9df71..e89daa8 100644
--- a/src/stores/user.js
+++ b/src/stores/user.js
@@ -1,27 +1,24 @@
-import { ref, onMounted } from 'vue'
+import { ref, onMounted, reactive } from 'vue'
import { defineStore } from 'pinia'
import { getUserInfo } from '../api/user/user'
-export const useUserStore = defineStore('useUserStore', () => {
- //用户头像
- const avatar = ref('')
- const username = ref('')
- //手机号
- const phone = ref('')
- //备注
- const remark = ref('')
- //获取用户信息
- const UserInfo = async() => {
- let res= await getUserInfo();
- console.log("用户信息",res)
- if(res.code==200){
- avatar.value=res.data.avatar;
- username.value=res.data.username;
- phone.value=res.data.phone;
- remark.value=res.data.remark;
+// export const useUserStore = defineStore('useUserStore', () => {
+// state: () => ({
+// user:{}
+// }),
+// actions: {
+
+// },
+// })
+
+export const useUserStore = defineStore('useUserStore', {
+ state: () => ({
+ user:{}
+ }),
+ actions: {
+ UserInfo(){
+ getUserInfo().then(res => {
+ this.user = res.data
+ })
}
- }
- onMounted(()=>{
- UserInfo();
- })
- return { avatar, username,phone,remark,UserInfo}
-})
+ },
+})
\ No newline at end of file
diff --git a/src/views/home/index.vue b/src/views/home/index.vue
index a470f56..07c5253 100644
--- a/src/views/home/index.vue
+++ b/src/views/home/index.vue
@@ -1,76 +1,84 @@
-