Single.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <!-- -->
  2. <template>
  3. <div class="Big-Book-Single" v-if="curQue">
  4. <div
  5. class="Big-Book-Single-content"
  6. style="margin-left: 20px; margin-top: 20px"
  7. v-for="(topic, toIndex) in curQue"
  8. :key="toIndex + 'topic'"
  9. >
  10. <div class="adult-book-input-item" v-if="type == 'single_chs'">
  11. <span class="adult-book-lable">题号:</span>
  12. <el-input
  13. class="adult-book-input"
  14. :autosize="{ minRows: 2 }"
  15. type="textarea"
  16. placeholder="请输入题号"
  17. v-model="topic.topicNumber"
  18. @blur="topic.topicNumber = topic.topicNumber.trim()"
  19. maxlength="200"
  20. show-word-limit
  21. ></el-input>
  22. <img
  23. @click="deletetopic(toIndex)"
  24. class="close"
  25. src="../../../assets/adult/del-close.png"
  26. alt=""
  27. />
  28. </div>
  29. <div class="adult-book-input-item" v-else>
  30. <span class="adult-book-lable">标题:</span>
  31. <el-input
  32. class="adult-book-input"
  33. :autosize="{ minRows: 2 }"
  34. type="textarea"
  35. placeholder="请输入标题"
  36. v-model="topic.title"
  37. @blur="topic.title = topic.title.trim()"
  38. maxlength="500"
  39. show-word-limit
  40. ></el-input>
  41. <img
  42. @click="deletetopic(toIndex)"
  43. class="close"
  44. src="../../../assets/adult/del-close.png"
  45. alt=""
  46. />
  47. </div>
  48. <div
  49. class="adult-book-input-item"
  50. v-if="type == 'single_chs' || type == 'checkbox_chs'"
  51. >
  52. <span class="adult-book-lable">录音:</span>
  53. <el-radio-group v-model="topic.IsRecord">
  54. <el-radio :label="true">需要</el-radio>
  55. <el-radio :label="false">不需要</el-radio>
  56. </el-radio-group>
  57. </div>
  58. <div class="adult-book-input-item" v-if="topic.IsRecord">
  59. <span class="adult-book-lable">录音控件:</span>
  60. <img src="../../../assets/adult/pro.png" alt="" />
  61. </div>
  62. <div class="adult-book-input-item">
  63. <span class="adult-book-lable">题目:</span>
  64. <el-input
  65. class="adult-book-input"
  66. :autosize="{ minRows: 2 }"
  67. type="textarea"
  68. placeholder="请输入题目"
  69. v-model="topic.topic.con"
  70. @blur="topic.topic.con = topic.topic.con.trim()"
  71. maxlength="500"
  72. show-word-limit
  73. ></el-input>
  74. </div>
  75. <div
  76. class="adult-book-input-item"
  77. v-if="type == 'single_chs' || type == 'checkbox_chs'"
  78. >
  79. <span class="adult-book-lable">题目图片:</span>
  80. <Upload
  81. :changeFillId="timuchangeImage"
  82. :datafileList="topic.topic.img_list"
  83. :filleNumber="imgNumber"
  84. :uploadType="'image'"
  85. :index="toIndex"
  86. />
  87. </div>
  88. <div class="adult-book-input-item">
  89. <span class="adult-book-lable">题目音频:</span>
  90. <Upload
  91. :changeFillId="timuchangeMp3"
  92. :datafileList="topic.topic.mp3_list"
  93. :filleNumber="mp3Number"
  94. :uploadType="'mp3'"
  95. :index="toIndex"
  96. />
  97. </div>
  98. <div
  99. class="Big-Book-main"
  100. v-for="(item, index) in topic.option"
  101. :key="item + index"
  102. style="border-bottom: 1px #ccc solid; margin-bottom: 20px"
  103. >
  104. <SingleModule
  105. :curQueItem="item"
  106. :index="index"
  107. :toIndex="toIndex"
  108. :changAnswer="changAnswer"
  109. :deleteOptionOne="deleteOptionOne"
  110. :type="type"
  111. />
  112. </div>
  113. <div class="addoption" @click="addOption(toIndex)">添加一个选项</div>
  114. <div class="Big-Book-divide">
  115. <el-divider content-position="center">功能设置</el-divider>
  116. <span style="margin: 0 10px">请选择每行数量</span>
  117. <el-select v-model="topic.numberList.con" placeholder="请选择">
  118. <el-option
  119. v-for="(item, i) in topic.numberList.arr"
  120. :key="i"
  121. :label="item.value"
  122. :value="item.id"
  123. >
  124. </el-option>
  125. </el-select>
  126. </div>
  127. </div>
  128. <div style="margin-top: 15px" class="addoption" @click="addtopic">
  129. 添加一个题
  130. </div>
  131. </div>
  132. </template>
  133. <script>
  134. import Inputmodule from "../common/Inputmodule.vue";
  135. import SingleModule from "../common/SingleModule.vue";
  136. import Upload from "../common/Upload.vue";
  137. export default {
  138. name: "Single",
  139. props: ["curQue", "fn_data", "changeCurQue", "type"],
  140. components: {
  141. Inputmodule,
  142. SingleModule,
  143. Upload,
  144. },
  145. data() {
  146. return {
  147. form: {
  148. stem: {
  149. con: "",
  150. pinyin: "",
  151. english: "",
  152. highlight: "",
  153. underline: "",
  154. img_url: [],
  155. mp3_url: [],
  156. },
  157. },
  158. imgNumber: 1,
  159. mp3Number: 1,
  160. data_structure: [
  161. {
  162. type: "single_chs",
  163. name: "单选题",
  164. topicNumber: "",
  165. IsRecord: false,
  166. topic: {
  167. con: "",
  168. img_list: [],
  169. mp3_list: [],
  170. },
  171. option: [
  172. {
  173. number: "",
  174. con: "",
  175. img_list: [],
  176. mp3_list: [],
  177. isAnswer: "",
  178. font: "",
  179. },
  180. {
  181. number: "",
  182. con: "",
  183. img_list: [],
  184. mp3_list: [],
  185. isAnswer: "",
  186. font: "",
  187. },
  188. ],
  189. correct: [],
  190. numberList: {
  191. type: "number",
  192. name: "每行几个",
  193. con: "2",
  194. arr: [
  195. {
  196. id: 1,
  197. value: 1,
  198. },
  199. {
  200. id: 2,
  201. value: 2,
  202. },
  203. {
  204. id: 3,
  205. value: 3,
  206. },
  207. {
  208. id: 4,
  209. value: 4,
  210. },
  211. ],
  212. },
  213. },
  214. ],
  215. data_structure2: [
  216. {
  217. type: "checkbox_chs",
  218. name: "多选题",
  219. title: "",
  220. IsRecord: false,
  221. topic: {
  222. con: "",
  223. img_list: [],
  224. mp3_list: [],
  225. },
  226. option: [
  227. {
  228. con: "",
  229. img_list: [],
  230. mp3_list: [],
  231. isAnswer: "",
  232. number: "",
  233. },
  234. {
  235. con: "",
  236. img_list: [],
  237. mp3_list: [],
  238. isAnswer: "",
  239. number: "",
  240. },
  241. ],
  242. correct: [],
  243. numberList: {
  244. type: "number",
  245. name: "每行几个",
  246. con: "2",
  247. arr: [
  248. {
  249. id: 1,
  250. value: 1,
  251. },
  252. {
  253. id: 2,
  254. value: 2,
  255. },
  256. {
  257. id: 3,
  258. value: 3,
  259. },
  260. {
  261. id: 4,
  262. value: 4,
  263. },
  264. ],
  265. },
  266. },
  267. ],
  268. data_structure3: [
  269. {
  270. type: "listen_record_single_chs",
  271. name: "听录音选答案",
  272. title: "",
  273. topic: {
  274. con: "",
  275. mp3_list: [],
  276. },
  277. option: [
  278. {
  279. con: "",
  280. mp3_list: [],
  281. isAnswer: "",
  282. number: "",
  283. },
  284. {
  285. con: "",
  286. mp3_list: [],
  287. isAnswer: "",
  288. number: "",
  289. },
  290. ],
  291. correct: [],
  292. numberList: {
  293. type: "number",
  294. name: "每行几个",
  295. con: "2",
  296. arr: [
  297. {
  298. id: 1,
  299. value: 1,
  300. },
  301. {
  302. id: 2,
  303. value: 2,
  304. },
  305. {
  306. id: 3,
  307. value: 3,
  308. },
  309. {
  310. id: 4,
  311. value: 4,
  312. },
  313. ],
  314. },
  315. },
  316. ],
  317. };
  318. },
  319. computed: {},
  320. watch: {},
  321. //方法集合
  322. methods: {
  323. // 修改正确选项中得某一个为正确答案
  324. changAnswer(index) {
  325. let arr = [];
  326. if (this.curQue.type == "single_chs") {
  327. this.curQue.option.forEach((item, i) => {
  328. if (index == i) {
  329. this.curQue.correct = [];
  330. arr.push(i);
  331. } else {
  332. item.isAnswer = "";
  333. }
  334. });
  335. this.curQue.correct = arr;
  336. } else if (this.curQue.type == "checkbox_chs") {
  337. this.curQue.option.forEach((item, i) => {
  338. if (index == i && item.isAnswer != "") {
  339. this.curQue.correct.push(i);
  340. } else if (index == i && item.isAnswer == "") {
  341. this.curQue.correct.splice(i, 1);
  342. }
  343. });
  344. }
  345. },
  346. // 删除其中一道题
  347. deletetopic(index) {
  348. if (this.curQue.length <= 1) {
  349. this.$message.warning("至少要保留1个题");
  350. return;
  351. }
  352. this.curQue.splice(index, 1);
  353. },
  354. // 删除其中一个选项
  355. deleteOptionOne(index, toIndex) {
  356. if (this.curQue[toIndex].option.length <= 2) {
  357. this.$message.warning("至少要保留两个选项");
  358. return;
  359. }
  360. this.curQue[toIndex].option.splice(index, 1);
  361. },
  362. // 添加一个题
  363. addtopic() {
  364. let obj;
  365. if (this.type == "single_chs") {
  366. obj = JSON.parse(JSON.stringify(this.data_structure[0]));
  367. } else if (this.type == "checkbox_chs") {
  368. obj = JSON.parse(JSON.stringify(this.data_structure2[0]));
  369. } else if (this.type == "listen_record_single_chs") {
  370. obj = JSON.parse(JSON.stringify(this.data_structure3[0]));
  371. }
  372. this.curQue.push(obj);
  373. },
  374. //添加一个选项
  375. addOption(index) {
  376. let obj;
  377. if (this.type == "single_chs") {
  378. obj = JSON.parse(JSON.stringify(this.data_structure[0].option[0]));
  379. } else if (this.type == "checkbox_chs") {
  380. obj = JSON.parse(JSON.stringify(this.data_structure2[0].option[0]));
  381. } else if (this.type == "listen_record_single_chs") {
  382. obj = JSON.parse(JSON.stringify(this.data_structure3[0].option[0]));
  383. }
  384. this.curQue[index].option.push(obj);
  385. },
  386. timuchangeMp3(fileList, items, index) {
  387. const articleImgList = JSON.parse(JSON.stringify(fileList));
  388. const articleImgRes = [];
  389. articleImgList.forEach((item) => {
  390. if (item.response) {
  391. const obj = {
  392. name: item.name,
  393. url: item.response.file_info_list[0].file_url,
  394. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  395. media_duration: item.response.file_info_list[0].media_duration, //音频时长
  396. };
  397. articleImgRes.push(obj);
  398. }
  399. });
  400. this.curQue[index].topic.mp3_list = JSON.parse(
  401. JSON.stringify(articleImgRes)
  402. );
  403. },
  404. timuchangeImage(fileList, items, index) {
  405. const articleImgList = JSON.parse(JSON.stringify(fileList));
  406. const articleImgRes = [];
  407. articleImgList.forEach((item) => {
  408. if (item.response) {
  409. const obj = {
  410. name: item.name,
  411. url: item.response.file_info_list[0].file_url,
  412. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  413. };
  414. articleImgRes.push(obj);
  415. }
  416. });
  417. this.curQue[index].topic.img_list = JSON.parse(
  418. JSON.stringify(articleImgRes)
  419. );
  420. },
  421. },
  422. //生命周期 - 创建完成(可以访问当前this实例)
  423. created() {
  424. if (!this.curQue) {
  425. if (this.type == "single_chs") {
  426. this.changeCurQue(this.data_structure);
  427. } else if (this.type == "checkbox_chs") {
  428. this.changeCurQue(this.data_structure2);
  429. } else if (this.type == "listen_record_single_chs") {
  430. this.changeCurQue(this.data_structure3);
  431. }
  432. }
  433. },
  434. //生命周期 - 挂载完成(可以访问DOM元素)
  435. mounted() {},
  436. beforeCreate() {}, //生命周期 - 创建之前
  437. beforeMount() {}, //生命周期 - 挂载之前
  438. beforeUpdate() {}, //生命周期 - 更新之前
  439. updated() {}, //生命周期 - 更新之后
  440. beforeDestroy() {}, //生命周期 - 销毁之前
  441. destroyed() {}, //生命周期 - 销毁完成
  442. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  443. };
  444. </script>
  445. <style lang='scss' scope>
  446. //@import url(); 引入公共css类
  447. .Big-Book-Single {
  448. &-content {
  449. &.m {
  450. display: flex;
  451. justify-content: flex-start;
  452. align-items: flex-start;
  453. }
  454. .Big-Book-title {
  455. font-size: 16px;
  456. line-height: 40px;
  457. color: #000;
  458. margin-right: 15px;
  459. }
  460. .Big-Book-main {
  461. > div {
  462. margin-bottom: 10px;
  463. &.Big-Book-pinyin {
  464. display: flex;
  465. justify-content: flex-start;
  466. align-items: center;
  467. }
  468. }
  469. }
  470. }
  471. .addoption {
  472. width: 565px;
  473. height: 40px;
  474. left: 40px;
  475. top: 304px;
  476. background: #f3f3f3;
  477. border: 1px dashed rgba(0, 0, 0, 0.15);
  478. box-sizing: border-box;
  479. border-radius: 4px;
  480. text-align: center;
  481. line-height: 40px;
  482. cursor: pointer;
  483. }
  484. .close {
  485. width: 24px;
  486. cursor: pointer;
  487. }
  488. }
  489. </style>
  490. <style lang="scss">
  491. </style>