index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <view class="ezy-cuoti-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="handleBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">我的错题</text>
  6. </view>
  7. <view class="cuoti-border-box">
  8. <uni-segmented-control :current="data.current" :values="data.items" active-color="#3A7FE9"
  9. @clickItem="onChangeTab" class="cuo-tab-box" />
  10. <view class="cuoti-content-box">
  11. <view v-if="data.current === 0">
  12. <scroll-view style="height: 300px;" scroll-y="true" refresher-enabled="true"
  13. :refresher-triggered="data.shuxue.loading" :refresher-threshold="50"
  14. refresher-background="lightgreen" @refresherrefresh="onRefresh" @refresherrestore="onRestore"
  15. @refresherabort="onAbort">
  16. <!--数学-->
  17. <uni-list>
  18. <uni-list-item v-for="item in data.shuxue.list">
  19. <template v-slot:body>
  20. <view class="slot-box">
  21. <!-- 时间 -->
  22. <text class="slot-text">日期{{ item.date }}</text>
  23. <!-- 数量 -->
  24. <text class="slot-text">错题数:{{ item.count }}题</text>
  25. <button @click="getCuotiData(item)">查看错题</button>
  26. </view>
  27. </template>
  28. </uni-list-item>
  29. <uni-load-more :status="data.shuxue.state" @click="getMore(0)"
  30. :contentText="data.shuxue.contentText"></uni-load-more>
  31. </uni-list>
  32. </scroll-view>
  33. </view>
  34. <view v-if="data.current === 1">
  35. <!--英语-->
  36. <uni-list>
  37. <uni-list-item v-for="item in data.yingyu.list">
  38. <template v-slot:body>
  39. <view class="slot-box">
  40. {{ item }}
  41. <text class="slot-text">title</text>
  42. <text class="slot-text">date</text>
  43. <text class="slot-text">wrong</text>
  44. <button>查看错题</button>
  45. </view>
  46. </template>
  47. </uni-list-item>
  48. <uni-load-more :status="data.yingyu.state" @click="getMore(1)"
  49. :contentText="data.yingyu.contentText"></uni-load-more>
  50. </uni-list>
  51. </view>
  52. </view>
  53. </view>
  54. <cuoti ref="wrongRef" :list="data.wrongList" @back="handleBackFromCuoti"></cuoti>
  55. </view>
  56. </template>
  57. <script setup>
  58. import {
  59. reactive,
  60. ref
  61. } from "vue";
  62. import {
  63. getWrongData
  64. } from "@/api/wrong";
  65. import {
  66. onLoad
  67. } from "@dcloudio/uni-app";
  68. import cuoti from "@/components/chengji/chengji.vue";
  69. import {
  70. getWrongInfo
  71. } from "@/api/wrong";
  72. const wrongRef = ref(null);
  73. const data = reactive({
  74. items: ['数学', '英语'],
  75. current: 0,
  76. shuxue: {
  77. page: 0,
  78. list: [],
  79. loading: false,
  80. state: 'more',
  81. state_text: '加载更多'
  82. },
  83. yingyu: {
  84. page: 0,
  85. list: [],
  86. loading: false,
  87. state: 'more',
  88. state_text: '加载更多'
  89. },
  90. wrongList: [],
  91. })
  92. function handleBack() {
  93. uni.redirectTo({
  94. url: '/pages/my/index'
  95. })
  96. }
  97. function handleBackFromCuoti() {
  98. wrongRef.value.closePopup();
  99. }
  100. function onChangeTab(e) {
  101. if (data.current !== e.currentIndex) {
  102. data.current = e.currentIndex;
  103. if (data.current == 0) {
  104. data.shuxue.page = 0
  105. } else if (data.current == 1) {
  106. data.yingyu.page = 0
  107. }
  108. refreshData(data.current);
  109. }
  110. }
  111. function refreshData(code) {
  112. const opt = {
  113. page: 1,
  114. size: 10, // 固定查询10条
  115. cardId: data.current + 1 // 前台索引加1为学科cardId
  116. }
  117. if (code == 0) {
  118. data.shuxue.list = [];
  119. // 数学
  120. data.shuxue.state = 'loading';
  121. data.shuxue.page++;
  122. opt.page = data.shuxue.page;
  123. } else if (code == 1) {
  124. data.yingyu.list = [];
  125. // 英语
  126. data.yingyu.state = 'loading';
  127. data.yingyu.page++;
  128. opt.page = data.yingyu.page;
  129. }
  130. getWrongData(opt).then(res => {
  131. if (code == 0) {
  132. data.shuxue.list = data.shuxue.list.concat(res.data.data);
  133. data.shuxue.loading = false;
  134. } else if (code == 1) {
  135. data.yingyu.list = data.yingyu.list.concat(res.data.data);
  136. data.yingyu.loading = false;
  137. }
  138. if (code == 0) {
  139. if (res.data.total >= data.shuxue.list.length) {
  140. // 数学
  141. data.shuxue.state = 'no-more';
  142. data.shuxue.state_text = '没有更多啦';
  143. data.shuxue.loading = false;
  144. } else {
  145. // 数学
  146. data.shuxue.state = 'more';
  147. data.shuxue.state_text = '加载更多';
  148. data.shuxue.loading = false;
  149. }
  150. } else if (code == 1) {
  151. if (res.data.total >= data.yingyu.list.length) {
  152. // 英语
  153. data.yingyu.state = 'no-more';
  154. data.yingyu.state_text = '没有更多啦';
  155. data.yingyu.loading = false;
  156. } else {
  157. // 英语
  158. data.yingyu.state = 'more';
  159. data.yingyu.state_text = '加载更多';
  160. data.yingyu.loading = false;
  161. }
  162. }
  163. }).catch(err => {
  164. if (code == 0) {
  165. // 数学
  166. data.shuxue.state = 'more';
  167. data.shuxue.state_text = '加载更多';
  168. data.shuxue.loading = false;
  169. } else if (code == 1) {
  170. // 英语
  171. data.yingyu.state = 'more';
  172. data.yingyu.state_text = '加载更多';
  173. data.yingyu.loading = false;
  174. }
  175. })
  176. }
  177. function getMore(code) {
  178. const opt = {
  179. page: 1,
  180. size: 10, // 固定查询10条
  181. cardId: data.current + 1 // 前台索引加1为学科cardId
  182. }
  183. if (code == 0) {
  184. if (data.shuxue.state == 'no-more' && !refresh) return;
  185. // 数学
  186. data.shuxue.state = 'loading';
  187. data.shuxue.page++;
  188. opt.page = data.shuxue.page;
  189. } else if (code == 1) {
  190. // 英语
  191. if (data.yingyu.state == 'no-more' && !refresh) return;
  192. data.yingyu.state = 'loading';
  193. data.yingyu.page++;
  194. opt.page = data.yingyu.page;
  195. }
  196. getWrongData(opt).then(res => {
  197. if (code == 0) {
  198. data.shuxue.list = data.shuxue.list.concat(res.data.data);
  199. data.shuxue.loading = false;
  200. } else if (code == 1) {
  201. data.yingyu.list = data.yingyu.list.concat(res.data.data);
  202. data.yingyu.loading = false;
  203. }
  204. if (code == 0) {
  205. if (res.data.total >= data.shuxue.list.length) {
  206. // 数学
  207. data.shuxue.state = 'no-more';
  208. data.shuxue.state_text = '没有更多啦';
  209. data.shuxue.loading = false;
  210. } else {
  211. // 数学
  212. data.shuxue.state = 'more';
  213. data.shuxue.state_text = '加载更多';
  214. data.shuxue.loading = false;
  215. }
  216. } else if (code == 1) {
  217. if (res.data.total >= data.yingyu.list.length) {
  218. // 英语
  219. data.yingyu.state = 'no-more';
  220. data.yingyu.state_text = '没有更多啦';
  221. data.yingyu.loading = false;
  222. } else {
  223. // 英语
  224. data.yingyu.state = 'more';
  225. data.yingyu.state_text = '加载更多';
  226. data.yingyu.loading = false;
  227. }
  228. }
  229. }).catch(err => {
  230. if (code == 0) {
  231. // 数学
  232. data.shuxue.state = 'more';
  233. data.shuxue.state_text = '加载更多';
  234. data.shuxue.loading = false;
  235. } else if (code == 1) {
  236. // 英语
  237. data.yingyu.state = 'more';
  238. data.yingyu.state_text = '加载更多';
  239. data.yingyu.loading = false;
  240. }
  241. })
  242. }
  243. function formatListToUse(list) {
  244. list.forEach((item, index) => {
  245. item.mta_show = false;
  246. item.reply = null;
  247. if (item.type == 3) {
  248. item.result = JSON.parse(item.result);
  249. item.placeholders = item.result.map((item, cindex) => `[bank${cindex}]`)
  250. item.reply = item.result.map(() => '');
  251. }
  252. })
  253. }
  254. function getCuotiData(item) {
  255. getWrongInfo({
  256. cardId: data.current + 1,
  257. cdate: item.cdate
  258. }).then(res => {
  259. formatListToUse(res.data)
  260. data.wrongList = res.data;
  261. wrongRef.value.showPopup();
  262. })
  263. }
  264. function onRefresh() {
  265. if (data.current == 0) {
  266. data.shuxue.page = 0;
  267. data.shuxue.list = [];
  268. data.shuxue.loading = true;
  269. } else if (data.current == 1) {
  270. data.yingyu.page = 0;
  271. data.yingyu.list = [];
  272. data.yingyu.loading = true;
  273. }
  274. refreshData(data.current);
  275. }
  276. function onRestore() {
  277. data.shuxue.loading = 'restore'; // 需要重置
  278. // console.log("onRestore");
  279. }
  280. function onAbort() {
  281. // console.log("onAbort");
  282. }
  283. onLoad(() => {
  284. getMore(data.current);
  285. })
  286. </script>
  287. <style>
  288. </style>