questionBank.vue 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. <!-- 题目编辑组件 -->
  2. <template>
  3. <div id="questionBank">
  4. <el-col :span="24" style="display: flex; justify-content: center">
  5. <el-col
  6. :span="2"
  7. style="
  8. display: flex;
  9. align-items: center;
  10. justify-content: flex-start;
  11. cursor: pointer;
  12. "
  13. >
  14. <el-button
  15. type="success"
  16. icon="el-icon-arrow-left"
  17. circle
  18. size="small"
  19. @click="back"
  20. v-if="statusPop === 2"
  21. ></el-button>
  22. </el-col>
  23. <el-col :span="20" class="contentMore">
  24. <div class="marg_play">
  25. <span class="spans">题目类型:</span>
  26. <el-radio-group v-model="dingForm.type" @change="changeTypes">
  27. <el-radio
  28. :disabled="statusPop === 2 || statusPop === 0"
  29. v-for="(item, index) in radioArrays"
  30. :key="index"
  31. :label="item.value"
  32. >{{ item.label }}</el-radio
  33. >
  34. </el-radio-group>
  35. </div>
  36. <div class="marg_play">
  37. <span class="spans"><span style="color: red">* </span>题目:</span>
  38. <div>
  39. <editor
  40. v-model="dingForm.content"
  41. :max-height="300"
  42. :uploadStatus="uploadStatus"
  43. />
  44. </div>
  45. </div>
  46. <!-- <div class="marg_play">
  47. <span class="spans">图片:</span>
  48. <div>
  49. <div class="imgBoxTopic">
  50. <label class="imgLabel">
  51. <div class="msPhoto" v-if="dingForm.imgUrl">
  52. <img
  53. :src="$methodsTools.splitImgHost(dingForm.imgUrl)"
  54. alt="图片加载失败"
  55. />
  56. </div>
  57. <div class="imgbbx" v-else>
  58. <p>点击添加图片</p>
  59. <i class="el-icon-plus"></i>
  60. </div>
  61. <input
  62. :disabled="statusPop === 2"
  63. :id="'inputstopic' + nums"
  64. type="file"
  65. ref="filetopic"
  66. style="display: none"
  67. @change="getImgFiletopic(nums, $event)"
  68. />
  69. </label>
  70. </div>
  71. <p style="color: #999999; line-height: 22px">
  72. 支持扩展名:.jpeg .bmp .png .jpg...<br />为保证显示效果,请上传分辨率为100x100且大小小于2M图片
  73. </p>
  74. </div>
  75. </div> -->
  76. <div
  77. class="marg_play"
  78. v-if="
  79. dingForm.type === 1 || dingForm.type === 2
  80. "
  81. >
  82. <span class="spans"
  83. ><span style="color: red" v-if="dingForm.type !== 5">* </span
  84. >选项:</span
  85. >
  86. <div style="flex: 1">
  87. <div
  88. style="display: flex; align-items: center; margin-bottom: 8px"
  89. v-for="(options, indexsop) in dingForm.optionsList"
  90. :key="indexsop"
  91. >
  92. <span>选项{{ indexsop + 1 }}:</span>
  93. <el-input
  94. style="flex: 1; margin: 0px 10px"
  95. type="textarea"
  96. :disabled="statusPop === 2"
  97. v-model="options.content"
  98. placeholder="请输入内容"
  99. :autosize="{ minRows: 2, maxRows: 2 }"
  100. maxlength="500"
  101. ></el-input>
  102. <span>{{ options.content.length }}/500</span>
  103. <el-button
  104. v-if="statusPop === 1"
  105. @click="delList(indexsop)"
  106. style="border-radius: 50%; margin: 0px 6px"
  107. type="danger"
  108. icon="el-icon-delete"
  109. size="mini"
  110. circle
  111. ></el-button>
  112. <label class="btnSty" v-if="statusPop !== 2"
  113. ><input
  114. type="file"
  115. style="display: none"
  116. @change="uploadListImg(indexsop, $event)"
  117. />{{
  118. options.imgUrl !== null && options.imgUrl
  119. ? "更换图片"
  120. : "上传图片"
  121. }}</label
  122. >
  123. <el-image
  124. v-if="options.imgUrl !== null && options.imgUrl"
  125. style="
  126. width: 50px;
  127. height: 50px;
  128. border-radius: 4px;
  129. border: 1px dotted #a4a4a4;
  130. padding: 4px;
  131. "
  132. :src="$methodsTools.splitImgHost(options.imgUrl)"
  133. :preview-src-list="[$methodsTools.splitImgHost(options.imgUrl)]"
  134. >
  135. </el-image>
  136. <!-- <img
  137. v-if="options.imgUrl !== null && options.imgUrl"
  138. style="
  139. width: 50px;
  140. height: 50px;
  141. border-radius: 4px;
  142. border: 1px dotted #a4a4a4;
  143. padding: 4px;
  144. "
  145. :src="$methodsTools.splitImgHost(options.imgUrl)"
  146. alt=""
  147. /> -->
  148. </div>
  149. <div
  150. style="display: flex; align-items: center"
  151. v-if="statusPop !== 2"
  152. >
  153. <i
  154. class="el-icon-circle-plus"
  155. style="margin-right: 5px; font-size: 30px; cursor: pointer"
  156. @click="addListcontent"
  157. ></i>
  158. <span
  159. style="color: #409eff; cursor: pointer"
  160. @click="addListcontent"
  161. >添加选项</span
  162. >
  163. </div>
  164. </div>
  165. </div>
  166. <div style="margin-bottom: 15px" v-if="dingForm.type === 4">
  167. <div
  168. style="display: flex; align-items: center"
  169. v-if="statusPop !== 2"
  170. >
  171. <i
  172. class="el-icon-circle-plus"
  173. style="margin-right: 5px; font-size: 30px; cursor: pointer"
  174. @click="addListItem"
  175. ></i
  176. ><span style="color: #409eff; cursor: pointer" @click="addListItem"
  177. >添加问题</span
  178. >
  179. </div>
  180. <!-- 案例题 -->
  181. <div style="padding-left: 50px">
  182. <div v-for="(ans, ain) in dingForm.optionsList" :key="ain">
  183. <div class="marg_play">
  184. <el-button
  185. v-if="statusPop !== 2"
  186. @click="delAnliChi(ain)"
  187. style="border-radius: 50%; margin: 0px 6px"
  188. type="danger"
  189. icon="el-icon-delete"
  190. size="mini"
  191. circle
  192. ></el-button>
  193. <span class="spans">题目类型:</span>
  194. <el-radio-group
  195. v-model="ans.type"
  196. @change="changeTypeChild(ain)"
  197. >
  198. <el-radio
  199. v-for="(tng, nindex) in radioArray"
  200. :key="nindex"
  201. :label="tng.value"
  202. :disabled="statusPop === 2"
  203. >{{ tng.label }}</el-radio
  204. >
  205. </el-radio-group>
  206. </div>
  207. <div class="marg_play">
  208. <span class="spans"
  209. ><span style="color: red">* </span>题目:</span
  210. >
  211. <div>
  212. <editor
  213. v-model="ans.content"
  214. :max-height="300"
  215. :uploadStatus="uploadStatus"
  216. />
  217. </div>
  218. </div>
  219. <!-- <div class="marg_play">
  220. <span class="spans">图片:</span>
  221. <div>
  222. <div class="imgBoxTopic">
  223. <label class="imgLabel">
  224. <div class="msPhoto" v-if="ans.imgUrl">
  225. <img
  226. :src="$methodsTools.splitImgHost(ans.imgUrl)"
  227. alt="图片加载失败"
  228. />
  229. </div>
  230. <div class="imgbbx" v-else>
  231. <p>点击添加图片</p>
  232. <i class="el-icon-plus"></i>
  233. </div>
  234. <input
  235. :id="'inputstopi' + nums + ain"
  236. type="file"
  237. :disabled="statusPop === 2"
  238. style="display: none"
  239. @change="getImgFiletopics(ain, $event)"
  240. />
  241. </label>
  242. </div>
  243. <p style="color: #999999; line-height: 22px">
  244. 支持扩展名:.jpeg .bmp .png .jpg...<br />为保证显示效果,请上传分辨率为100x100且大小小于2M图片
  245. </p>
  246. </div>
  247. </div> -->
  248. <div
  249. class="marg_play"
  250. v-if="ans.type === 1 || ans.type === 2"
  251. >
  252. <span class="spans"
  253. ><span style="color: red" v-if="ans.type !== 5">* </span
  254. >选项:</span
  255. >
  256. <div style="flex: 1">
  257. <div
  258. style="
  259. display: flex;
  260. align-items: center;
  261. margin-bottom: 8px;
  262. "
  263. v-for="(answerItem, indexsops) in ans.optionsList"
  264. :key="indexsops"
  265. >
  266. <span>选项{{ indexsops + 1 }}:</span>
  267. <el-input
  268. style="flex: 1; margin: 0px 10px"
  269. type="textarea"
  270. :disabled="statusPop === 2"
  271. v-model="answerItem.content"
  272. placeholder="请输入内容"
  273. :autosize="{ minRows: 2, maxRows: 2 }"
  274. maxlength="500"
  275. ></el-input>
  276. <span>{{ answerItem.content.length }}/500</span>
  277. <el-button
  278. v-if="statusPop === 1"
  279. @click="delListchi(ain, indexsops)"
  280. style="border-radius: 50%; margin: 0px 6px"
  281. type="danger"
  282. icon="el-icon-delete"
  283. size="mini"
  284. circle
  285. ></el-button>
  286. <label class="btnSty" v-if="statusPop !== 2"
  287. ><input
  288. type="file"
  289. style="display: none"
  290. @change="uploadListImgchi(ain, indexsops, $event)"
  291. />{{
  292. answerItem.imgUrl !== null && answerItem.imgUrl
  293. ? "更换图片"
  294. : "上传图片"
  295. }}</label
  296. >
  297. <el-image
  298. v-if="answerItem.imgUrl !== null && answerItem.imgUrl"
  299. style="
  300. width: 50px;
  301. height: 50px;
  302. border-radius: 4px;
  303. border: 1px dotted #a4a4a4;
  304. padding: 4px;
  305. "
  306. :src="$methodsTools.splitImgHost(answerItem.imgUrl)"
  307. :preview-src-list="[
  308. $methodsTools.splitImgHost(answerItem.imgUrl),
  309. ]"
  310. >
  311. </el-image>
  312. <!-- <img
  313. v-if="answerItem.imgUrl !== null && answerItem.imgUrl"
  314. style="
  315. width: 50px;
  316. height: 50px;
  317. border-radius: 4px;
  318. border: 1px dotted #a4a4a4;
  319. padding: 4px;
  320. "
  321. :src="$methodsTools.splitImgHost(answerItem.imgUrl)"
  322. alt=""
  323. /> -->
  324. </div>
  325. <div
  326. style="display: flex; align-items: center"
  327. v-if="statusPop !== 2"
  328. >
  329. <i
  330. class="el-icon-circle-plus"
  331. style="
  332. margin-right: 5px;
  333. font-size: 30px;
  334. cursor: pointer;
  335. "
  336. @click="addListcontentchi(ain)"
  337. ></i>
  338. <span
  339. style="color: #409eff; cursor: pointer"
  340. @click="addListcontentchi(ain)"
  341. >添加选项</span
  342. >
  343. </div>
  344. </div>
  345. </div>
  346. <div class="marg_play" v-if="ans.type === 1">
  347. <span class="spans"
  348. ><span style="color: red">* </span>正确答案:</span
  349. >
  350. <el-radio-group
  351. v-for="(oAsz, oindexsz) in ans.optionsList"
  352. :key="oindexsz"
  353. v-model="ans.answerQuestion"
  354. >
  355. <el-radio
  356. style="margin-right: 12px"
  357. :disabled="statusPop === 2"
  358. :label="oindexsz + 1 + ''"
  359. >选项{{ oindexsz + 1 }}</el-radio
  360. >
  361. </el-radio-group>
  362. </div>
  363. <div class="marg_play" v-else-if="ans.type === 2">
  364. <span class="spans"
  365. ><span style="color: red">* </span>正确答案:</span
  366. >
  367. <el-checkbox-group v-model="ans.answerQuestionList">
  368. <el-checkbox
  369. style="margin-right: 12px"
  370. v-for="(oAsz, oindexsz) in ans.optionsList"
  371. :key="oindexsz"
  372. :disabled="statusPop === 2"
  373. :label="oindexsz + 1"
  374. >选项{{ oindexsz + 1 }}</el-checkbox
  375. >
  376. </el-checkbox-group>
  377. </div>
  378. <div class="marg_play" v-if="ans.type === 3">
  379. <span class="spans"
  380. ><span style="color: red">* </span>正确答案:</span
  381. >
  382. <el-radio-group v-model="ans.answerQuestion">
  383. <el-radio :disabled="statusPop === 2" label="1"
  384. >正确</el-radio
  385. >
  386. <el-radio :disabled="statusPop === 2" label="0"
  387. >错误</el-radio
  388. >
  389. </el-radio-group>
  390. </div>
  391. <div class="marg_play">
  392. <span class="spans">答案解析:</span>
  393. <div>
  394. <editor
  395. v-model="ans.analysisContent"
  396. :max-height="300"
  397. :uploadStatus="uploadStatus"
  398. />
  399. </div>
  400. </div>
  401. </div>
  402. </div>
  403. <!-- 案例题 -->
  404. </div>
  405. <div class="marg_play" v-if="dingForm.type === 1">
  406. <span class="spans"
  407. ><span style="color: red">* </span>正确答案:</span
  408. >
  409. <el-radio-group
  410. v-for="(oA, oindex) in dingForm.optionsList"
  411. :key="oindex"
  412. v-model="dingForm.answerQuestion"
  413. >
  414. <el-radio
  415. style="margin-right: 12px"
  416. :disabled="statusPop === 2"
  417. :label="oindex + 1 + ''"
  418. >选项{{ oindex + 1 }}</el-radio
  419. >
  420. </el-radio-group>
  421. </div>
  422. <div class="marg_play" v-else-if="dingForm.type === 2">
  423. <span class="spans"
  424. ><span style="color: red">* </span>正确答案:</span
  425. >
  426. <el-checkbox-group v-model="dingForm.answerQuestionList">
  427. <el-checkbox
  428. style="margin-right: 12px"
  429. v-for="(oA, oindex) in dingForm.optionsList"
  430. :key="oindex"
  431. :disabled="statusPop === 2"
  432. :label="oindex + 1"
  433. >选项{{ oindex + 1 }}</el-checkbox
  434. >
  435. </el-checkbox-group>
  436. </div>
  437. <div class="marg_play" v-if="dingForm.type === 3">
  438. <span class="spans"
  439. ><span style="color: red">* </span>正确答案:</span
  440. >
  441. <el-radio-group v-model="dingForm.answerQuestion">
  442. <el-radio :disabled="statusPop === 2" label="1">正确</el-radio>
  443. <el-radio :disabled="statusPop === 2" label="0">错误</el-radio>
  444. </el-radio-group>
  445. </div>
  446. <div class="marg_play" v-if="dingForm.type !== 4">
  447. <span class="spans">答案解析:</span>
  448. <div>
  449. <editor
  450. v-model="dingForm.analysisContent"
  451. :max-height="300"
  452. :uploadStatus="uploadStatus"
  453. />
  454. </div>
  455. </div>
  456. <!-- <div class="marg_play">
  457. <span class="spans">是否启用:</span>
  458. <el-radio-group v-model="dingForm.status">
  459. <el-radio :disabled="statusPop === 2" :label="1">启用</el-radio>
  460. <el-radio :disabled="statusPop === 2" :label="0">停用</el-radio>
  461. </el-radio-group>
  462. </div> -->
  463. </el-col>
  464. <el-col
  465. :span="2"
  466. style="
  467. display: flex;
  468. align-items: center;
  469. justify-content: flex-end;
  470. cursor: pointer;
  471. "
  472. >
  473. <el-button
  474. type="success"
  475. icon="el-icon-arrow-right"
  476. circle
  477. @click="next"
  478. v-if="statusPop === 2"
  479. ></el-button>
  480. </el-col>
  481. </el-col>
  482. </div>
  483. </template>
  484. <script>
  485. import Editor from "@/components/Editor";
  486. export default {
  487. components: { Editor },
  488. name: "questionBank",
  489. props: ["nums", "dingFormInfo"],
  490. data() {
  491. return {
  492. dingForm: {},
  493. uploadStatus: 2,
  494. statusPop: 1,
  495. innerVisiblePaperTopic: false,
  496. fullscreenChildPaperTopic: false, //当前打开窗数据
  497. radioArrays: [
  498. {
  499. label: "单选题",
  500. value: 1,
  501. },
  502. {
  503. label: "多选题",
  504. value: 2,
  505. },
  506. {
  507. label: "判断题",
  508. value: 3,
  509. },
  510. {
  511. label: "简答题",
  512. value: 5,
  513. },
  514. {
  515. label: "案例题",
  516. value: 4,
  517. },
  518. ],
  519. radioArray: [
  520. {
  521. label: "单选题",
  522. value: 1,
  523. },
  524. {
  525. label: "多选题",
  526. value: 2,
  527. },
  528. {
  529. label: "判断题",
  530. value: 3,
  531. },
  532. {
  533. label: "简答题",
  534. value: 5,
  535. },
  536. ],
  537. queryData: 1,
  538. };
  539. },
  540. mounted() {
  541. // this.$nextTick(function () {
  542. // this.$on("childmethods", function (v, int) {
  543. // this.addClick(v, int);
  544. // });
  545. // });
  546. },
  547. watch: {
  548. dingFormInfo: {
  549. handler(newVal, oldVal) {
  550. console.log(newVal)
  551. this.dingForm = newVal;
  552. },
  553. // 立即处理 进入页面就触发
  554. immediate: true,
  555. },
  556. },
  557. methods: {
  558. changeTypes(int) {
  559. var data = {
  560. questionId: this.dingForm.questionId ? this.dingForm.questionId : "",
  561. type: int,
  562. optionsList: [],
  563. answerQuestionList: [],
  564. answerQuestion: "",
  565. content: "",
  566. analysisContent: "",
  567. };
  568. switch (int) {
  569. case 1:
  570. for (let i = 0; i < 4; i++) {
  571. data.optionsList.push({
  572. content: "",
  573. imgUrl: null,
  574. optionsId: i + 1,
  575. });
  576. }
  577. break;
  578. case 2:
  579. for (let i = 0; i < 5; i++) {
  580. data.optionsList.push({
  581. content: "",
  582. imgUrl: null,
  583. optionsId: i + 1,
  584. });
  585. }
  586. break;
  587. case 4:
  588. var datas = {
  589. analysisContent: "",
  590. answerQuestion: "",
  591. answerQuestionList: [],
  592. content: "",
  593. optionsList: [],
  594. type: 1,
  595. };
  596. for (let i = 0; i < 4; i++) {
  597. datas.optionsList.push({
  598. content: "",
  599. imgUrl: null,
  600. optionsId: i + 1,
  601. });
  602. }
  603. data.optionsList.push(datas);
  604. default:
  605. break;
  606. }
  607. this.dingForm = data;
  608. },
  609. changeTypeChild(index) {
  610. this.dingForm.optionsList[index].optionsList = [];
  611. this.dingForm.optionsList[index].answerQuestion = "";
  612. switch (this.dingForm.optionsList[index].type) {
  613. case 1:
  614. for (let i = 0; i < 4; i++) {
  615. this.dingForm.optionsList[index].optionsList.push({
  616. content: "",
  617. imgUrl: null,
  618. optionsId: i + 1,
  619. });
  620. }
  621. break;
  622. case 2:
  623. for (let i = 0; i < 5; i++) {
  624. this.dingForm.optionsList[index].optionsList.push({
  625. content: "",
  626. imgUrl: null,
  627. optionsId: i + 1,
  628. });
  629. }
  630. break;
  631. default:
  632. break;
  633. }
  634. // this.dingForm.optionsList[index].optionsList = [];
  635. // this.dingForm.optionsList[index].answerQuestion = "";
  636. },
  637. getInfosPage() {
  638. return this.dingForm;
  639. },
  640. back() {
  641. this.tableData.forEach((item, index) => {
  642. if (item.questionId === this.dingForm.questionId) {
  643. if (index === 0) {
  644. this.$message.warning("这是当前页第一题了");
  645. } else {
  646. var datas = this.tableData[index - 1].questionId;
  647. this.$api.obtainbankquestion(datas).then((res) => {
  648. this.dingForm = res.data;
  649. });
  650. }
  651. }
  652. });
  653. },
  654. next() {
  655. this.tableData.forEach((item, index) => {
  656. if (item.questionId === this.dingForm.questionId) {
  657. if (this.tableData.length - 1 === index) {
  658. this.$message.warning("这是当前页最后一题了");
  659. } else {
  660. var datas = this.tableData[index + 1].questionId;
  661. this.$api.obtainbankquestion(datas).then((res) => {
  662. this.dingForm = res.data;
  663. });
  664. }
  665. }
  666. });
  667. },
  668. addClick(v, int) {
  669. if (v === undefined) {
  670. this.dingForm = {
  671. optionsList: [],
  672. status: 1,
  673. };
  674. this.statusPop = 1;
  675. } else {
  676. var datas = v.questionId;
  677. this.statusPop = int;
  678. this.$api.obtainbankquestion(datas).then((res) => {
  679. this.dingForm = res.data;
  680. });
  681. }
  682. this.innerVisiblePaperTopic = true;
  683. },
  684. delTopic() {
  685. this.$confirm("此操作将删除该题目, 是否继续?", "提示", {
  686. confirmButtonText: "确定",
  687. cancelButtonText: "取消",
  688. type: "warning",
  689. })
  690. .then(async () => {
  691. var data = JSON.parse(JSON.stringify(this.dingForm));
  692. data.parentType = Number(this.queryData.typeId);
  693. // data.status = -1;
  694. console.log(data);
  695. this.$message.success("删除成功");
  696. this.search();
  697. this.innerVisiblePaperTopic = false;
  698. })
  699. .catch(() => {
  700. this.$message({
  701. type: "info",
  702. message: "已取消删除",
  703. });
  704. });
  705. },
  706. //删除案例问题
  707. delAnliChi(int) {
  708. this.dingForm.optionsList.splice(int, 1);
  709. },
  710. //删除选项 非案例
  711. delList(index) {
  712. this.dingForm.optionsList.splice(index, 1);
  713. this.dingForm.optionsList.map((items, indexs) => {
  714. items.optionsId = indexs + 1;
  715. });
  716. if (this.dingForm.type === 1) {
  717. this.dingForm.answerQuestion = "";
  718. }
  719. if (this.dingForm.type === 2) {
  720. this.dingForm.answerQuestionList = [];
  721. }
  722. },
  723. //删除选项 案例
  724. delListchi(fatherIndex, childrenIndex) {
  725. this.dingForm.optionsList[fatherIndex].optionsList.splice(
  726. childrenIndex,
  727. 1
  728. );
  729. this.dingForm.optionsList[fatherIndex].optionsList.map(
  730. (items, indexs) => {
  731. items.optionsId = indexs + 1;
  732. }
  733. );
  734. if (this.dingForm.optionsList[fatherIndex].type === 1) {
  735. this.dingForm.optionsList[fatherIndex].answerQuestion = "";
  736. }
  737. if (this.dingForm.optionsList[fatherIndex].type === 2) {
  738. this.dingForm.optionsList[fatherIndex].answerQuestionList = [];
  739. }
  740. },
  741. //新增选项 非案例
  742. addListcontent() {
  743. var data = {
  744. content: "",
  745. imgUrl: null,
  746. optionsId: this.dingForm.optionsList.length + 1,
  747. };
  748. this.dingForm.optionsList.push(data);
  749. },
  750. //新增选项 案例
  751. addListcontentchi(int) {
  752. var data = {
  753. content: "",
  754. imgUrl: null,
  755. optionsId: this.dingForm.optionsList[int].optionsList.length + 1,
  756. };
  757. this.dingForm.optionsList[int].optionsList.push(data);
  758. },
  759. //新增问题 案例
  760. addListItem() {
  761. var data = {
  762. analysisContent: "",
  763. answerQuestion: "",
  764. answerQuestionList: [],
  765. content: "",
  766. optionsList: [],
  767. type: 1,
  768. };
  769. for (let i = 0; i < 4; i++) {
  770. data.optionsList.push({
  771. content: "",
  772. imgUrl: null,
  773. optionsId: i + 1,
  774. });
  775. }
  776. this.dingForm.optionsList.push(data);
  777. },
  778. // 上传图片
  779. async getImgFiletopic(nums, e) {
  780. var file = e.target.files[0];
  781. if (file === undefined) {
  782. return;
  783. }
  784. if (file.size > 2 * 1024 * 1024) {
  785. this.$message.error("图片不得大于2MB");
  786. return;
  787. }
  788. var type = e.target.value.toLowerCase().split(".").splice(-1);
  789. if (
  790. type[0] != "jpg" &&
  791. type[0] != "png" &&
  792. type[0] != "jpeg" &&
  793. type[0] != "bmp"
  794. ) {
  795. this.$message.error("上传格式需为:.jpg/.png/.jpeg/bmp");
  796. return;
  797. }
  798. const imgUrls = await this.imgUpload(file, 2);
  799. console.log(this.dingForm, nums);
  800. this.$set(this.dingForm, "imgUrl", imgUrls);
  801. },
  802. // 上传内容list图片
  803. async uploadListImg(k, e) {
  804. var file = e.target.files[0];
  805. if (file === undefined) {
  806. return;
  807. }
  808. if (file.size > 2 * 1024 * 1024) {
  809. this.$message.error("图片不得大于2MB");
  810. return;
  811. }
  812. var type = e.target.value.toLowerCase().split(".").splice(-1);
  813. if (
  814. type[0] != "jpg" &&
  815. type[0] != "png" &&
  816. type[0] != "jpeg" &&
  817. type[0] != "bmp"
  818. ) {
  819. this.$message.error("上传格式需为:.jpg/.png/.jpeg/bmp");
  820. return;
  821. }
  822. const imgUrls = await this.imgUpload(file, 2);
  823. this.$set(this.dingForm.optionsList[k], "imgUrl", imgUrls);
  824. },
  825. // 案例上传内容list图片
  826. async uploadListImgchi(fatherIndex, k, e) {
  827. var file = e.target.files[0];
  828. if (file === undefined) {
  829. return;
  830. }
  831. if (file.size > 2 * 1024 * 1024) {
  832. this.$message.error("图片不得大于2MB");
  833. return;
  834. }
  835. var type = e.target.value.toLowerCase().split(".").splice(-1);
  836. if (
  837. type[0] != "jpg" &&
  838. type[0] != "png" &&
  839. type[0] != "jpeg" &&
  840. type[0] != "bmp"
  841. ) {
  842. this.$message.error("上传格式需为:.jpg/.png/.jpeg/bmp");
  843. return;
  844. }
  845. const imgUrls = await this.imgUpload(file, 2);
  846. this.$set(
  847. this.dingForm.optionsList[fatherIndex].optionsList[k],
  848. "imgUrl",
  849. imgUrls
  850. );
  851. },
  852. //案例 子题目图片
  853. async getImgFiletopics(int, e) {
  854. var file = e.target.files[0];
  855. if (file === undefined) {
  856. return;
  857. }
  858. if (file.size > 2 * 1024 * 1024) {
  859. this.$message.error("图片不得大于2MB");
  860. return;
  861. }
  862. var type = e.target.value.toLowerCase().split(".").splice(-1);
  863. if (
  864. type[0] != "jpg" &&
  865. type[0] != "png" &&
  866. type[0] != "jpeg" &&
  867. type[0] != "bmp"
  868. ) {
  869. this.$message.error("上传格式需为:.jpg/.png/.jpeg/bmp");
  870. return;
  871. }
  872. const imgUrls = await this.imgUpload(file, 2);
  873. this.$set(this.dingForm.optionsList[int], "imgUrl", imgUrls);
  874. },
  875. imgUpload(file, int) {
  876. var self = this;
  877. return new Promise((resolve, reject) => {
  878. this.$upload
  879. .upload(file, int)
  880. .then((res) => {
  881. resolve(res);
  882. })
  883. .catch((err) => {
  884. self.$message.error("图片上传错误");
  885. });
  886. });
  887. },
  888. },
  889. };
  890. </script>
  891. <style lang="less" scoped>
  892. .contentMore {
  893. border: 1px solid #999;
  894. padding: 10px;
  895. }
  896. .marg_play {
  897. display: flex;
  898. margin-bottom: 15px;
  899. .spans {
  900. flex-shrink: 0;
  901. text-align: right;
  902. width: 80px;
  903. }
  904. }
  905. .imgBox {
  906. width: 100%;
  907. // height: 210px;
  908. border: 1px solid #e2e2e2;
  909. border-radius: 8px;
  910. padding: 8px 8px 3px;
  911. display: flex;
  912. flex-direction: column;
  913. align-items: center;
  914. .imgLabel {
  915. flex: 1;
  916. width: 100%;
  917. border: 1px dotted #e2e2e2;
  918. color: #999;
  919. font-size: 14px;
  920. cursor: pointer;
  921. border-radius: 8px;
  922. .msPhoto {
  923. display: flex;
  924. justify-content: center;
  925. align-items: center;
  926. max-width: 100%;
  927. max-height: 270px;
  928. img {
  929. max-width: 100%;
  930. max-height: 270px;
  931. }
  932. }
  933. .imgbbx {
  934. display: flex;
  935. flex-direction: column;
  936. align-items: center;
  937. justify-content: center;
  938. width: 100%;
  939. height: 100%;
  940. i {
  941. font-weight: bold;
  942. margin: 14px 0;
  943. font-size: 24px;
  944. }
  945. }
  946. }
  947. p {
  948. margin: 5px 0px;
  949. }
  950. }
  951. .imgBoxTopic {
  952. width: 150px;
  953. height: 150px;
  954. border: 1px solid #e2e2e2;
  955. border-radius: 8px;
  956. display: flex;
  957. flex-direction: column;
  958. align-items: center;
  959. .imgLabel {
  960. flex: 1;
  961. width: 100%;
  962. background-color: #f9f9f9;
  963. color: #999;
  964. font-size: 14px;
  965. cursor: pointer;
  966. border-radius: 8px;
  967. .msPhoto {
  968. display: flex;
  969. justify-content: center;
  970. align-items: center;
  971. height: 100%;
  972. max-width: 100%;
  973. max-height: 150px;
  974. img {
  975. max-width: 100%;
  976. max-height: 150px;
  977. }
  978. }
  979. .imgbbx {
  980. display: flex;
  981. flex-direction: column;
  982. align-items: center;
  983. justify-content: center;
  984. width: 100%;
  985. height: 100%;
  986. i {
  987. font-weight: bold;
  988. margin: 8px 0;
  989. font-size: 20px;
  990. }
  991. }
  992. }
  993. }
  994. .btnSty {
  995. cursor: pointer;
  996. padding: 4px 10px;
  997. background-color: #409eff;
  998. color: #fff;
  999. text-align: center;
  1000. border-radius: 8px;
  1001. margin-right: 6px;
  1002. }
  1003. </style>