Picture.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <!-- -->
  2. <template>
  3. <div :class="['Big-Book-PictureBox']" v-if="curQue">
  4. <!-- <ul class="Big-Book-PictureBox-item" v-for="(item,index) in curQue.queList" :key="index"> -->
  5. <li v-for="(items,indexs) in curQue.option" :key="indexs">
  6. <div v-for="(itemss,indexss) in items.img_list" :key="indexss">
  7. <el-image
  8. :src="itemss.url"
  9. fit="scale-down"
  10. class="img_url"
  11. >
  12. <div slot="placeholder" class="image-slot">
  13. <img src="../../../assets/common/icon-imgloading.png" />
  14. </div>
  15. </el-image>
  16. </div>
  17. <template v-if="curQue.ChildType!='image_gdcy'">
  18. <p v-if="items.hanzi">{{items.hanzi}}</p>
  19. </template>
  20. <template v-if="curQue.ChildType=='image_input'||curQue.ChildType=='image_input_three'||curQue.ChildType=='image_wordInput'">
  21. <input class="singleInput" v-model="userAnswer.input" placeholder="输入" @blur="handleInput('input')">
  22. </template>
  23. <!-- <input class="singleInput" placeholder="输入" @blur="handleInput(index,indexs)" v-if="fn_list_obj[index]&&fn_list_obj[index].indexOf('input')>-1"> -->
  24. <!-- 补齐输入 -->
  25. <template v-if="curQue.ChildType=='image_gdcy'">
  26. <div class="fill-box">
  27. <b v-if="items.hanzi">{{items.hanzi}}</b>
  28. <input v-model="userAnswer.input" placeholder="输入" @blur="handleInput('input')">
  29. </div>
  30. </template>
  31. <!-- 双输入 -->
  32. <template v-if="curQue.ChildType=='image_dobleinput'">
  33. <div class="DoubleInput-box">
  34. <input placeholder="输入" @blur="handleInput('dInput',0)" v-model="userAnswer.dInput[0]">
  35. <input placeholder="输入" @blur="handleInput('dInput',1)" v-model="userAnswer.dInput[1]">
  36. </div>
  37. </template>
  38. <!-- 判断 -->
  39. <template v-if="curQue.ChildType=='image_judge'">
  40. <div class="judge-box">
  41. <a :class="['right-btn',userAnswer.judge=='right'?'active':'']" @click="handleSelectJudge('right')"></a>
  42. <a :class="['error-btn',userAnswer.judge=='error'?'active':'']" @click="handleSelectJudge('error')"></a>
  43. </div>
  44. </template>
  45. <!-- 单选 -->
  46. <template v-if="curQue.ChildType=='image_single'">
  47. <el-radio v-model="userAnswer.singleRadio" label="1"><span></span></el-radio>
  48. </template>
  49. <!-- 复选 -->
  50. <template v-if="curQue.ChildType=='image_checkBox'">
  51. <el-checkbox v-model="userAnswer.singlechecked"><span></span></el-checkbox>
  52. </template>
  53. <!-- 三件套 -->
  54. <div class="luyinVoice-box" v-if="items.mp3_list.length>0||fn_list_obj&&fn_list_obj.indexOf('image_record')>-1">
  55. <template v-if="items.mp3_list.length>0">
  56. <span :class="['voice',mp3Play]" @click="playmicrophone(items.mp3_list[0].url,'mp3')"></span>
  57. </template>
  58. <Soundrecord @handleWav="handleWav" type="normal" class="luyin-box" v-if="fn_list_obj.indexOf('image_record')>-1"/>
  59. <!-- <span :class="['luyin',microphoneStatus?'active':'']" @click="microphone"></span>
  60. <span :class="['play',hasMicro]" @click="playmicrophone(wavblob)"></span> -->
  61. </div>
  62. </li>
  63. <!-- </ul> -->
  64. </div>
  65. </template>
  66. <script>
  67. import Soundrecord from "../preview/Soundrecord.vue"; // 录音模板
  68. import Recorder from "js-audio-recorder"; //录音插件
  69. export default {
  70. components: { Soundrecord, },
  71. props: ["curQue",],
  72. data() {
  73. return {
  74. fn_list_obj: '',
  75. answer: [],
  76. userAnswer: {
  77. input:'', // 输入
  78. dInput: ['',''], //双输入
  79. judge:'',// 判断
  80. singleRadio:'',
  81. singlechecked: false,
  82. }, // 记录用户答题内容
  83. recorder: new Recorder({
  84. sampleBits: 16, // 采样位数,支持 8 或 16,默认是16
  85. sampleRate: 16000, // 采样率,支持 11025、16000、22050、24000、44100、48000,根据浏览器默认值,我的chrome是48000
  86. numChannels: 1, // 声道,支持 1 或 2, 默认是1
  87. }),
  88. microphoneStatus: false,
  89. hasMicro: "", // 录音后的样式class
  90. wavblob: null,
  91. audio: new window.Audio(),
  92. oldUrl: null, // 存储上个播放音频地址
  93. mp3Play: '',// 音频播放
  94. };
  95. },
  96. computed: {},
  97. watch: {},
  98. //方法集合
  99. methods: {
  100. handleFnList() {
  101. let obj = '';
  102. this.curQue.fn_list.forEach(node=>{
  103. if (node.isFn) {
  104. obj += node.type + ','
  105. }
  106. // if(obj.indexOf('input')>-1){
  107. // node.option.forEach((i)=>{
  108. // userItem.push('')
  109. // })
  110. // }
  111. // this.userAnswer.push(userItem)
  112. })
  113. this.fn_list_obj = obj
  114. },
  115. // 修改正确选项中得某一个为正确答案
  116. changAnswer(index, type) {
  117. if (type == "single") {
  118. console.log(this.answer);
  119. } else if (type == "checkBox") {
  120. let correct = [];
  121. this.curQue.option.forEach((item, i) => {
  122. if (item.isChecked) {
  123. correct.push(i);
  124. }
  125. });
  126. this.answer[0].checkBox = correct;
  127. console.log(this.answer);
  128. } else if (type == "judge") {
  129. console.log(this.answer);
  130. }
  131. },
  132. // 去掉前后空格
  133. handleInput(index,indexs){
  134. if(indexs||indexs==0){
  135. let res = this.userAnswer[index][indexs].trim()
  136. this.$set(this.userAnswer[index],indexs,res)
  137. }else{
  138. this.userAnswer[index] = this.userAnswer[index].trim()
  139. }
  140. },
  141. playmicrophone (url,type) {
  142. if(url){
  143. let _this = this;
  144. if (!this.audio.paused) {
  145. this.audio.pause();
  146. if(type=='mp3'){
  147. _this.mp3Play = ''
  148. }
  149. }else if( this.audio.paused && _this.oldUrl == url ){
  150. _this.audio.play();
  151. if(type=='mp3'){
  152. _this.mp3Play = 'active'
  153. }
  154. } else {
  155. _this.audio.pause();
  156. _this.audio.load();
  157. if(type=='mp3'){
  158. _this.mp3Play = 'active'
  159. _this.audio.src = url
  160. }
  161. _this.oldUrl = url
  162. _this.audio.play();
  163. }
  164. }
  165. },
  166. // 判断题选择
  167. handleSelectJudge(obj){
  168. this.userAnswer.judge = obj
  169. },
  170. handleWav(data) {
  171. this.userAnswer = []
  172. this.userAnswer.push(data)
  173. // this.getAnswer(this.userAnswer, this.queIndex);
  174. this.cur.BookWavAnswerWav = [data]
  175. },
  176. },
  177. //生命周期 - 创建完成(可以访问当前this实例)
  178. created() {},
  179. //生命周期 - 挂载完成(可以访问DOM元素)
  180. mounted() {
  181. if (this.curQue) {
  182. this.handleFnList();
  183. let obj = {
  184. single: [],
  185. checkBox: [],
  186. judge: [],
  187. input: [],
  188. spell: [],
  189. };
  190. this.answer.push(obj);
  191. }
  192. let _this = this;
  193. _this.audio.addEventListener("ended", function () {
  194. _this.mp3Play = ''
  195. _this.hasMicro = 'normal'
  196. });
  197. },
  198. beforeCreate() {}, //生命周期 - 创建之前
  199. beforeMount() {}, //生命周期 - 挂载之前
  200. beforeUpdate() {}, //生命周期 - 更新之前
  201. updated() {}, //生命周期 - 更新之后
  202. beforeDestroy() {}, //生命周期 - 销毁之前
  203. destroyed() {}, //生命周期 - 销毁完成
  204. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  205. };
  206. </script>
  207. <style lang='scss' scoped>
  208. //@import url(); 引入公共css类
  209. .Big-Book-PictureBox{
  210. width: 100%;
  211. // &.PictureBoxFlex{
  212. // display: flex;
  213. // justify-content: space-between;
  214. // .Big-Book-PictureBox-item{
  215. // width: 384px;
  216. // }
  217. // }
  218. // .Big-Book-PictureBox-item{
  219. // list-style: none;
  220. // background: #F3F3F3;
  221. // border-radius: 8px;
  222. // padding: 16px;
  223. // margin: 0;
  224. // display: flex;
  225. // flex-flow: wrap;
  226. li{
  227. list-style: none;
  228. padding: 8px;
  229. border-radius: 8px;
  230. border: 1px solid rgba(0, 0, 0, 0.1);
  231. background: #fff;
  232. >p{
  233. color: #000000;
  234. font-size: 16px;
  235. line-height: 150%;
  236. text-align: center;
  237. margin: 0;
  238. width: 100%;
  239. margin-top: 8px;
  240. padding: 4px 8px;
  241. }
  242. input{
  243. flex: 1;
  244. width: 100%;
  245. border: 1px solid rgba(0, 0, 0, 0.15);
  246. box-sizing: border-box;
  247. border-radius: 4px;
  248. outline: none;
  249. height: 32px;
  250. padding: 4px 8px;
  251. color: #000000;
  252. text-align: center;
  253. font-size: 16px;
  254. line-height: 150%;
  255. &.singleInput{
  256. margin-top: 8px;
  257. }
  258. }
  259. .luyinVoice-box{
  260. width: 100%;
  261. margin-top: 8px;
  262. display: flex;
  263. -ms-flex-pack: justify;
  264. align-items: center;
  265. span{
  266. width: 24px;
  267. height: 24px;
  268. background-position: center;
  269. background-repeat: no-repeat;
  270. background-size: 24px;
  271. margin-right: 8px;
  272. cursor: pointer;
  273. &:first-child{
  274. margin-left: 0px;
  275. }
  276. &.voice{
  277. background-image: url('../../../assets/newImage/common/icon-voice-red.png');
  278. }
  279. &.active {
  280. background-image: url('../../../assets/newImage/common/icon-voice-play-red.png');
  281. }
  282. // &.luyin{
  283. // background-image: url('../../../assets/newImage/common/luyin.png');
  284. // &.active {
  285. // background-image: url('../../../assets/newImage/common/luyin-active.png');
  286. // }
  287. // }
  288. // &.play{
  289. // background-image: url('../../../assets/newImage/common/luyin-play.png');
  290. // &.normal {
  291. // background-image: url('../../../assets/newImage/common/luyin-play-active.png');
  292. // }
  293. // &.stop {
  294. // background-image: url('../../../assets/newImage/common/luyin-play-stop.png');
  295. // }
  296. // }
  297. }
  298. .luyin-box{
  299. flex: 1;
  300. justify-content: start;
  301. padding-left: 8px;
  302. border: 1px solid rgba(0, 0, 0, 0.1);
  303. border-radius: 8px;
  304. }
  305. }
  306. .fill-box{
  307. display: flex;
  308. align-items: center;
  309. margin-top: 8px;
  310. b{
  311. margin-right: 8px;
  312. color: #000000;
  313. font-weight: normal;
  314. font-size: 16px;
  315. }
  316. }
  317. .DoubleInput-box{
  318. display: flex;
  319. align-items: center;
  320. margin-top: 8px;
  321. >input:first-child{
  322. margin-right: 8px;
  323. }
  324. }
  325. .el-radio,.el-checkbox{
  326. width: 100%;
  327. margin: 8px 0 0;
  328. text-align: center;
  329. height: 32px;
  330. line-height: 32px;
  331. }
  332. .judge-box{
  333. margin-top: 8px;
  334. display: flex;
  335. justify-content: center;
  336. a{
  337. width: 70px;
  338. height: 32px;
  339. background: #F7F7F7 url('../../../assets/newImage/common/right-btn.png') center no-repeat;
  340. background-size: 24px;
  341. border-radius: 4px;
  342. border: 1px solid #F7F7F7;
  343. &:hover,&.active{
  344. background-color: #E5FFF0;
  345. border-color: #00C850;
  346. }
  347. }
  348. a.error-btn{
  349. background: #F7F7F7 url('../../../assets/newImage/common/error-btn.png') center no-repeat;
  350. background-size: 24px;
  351. margin-left: 4px;
  352. &:hover,&.active{
  353. background-color: #FFE5E5;
  354. border-color: #DE4444;
  355. }
  356. }
  357. }
  358. }
  359. .img_url{
  360. width: 100%;
  361. height: 128px;
  362. }
  363. // }
  364. }
  365. </style>
  366. <style lang="scss">
  367. ul,li{
  368. list-style: none;
  369. padding: 0;
  370. margin: 0;
  371. }
  372. .Big-Book-PictureBox{
  373. .el-checkbox__label,.el-radio__label{
  374. padding: 0;
  375. }
  376. }
  377. </style>