Single.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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. title:"",
  165. topicNumber: "",
  166. IsRecord: false,
  167. topic: {
  168. con: "",
  169. img_list: [],
  170. mp3_list: [],
  171. },
  172. option: [
  173. {
  174. number: "",
  175. con: "",
  176. img_list: [],
  177. mp3_list: [],
  178. isAnswer: "",
  179. font: "",
  180. },
  181. {
  182. number: "",
  183. con: "",
  184. img_list: [],
  185. mp3_list: [],
  186. isAnswer: "",
  187. font: "",
  188. },
  189. ],
  190. correct: [],
  191. numberList: {
  192. type: "number",
  193. name: "每行几个",
  194. con: "2",
  195. arr: [
  196. {
  197. id: 1,
  198. value: 1,
  199. },
  200. {
  201. id: 2,
  202. value: 2,
  203. },
  204. {
  205. id: 3,
  206. value: 3,
  207. },
  208. {
  209. id: 4,
  210. value: 4,
  211. },
  212. ],
  213. },
  214. },
  215. ],
  216. data_structure2: [
  217. {
  218. type: "checkbox_chs",
  219. name: "多选题",
  220. title: "",
  221. IsRecord: false,
  222. topic: {
  223. con: "",
  224. img_list: [],
  225. mp3_list: [],
  226. },
  227. option: [
  228. {
  229. con: "",
  230. img_list: [],
  231. mp3_list: [],
  232. isAnswer: "",
  233. number: "",
  234. },
  235. {
  236. con: "",
  237. img_list: [],
  238. mp3_list: [],
  239. isAnswer: "",
  240. number: "",
  241. },
  242. ],
  243. correct: [],
  244. numberList: {
  245. type: "number",
  246. name: "每行几个",
  247. con: "2",
  248. arr: [
  249. {
  250. id: 1,
  251. value: 1,
  252. },
  253. {
  254. id: 2,
  255. value: 2,
  256. },
  257. {
  258. id: 3,
  259. value: 3,
  260. },
  261. {
  262. id: 4,
  263. value: 4,
  264. },
  265. ],
  266. },
  267. },
  268. ],
  269. data_structure3: [
  270. {
  271. type: "listen_record_single_chs",
  272. name: "听录音选答案",
  273. title: "",
  274. topic: {
  275. con: "",
  276. mp3_list: [],
  277. },
  278. option: [
  279. {
  280. con: "",
  281. mp3_list: [],
  282. isAnswer: "",
  283. number: "",
  284. },
  285. {
  286. con: "",
  287. mp3_list: [],
  288. isAnswer: "",
  289. number: "",
  290. },
  291. ],
  292. correct: [],
  293. numberList: {
  294. type: "number",
  295. name: "每行几个",
  296. con: "2",
  297. arr: [
  298. {
  299. id: 1,
  300. value: 1,
  301. },
  302. {
  303. id: 2,
  304. value: 2,
  305. },
  306. {
  307. id: 3,
  308. value: 3,
  309. },
  310. {
  311. id: 4,
  312. value: 4,
  313. },
  314. ],
  315. },
  316. },
  317. ],
  318. };
  319. },
  320. computed: {},
  321. watch: {},
  322. //方法集合
  323. methods: {
  324. // 修改正确选项中得某一个为正确答案
  325. changAnswer(index) {
  326. let arr = [];
  327. if (this.curQue.type == "single_chs") {
  328. this.curQue.option.forEach((item, i) => {
  329. if (index == i) {
  330. this.curQue.correct = [];
  331. arr.push(i);
  332. } else {
  333. item.isAnswer = "";
  334. }
  335. });
  336. this.curQue.correct = arr;
  337. } else if (this.curQue.type == "checkbox_chs") {
  338. this.curQue.option.forEach((item, i) => {
  339. if (index == i && item.isAnswer != "") {
  340. this.curQue.correct.push(i);
  341. } else if (index == i && item.isAnswer == "") {
  342. this.curQue.correct.splice(i, 1);
  343. }
  344. });
  345. }
  346. },
  347. // 删除其中一道题
  348. deletetopic(index) {
  349. this.$confirm("确定要删除吗?", "提示", {
  350. confirmButtonText: "确定",
  351. cancelButtonText: "取消",
  352. type: "warning",
  353. })
  354. .then(() => {
  355. if (this.curQue.length <= 1) {
  356. this.$message.warning("至少要保留1个题");
  357. return;
  358. }
  359. this.curQue.splice(index, 1);
  360. })
  361. },
  362. // 删除其中一个选项
  363. deleteOptionOne(index, toIndex) {
  364. this.$confirm("确定要删除吗?", "提示", {
  365. confirmButtonText: "确定",
  366. cancelButtonText: "取消",
  367. type: "warning",
  368. })
  369. .then(() => {
  370. if (this.curQue[toIndex].option.length <= 2) {
  371. this.$message.warning("至少要保留两个选项");
  372. return;
  373. }
  374. this.curQue[toIndex].option.splice(index, 1);
  375. })
  376. },
  377. // 添加一个题
  378. addtopic() {
  379. let obj;
  380. if (this.type == "single_chs") {
  381. obj = JSON.parse(JSON.stringify(this.data_structure[0]));
  382. } else if (this.type == "checkbox_chs") {
  383. obj = JSON.parse(JSON.stringify(this.data_structure2[0]));
  384. } else if (this.type == "listen_record_single_chs") {
  385. obj = JSON.parse(JSON.stringify(this.data_structure3[0]));
  386. }
  387. this.curQue.push(obj);
  388. },
  389. //添加一个选项
  390. addOption(index) {
  391. let obj;
  392. if (this.type == "single_chs") {
  393. obj = JSON.parse(JSON.stringify(this.data_structure[0].option[0]));
  394. } else if (this.type == "checkbox_chs") {
  395. obj = JSON.parse(JSON.stringify(this.data_structure2[0].option[0]));
  396. } else if (this.type == "listen_record_single_chs") {
  397. obj = JSON.parse(JSON.stringify(this.data_structure3[0].option[0]));
  398. }
  399. this.curQue[index].option.push(obj);
  400. },
  401. timuchangeMp3(fileList, items, index) {
  402. const articleImgList = JSON.parse(JSON.stringify(fileList));
  403. const articleImgRes = [];
  404. articleImgList.forEach((item) => {
  405. if (item.response) {
  406. const obj = {
  407. name: item.name,
  408. url: item.response.file_info_list[0].file_url,
  409. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  410. media_duration: item.response.file_info_list[0].media_duration, //音频时长
  411. };
  412. articleImgRes.push(obj);
  413. }
  414. });
  415. this.curQue[index].topic.mp3_list = JSON.parse(
  416. JSON.stringify(articleImgRes)
  417. );
  418. },
  419. timuchangeImage(fileList, items, index) {
  420. const articleImgList = JSON.parse(JSON.stringify(fileList));
  421. const articleImgRes = [];
  422. articleImgList.forEach((item) => {
  423. if (item.response) {
  424. const obj = {
  425. name: item.name,
  426. url: item.response.file_info_list[0].file_url,
  427. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  428. };
  429. articleImgRes.push(obj);
  430. }
  431. });
  432. this.curQue[index].topic.img_list = JSON.parse(
  433. JSON.stringify(articleImgRes)
  434. );
  435. },
  436. },
  437. //生命周期 - 创建完成(可以访问当前this实例)
  438. created() {
  439. if (!this.curQue) {
  440. if (this.type == "single_chs") {
  441. this.changeCurQue(this.data_structure);
  442. } else if (this.type == "checkbox_chs") {
  443. this.changeCurQue(this.data_structure2);
  444. } else if (this.type == "listen_record_single_chs") {
  445. this.changeCurQue(this.data_structure3);
  446. }
  447. }
  448. },
  449. //生命周期 - 挂载完成(可以访问DOM元素)
  450. mounted() {},
  451. beforeCreate() {}, //生命周期 - 创建之前
  452. beforeMount() {}, //生命周期 - 挂载之前
  453. beforeUpdate() {}, //生命周期 - 更新之前
  454. updated() {}, //生命周期 - 更新之后
  455. beforeDestroy() {}, //生命周期 - 销毁之前
  456. destroyed() {}, //生命周期 - 销毁完成
  457. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  458. };
  459. </script>
  460. <style lang='scss' scope>
  461. //@import url(); 引入公共css类
  462. .Big-Book-Single {
  463. &-content {
  464. &.m {
  465. display: flex;
  466. justify-content: flex-start;
  467. align-items: flex-start;
  468. }
  469. .Big-Book-title {
  470. font-size: 16px;
  471. line-height: 40px;
  472. color: #000;
  473. margin-right: 15px;
  474. }
  475. .Big-Book-main {
  476. > div {
  477. margin-bottom: 10px;
  478. &.Big-Book-pinyin {
  479. display: flex;
  480. justify-content: flex-start;
  481. align-items: center;
  482. }
  483. }
  484. }
  485. }
  486. .addoption {
  487. width: 565px;
  488. height: 40px;
  489. left: 40px;
  490. top: 304px;
  491. background: #f3f3f3;
  492. border: 1px dashed rgba(0, 0, 0, 0.15);
  493. box-sizing: border-box;
  494. border-radius: 4px;
  495. text-align: center;
  496. line-height: 40px;
  497. cursor: pointer;
  498. }
  499. .close {
  500. width: 24px;
  501. cursor: pointer;
  502. }
  503. }
  504. </style>
  505. <style lang="scss">
  506. </style>