questionBank.vue 28 KB

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