mtm_book.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. //播放音频图片地址
  2. var PicInfo = {
  3. yaoshiShowImgUrl: "yaoshi-show.png",
  4. yaoshiHideImgUrl: "yaoshi-hide.png",
  5. updateAnswerImgUrl: "update-answer.png",
  6. recordPlayImgUrl: "file:///android_asset/js/play.png",
  7. recordPauseImgUrl: "file:///android_asset/js/pause.png",
  8. audioPlayImgUrl: "file:///android_asset/js/dynaiselaba.gif",
  9. audioPauseImgUrl: "file:///android_asset/js/dynaiselaba.png"
  10. }
  11. //显示、隐藏答案
  12. function showHideAnswer(flag) {
  13. if (flag) {
  14. //$(".underlineContent").show();
  15. $(".underlineContent").css("color", "#92D050");
  16. $(".yaoshi").attr("src", PicInfo.yaoshiShowImgUrl);
  17. }
  18. else {
  19. //$(".underlineContent").hide();
  20. $(".underlineContent").css("color", "#ffffff");
  21. $(".yaoshi").attr("src", PicInfo.yaoshiHideImgUrl);
  22. }
  23. }
  24. ///显示、隐藏钥匙及答案 isShowYX:显示和隐藏钥匙,isShowAS:显示和隐藏答案
  25. function showHideAnswerEx(isShowYX, isShowAS) {
  26. if (isShowYX) {
  27. $(".yaoshi").show();
  28. }
  29. else {
  30. $(".yaoshi").hide();
  31. }
  32. if (isShowAS) {
  33. $.each($(".underlineContent"), function (index, item) {
  34. //$(item).html($(item).attr("data-text"));
  35. $(item).css("color", "#92D050");
  36. });
  37. $(".yaoshi").data("status", "1");
  38. $(".yaoshi").attr("src", PicInfo.yaoshiShowImgUrl);
  39. }
  40. else {
  41. $.each($(".underlineContent,.underlineContent.no-answer"), function (index, item) {
  42. //var count = 0;
  43. //var text = $(item).attr("data-text");
  44. //if (text != "" && text) {
  45. // $(item).html(text.replace(/./g, function (match, group) {
  46. // //最多替换30个
  47. // if (count < 30) {
  48. // count++;
  49. // return "&nbsp;";
  50. // }
  51. // return "";
  52. // }));
  53. //}
  54. $(item).css("color", "#ffffff");
  55. });
  56. $(".yaoshi").data("status", "0");
  57. $(".yaoshi").attr("src", PicInfo.yaoshiHideImgUrl);
  58. }
  59. }
  60. //页面加载完,原文 绑定事件
  61. function bindEventTeaOrignalYS() {
  62. //显示/隐藏习题答案
  63. $(".yaoshi").on("click", function () {
  64. var curDisplay = $(this).nextUntil(".yaoshi").find(".underlineContent").eq(0).css("display");
  65. if (curDisplay == "undefined" || curDisplay == undefined) return;
  66. if (curDisplay == "none") {
  67. $(this).nextUntil(".yaoshi").find(".underlineContent").show()
  68. $(this).attr("src", PicInfo.yaoshiShowImgUrl);
  69. } else {
  70. $(this).nextUntil(".yaoshi").find(".underlineContent").hide();
  71. $(this).attr("src", PicInfo.yaoshiHideImgUrl);
  72. }
  73. });
  74. //处理答题点
  75. $.each($(".underlineContent"), function (index, item) {
  76. $(item).attr("data-text", $(item).html());
  77. });
  78. //给音频绑定一个ID
  79. $.each($(".audioImg"), function (index, item) {
  80. $(item).attr("audiourl", "");
  81. $(item).attr('audio-id', index);
  82. });
  83. //给视频图标处理
  84. $.each($(".videoImg"), function (index, item) {
  85. $(item).attr("audiourl", "");
  86. });
  87. //给口语图标处理
  88. $.each($(".oralLanguageImg"), function (index, item) {
  89. $(item).attr("audiourl", "");
  90. });
  91. //去除多余的U空标签
  92. $.each($("u"), function (index, item) {
  93. var text = $(item).text();
  94. text = text.replace(/\s+/g, "");
  95. if (text == "") {
  96. $(item).remove();
  97. }
  98. });
  99. //处理暂无参考答案
  100. $.each($(".yaoshi"), function (index, item) {
  101. var prev = $(item).nextUntil(".yaoshi").find(".underlineContent");
  102. if (prev.length == 0) {
  103. var uHtml = document.createElement("u");
  104. uHtml.className = "underlineContent no-answer";
  105. uHtml.innerText = "暂无参考答案";
  106. uHtml.setAttribute("data-text", uHtml.innerText);
  107. $(item).after(uHtml);
  108. }
  109. });
  110. //处理表格宽度
  111. $.each($(".wordTable"), function (index, item) {
  112. $(item).css("width", bodyWidth + "px");
  113. });
  114. //点击喇叭事件,音频播放
  115. $(".audioImg").on("click", function () {
  116. audioPlayClick(this);
  117. });
  118. //点击播放事件,视频播放
  119. $(".videoImg").on("click", function () {
  120. var curHtml = $(this).parent().find(".videoUrl").html();
  121. var curAlt = $(this).attr("alt");//播放视频地址
  122. playVisiableAudioCallBack(2, $(this).attr("alt"));
  123. });
  124. //处理表格样式
  125. $("td").attr("style", "");
  126. //处理文章标题的样式(目前资料源已处理)
  127. //$("p").eq(2).addClass("p-title-top");
  128. }
  129. //页面加载完,课件 绑定事件
  130. function bindEventYS() {
  131. var bodyWidth = $(document.body).width();
  132. //给每个答题点加上ID
  133. $.each($(".yaoshi"), function (index, item) {
  134. $(item).attr('answer-id', index);
  135. });
  136. //给音频绑定一个ID
  137. $.each($(".audioImg"), function (index, item) {
  138. $(item).attr("audiourl", "");
  139. $(item).attr('audio-id', index);
  140. });
  141. //给视频图标处理
  142. $.each($(".videoImg"), function (index, item) {
  143. $(item).attr("audiourl", "");
  144. });
  145. //给口语图标处理
  146. $.each($(".oralLanguageImg"), function (index, item) {
  147. $(item).attr("audiourl", "");
  148. });
  149. //去除多余的U空标签
  150. $.each($("u"), function (index, item) {
  151. var text = $(item).text();
  152. text = text.replace(/\s+/g, "");
  153. if (text == "") {
  154. $(item).remove();
  155. }
  156. });
  157. //处理暂无参考答案
  158. $.each($(".yaoshi"), function (index, item) {
  159. var prev = $(item).nextAll(".underlineContent");
  160. if (prev.length == 0) {
  161. var uHtml = document.createElement("u");
  162. uHtml.className = "underlineContent no-answer";
  163. uHtml.innerText = "暂无参考答案";
  164. uHtml.setAttribute("data-text", uHtml.innerText);
  165. $(item).after(uHtml);
  166. }
  167. });
  168. //处理表格宽度
  169. $.each($(".wordTable"), function (index, item) {
  170. $(item).css("width", bodyWidth + "px");
  171. });
  172. //显示/隐藏习题答案
  173. $(".yaoshi").on("click", function () {
  174. if ($(this).data("status") == "0") {
  175. $(this).data("status", "1");
  176. $(this).attr("src", PicInfo.yaoshiShowImgUrl);
  177. $(this).nextUntil(".yaoshi").filter(".underlineContent").css("color", "#92D050");
  178. }
  179. else {
  180. $(this).data("status", "0");
  181. $(this).attr("src", PicInfo.yaoshiHideImgUrl);
  182. $(this).nextUntil(".yaoshi").filter(".underlineContent").css("color", "#ffffff");
  183. }
  184. });
  185. //点击喇叭事件,音频播放
  186. $(".audioImg").on("click", function () {
  187. audioPlayClick(this);
  188. });
  189. //点击播放事件,视频播放
  190. $(".videoImg").on("click", function () {
  191. $(this).attr("audiourl", "");
  192. var curHtml = $(this).parent().find(".videoUrl").html();
  193. var curAlt = $(this).attr("alt");//播放视频地址
  194. playVisiableAudioCallBack(2, $(this).attr("alt"));
  195. });
  196. //处理表格样式
  197. $("td").attr("style", "");
  198. //处理文章标题的样式(目前资料源已处理)
  199. //$("p").eq(2).addClass("p-title-top");
  200. }
  201. //获取所有作答答案及参考答案
  202. function getAllAnswer() {
  203. return answerData;
  204. }
  205. //学生端 处理作答区域
  206. var answerData = new Array();
  207. function handleAnswerRange() {
  208. //规范文本格式
  209. var answerId = "";
  210. var tempJson = new Array();
  211. $.each($(".yaoshi").nextUntil(".yaoshi").filter(".underline"), function (index, item) {
  212. tempId = $(item).prevAll(".yaoshi").attr("answer-id");
  213. //记录上一次的ID
  214. if (tempId == undefined) {
  215. tempId = answerId;
  216. }
  217. else {
  218. answerId = tempId;
  219. }
  220. var prev = $(item).prev();
  221. if ((prev.length == 0 || $(prev).attr("class") != "tag-span") && $(prev).attr("class") != "underlineContent") {
  222. if ($("span[answer-id='" + tempId + "']").length == 0) {
  223. $(item).prop("outerHTML", "<span answer-id='" + tempId + "' class='tag-span' answer-isky='0'>_</span>");
  224. }
  225. }
  226. $(item).remove();
  227. });
  228. //提取参考答案并规范文本格式
  229. answerId = "";
  230. $.each($(".yaoshi").nextUntil(".yaoshi").filter(".underlineContent"), function (index, item) {
  231. var info = new Object();
  232. info.Id = $(item).prevAll(".yaoshi").attr("answer-id");
  233. //记录上一次的ID
  234. if (info.Id == undefined) {
  235. info.Id = answerId;
  236. }
  237. else {
  238. answerId = info.Id;
  239. }
  240. info.AnsText = $(item).text();
  241. tempJson.push(info);
  242. var prev = $(item).prev();
  243. if (prev.length == 0 || $(prev).attr("class") != "tag-span") {
  244. //替换答案
  245. $(item).prop("outerHTML", "<span answer-id='" + info.Id + "' class='tag-span' answer-isky='0'>_</span>");
  246. }
  247. else {
  248. $(item).remove();
  249. }
  250. });
  251. //补充空钥匙的处理
  252. $.each($(".yaoshi"), function (index, item) {
  253. var Id = $(item).attr("answer-id");
  254. var prev = $(item).next();
  255. if (prev.length == 0 || $(prev).attr("class") != "tag-span") {
  256. if ($("span[answer-id='" + Id + "']").length == 0) {
  257. var uHtml = document.createElement("span");
  258. uHtml.className = "tag-span";
  259. uHtml.innerText = "_";
  260. uHtml.setAttribute("answer-id", Id);
  261. $(item).after(uHtml);
  262. }
  263. }
  264. });
  265. //处理口语试题
  266. $.each($(".oralLanguage").nextUntil(".oralLanguageDone"), function (num, part) {
  267. if ($(part).hasClass("underlinePart")) {
  268. $.each($(part).find(".tag-span"), function (index, item) {
  269. $(item).attr("answer-isky", "1");
  270. });
  271. }
  272. });
  273. //合并参考答案数据
  274. var tempid = "";
  275. var temptext = "";
  276. for (var i = 0; i < tempJson.length; i++) {
  277. if (tempid == tempJson[i].Id) {
  278. temptext = temptext + tempJson[i].AnsText;
  279. }
  280. else {
  281. if (tempid != "") {
  282. var info = new Object();
  283. info.Id = tempid;
  284. info.AnsText = temptext;
  285. answerData.push(info);
  286. //重置
  287. tempid = "";
  288. temptext = "";
  289. }
  290. tempid = tempJson[i].Id;
  291. temptext = tempJson[i].AnsText;
  292. //最后一个存入
  293. if (i == tempJson.length - 1) {
  294. var info = new Object();
  295. info.Id = tempid;
  296. info.AnsText = temptext;
  297. answerData.push(info);
  298. }
  299. }
  300. }
  301. //补全答题点
  302. var Num = 0;
  303. if (answerData.length > 0) {
  304. //Num = Number.parseInt(answerData[answerData.length - 1].Id);
  305. Num = Number.parseInt($(".yaoshi:last").attr('answer-id'));
  306. for (var i = 0; i < Num+1; i++) {
  307. if (i < answerData.length) {
  308. var index = Number(answerData[i].Id) - i;
  309. for (var j = 0; j < index; j++) {
  310. var info = new Object();
  311. info.Id = (i + j).toString();
  312. info.AnsText = "";
  313. answerData.splice(i, 0, info);
  314. }
  315. }
  316. else {
  317. var info = new Object();
  318. info.Id = (i).toString();
  319. info.AnsText = "";
  320. answerData.splice(i, 0, info);
  321. }
  322. }
  323. }
  324. //添加答题点的点击UI及交互
  325. $.each($(".tag-span"), function (index, item) {
  326. var answerText = "";
  327. var isky = $(item).attr('answer-isky');
  328. var answerid = $(item).attr('answer-id');
  329. for (var i = 0; i < answerData.length; i++) {
  330. if (answerid == answerData[i].Id) {
  331. answerText = answerData[i].AnsText;
  332. break;
  333. }
  334. }
  335. $(item).prop("outerHTML", "<buttom answer-id='" + answerid + "' answer-text='" + answerText + "' answer-isky='" + isky + "' class='answertext btn-bgimg'>点击作答</buttom>");
  336. //删除钥匙节点
  337. var prev = $("img[answer-id='" + answerid + "']");
  338. if (prev.length > 0) {
  339. $(prev).remove();
  340. }
  341. });
  342. //添加点击事件
  343. $(".answertext").on("click", function () {
  344. var curObj = new Object();
  345. curObj.Id = $(this).attr("answer-id");//答题点ID
  346. curObj.IsKY = $(this).attr("answer-isky");//是否是口语试题,0-不是口语题,1-是口语题
  347. curObj.Text = $(this).attr("answer-text");//用户作答内容
  348. curObj.Score = $(this).attr("answer-score");//作答评分
  349. curObj.AnsText = $(this).attr("answer-anstext");//参考答案
  350. curObj.Comment = $(this).attr("answer-comment");//评语
  351. //已作答,弹出作答答案
  352. if ($(this).data("ans-status") == "1") {
  353. //移动端添加外部处理
  354. onClickAnswerPoint(JSON.stringify(curObj));
  355. }
  356. else {
  357. //移动端添加外部处理,弹出作答操作
  358. onClickAnswerPoint(JSON.stringify(curObj));
  359. }
  360. });
  361. //去除多余的空格横线
  362. $.each($(".underline"), function (index, item) {
  363. var text = $(item).text();
  364. text = text.replace(/\s+/g, "");
  365. if (text == "") {
  366. $(item).remove();
  367. }
  368. });
  369. return answerData;
  370. }
  371. //接收学生的作答
  372. function reviewAnswer(answerJson) {
  373. //测试数据
  374. //answerJson = "{\"AudioLength\":0,\"Id\":\"2\",\"Text\":\"i am how i know\",\"Type\":1}";
  375. //answerJson = "{\"AudioLength\":3,\"AudioUrl\":\"http://172.16.41.241:10103/http_TBookEditor51/exerciseAnswerAudio/2020-11-06_09-31-19.wav\",\"Id\":\"4\",\"Text\":\"i know how i know \",\"Type\":3}";
  376. if (answerJson != "" && answerJson) {
  377. var answerObj = JSON.parse(answerJson);
  378. var selectElement = $(".answertext[answer-id='" + answerObj.Id + "']");
  379. var audioElement = $(".btn-play[answer-id='" + answerObj.Id + "']>span");
  380. //是否是音频作答
  381. if ((answerObj.Type == 3 || answerObj.Type == 4) && answerObj.AudioUrl != "") {
  382. answerObj.Text = answerObj.Text == "" ? answerObj.Text : "(" + answerObj.Text + ")";
  383. $(selectElement).text(answerObj.Text);
  384. //移除作答样式
  385. if ($(selectElement).hasClass("btn-bgimg")) {
  386. $(selectElement).removeClass("btn-bgimg");
  387. }
  388. //是否之前存在作答音频
  389. if (audioElement.length > 0) {
  390. $(audioElement).text("作答音频(" + answerObj.AudioLength + "s)");
  391. $(audioElement).parent().attr("answer-url", answerObj.AudioUrl);
  392. }
  393. else {
  394. var divHtml = document.createElement("div");
  395. divHtml.className = "btn-play";
  396. divHtml.innerHTML = "<img src='file:///android_asset/js/play.png'/><span>作答音频(" + answerObj.AudioLength + "s)</span>";
  397. divHtml.setAttribute("answer-id", answerObj.Id);
  398. divHtml.setAttribute("answer-url", answerObj.AudioUrl);
  399. divHtml.setAttribute("play-status", "0");
  400. //增加节点
  401. $(selectElement).before(divHtml);
  402. //独立绑定事件
  403. $(selectElement).prev().children("img").on("click", function () {
  404. recordAudioClick(this, answerObj.Id, answerObj.AudioUrl);
  405. });
  406. $(selectElement).prev().children("span").on("click", function () {
  407. //移动端的修改
  408. onClickAnswerPoint(JSON.stringify(answerObj));
  409. });
  410. }
  411. }
  412. else {
  413. answerObj.Text = answerObj.Text == "" ? "点击作答" : answerObj.Text;
  414. $(selectElement).text(answerObj.Text);
  415. //之前作答存在音频,但是现在没有音频传入,要删除音频节点
  416. if (audioElement.length > 0) {
  417. $(".btn-play[answer-id='" + answerObj.Id + "']").unbind('click');
  418. $(".btn-play[answer-id='" + answerObj.Id + "']").remove();
  419. }
  420. //增加作答样式
  421. if (!$(selectElement).hasClass("btn-bgimg")) {
  422. $(selectElement).addClass("btn-bgimg");
  423. }
  424. }
  425. }
  426. }
  427. //提交,获取所有作答答案及参考答案
  428. function getAllAnswer1() {
  429. //处理作答
  430. $.each($(".answertext"), function (index, item) {
  431. var mytext = $(item).text();
  432. if (mytext == "点击作答") {
  433. mytext = "未作答";
  434. $(item).text(mytext);
  435. }
  436. //移除作答样式
  437. if ($(item).hasClass("btn-bgimg")) {
  438. $(item).removeClass("btn-bgimg");
  439. }
  440. });
  441. $(".answertext").unbind('click');//取消点击绑定事件
  442. $(".btn-play>span").unbind('click');//取消点击绑定事件
  443. return answerData;
  444. }
  445. //回填所有答案,answerJson:所有作答及参考答案List,statusType:0-可作答,1-已提交,2-查看评阅
  446. function backupAllAnswer(answerJson, statusType) {
  447. if (answerJson != "" && answerJson) {
  448. var answerList = JSON.parse(answerJson);
  449. answerList = JSON.parse(answerList);
  450. //获取Dom一个个回填
  451. $.each($(".answertext"), function (index, item) {
  452. //提交直接还原作答现场
  453. var mytext = answerList[index].Text;//我的答案
  454. //可作答状态,作答还原
  455. if (statusType == 0) {
  456. //已作答过,还原作答,增加作答后的UI节点
  457. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  458. mytext = mytext == "" ? mytext : "(" + mytext + ")";
  459. $(item).text(mytext);
  460. //移除作答样式
  461. if ($(item).hasClass("btn-bgimg")) {
  462. $(item).removeClass("btn-bgimg");
  463. }
  464. //添加音频节点
  465. var divHtml = document.createElement("div");
  466. divHtml.className = "btn-play";
  467. divHtml.innerHTML = "<img src='" + PicInfo.recordPlayImgUrl + "'/><span>作答音频(" + answerList[index].AudioLength + "s)</span>";
  468. divHtml.setAttribute("answer-id", answerList[index].Id);
  469. divHtml.setAttribute("answer-url", answerList[index].AudioUrl);
  470. divHtml.setAttribute("play-status", "0");
  471. //增加节点
  472. $(item).before(divHtml);
  473. //独立绑定事件
  474. $(item).prev().children("img").on("click", function () {
  475. recordAudioClick(this, answerList[index].Id, answerList[index].AudioUrl);
  476. });
  477. $(item).prev().children("span").on("click", function () {
  478. onClickAnswerPoint(JSON.stringify(answerList[index]));
  479. });
  480. }
  481. else {
  482. //文本作答
  483. mytext = mytext == "" ? "点击作答" : mytext;//我的答案
  484. $(item).text(mytext);
  485. }
  486. }
  487. //已提交,作答还原
  488. if (statusType == 1) {
  489. $(item).unbind('click');//取消点击绑定事件
  490. //添加音频控制
  491. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  492. mytext = mytext == "" ? mytext : "(" + mytext + ")";
  493. $(item).text(mytext);
  494. //移除作答样式
  495. if ($(item).hasClass("btn-bgimg")) {
  496. $(item).removeClass("btn-bgimg");
  497. }
  498. //添加音频节点
  499. var divHtml = document.createElement("div");
  500. divHtml.className = "btn-play";
  501. divHtml.innerHTML = "<img src='" + PicInfo.recordPlayImgUrl + "'/><span>作答音频(" + answerList[index].AudioLength + "s)</span>";
  502. divHtml.setAttribute("answer-id", answerList[index].Id);
  503. divHtml.setAttribute("answer-url", answerList[index].AudioUrl);
  504. divHtml.setAttribute("play-status", "0");
  505. //增加节点
  506. $(item).before(divHtml);
  507. //独立绑定事件
  508. $(item).prev().children("img").on("click", function () {
  509. recordAudioClick(this, answerList[index].Id, answerList[index].AudioUrl);
  510. });
  511. }
  512. else {
  513. if (mytext == "") {
  514. mytext = "未作答";
  515. $(item).addClass("no-answer");
  516. //移除作答样式
  517. if ($(item).hasClass("btn-bgimg")) {
  518. $(item).removeClass("btn-bgimg");
  519. }
  520. }
  521. $(item).text(mytext);
  522. }
  523. }
  524. //已评阅,查看评阅详情
  525. if (statusType == 2) {
  526. //添加音频控制
  527. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  528. mytext = mytext == "" ? mytext : "(" + mytext + ")";
  529. $(item).text(mytext);
  530. //添加音频节点
  531. var divHtml = document.createElement("div");
  532. divHtml.className = "btn-play";
  533. divHtml.innerHTML = "<img src='" + PicInfo.recordPlayImgUrl + "'/><span>作答音频(" + answerList[index].AudioLength + "s)</span>";
  534. divHtml.setAttribute("answer-id", answerList[index].Id);
  535. divHtml.setAttribute("answer-url", answerList[index].AudioUrl);
  536. divHtml.setAttribute("play-status", "0");
  537. //增加节点
  538. $(item).before(divHtml);
  539. //独立绑定事件
  540. $(item).prev().children("img").on("click", function () {
  541. recordAudioClick(this, answerList[index].Id, answerList[index].AudioUrl);
  542. });
  543. $(item).prev().children("span").on("click", function () {
  544. onClickAnswerPoint(JSON.stringify(answerList[index]));
  545. });
  546. }
  547. else {
  548. if (mytext == "") {
  549. mytext = "未作答";
  550. $(item).addClass("no-answer");
  551. }
  552. $(item).text(mytext);
  553. }
  554. //评阅样式
  555. if (answerList[index].Score == 0 && answerList[index].Text != "") {
  556. $(item).addClass("bad-answer");
  557. }
  558. if (answerList[index].Score > 0) {
  559. $(item).addClass("good-answer");
  560. }
  561. //移除作答样式
  562. if ($(item).hasClass("btn-bgimg")) {
  563. $(item).removeClass("btn-bgimg");
  564. }
  565. }
  566. });
  567. }
  568. }
  569. //老师评阅学生作答
  570. function reviewStuAnswer(answerJson) {
  571. if (answerJson != "" && answerJson) {
  572. var answerObj = JSON.parse(answerJson);
  573. var selectElement = $(".answertext[answer-id='" + answerObj.Id + "']");
  574. //$(selectElement).attr("answer-text", answerObj.Text);//用户作答内容
  575. $(selectElement).attr("answer-score", answerObj.Score);//作答评分
  576. $(selectElement).attr("answer-anstext ", answerObj.AnsText);//参考答案
  577. $(selectElement).attr("answer-comment", answerObj.Comment);//评语
  578. //评阅样式
  579. if (answerObj.Score == 0) {
  580. $(selectElement).addClass("bad-answer");
  581. }
  582. if (answerObj.Score > 0) {
  583. $(selectElement).addClass("good-answer");
  584. }
  585. }
  586. }
  587. //回填所有评阅信息,answerJson:所有作答及参考答案评阅信息List
  588. function backupAllReview(answerJson) {
  589. //测试数据
  590. //answerJson = "[{\"AudioLength\":11,\"AudioUrl\":\"http://172.16.41.241:10103/http_TBookEditor51/exerciseAnswerAudio/2020-11-10_11-18-54.mp3\",\"Id\":\"2\",\"Text\":\"\",\"Type\":3}]";
  591. if (answerJson != "" && answerJson) {
  592. var answerList = JSON.parse(answerJson);
  593. //answerList = JSON.parse(answerList);
  594. //获取Dom一个个回填
  595. $.each($(".answertext"), function (index, item) {
  596. //$(item).attr("answer-id", answerList[index].Id);//答题点ID
  597. //$(item).attr("answer-text", answerList[index].Text);//用户作答内容
  598. $(item).attr("answer-score", answerList[index].Score);//作答评分
  599. $(item).attr("answer-anstext ", answerList[index].AnsText);//参考答案
  600. $(item).attr("answer-comment", answerList[index].Comment);//评语
  601. //提交直接还原作答现场
  602. var mytext = answerList[index].Text;//我的答案
  603. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  604. mytext = mytext == "" ? mytext : "(" + mytext + ")";
  605. $(item).text(mytext);
  606. //添加音频节点
  607. var divHtml = document.createElement("div");
  608. divHtml.className = "btn-play";
  609. divHtml.innerHTML = "<img src='" + PicInfo.recordPlayImgUrl + "'/><span>作答音频(" + answerList[index].AudioLength + "s)</span>";
  610. divHtml.setAttribute("answer-id", answerList[index].Id);
  611. divHtml.setAttribute("answer-url", answerList[index].AudioUrl);
  612. divHtml.setAttribute("play-status", "0");
  613. //增加节点
  614. $(item).before(divHtml);
  615. //独立绑定事件
  616. $(item).prev().children("img").on("click", function () {
  617. recordAudioClick(this, answerList[index].Id, answerList[index].AudioUrl);
  618. });
  619. $(item).prev().children("span").on("click", function () {
  620. onClickAnswerPoint(JSON.stringify(answerList[index]));//移动端的修改
  621. });
  622. }
  623. else {
  624. if (mytext == "") {
  625. mytext = "未作答";
  626. $(item).addClass("no-answer");
  627. }
  628. $(item).text(mytext);
  629. }
  630. //评阅样式
  631. if (answerList[index].Score == 0) {
  632. $(item).addClass("bad-answer");
  633. }
  634. if (answerList[index].Score > 0) {
  635. $(item).addClass("good-answer");
  636. }
  637. //移除作答样式
  638. if ($(item).hasClass("btn-bgimg")) {
  639. $(item).removeClass("btn-bgimg");
  640. }
  641. });
  642. }
  643. }
  644. //处理播放录音,answerid:答题点ID,isPlay:是否播放(0-暂停,1-播放)
  645. function playRecordAudio(answerid, isPlay) {
  646. //获取其他正在播放的音频
  647. var playing = $(".btn-play[answer-id='" + answerid + "']");
  648. if (playing.length > 0) {
  649. if (isPlay == "1") {
  650. $(playing).attr("play-status", "1");
  651. $(playing).find("img").attr("src", PicInfo.recordPauseImgUrl);//移动端要根据本地路径替换
  652. }
  653. else {
  654. $(playing).attr("play-status", "0");
  655. $(playing).find("img").attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地路径替换
  656. }
  657. }
  658. }
  659. //滚动到相应DIV
  660. function scrollAnswer(answerid) {
  661. $(".answertext").removeClass("select-answer");
  662. var ansDom = $(".answertext[answer-id='" + answerid + "']");
  663. $(ansDom).addClass("select-answer");
  664. var scroll_offset = $(ansDom).offset(); //得到box这个div层的offset,包含两个值,top和left
  665. $("body,html").animate({
  666. scrollTop: scroll_offset.top //让body的scrollTop等于pos的top,就实现了滚动
  667. });
  668. }
  669. //暂停播放原文音频
  670. function pauseTextAudio(audioid) {
  671. //获取其他正在播放的音频
  672. var playing = $(".audioImg[audio-id='" + audioid + "']");
  673. if (playing.length > 0) {
  674. $(playing).attr("play-status", "0");
  675. $(playing).attr("src", PicInfo.audioPauseImgUrl);//移动端要根据本地 喇叭 路径替换
  676. }
  677. }
  678. //原文音频播放按钮点击事件
  679. function audioPlayClick(myobj) {
  680. var curHtml = $(myobj).parent().find(".audioUrl").html();
  681. var curAlt = $(myobj).attr("alt");
  682. //处理当前按钮的状
  683. if ($(myobj).attr("play-status") == "1") {
  684. $(myobj).attr("play-status", "0");
  685. $(myobj).attr("src", PicInfo.audioPauseImgUrl);//移动端要根据本地 喇叭 路径替换
  686. }
  687. else {
  688. //停止其他作答音频播放
  689. var isRecordPlaying = $(".btn-play[play-status='1']");
  690. if (isRecordPlaying.length > 0) {
  691. $(isRecordPlaying).attr("play-status", "0");
  692. $(isRecordPlaying).find("img").attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地路径替换
  693. }
  694. //停止其他原文音频播放
  695. var audioPlaying = $(".audioImg[play-status='1']");
  696. if (audioPlaying.length > 0) {
  697. $(audioPlaying).attr("play-status", "0");
  698. $(audioPlaying).attr("src", PicInfo.audioPauseImgUrl);//移动端要根据本地 喇叭 路径替换
  699. }
  700. //设置播放状态
  701. $(myobj).attr("play-status", "1");
  702. $(myobj).attr("src", PicInfo.audioPlayImgUrl);//移动端要根据本地 喇叭 路径替换
  703. }
  704. var info = new Object();
  705. info.Id = $(myobj).attr("audio-id");
  706. info.AudioUrl = curAlt;
  707. //移动端添加外部处理
  708. playVisiableAudioCallBack(1, JSON.stringify(info));
  709. }
  710. //作答录音播放按钮点击事件
  711. function recordAudioClick(myobj, id, url) {
  712. //处理当前按钮的状态
  713. if ($(myobj).parent().attr("play-status") == "0") {
  714. //停止其他作答音频播放
  715. var isRecordPlaying = $(".btn-play[play-status='1']");
  716. if (isRecordPlaying.length > 0) {
  717. $(isRecordPlaying).attr("play-status", "0");
  718. $(isRecordPlaying).find("img").attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地路径替换
  719. }
  720. //停止其他原文音频播放
  721. var audioPlaying = $(".audioImg[play-status='1']");
  722. if (audioPlaying.length > 0) {
  723. $(audioPlaying).attr("play-status", "0");
  724. $(audioPlaying).attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地 喇叭 路径替换
  725. }
  726. //设置播放状态
  727. $(myobj).parent().attr("play-status", "1");
  728. $(myobj).attr("src", PicInfo.recordPauseImgUrl);//移动端要根据本地路径替换
  729. }
  730. else {
  731. $(myobj).parent().attr("play-status", "0");
  732. $(myobj).attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地路径替换
  733. }
  734. //移动端添加外部处理,播放录音
  735. var info = new Object();
  736. info.Id = id;
  737. info.AudioUrl = url;
  738. //移动端添加外部处理,播放录音
  739. playVisiableAudioCallBack(3, JSON.stringify(info));
  740. }
  741. function playVisiableAudioCallBack(type, url) {
  742. cancelBubble();
  743. plugin.startPlay(type, url);
  744. }
  745. function onClickAnswerPoint(data) {
  746. cancelBubble();
  747. plugin.onClickAnswerPoint(data);
  748. }