Single.vue 12 KB

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