index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view>
  3. <!-- #ifdef H5 -->
  4. <!-- 顶部自定义导航 -->
  5. <tn-nav-bar fixed :bottomShadow="false" backTitle=" ">
  6. <view class="">
  7. <text class="tn-text-lg">题目搜索</text>
  8. <text class="tn-text-xl tn-padding-left-sm tn-icon-group-circle"></text>
  9. </view>
  10. </tn-nav-bar>
  11. <!-- #endif -->
  12. <view class="cu-bar search bg-white">
  13. <view class="search-form round">
  14. <text class="cuIcon-search"></text>
  15. <input v-model="keyword" @input="inputSearch" @confirm="search()" :adjust-position="false" type="text"
  16. placeholder="请输入题目关键词进行搜索" confirm-type="search"></input>
  17. </view>
  18. <view class="action">
  19. <button class="cu-btn bg-primary shadow-blur round" @click="search()">搜索</button>
  20. </view>
  21. </view>
  22. <view class="question-list">
  23. <view class="question-card" v-for="(item, index) in list" :key="index">
  24. <tui-card :title="{text: item.cates.name, size: 30, color: '#7A7A7A'}"
  25. :tag="{text: item.kind_text, size: 24}" :header="item.title">
  26. <template v-slot:body>
  27. <view class="m-lr-20">
  28. <view class="m-t-20" v-if="item.is_material_child && item.material_question_id && item.material_parent">
  29. <text>材料题干:</text>
  30. <!-- <rich-text :nodes="formatRichtext(item.material_parent.title)" style="font-size: 36rpx; font-weight: bold;"></rich-text> -->
  31. <mp-html :content="formatRichtext(item.material_parent.title)"
  32. style="font-size: 36rpx; font-weight: bold;"></mp-html>
  33. </view>
  34. <view class="m-t-20">
  35. <text>{{ item.kind_text }}:</text>
  36. <!-- <rich-text :nodes="formatRichtext(item.title)" style="font-size: 36rpx; font-weight: bold;"></rich-text> -->
  37. <mp-html :content="formatRichtext(item.title)" style="font-size: 36rpx; font-weight: bold;"></mp-html>
  38. </view>
  39. <view class="options">
  40. <view v-if="item.kind == 'FILL'" v-html="getFillAnswer(item)"></view>
  41. <view v-for="(option, i) in item.options_json"
  42. :key="i"
  43. :class="item.answer.indexOf(option.key) > -1 ? ['text-green'] : []"
  44. v-else
  45. >
  46. {{ option.key }}:
  47. <mp-html :content="option.value"></mp-html>
  48. <!-- {{ option.value }} -->
  49. <block v-if="item.options_img && item.options_img[i]">
  50. <image :src="item.options_img[i].value" @click="previewOptionImage(item.options_img[i].value)"
  51. class="option-img"></image>
  52. </block>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <template v-slot:footer>
  58. <text class="margin-left-sm">解析:</text>
  59. <view class="explain" v-if="item.explain">
  60. <!-- <rich-text :nodes="formatRichtext(item.explain)" style="border-top: solid 1px #ccc;width: 100%;display: block;" v-if="item.explain"></rich-text> -->
  61. <mp-html :content="formatRichtext(item.explain)"
  62. style="border-top: solid 1px #ccc;width: 100%;display: block;" v-if="item.explain"></mp-html>
  63. </view>
  64. <view class="explain" v-else>无</view>
  65. </template>
  66. </tui-card>
  67. </view>
  68. <!-- 加载状态条 -->
  69. <view class="cu-load bg-grey" :class="loadFlag" v-show="has_more || loadFlag == 'over'"></view>
  70. </view>
  71. <tui-loading v-if="showLoading"></tui-loading>
  72. <tui-no-data imgUrl="/static/img/img_noorder_3x.png" v-if="showNodata">暂无数据</tui-no-data>
  73. <!--流量主组件-->
  74. <!-- #ifdef MP-WEIXIN -->
  75. <view :class="showNodata ? ['margin-top-100'] : ['margin-top-10']" v-show="false">
  76. <kz-ad ref="adSearch" kind="BANNER" :config="ad" field="question_search_banner"></kz-ad>
  77. <kz-ad ref="adSearch" kind="VIDEO" :config="ad" field="question_search_video"></kz-ad>
  78. <kz-ad ref="adSearch" kind="VIDEO_PATCH" :config="ad" field="question_search_video_patch"></kz-ad>
  79. </view>
  80. <!-- #endif -->
  81. <login ref="login"></login>
  82. <tabbar></tabbar>
  83. </view>
  84. </template>
  85. <script>
  86. export default {
  87. data() {
  88. return {
  89. showLoading: false,
  90. showNodata: true,
  91. keyword: '',
  92. list: [],
  93. loadFlag: 'loading',
  94. current_page: 1,
  95. has_more: false,
  96. ad: {}
  97. }
  98. },
  99. computed: {
  100. // 显示填空题答案
  101. getFillAnswer(item) {
  102. return function (item) {
  103. let answer = ''
  104. if (item.answer && item.kind == 'FILL') {
  105. try {
  106. answer = '';
  107. for (let i = 0; i < item.answer.length; i++) {
  108. answer += '填空位' + (i + 1) + ':' + item.answer[i].answers.join('、') + '<br>';
  109. }
  110. } catch (e) {
  111. console.log('answer', answer, e);
  112. return value;
  113. }
  114. }
  115. return answer
  116. }
  117. },
  118. },
  119. onLoad(e) {
  120. this.ad = this.utils.getData('ad')
  121. console.log('ad data', this.ad)
  122. // 插屏广告
  123. if (this.ad.question_search_cp_open == 1) {
  124. this.adUtils.interstitial.load(this.ad.question_search_cp)
  125. this.adUtils.interstitial.show()
  126. }
  127. if (e.keyword) {
  128. this.keyword = e.keyword
  129. this.search()
  130. }
  131. },
  132. async onReachBottom() {
  133. console.log("onReachBottom")
  134. if (this.has_more) {
  135. this.current_page++
  136. this.search()
  137. }
  138. },
  139. methods: {
  140. search() {
  141. if (!this.keyword) {
  142. uni.showToast({
  143. title: '请输入关键词',
  144. icon: 'none'
  145. })
  146. return
  147. }
  148. this.loadFlag = 'loading'
  149. this.has_more = true
  150. this.http('question/search', {
  151. keyword: this.keyword,
  152. page: this.current_page
  153. }, 'post').then(res => {
  154. console.log('search res', res)
  155. if (res.code == 0) {
  156. uni.showToast({
  157. title: res.msg,
  158. icon: 'none'
  159. })
  160. return
  161. } else {
  162. this.list = res.data.list.data //this.list.concat(res.data.list.data)
  163. this.current_page = res.data.list.current_page
  164. this.has_more = res.data.list.has_more
  165. this.loadFlag = !this.has_more ? 'over' : ''
  166. this.showNodata = !this.list.length
  167. }
  168. })
  169. },
  170. inputSearch(e) {
  171. console.log('input e', e)
  172. this.keyword = e.detail.value
  173. },
  174. // 试题标题
  175. formatRichtext(text) {
  176. if (text) {
  177. return this.utils.formatRichText(text)
  178. }
  179. return '无'
  180. },
  181. // 选项图片yulan
  182. previewOptionImage(src) {
  183. if (!src) {
  184. return
  185. }
  186. uni.previewImage({
  187. current: 0,
  188. urls: [src]
  189. });
  190. }
  191. }
  192. }
  193. </script>
  194. <style>
  195. .question-list {
  196. padding-bottom: 20rpx;
  197. }
  198. .question-card {
  199. margin: 20rpx 0;
  200. }
  201. .options {
  202. margin: 20rpx 0;
  203. line-height: 50rpx;
  204. }
  205. .explain {
  206. margin: 20rpx 0;
  207. padding: 15rpx;
  208. padding-top: 0rpx;
  209. }
  210. .margin-top-10 {
  211. margin-top: 10px;
  212. }
  213. .margin-top-100 {
  214. margin-top: 100%;
  215. }
  216. .option-img {
  217. width: 100rpx;
  218. height: 100rpx;
  219. }
  220. </style>