index.vue 7.8 KB

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