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