collectBank.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  1. <template>
  2. <view id="questionBank">
  3. <swiper class="swiper" :current="current" @change="swiperChange" :interval="interval">
  4. <swiper-item v-for="(bank,bankIndex) in questionList" :key="bankIndex">
  5. <view class="pageContent">
  6. <view class="pad_8 titBox" >
  7. <view class="firstLetter">
  8. <view class="leftLetters">
  9. <view class="btnType">
  10. <text v-if="bank.type==1">单选</text>
  11. <text v-if="bank.type==2">多选</text>
  12. <text v-if="bank.type==3">判断</text>
  13. <text v-if="bank.type==4">案例题</text>
  14. <text v-if="bank.type==5">简答题</text>
  15. </view>
  16. <text>{{bankIndex+1}}/{{questionList.length}}</text>
  17. </view>
  18. <view style="color: #666;font-size: 28rpx;"></view>
  19. <view class="leftLetters"></view>
  20. </view>
  21. <view class="titles">
  22. <rich-text :nodes="bank.content"></rich-text>
  23. </view>
  24. </view>
  25. <view class="pad_8 titBox">
  26. <template v-if="bank.type == 1">
  27. <view v-if="!bank.ques">
  28. <view v-for="(item, index) in bank.jsonStr" :key="index" class="lisSty" @click="radioSelect(item.optionsId,bankIndex)">
  29. <view class="activeTI">{{ ast[index] }}</view>
  30. {{ item.content }}
  31. </view>
  32. </view>
  33. <view v-if="bank.ques">
  34. <view v-for="(item, index) in bank.jsonStr" :key="index" class="lisSty">
  35. <text :class="{right:(item.optionsId == bank.ques) || (item.optionsId == bank.ans),wrong:(item.optionsId == bank.ques) && (bank.ques != bank.ans)}" class="activeTI">{{ ast[index] }}</text>
  36. {{ item.content }}
  37. </view>
  38. </view>
  39. <view v-if="bank.ques">
  40. <view class="pad_8 answer">
  41. <view>正确答案:{{ast[bank.ans-1]}}</view>
  42. <view v-if="!explain">我的答案:{{ast[bank.ques-1]}}</view>
  43. </view>
  44. <view class="pad_8 answerInfos">
  45. <view class="answerTitle">答案解析</view>
  46. <view class="answerContent">
  47. <rich-text :nodes="bank.analysisContent"></rich-text>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <template v-if="bank.type == 2">
  53. <view v-if="!bank.ques">
  54. <view v-for="(item, index) in bank.jsonStr" :key="index" class="lisSty" @click="checkboxSelect(item.optionsId,bankIndex,index)">
  55. <view :class="{checked:item.checked}" class="activeTI">{{ ast[index] }}</view>
  56. {{ item.content }}
  57. </view>
  58. </view>
  59. <view v-if="!bank.ques" class="submit_checkbox" @click="checkboxSubmit(bankIndex)">
  60. 确认答案
  61. </view>
  62. <view v-if="bank.ques">
  63. <view v-for="(item, index) in bank.jsonStr" :key="index" class="lisSty">
  64. <text :class="{right:(bank.ques.indexOf(item.optionsId) != -1 ) || (bank.ans.indexOf(item.optionsId) != -1),wrong:(bank.ques.indexOf(item.optionsId) != -1 ) && (bank.ans.indexOf(item.optionsId) == -1)}" class="activeTI">{{ ast[index] }}</text>
  65. {{ item.content }}
  66. </view>
  67. </view>
  68. <view v-if="bank.ques">
  69. <view class="pad_8 answer">
  70. <view>正确答案:
  71. <text v-for="ansItem in bank.ans">{{ast[ansItem-1]}}</text>
  72. </view>
  73. <view v-if="!explain">我的答案:
  74. <text v-for="quesItem in bank.ques">{{ast[quesItem-1]}}</text>
  75. </view>
  76. </view>
  77. <view class="pad_8 answerInfos">
  78. <view class="answerTitle">答案解析</view>
  79. <view class="answerContent">
  80. <rich-text :nodes="bank.analysisContent"></rich-text>
  81. </view>
  82. </view>
  83. </view>
  84. </template>
  85. <template v-if="bank.type == 3">
  86. <view v-if="!bank.ques">
  87. <view v-for="(item, index) in judge" :key="index" class="lisSty" @click="judgeSelect(index,bankIndex)">
  88. <view class="activeTI">{{ ast[index] }}</view>
  89. {{ item }}
  90. </view>
  91. </view>
  92. <view v-if="bank.ques">
  93. <view v-for="(item, index) in judge" :key="index" class="lisSty">
  94. <text :class="{right:(index == bank.ques) || (index == bank.ans),wrong:(index == bank.ques) && (bank.ques != bank.ans)}" class="activeTI">{{ ast[index] }}</text>
  95. {{ item }}
  96. </view>
  97. </view>
  98. <view v-if="bank.ques">
  99. <view class="pad_8 answer">
  100. <view>正确答案:{{ast[bank.ans]}}</view>
  101. <view v-if="!explain">我的答案:{{ast[bank.ques]}}</view>
  102. </view>
  103. <view class="pad_8 answerInfos">
  104. <view class="answerTitle">答案解析</view>
  105. <view class="answerContent">
  106. <rich-text :nodes="bank.analysisContent"></rich-text>
  107. </view>
  108. </view>
  109. </view>
  110. </template>
  111. <!-- 简答题 -->
  112. <template v-if="bank.type == 5">
  113. <view class="ans">
  114. <view class="ans_input" v-if="!bank.ques">
  115. <view class="top flex">
  116. <image :data-index="bankIndex" class="icon" @click="chooseImg(bankIndex)" src="/static/08-10_032.jpg" mode=""></image>
  117. <view class="progress">0/4</view>
  118. <view class="submit" @click="submitAns(bankIndex)" >确认答案</view>
  119. </view>
  120. <view class="textarea">
  121. <textarea v-model="bank.ansText.text" placeholder="在此输入答案"></textarea>
  122. </view>
  123. <view class="imgs">
  124. <view class="img" v-for="(img,imgIndex) in bank.ansText.imageList" >
  125. <text @click="deleteImg(imgIndex,bankIndex)">x</text>
  126. <image :src="$method.splitImgHost(img, true)"></image>
  127. </view>
  128. </view>
  129. </view>
  130. <view class="ans_submit answerInfos" v-if="bank.ques && !explain">
  131. <view class="answerTitle">答案我的</view>
  132. {{bank.ques.text}}
  133. <view class="imgs">
  134. <image class="img" v-for="ques in bank.ques.imageList" :src="ques"></image>
  135. </view>
  136. </view>
  137. </view>
  138. <view v-if="bank.ques">
  139. <view class="pad_8 answerInfos">
  140. <view class="answerTitle">答案解析</view>
  141. <view class="answerContent">
  142. <rich-text :nodes="bank.analysisContent"></rich-text>
  143. </view>
  144. </view>
  145. </view>
  146. </template>
  147. <!-- 案例题 -->
  148. <template v-if="bank.type == 4">
  149. <view class="tabs">
  150. <view class="tab" :class="{current:tabIndex == bank.current}" :key="tabIndex" v-for="(tab,tabIndex) in bank.jsonStr" @click="tabSelect(tabIndex,bankIndex)">问题{{tabIndex}}</view>
  151. </view>
  152. <view v-for="(ansItem,ansIndex) in bank.jsonStr" v-if="bank.current == ansIndex" :key="ansIndex">
  153. <view class="titles">
  154. <rich-text :nodes="ansItem.content"></rich-text>
  155. </view>
  156. <template v-if="ansItem.type == 1">
  157. <view v-if="!bank.ques[ansIndex]">
  158. <view v-for="(option, childIndex) in ansItem.optionsList" :key="childIndex" class="lisSty" @click="radioSelectChild(option.optionsId,ansIndex,bankIndex)">
  159. <view class="activeTI">{{ ast[childIndex] }}</view>
  160. <rich-text class="textChild" :nodes="option.content"></rich-text>
  161. </view>
  162. </view>
  163. <view v-if="bank.ques[ansIndex]">
  164. <view v-for="(option, childIndex) in ansItem.optionsList" :key="index" class="lisSty">
  165. <text :class="{right:(option.optionsId == bank.ques[ansIndex]) || (option.optionsId == bank.ans[ansIndex]),wrong:(option.optionsId == bank.ques[ansIndex]) && (bank.ques[ansIndex] != bank.ans[ansIndex])}" class="activeTI">{{ ast[childIndex] }}</text>
  166. <rich-text :nodes="option.content"></rich-text>
  167. </view>
  168. </view>
  169. <view v-if="bank.ques[ansIndex]">
  170. <view class="pad_8 answer">
  171. <view>正确答案:{{ast[bank.ans[ansIndex]-1]}}</view>
  172. <view v-if="!explain">我的答案:{{ast[bank.ques[ansIndex]-1]}}</view>
  173. </view>
  174. <view class="pad_8 answerInfos">
  175. <view class="answerTitle">答案解析</view>
  176. <view class="answerContent">
  177. <rich-text :nodes="option.analysisContent"></rich-text>
  178. </view>
  179. </view>
  180. </view>
  181. </template>
  182. <template v-if="ansItem.type == 2">
  183. <view v-if="!bank.ques[ansIndex]">
  184. <view v-for="(option, childindex) in ansItem.optionsList" :key="childindex" class="lisSty" @click="checkboxSelectChild(bankIndex,ansIndex,childindex)">
  185. <view :class="{checked:option.checked}" class="activeTI">{{ ast[childindex] }}</view>
  186. <rich-text :nodes="option.content"></rich-text>
  187. </view>
  188. </view>
  189. <view v-if="!bank.ques[ansIndex]" class="submit_checkbox" @click="checkboxSubmitChild(bankIndex,ansIndex)">
  190. 确认答案
  191. </view>
  192. <view v-if="bank.ques && bank.ques[ansIndex]">
  193. <view v-for="(option, childindex) in ansItem.optionsList" :key="childindex" class="lisSty">
  194. <text :class="{right:right(bankIndex,ansIndex,option),wrong:wrong(bankIndex,ansIndex,option)}" class="activeTI">{{ ast[childindex] }}</text>
  195. <rich-text :nodes="option.content"></rich-text>
  196. </view>
  197. </view>
  198. <view v-if="bank.ques[ansIndex]">
  199. <view class="pad_8 answer">
  200. <view>正确答案:
  201. <text v-for="ansItem1 in bank.ans[ansIndex]">{{ast[ansItem1-1]}}</text>
  202. </view>
  203. <view v-if="!explain">我的答案:
  204. <text v-for="quesItem in bank.ques[ansIndex]">{{ast[quesItem-1]}}</text>
  205. </view>
  206. </view>
  207. <view class="pad_8 answerInfos">
  208. <view class="answerTitle">答案解析</view>
  209. <view class="answerContent">
  210. <rich-text :nodes="ansItem.analysisContent"></rich-text>
  211. </view>
  212. </view>
  213. </view>
  214. </template>
  215. <template v-if="ansItem.type == 3">
  216. <view v-if="!bank.ques[ansIndex]">
  217. <view v-for="(option, childindex) in judge" :key="childindex" class="lisSty" @click="judgeSelectChild(ansIndex,childindex,bankIndex)">
  218. <view class="activeTI">{{ ast[childindex] }}</view>
  219. {{ option }}
  220. </view>
  221. </view>
  222. <view v-if="bank.ques[ansIndex]">
  223. <view v-for="(option, childindex) in judge" :key="childindex" class="lisSty">
  224. <text :class="{right:(childindex == bank.ques[ansIndex]) || (childindex == bank.ans[ansIndex]),wrong:(childindex == bank.ques[ansIndex]) && (bank.ques[ansIndex] != bank.ans[ansIndex])}" class="activeTI">{{ ast[childindex] }}</text>
  225. {{ option }}
  226. </view>
  227. </view>
  228. <view v-if="bank.ques[ansIndex]">
  229. <view class="pad_8 answer">
  230. <view>正确答案:{{ast[bank.ans[ansIndex]]}}</view>
  231. <view v-if="!explain">我的答案:{{ast[bank.ques[ansIndex]]}}</view>
  232. </view>
  233. <view class="pad_8 answerInfos">
  234. <view class="answerTitle">答案解析</view>
  235. <view class="answerContent">
  236. <rich-text :nodes="ansItem.analysisContent"></rich-text>
  237. </view>
  238. </view>
  239. </view>
  240. </template>
  241. <!-- 简答题 -->
  242. <template v-if="ansItem.type == 5">
  243. <view class="ans">
  244. <view class="ans_input" v-if="!bank.ques[ansIndex]">
  245. <view class="top flex">
  246. <image class="icon" @click="chooseImgChild(bankIndex,ansIndex)" src="/static/08-10_032.jpg" mode=""></image>
  247. <view class="progress">0/4</view>
  248. <view class="submit" @click="submitAnsChild(bankIndex,ansIndex)">确认答案</view>
  249. </view>
  250. <view class="textarea">
  251. <textarea v-model="ansItem.ansText.text" placeholder="在此输入答案"></textarea>
  252. </view>
  253. <view class="imgs">
  254. <view class="img" v-for="(img,imgIndex) in ansItem.ansText.imageList" >
  255. <text @click="deleteImgChild(imgIndex,bankIndex,ansIndex)">x</text>
  256. <image :src="$method.splitImgHost(img, true)"></image>
  257. </view>
  258. </view>
  259. </view>
  260. <view class="ans_submit answerInfos" v-if="bank.ques[ansIndex] && !explain">
  261. <view class="answerTitle">答案我的</view>
  262. {{bank.ques[ansIndex].text}}
  263. <view class="imgs">
  264. <image class="img" v-for="ques in bank.ques[ansIndex].imageList" :src="ques"></image>
  265. </view>
  266. </view>
  267. </view>
  268. <view v-if="bank.ques[ansIndex]">
  269. <view class="pad_8 answerInfos">
  270. <view class="answerTitle">答案解析</view>
  271. <view class="answerContent">
  272. <rich-text :nodes="ansItem.analysisContent"></rich-text>
  273. </view>
  274. </view>
  275. </view>
  276. </template>
  277. </view>
  278. </template>
  279. </view>
  280. <view class="footer_btn">
  281. <view @click="openFooterTab">答题卡</view>
  282. </view>
  283. </view>
  284. </swiper-item>
  285. </swiper>
  286. <u-popup v-model="show" mode="bottom" border-radius="14" height="680rpx">
  287. <view class="popupView">
  288. <view class="popupTops">
  289. <view class="topIcon"></view>
  290. 点击编号即可跳转至对应题目
  291. </view>
  292. <view class="popupContent">
  293. <scroll-view scroll-y="true" style="height: 506rpx;">
  294. <view class="boxSty">
  295. <view v-for="(item, index) in questionList" :key="index" @click="changeIndex(index)" :class="{isRight:isRight(item,index),isWrong:isWrong(item,index)}" class="liListSty">{{ index + 1 }}</view>
  296. </view>
  297. </scroll-view>
  298. </view>
  299. </view>
  300. </u-popup>
  301. <view class="dialog" v-if="showDialog">
  302. <view class="text">左右滑动切换上下题</view>
  303. <view class="btn" @click="hideDialog">我知道了</view>
  304. </view>
  305. </view>
  306. </template>
  307. <script>
  308. export default {
  309. data() {
  310. return {
  311. id:'',
  312. current:0,
  313. questionList:[],
  314. ast: ['A', 'B', 'C', 'D','E','F','G'],
  315. judge:['错误','正确'],
  316. show: false,
  317. showDialog:true,
  318. bankList: [],
  319. collectList:[],
  320. goodsId:'',
  321. explain:''
  322. };
  323. },
  324. onLoad(option){
  325. this.id = option.id;
  326. this.explain = option.explain;
  327. this.goodsQuestionList();
  328. },
  329. onUnload() {
  330. },
  331. methods: {
  332. goodsQuestionList() {
  333. this.$api.goodsQuestionList({
  334. examId:this.id
  335. }).then(res => {
  336. res.data.data.forEach((item,index) => {
  337. if(typeof item.jsonStr == 'string') {
  338. item.jsonStr = JSON.parse(item.jsonStr)
  339. if(item.type == 2) { //多选
  340. item.jsonStr.forEach(str => {
  341. str.optionsId = ''+str.optionsId;
  342. })
  343. let arr = item.answerQuestion.split(',');
  344. arr.forEach((a,i) => {
  345. arr[i] = ''+a;
  346. })
  347. item.ans = arr;
  348. if(this.explain) {
  349. item.ques = item.ans;
  350. }
  351. return;
  352. } else if(item.type == 5) {
  353. item.ansText = {
  354. text: '',
  355. imageList: []
  356. }
  357. if(this.explain) {
  358. item.ques = {
  359. text:item.analysisContent
  360. }
  361. return;
  362. }
  363. } else if(item.type == 4) {
  364. console.log(item.jsonStr)
  365. item.ques = []
  366. item.current = 0;
  367. let ansArr = [];
  368. item.jsonStr.forEach((json,index) => {
  369. if(json.type == 1) {
  370. ansArr[index] = json.answerQuestion;
  371. } else if(json.type == 2) {
  372. json.optionsList.forEach(str => {
  373. str.optionsId = ''+str.optionsId;
  374. })
  375. let arr = json.answerQuestion.split(',');
  376. arr.forEach((a,i) => {
  377. arr[i] = ''+a;
  378. })
  379. ansArr[index] = arr
  380. } else if(json.type == 3) {
  381. ansArr[index] = json.answerQuestion;
  382. } else if(json.type == 5) {
  383. ansArr[index] = {
  384. text: '',
  385. imageList: []
  386. }
  387. json.ansText = {
  388. text: '',
  389. imageList: []
  390. }
  391. }
  392. })
  393. item.ans = ansArr
  394. if(this.explain) {
  395. item.ques = item.ans;
  396. }
  397. return;
  398. }
  399. item.ans = item.answerQuestion
  400. if(this.explain) {
  401. item.ques = item.ans;
  402. }
  403. } else {
  404. if(this.explain) {
  405. item.ques = item.ans;
  406. }
  407. }
  408. })
  409. this.questionList = res.data.data;
  410. })
  411. },
  412. /**
  413. * @param {Object} e单选点击
  414. */
  415. radioSelect(optionsId,bindex) {
  416. if(this.questionList[bindex].ques) return;
  417. this.$set(this.questionList[bindex],'ques',optionsId)
  418. },
  419. /**
  420. * @param {Object} e单选点击
  421. */
  422. radioSelectChild(optionsId,ansIndex,bindex) {
  423. if(this.questionList[bindex].ques[ansIndex]) return;
  424. this.$set(this.questionList[bindex].ques,ansIndex,optionsId)
  425. },
  426. /**
  427. * @param {Object} 多选点击
  428. */
  429. checkboxSelect(optionsId,bindex,index) {
  430. this.$set(this.questionList[bindex].jsonStr[index],'checked',!this.questionList[bindex].jsonStr[index].checked)
  431. },
  432. /**
  433. * @param {Object} 多选点击
  434. */
  435. checkboxSelectChild(bindex,ansIndex,childIndex) {
  436. this.$set(this.questionList[bindex].jsonStr[ansIndex].optionsList[childIndex],'checked',!this.questionList[bindex].jsonStr[ansIndex].optionsList[childIndex].checked)
  437. },
  438. /**
  439. * @param {Object} 多选确认
  440. */
  441. checkboxSubmit(bindex) {
  442. if(this.questionList[bindex].ques) return;
  443. let arr = [];
  444. this.questionList[bindex].jsonStr.forEach(item => {
  445. if(item.checked) {
  446. arr.push(item.optionsId)
  447. }
  448. })
  449. this.$set(this.questionList[bindex],'ques',arr)
  450. },
  451. /**
  452. * @param {Object} 多选确认
  453. */
  454. checkboxSubmitChild(bindex,ansIndex) {
  455. if(this.questionList[bindex].ques[ansIndex]) return;
  456. let arr = [];
  457. this.questionList[bindex].jsonStr[ansIndex].optionsList.forEach(item => {
  458. if(item.checked) {
  459. arr.push(item.optionsId)
  460. }
  461. })
  462. this.$set(this.questionList[bindex].ques,ansIndex,arr)
  463. },
  464. judgeSelect(index,bindex) {
  465. if(this.questionList[bindex].ques) return;
  466. this.$set(this.questionList[bindex],'ques',index+'')
  467. },
  468. judgeSelectChild(ansindex,childindex,bindex) {
  469. if(this.questionList[bindex].ques[ansindex]) return;
  470. this.$set(this.questionList[bindex].ques,ansindex,childindex+'')
  471. },
  472. openFooterTab() {
  473. this.show = true;
  474. },
  475. hideDialog() {
  476. this.showDialog = false
  477. },
  478. changeIndex(index) {
  479. this.current = index
  480. },
  481. swiperChange(e) {
  482. this.current = e.detail.current;
  483. },
  484. deleteImg(imgIndex,bankIndex) {
  485. this.questionList[bankIndex].ansText.imageList.splice(imgIndex,1)
  486. },
  487. deleteImgChild(imgIndex,bankIndex,ansIndex) {
  488. this.questionList[bankIndex].jsonStr[ansIndex].ansText.imageList.splice(imgIndex,1)
  489. },
  490. chooseImg(bankindex) {
  491. uni.chooseImage({
  492. count: 1, //默认9
  493. sizeType: ['compressed', ], //可以指定是原图还是压缩图,默认二者都有
  494. sourceType: ['album','camera'], //从相册选择
  495. success: (res) => {
  496. let self = this;
  497. // console.log(JSON.stringify(res.tempFilePaths));
  498. let img = res.tempFilePaths[0];
  499. uni.getImageInfo({
  500. src: img,
  501. success: async res => {
  502. let canvasWidth = res.width; //图片原始长宽
  503. let canvasHeight = res.height;
  504. if (canvasWidth > 1000 || canvasHeight > 1000) {
  505. uni.compressImage({
  506. src: img,
  507. quality: 75,
  508. width: '50%',
  509. height: '50%',
  510. success: async rest => {
  511. const dir = await self.uploadFile(rest.tempFilePath, 0);
  512. this.questionList[bankindex].ansText.imageList.push(dir)
  513. }
  514. });
  515. } else {
  516. const dir = await self.uploadFile(img, 0);
  517. this.questionList[bankindex].ansText.imageList.push(dir)
  518. }
  519. }
  520. });
  521. }
  522. })
  523. },
  524. chooseImgChild(bankindex,ansindex) {
  525. uni.chooseImage({
  526. count: 1, //默认9
  527. sizeType: ['compressed', ], //可以指定是原图还是压缩图,默认二者都有
  528. sourceType: ['album','camera'], //从相册选择
  529. success: (res) => {
  530. let self = this;
  531. // console.log(JSON.stringify(res.tempFilePaths));
  532. let img = res.tempFilePaths[0];
  533. uni.getImageInfo({
  534. src: img,
  535. success: async res => {
  536. let canvasWidth = res.width; //图片原始长宽
  537. let canvasHeight = res.height;
  538. if (canvasWidth > 1000 || canvasHeight > 1000) {
  539. uni.compressImage({
  540. src: img,
  541. quality: 75,
  542. width: '50%',
  543. height: '50%',
  544. success: async rest => {
  545. const dir = await self.uploadFile(rest.tempFilePath, 0);
  546. this.questionList[bankindex].jsonStr[ansindex].ansText.imageList.push(dir)
  547. }
  548. });
  549. } else {
  550. const dir = await self.uploadFile(img, 0);
  551. this.questionList[bankindex].jsonStr[ansindex].ansText.imageList.push(dir)
  552. }
  553. }
  554. });
  555. }
  556. })
  557. },
  558. uploadFile(options, int) {
  559. var self = this;
  560. return new Promise((resolve, reject) => {
  561. var data = {
  562. imageStatus: int
  563. };
  564. self.$api.aliyunpolicy(data).then(res => {
  565. console.log(res.data,6)
  566. if(res.data.code!=200){
  567. self.$method.showToast('签名错误'+JSON.stringify(res.data))
  568. return
  569. }
  570. var ossToken = res.data.data.resultContent;
  571. if(ossToken.host==null||ossToken.host==undefined){
  572. self.$method.showToast('上传路径报错'+JSON.stringify(res.data))
  573. return
  574. }
  575. uni.uploadFile({
  576. url: ossToken.host,
  577. name: 'file',
  578. filePath: options,
  579. fileType: 'image',
  580. header: {
  581. AuthorizationToken: 'WX ' + uni.getStorageSync('token')
  582. },
  583. formData: {
  584. key: ossToken.dir,
  585. OSSAccessKeyId: ossToken.accessid,
  586. policy: ossToken.policy,
  587. Signature: ossToken.signature,
  588. callback: ossToken.callback,
  589. success_action_status: 200
  590. },
  591. success: result => {
  592. if (result.statusCode === 200) {
  593. resolve(ossToken.dir);
  594. } else {
  595. uni.showToast({
  596. title: '上传失败',
  597. icon: 'none'
  598. });
  599. return;
  600. }
  601. },
  602. fail: error => {
  603. uni.showToast({
  604. title: '上传接口报错'+error,
  605. icon: 'none'
  606. });
  607. return;
  608. }
  609. });
  610. });
  611. });
  612. },
  613. submitAns(type,bankindex) {
  614. console.log(this.questionList[bankindex])
  615. if(!this.questionList[bankindex].ansText.text && !this.questionList[bankindex].ansText.imageList.length) {
  616. uni.showToast({
  617. title: '请输入内容或上传图片',
  618. duration: 2000,
  619. icon:'none'
  620. });
  621. return
  622. }
  623. this.$set(this.ques,bankindex,{
  624. imageList:this.questionList[bankindex].ansText.imageList,
  625. text:this.questionList[bankindex].ansText.text,
  626. })
  627. },
  628. submitAnsChild(bankindex,ansindex) {
  629. if(!this.questionList[bankindex].jsonStr[ansindex].ansText.text && !this.questionList[bankindex].jsonStr[ansindex].ansText.imageList.length) {
  630. uni.showToast({
  631. title: '请输入内容或上传图片',
  632. duration: 2000,
  633. icon:'none'
  634. });
  635. return
  636. }
  637. this.$set(this.questionList[bankindex].ques,ansindex,{
  638. imageList:this.questionList[bankindex].jsonStr[ansindex].ansText.imageList,
  639. text:this.questionList[bankindex].jsonStr[ansindex].ansText.text,
  640. })
  641. },
  642. isRight(item,index) {
  643. //单选
  644. if(this.questionList[index].ques) {
  645. if(item.type == 1) {
  646. return this.questionList[index].ques == this.questionList[index].ans;
  647. //多选
  648. } else if(item.type == 2) {
  649. //每一项都相等
  650. return this.questionList[index].ques.every((item,index) => {
  651. return item == this.questionList[index].ans;
  652. })
  653. //判断
  654. } else if(item.type == 3) {
  655. return this.questionList[index].ques == this.questionList[index].ans;
  656. } else {
  657. return false;
  658. }
  659. } else {
  660. return false;
  661. }
  662. },
  663. right(bankIndex,ansIndex,option) {
  664. if(this.questionList[bankIndex].ques[ansIndex] && this.questionList[bankIndex].ans[ansIndex]) {
  665. if((this.questionList[bankIndex].ques[ansIndex].indexOf(option.optionsId) != -1 ) || (this.questionList[bankIndex].ans[ansIndex].indexOf(option.optionsId) != -1)) {
  666. return true
  667. } else {
  668. return false;
  669. }
  670. } else {
  671. return false;
  672. }
  673. },
  674. wrong(bankIndex,ansIndex,option) {
  675. if(this.questionList[bankIndex].ques[ansIndex] && this.questionList[bankIndex].ans[ansIndex]) {
  676. if((this.questionList[bankIndex].ques[ansIndex].indexOf(option.optionsId) != -1 ) && (this.questionList[bankIndex].ans[ansIndex].indexOf(option.optionsId) == -1)) {
  677. return true;
  678. } else {
  679. return false;
  680. }
  681. } else {
  682. return false;
  683. }
  684. },
  685. isWrong(item,index) {
  686. if(this.questionList[index].ques) {
  687. //单选
  688. if(item.type == 1) {
  689. return this.questionList[index].ques != this.questionList[index].ans;
  690. //多选
  691. } else if(item.type == 2) {
  692. //每一项都相等
  693. return this.questionList[index].ques.some((item,index) => {
  694. return item != this.questionList[index].ans;
  695. })
  696. //判断
  697. } else if(item.type == 3) {
  698. return this.questionList[index].ques != this.questionList[index].ans;
  699. } else {
  700. return false;
  701. }
  702. } else {
  703. return false;
  704. }
  705. },
  706. tabSelect(index,bankindex) {
  707. this.$set(this.questionList[bankindex],'current',index)
  708. },
  709. }
  710. };
  711. </script>
  712. <style lang="scss" scoped>
  713. .swiper {
  714. width:100%;
  715. height:100vh;
  716. }
  717. .lisSty {
  718. margin-bottom: 16rpx;
  719. display: flex;
  720. }
  721. .activeTI {
  722. vertical-align: middle;
  723. display: inline-block;
  724. border: 1rpx solid #eee;
  725. border-radius: 50rpx;
  726. height: 48rpx;
  727. line-height: 46rpx;
  728. text-align: center;
  729. width: 48rpx;
  730. margin-right: 15rpx;
  731. color: #666;
  732. font-size: 30rpx;
  733. &.right {
  734. color:#fff;
  735. background:green;
  736. }
  737. &.wrong {
  738. color:#fff;
  739. background:red;
  740. }
  741. &.checked {
  742. color:#fff;
  743. background:blue;
  744. }
  745. }
  746. .submit_checkbox {
  747. margin:20rpx auto;
  748. width: 526rpx;
  749. height: 80rpx;
  750. background: rgba(0, 122, 255, 1);
  751. color:#fff;
  752. text-align: center;
  753. line-height: 80rpx;
  754. font-size: 30rpx;
  755. border-radius: 40rpx;
  756. }
  757. .titles {
  758. overflow: hidden;
  759. margin-bottom: 24rpx;
  760. }
  761. .titBox {
  762. padding: 41rpx 25rpx 24rpx 25rpx;
  763. }
  764. .tabs {
  765. margin:10rpx;
  766. display: flex;
  767. .tab {
  768. margin:0 10rpx;
  769. width: 96rpx;
  770. height: 48rpx;
  771. line-height: 48rpx;
  772. text-align: center;
  773. color:#007AFF;
  774. font-size: 28rpx;
  775. border-radius: 16rpx;
  776. &.current {
  777. color:#fff;
  778. background: #007AFF;
  779. }
  780. }
  781. }
  782. .ans {
  783. margin:8rpx 8rpx 8rpx;
  784. .ans_input {
  785. border-radius: 16rpx;
  786. background:#fff;
  787. .top {
  788. border-bottom:1rpx solid #EEEEEE;
  789. padding: 16rpx;
  790. display: flex;
  791. align-items: center;
  792. .icon {
  793. margin-right:20rpx;
  794. width: 40rpx;
  795. height: 38rpx;
  796. }
  797. .progress {
  798. flex:1;
  799. }
  800. .submit {
  801. width: 168rpx;
  802. height: 48rpx;
  803. line-height: 48rpx;
  804. text-align: center;
  805. color:#fff;
  806. font-size: 30rpx;
  807. background: #007AFF;
  808. border-radius: 24rpx;
  809. }
  810. }
  811. .textarea {
  812. textarea {
  813. width:100%;
  814. height:287rpx;
  815. padding:10rpx;
  816. }
  817. }
  818. .imgs {
  819. overflow: hidden;
  820. display: flex;
  821. width:100%;
  822. .img {
  823. width: 104rpx;
  824. height: 104rpx;
  825. border-radius: 8rpx;
  826. position:relative;
  827. margin:20rpx;
  828. text {
  829. position:absolute;
  830. right:-15rpx;
  831. top:-15rpx;
  832. width:30rpx;
  833. height:30rpx;
  834. text-align: center;
  835. line-height: 30rpx;
  836. color:#fff;
  837. background:red;
  838. border-radius:50%;
  839. }
  840. image {
  841. width:100%;
  842. height:100%;
  843. }
  844. }
  845. }
  846. }
  847. .ans_submit {
  848. padding:16rpx;
  849. border-radius: 16rpx;
  850. background:#fff;
  851. .imgs {
  852. overflow: hidden;
  853. display: flex;
  854. width:100%;
  855. .img {
  856. width: 104rpx;
  857. height: 104rpx;
  858. border-radius: 8rpx;
  859. position:relative;
  860. margin:20rpx;
  861. image {
  862. width:100%;
  863. height:100%;
  864. }
  865. }
  866. }
  867. }
  868. }
  869. .firstLetter {
  870. display: flex;
  871. justify-content: space-between;
  872. align-items: center;
  873. margin-bottom: 30rpx;
  874. .leftLetters {
  875. display: flex;
  876. align-items: center;
  877. width: 220rpx;
  878. .btnType {
  879. padding: 5rpx 10rpx;
  880. border: 1rpx solid #007aff;
  881. border-radius: 10rpx;
  882. background-color: rgba(0, 122, 255, 0.1);
  883. font-size: 28rpx;
  884. color: #007aff;
  885. margin-right: 15rpx;
  886. }
  887. }
  888. }
  889. .popupView {
  890. height: 100%;
  891. padding-bottom: 100rpx;
  892. .popupTops {
  893. height: 77rpx;
  894. border-bottom: 1rpx solid #eee;
  895. text-align: center;
  896. line-height: 77rpx;
  897. font-size: 24rpx;
  898. color: #999;
  899. position: relative;
  900. .topIcon {
  901. position: absolute;
  902. top: 10rpx;
  903. left: 50%;
  904. transform: translateX(-50%);
  905. width: 80rpx;
  906. height: 8rpx;
  907. background-color: #999;
  908. border-radius: 4rpx;
  909. }
  910. }
  911. .popupContent {
  912. }
  913. }
  914. .pageContent {
  915. position:relative;
  916. background-color: #eaeef1;
  917. min-height: 100vh;
  918. padding-top: 8rpx;
  919. padding-bottom: 100rpx;
  920. }
  921. .pad_8 {
  922. background-color: #fff;
  923. margin: 0rpx 8rpx 8rpx;
  924. border-radius: 16rpx;
  925. }
  926. .answer {
  927. height: 80rpx;
  928. line-height: 80rpx;
  929. padding: 0rpx 24rpx;
  930. display: flex;
  931. align-items: center;
  932. justify-content: space-between;
  933. color: #666;
  934. font-size: 30rpx;
  935. }
  936. .footer_btn {
  937. background-color: #fff;
  938. z-index: 10078;
  939. position: absolute;
  940. bottom: 0rpx;
  941. display: flex;
  942. align-items: center;
  943. justify-content: space-between;
  944. width: 100%;
  945. height: 98rpx;
  946. padding: 0rpx 38rpx;
  947. border-top: 1rpx solid #eee;
  948. .collect {
  949. visibility: hidden;
  950. &.show {
  951. visibility: visible;
  952. }
  953. }
  954. }
  955. .boxSty {
  956. padding: 44rpx 41rpx 0rpx;
  957. }
  958. .liListSty {
  959. border:1rpx solid #EEEEEE;
  960. width: 88rpx;
  961. height: 88rpx;
  962. border-radius: 32rpx;
  963. text-align: center;
  964. line-height: 88rpx;
  965. color: #333;
  966. font-size: 32rpx;
  967. float: left;
  968. margin: 20rpx 23rpx;
  969. &.isRight {
  970. border:1rpx solid #EEEEEE;
  971. color:#fff;
  972. background: green;
  973. }
  974. &.isWrong {
  975. border:1rpx solid #EEEEEE;
  976. color:#fff;
  977. background: red;
  978. }
  979. }
  980. .answerInfos {
  981. padding: 25rpx 25rpx 25rpx 23rpx;
  982. }
  983. .answerTitle {
  984. margin-bottom: 28rpx;
  985. color: #666;
  986. font-size: 30rpx;
  987. }
  988. .answerContent {
  989. font-size: 30rpx;
  990. color: #666;
  991. }
  992. .textChild {
  993. display: inline-block;
  994. vertical-align: middle;
  995. }
  996. .dialog {
  997. position: fixed;
  998. left:0;
  999. top:0;
  1000. width:100%;
  1001. height:100%;
  1002. background-color: rgba(0,0,0,0.8);
  1003. display: flex;
  1004. flex-direction: column;
  1005. align-items: center;
  1006. justify-content: center;
  1007. z-index: 20000;
  1008. .text {
  1009. font-size: 32rpx;
  1010. color: #FFFFFF;
  1011. text-align: center;
  1012. }
  1013. .btn {
  1014. width: 242rpx;
  1015. height: 82rpx;
  1016. border: 2rpx solid #FFFFFF;
  1017. border-radius: 16rpx;
  1018. text-align: center;
  1019. line-height: 82rpx;
  1020. margin:41rpx auto;
  1021. color:#fff;
  1022. font-size: 32rpx;
  1023. }
  1024. }
  1025. </style>