diff --git a/.env.development b/.env.development index 671589d..588a97c 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,2 @@ # VITE_APP_BASE_API = 'http://127.0.0.1:8088' -VITE_APP_BASE_API = 'http://aw.9miao.fun/prod-api' \ No newline at end of file +VITE_APP_BASE_API = 'https://xuaua.com/prod-api' \ No newline at end of file diff --git a/.env.production b/.env.production index 38492bc..0f866b8 100644 --- a/.env.production +++ b/.env.production @@ -1 +1 @@ -VITE_APP_BASE_API = 'http://aw.9miao.fun/prod-api' \ No newline at end of file +VITE_APP_BASE_API = 'https://xuaua.com/prod-api' \ No newline at end of file diff --git a/index.html b/index.html index afbe082..aa1a2de 100644 --- a/index.html +++ b/index.html @@ -2,10 +2,10 @@ - + - Vite App + Xuaxua
diff --git a/package-lock.json b/package-lock.json index 42f6580..3bf9138 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,9 @@ "axios": "^1.7.2", "element-plus": "^2.7.7", "pinia": "^2.1.7", + "swiper": "^8.4.7", "vue": "^3.4.29", + "vue-awesome-swiper": "^5.0.1", "vue-router": "^4.3.3" }, "devDependencies": { @@ -1371,6 +1373,14 @@ "node": ">=6.0.0" } }, + "node_modules/dom7": { + "version": "4.0.6", + "resolved": "https://registry.npmmirror.com/dom7/-/dom7-4.0.6.tgz", + "integrity": "sha512-emjdpPLhpNubapLFdjNL9tP06Sr+GZkrIHEXLWvOGsytACUrkbeIdjO5g77m00BrHTznnlcNqgmn7pCN192TBA==", + "dependencies": { + "ssr-window": "^4.0.0" + } + }, "node_modules/element-plus": { "version": "2.7.7", "resolved": "https://registry.npmjs.org/element-plus/-/element-plus-2.7.7.tgz", @@ -2654,6 +2664,11 @@ "node": ">=0.10.0" } }, + "node_modules/ssr-window": { + "version": "4.0.2", + "resolved": "https://registry.npmmirror.com/ssr-window/-/ssr-window-4.0.2.tgz", + "integrity": "sha512-ISv/Ch+ig7SOtw7G2+qkwfVASzazUnvlDTwypdLoPoySv+6MqlOV10VwPSE6EWkGjhW50lUmghPmpYZXMu/+AQ==" + }, "node_modules/strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", @@ -2702,6 +2717,29 @@ "node": ">=8" } }, + "node_modules/swiper": { + "version": "8.4.7", + "resolved": "https://registry.npmmirror.com/swiper/-/swiper-8.4.7.tgz", + "integrity": "sha512-VwO/KU3i9IV2Sf+W2NqyzwWob4yX9Qdedq6vBtS0rFqJ6Fa5iLUJwxQkuD4I38w0WDJwmFl8ojkdcRFPHWD+2g==", + "funding": [ + { + "type": "patreon", + "url": "https://www.patreon.com/swiperjs" + }, + { + "type": "open_collective", + "url": "http://opencollective.com/swiper" + } + ], + "hasInstallScript": true, + "dependencies": { + "dom7": "^4.0.4", + "ssr-window": "^4.0.2" + }, + "engines": { + "node": ">= 4.7.0" + } + }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -3016,6 +3054,15 @@ } } }, + "node_modules/vue-awesome-swiper": { + "version": "5.0.1", + "resolved": "https://registry.npmmirror.com/vue-awesome-swiper/-/vue-awesome-swiper-5.0.1.tgz", + "integrity": "sha512-mWjFJzUqA4lG+DmsmibvMpoiBnl+IH2SSeiiQ3i5M0t1y9FknTxnGT0DsMb2YdJLgjYMEK3sYOWzqgLnZMH8Lg==", + "peerDependencies": { + "swiper": "^7.0.0 || ^8.0.0", + "vue": "3.x" + } + }, "node_modules/vue-eslint-parser": { "version": "9.4.3", "resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-9.4.3.tgz", diff --git a/package.json b/package.json index 253a77f..f707f25 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "vite", - "build:prod": "vite build", + "build:prod": "vite build", "preview": "vite preview", "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore" }, @@ -14,7 +14,9 @@ "axios": "^1.7.2", "element-plus": "^2.7.7", "pinia": "^2.1.7", + "swiper": "^8.4.7", "vue": "^3.4.29", + "vue-awesome-swiper": "^5.0.1", "vue-router": "^4.3.3" }, "devDependencies": { diff --git a/src/App.vue b/src/App.vue index 9fa8904..6ace223 100644 --- a/src/App.vue +++ b/src/App.vue @@ -8,4 +8,7 @@ import { RouterView } from 'vue-router' diff --git a/src/api/question/question.js b/src/api/question/question.js index 193a232..2651943 100644 --- a/src/api/question/question.js +++ b/src/api/question/question.js @@ -1,4 +1,5 @@ import http from "@/utils/http"; +import keyboard from "uview-ui/libs/config/props/keyboard"; //获取题目 export const getQuestion= (type)=>{ if(type==null||type==undefined){ @@ -47,3 +48,20 @@ export const validationAnswer = ({questionId,answer})=>{ } }) } +export const answered = (questionId)=>{ + return http({ + url:"/question/answered", + method:"get", + params:{ + questionId + } + }) +} + +export const searchQuestion = (data)=>{ + return http({ + url:"/search", + method:"get", + params:data + }) +} \ No newline at end of file diff --git a/src/components/TopicBox.vue b/src/components/TopicBox.vue index f2e2df0..aeb2464 100644 --- a/src/components/TopicBox.vue +++ b/src/components/TopicBox.vue @@ -1,16 +1,22 @@ \ No newline at end of file + diff --git a/src/components/VideoBox.vue b/src/components/VideoBox.vue index 06fdd62..bb65208 100644 --- a/src/components/VideoBox.vue +++ b/src/components/VideoBox.vue @@ -1,6 +1,7 @@ + + 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 @@ + diff --git a/src/views/user/index.vue b/src/views/user/index.vue index 18e7298..2d31ecf 100644 --- a/src/views/user/index.vue +++ b/src/views/user/index.vue @@ -1,7 +1,7 @@ + + - + \ No newline at end of file diff --git a/vite.config.js b/vite.config.js index 865b944..962621d 100644 --- a/vite.config.js +++ b/vite.config.js @@ -22,6 +22,7 @@ export default defineConfig({ resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) + } } })