Single.vue 13 KB

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