index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <div class="collection-box">
  3. <van-nav-bar title="错题收藏" left-arrow @click-left="onClickLeft" placeholder> </van-nav-bar>
  4. <div>
  5. <img class="collectionHeader" :src="collectionHeader" />
  6. </div>
  7. <div class="choose">
  8. <div @click="goExercise('wrong')" class="choose-img">
  9. <span class="choose-text1"> 做错题 </span>
  10. <span class="choose-text2"> 共 {{ wrongList.length }} 题 </span>
  11. <img class="" :src="wrongBg" />
  12. <img class="goArrow" :src="goArrow" />
  13. <button @click="clearTopicsWrong" style="color: #498ef5" class="clear">清空错题</button>
  14. <button
  15. @click.stop="
  16. () => {
  17. wrongSyncVisible = true;
  18. }
  19. "
  20. style="color: #498ef5; left: 60vw"
  21. class="clear">
  22. 同步错题
  23. </button>
  24. </div>
  25. <div @click="goExercise('collection')" class="choose-img">
  26. <span class="choose-text1">收藏题</span>
  27. <span class="choose-text2"> 共 {{ collectionList.length }} 题 </span>
  28. <img class="" :src="collectionBg" />
  29. <img class="goArrow" :src="goArrow" />
  30. <button @click="clearTopicsCollection" style="color: #01c18d" class="clear">清空收藏</button>
  31. <button
  32. @click.stop="
  33. () => {
  34. collectSyncVisible = true;
  35. }
  36. "
  37. style="color: #01c18d; left: 60vw"
  38. class="clear">
  39. 同步收藏
  40. </button>
  41. </div>
  42. </div>
  43. <div class="bottom">
  44. <img :src="collectionBottomBg" />
  45. </div>
  46. <van-popup position="bottom" v-model:show="wrongSyncVisible">
  47. <van-picker
  48. @cancel="
  49. () => {
  50. wrongSyncVisible = false;
  51. }
  52. "
  53. :columns="['合并本机和云端错题', '备份本机收藏到错题', '恢复云端收藏到错题']"></van-picker>
  54. </van-popup>
  55. <van-popup position="bottom" v-model:show="collectSyncVisible">
  56. <van-picker
  57. @cancel="
  58. () => {
  59. collectSyncVisible = false;
  60. }
  61. "
  62. :columns="['合并本机和云端收藏', '备份本机收藏到云端', '恢复云端收藏到本机']"></van-picker>
  63. </van-popup>
  64. <!-- <listCom type="wrong"></listCom> -->
  65. <!-- <van-swipe ref="swiper" :show-indicators="false" :touchable="false">
  66. <van-swipe-item> <listCom type="wrong" /> </van-swipe-item>
  67. <van-swipe-item> <listCom type="collection" /> </van-swipe-item>
  68. </van-swipe> -->
  69. </div>
  70. </template>
  71. <script setup lang="ts">
  72. import { ref, onMounted } from "vue";
  73. import { useRouter, useRoute } from "vue-router";
  74. import listCom from "./components/list.vue";
  75. import collectionHeader from "@/assets/img/collectionHeader.png";
  76. import collectionBg from "@/assets/img/collectionBg.png";
  77. import wrongBg from "@/assets/img/wrongBg.png";
  78. import collectionBottomBg from "@/assets/img/collectionBottomBg.png";
  79. import goArrow from "@/assets/img/goArrow.png";
  80. import { CollectionModel } from "@/model/collection";
  81. import { CollectionAndWrong } from "@/api/index";
  82. import { Dialog } from "vant";
  83. import { RouterBus } from "@/hooks";
  84. const router = useRouter();
  85. const query = useRoute().query;
  86. const wrongList = ref<CollectionAndWrongType.Question[]>([]);
  87. const collectionList = ref<CollectionAndWrongType.Question[]>([]);
  88. onMounted(() => {
  89. let wrongModel = new CollectionAndWrong("wrong");
  90. wrongModel
  91. .getList({
  92. km: router.currentRoute.value.query.subject === "1" ? "科目一" : "科目四",
  93. carType: router.currentRoute.value.query.vehicle as CollectionAndWrongType.CarType,
  94. })
  95. .then((res) => {
  96. wrongList.value = res.rows;
  97. });
  98. let collectionModel = new CollectionAndWrong("collection");
  99. collectionModel
  100. .getList({
  101. km: router.currentRoute.value.query.subject === "1" ? "科目一" : "科目四",
  102. carType: router.currentRoute.value.query.vehicle as CollectionAndWrongType.CarType,
  103. })
  104. .then((res) => {
  105. collectionList.value = res.rows;
  106. });
  107. });
  108. const onClickLeft = () => {
  109. router.back();
  110. };
  111. const {
  112. router: { push },
  113. } = new RouterBus();
  114. const gsMap: {
  115. xc: string;
  116. hc: string;
  117. kc: string;
  118. mtc: string;
  119. } = {
  120. xc: "小车",
  121. hc: "货车",
  122. kc: "客车",
  123. mtc: "摩托车",
  124. };
  125. const clearTopicsCollection = (e: PointerEvent) => {
  126. e.preventDefault();
  127. e.stopPropagation();
  128. let collectionModel = new CollectionModel("collection");
  129. Dialog.confirm({
  130. title: "清除收藏",
  131. message: "是否清除收藏",
  132. })
  133. .then(() => {
  134. // on confirm
  135. collectionModel
  136. .deleteAll({
  137. km: router.currentRoute.value.query.subject === "1" ? "科目一" : "科目四",
  138. carType: gsMap[router.currentRoute.value.query.gs] as CollectionAndWrongType.CarType,
  139. })
  140. .then((res) => {
  141. Dialog.alert({ message: "清除成功" });
  142. let collectionModel = new CollectionAndWrong("collection");
  143. collectionModel
  144. .getList({
  145. km: router.currentRoute.value.query.subject === "1" ? "科目一" : "科目四",
  146. carType: router.currentRoute.value.query.vehicle as CollectionAndWrongType.CarType,
  147. })
  148. .then((res) => {
  149. collectionList.value = res.rows;
  150. });
  151. });
  152. })
  153. .catch(() => {
  154. // on cancel
  155. });
  156. };
  157. const clearTopicsWrong = (e: PointerEvent) => {
  158. e.preventDefault();
  159. e.stopPropagation();
  160. let collectionModel = new CollectionModel("wrong");
  161. Dialog.confirm({
  162. title: "清除错题",
  163. message: "是否清除错题",
  164. })
  165. .then(() => {
  166. // on confirm
  167. collectionModel
  168. .deleteAll({
  169. km: router.currentRoute.value.query.subject === "1" ? "科目一" : "科目四",
  170. carType: router.currentRoute.value.query.vehicle as CollectionAndWrongType.CarType,
  171. })
  172. .then((res) => {
  173. Dialog.alert({ message: "清除成功" });
  174. let wrongModel = new CollectionAndWrong("wrong");
  175. wrongModel
  176. .getList({
  177. km: router.currentRoute.value.query.subject === "1" ? "科目一" : "科目四",
  178. carType: router.currentRoute.value.query.vehicle as CollectionAndWrongType.CarType,
  179. })
  180. .then((res) => {
  181. wrongList.value = res.rows;
  182. });
  183. });
  184. })
  185. .catch(() => {
  186. // on cancel
  187. });
  188. };
  189. const goExercise = (type: string) => {
  190. switch (type) {
  191. case "wrong":
  192. if (wrongList.value.length == 0) {
  193. Dialog.alert({ title: "没有题目" });
  194. return;
  195. }
  196. push({
  197. name: "wrongExercise",
  198. query: {
  199. ...query,
  200. title: "错题",
  201. },
  202. });
  203. break;
  204. case "collection":
  205. if (collectionList.value.length == 0) {
  206. Dialog.alert({ title: "没有题目" });
  207. return;
  208. }
  209. push({
  210. name: "collectionExercise",
  211. query: {
  212. ...query,
  213. title: "收藏",
  214. },
  215. });
  216. break;
  217. default:
  218. break;
  219. }
  220. };
  221. const isType = ref(0); //0错题 1收藏
  222. const swiper = ref();
  223. const wrongSyncVisible = ref(false);
  224. const collectSyncVisible = ref(false);
  225. </script>
  226. <style lang="scss" scoped>
  227. .bottom {
  228. bottom: 0;
  229. img {
  230. width: 100%;
  231. }
  232. }
  233. .choose {
  234. width: 100%;
  235. display: flex;
  236. justify-content: center;
  237. flex-wrap: wrap;
  238. transform: translate(0%, -8%);
  239. .choose-img {
  240. width: 92%;
  241. position: relative;
  242. .clear {
  243. background: #fff;
  244. border-radius: 15px;
  245. position: absolute;
  246. bottom: 20px;
  247. width: 100px;
  248. height: 30px;
  249. left: 20px;
  250. bottom: 20px;
  251. border: 0;
  252. font-size: 13px;
  253. }
  254. .goArrow {
  255. position: absolute;
  256. top: 32px;
  257. right: 20px;
  258. width: 73px;
  259. }
  260. .choose-text1 {
  261. position: absolute;
  262. font-size: 25px;
  263. color: #fff;
  264. left: 20px;
  265. top: 20px;
  266. }
  267. .choose-text2 {
  268. position: absolute;
  269. top: 56px;
  270. left: 22px;
  271. font-size: 25px;
  272. color: #fff;
  273. }
  274. img {
  275. width: 100%;
  276. }
  277. }
  278. }
  279. .collectionHeader {
  280. width: 100%;
  281. }
  282. .collection-box {
  283. height: 100vh;
  284. display: flex;
  285. flex-direction: column;
  286. }
  287. .title {
  288. display: flex;
  289. width: 130px;
  290. justify-content: space-between;
  291. align-items: center;
  292. span {
  293. font-size: 15px;
  294. font-family: PingFang SC;
  295. font-weight: 400;
  296. line-height: 13px;
  297. color: #0a1a33;
  298. position: relative;
  299. padding: 8px;
  300. }
  301. .active {
  302. &:after {
  303. position: absolute;
  304. content: "";
  305. width: 20px;
  306. height: 4px;
  307. border-radius: 3px;
  308. background-color: #498ef5;
  309. bottom: 0;
  310. left: 50%;
  311. transform: translateX(-50%);
  312. z-index: 100;
  313. }
  314. }
  315. }
  316. </style>