add.js 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. const PracticeTimeArr = [{
  5. Name: "还原",
  6. CSS: "numberContainerFooter1121Select"
  7. },
  8. {
  9. Name: "今天必练",
  10. },
  11. {
  12. Name: "推迟一周",
  13. },
  14. {
  15. Name: "推迟一个月",
  16. },
  17. {
  18. Name: "推迟三个月",
  19. }
  20. ];
  21. var arrTag = [];
  22. var tempCursor = undefined,
  23. btnName = "";
  24. var arrSoundMark = [];
  25. var isUnload = true;
  26. var isEdit = true;
  27. var isSave = true;
  28. var interval;
  29. var timeoutUploadImage = 0;
  30. var intervalRecorder = 0; //录音计时器
  31. var recorderManager;
  32. var tempRecorderFile = "";
  33. var innerAudioContext;
  34. var isViolate = false; //是否是违禁词
  35. var isFirstAdd = true;//是第一个填加
  36. Page({
  37. data: {
  38. HiddenFieldEdit: true,
  39. FieldContent: "",
  40. SoundSign: "[读]",
  41. LineSign: "[线]",
  42. HighlighterSign: "[光]",
  43. IsPracticeTime: false,
  44. IsRecorder: false,
  45. PracticeTimeArr: PracticeTimeArr,
  46. IsIPhoneX: app.globalData.IsIPhoneX,
  47. },
  48. onReady: function () {
  49. recorderManager = wx.getRecorderManager();
  50. recorderManager.onStart(() => {
  51. console.log('recorder start')
  52. });
  53. recorderManager.onStop((res) => {
  54. console.log('recorder stop', res);
  55. tempRecorderFile = res.tempFilePath;
  56. });
  57. recorderManager.onError((err) => {
  58. // console.log('err', err);
  59. // if (err.errMsg =="operateRecorder:fail auth deny"){
  60. // wx.navigateTo({
  61. // url: '../index/openSetting',
  62. // })
  63. // }
  64. });
  65. },
  66. onLoad: function (options) {
  67. var that = this;
  68. var fieldNumber = 0;
  69. if (options.fieldid)
  70. fieldNumber = options.fieldid;
  71. that.setData({
  72. Containnerheight: main.getWindowHeight(),
  73. UpdateType: options.type,
  74. MiaoguoCardID: options.id,
  75. FieldNumber: fieldNumber,
  76. PracticeTimeStr: PracticeTimeArr[0].Name,
  77. IsShow: app.globalData.userInfo.IsShow,
  78. IsShowPracticeTimeStart: true,
  79. });
  80. var list = app.globalData.CardList;
  81. for (var i = 0; i < list.length; i++) {
  82. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  83. wx.setStorageSync("TempCardInfo", list[i]);
  84. break;
  85. }
  86. }
  87. app.globalData.TempFieldNumber = 0;
  88. app.globalData.TempMiaoguoCardID = that.data.MiaoguoCardID;
  89. isViolate = false;
  90. isFirstAdd = true;
  91. },
  92. onShow: function () {
  93. var that = this;
  94. if (that.data.UpdateType == "add") {
  95. that.initAddCard();
  96. that.setData({
  97. PracticeTimeStr2: "智能安排",
  98. });
  99. } else {
  100. var card = {},
  101. content = "";
  102. var list = app.globalData.CardList;
  103. for (var i = 0; i < list.length; i++) {
  104. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  105. card = main.changeStringToView(list[i].Content);
  106. card.MiaoguoCardID = list[i].MiaoguoCardID;
  107. card.LimitTime = list[i].LimitTime;
  108. if (that.data.FieldNumber && that.data.FieldNumber > 0)
  109. content = main.encryptUrl(list[i].Content[that.data.FieldNumber].Content);
  110. break;
  111. }
  112. }
  113. that.setData({
  114. MiaoguoCardID: card.MiaoguoCardID,
  115. LimitTime: common.formatTime(card.LimitTime),
  116. PracticeTimeStr2: common.formatDateCHS(common.formatTime(card.LimitTime)),
  117. Field: card.Field,
  118. Tags: card.Tags,
  119. FieldContent: content,
  120. });
  121. if (that.data.UpdateType != "add2") {
  122. wx.setNavigationBarTitle({
  123. title: '编辑题卡'
  124. });
  125. }
  126. if (that.data.UpdateType == "edit3") {
  127. that.gotoAddItem({
  128. currentTarget: {
  129. dataset: {
  130. fieldid: that.data.FieldNumber
  131. }
  132. }
  133. });
  134. }
  135. }
  136. common.getStorageValue(that, "SymbolMain", app.globalData.SymbolMain, function () { });
  137. },
  138. onHide: function () {
  139. //用于恢复未保存的新题卡
  140. //console.log("onHide");
  141. var that = this;
  142. if (!that.data.HiddenFieldEdit) {
  143. that.updateField();
  144. }
  145. if (!(that.data && that.data.Field && that.data.Field[1].length == 0 &&
  146. that.data.Field[2].length == 0 &&
  147. that.data.Field[3].length == 0)) {
  148. if (!isViolate && (that.data.UpdateType == "add" || that.data.UpdateType == "add2")) {
  149. var card = {};
  150. card.MiaoguoCardID = that.data.MiaoguoCardID;
  151. card.Content = [];
  152. var param1 = {};
  153. param1 = that.formatField(that.data.Field);
  154. for (var i = 0; i < 4; i++) {
  155. var obj = {};
  156. obj.ContentType = i;
  157. if (i == 0)
  158. obj.Content = that.data.Tags;
  159. else
  160. obj.Content = param1["Field" + i];
  161. card.Content.push(obj);
  162. }
  163. wx.setStorageSync("TempCardNoSaved", card);
  164. }
  165. }
  166. },
  167. onUnload: function () {
  168. this.onHide();
  169. var card = wx.getStorageSync("TempCardInfo");
  170. if (card) {
  171. var list = app.globalData.CardList;
  172. for (var i = 0; i < list.length; i++) {
  173. if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  174. list[i] = card;
  175. break;
  176. }
  177. }
  178. app.globalData.CardList = list;
  179. wx.removeStorageSync("TempCardInfo");
  180. }
  181. clearInterval(interval);
  182. clearTimeout(timeoutUploadImage);
  183. clearInterval(intervalRecorder);
  184. if (this.data.IsRecorder)
  185. this.closeRecorder();
  186. },
  187. onClose: function () {
  188. wx.navigateBack({
  189. delta: 1,
  190. });
  191. clearInterval(intervalRecorder);
  192. },
  193. gotoAddItem: function (e) {
  194. var that = this;
  195. var fieldid = e.currentTarget.dataset.fieldid;
  196. var content;
  197. var list = app.globalData.CardList;
  198. for (var i = 0; i < list.length; i++) {
  199. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  200. content = main.encryptUrl(list[i].Content[fieldid].Content);
  201. break;
  202. }
  203. }
  204. wx.setStorageSync("TempCardInfoAddItem", content);
  205. that.setData({
  206. HiddenFieldEdit: false,
  207. Focus: true,
  208. FieldNumber: fieldid,
  209. FieldContent: content,
  210. });
  211. wx.setNavigationBarTitle({
  212. title: '编辑 段落' + fieldid,
  213. });
  214. },
  215. onSearch: function (e) {
  216. app.globalData.TempFieldNumber = 0;
  217. wx.navigateTo({
  218. url: './searchWeb',
  219. })
  220. },
  221. onPreview: function (e) {
  222. var that = this;
  223. if (that.data.Field[1] == "") {
  224. wx.showToast({
  225. title: '第一段必填',
  226. image: "../images/universalpic_wrong_white_120x120.png",
  227. });
  228. } else {
  229. wx.navigateTo({
  230. url: './preview?type=preview&id=' + this.data.MiaoguoCardID,
  231. });
  232. }
  233. },
  234. saveCard: function () {
  235. var that = this;
  236. if (that.data.Field[1] == "") {
  237. wx.showToast({
  238. title: '第一段必填',
  239. image: "../images/universalpic_wrong_white_120x120.png",
  240. });
  241. } else {
  242. if (isSave) {
  243. isSave = false;
  244. setTimeout(function () {
  245. isSave = true;
  246. }, 5000);
  247. if (that.checkImageCount(that.data.Field)) {
  248. that.uploadImageAll(that.data.Field, function (success, field) {
  249. if (success) {
  250. that.data.Field = field;
  251. var userid = app.globalData.userInfo.UserID;
  252. var tags = [];
  253. for (var i = 0; i < that.data.Tags.length; i++) {
  254. if (that.data.Tags[i])
  255. tags.push(that.data.Tags[i]);
  256. }
  257. var param1 = {};
  258. param1 = that.formatField(that.data.Field);
  259. param1.Tags = tags;
  260. param1.IsTodayStudy = 0;
  261. if (that.data.PracticeTimeStr == PracticeTimeArr[1].Name)
  262. param1.IsTodayStudy = 1;
  263. param1.LimitTime = that.getLimitTimeStr();
  264. param1.ID = that.data.MiaoguoCardID;
  265. that.saveLocalCardList(param1);
  266. wx.hideLoading();
  267. wx.showLoading({
  268. title: '保存数据请稍候',
  269. mask: true,
  270. });
  271. timeoutUploadImage = setTimeout(function () {
  272. wx.hideLoading();
  273. }, 15000);
  274. main.postData('AddMiaoguoCard?Type=' + that.data.UpdateType + '&UserID=' + userid, param1, function (data) {
  275. wx.removeStorageSync("TempCardNoSaved");
  276. if (that.data.UpdateType == "edit" || that.data.UpdateType == "edit2" || that.data.UpdateType == "edit3") {
  277. that.onClose();
  278. } else {
  279. wx.hideLoading();
  280. wx.showToast({
  281. title: '已保存!',
  282. image: "../images/universalpic_saved_white_120x120.png",
  283. });
  284. if (that.data.UpdateType == "add2") {
  285. isFirstAdd = false;
  286. that.initAddCard();
  287. }
  288. }
  289. wx.removeStorageSync("TempCardInfo");
  290. });
  291. } else {
  292. wx.showToast({
  293. title: '图片上传失败1',
  294. mask: true,
  295. });
  296. }
  297. });
  298. }
  299. } else {
  300. wx.showToast({
  301. title: '点击太频繁',
  302. mask: true,
  303. });
  304. }
  305. }
  306. },
  307. formatField: function (field) {
  308. var result = {};
  309. for (var i = 1; i <= 3; i++) {
  310. result["Field" + i] = "";
  311. if (field[i]) {
  312. for (var key in field[i]) {
  313. var item = field[i][key];
  314. var str = "";
  315. if (item.Type == "image") {
  316. str = "[图 w='" + item.Width + "' h='" + item.Height + "']" + item.Content + "[/图]";
  317. } else if (item.Type == "line") {
  318. for (var j = 0; j < item.Content.length; j++) {
  319. if (item.Content[j].key == "normal")
  320. str += item.Content[j].value;
  321. if (item.Content[j].key == "line") {
  322. str += "[线]" + item.Content[j].value + "[/线]";
  323. }
  324. if (item.Content[j].key == "highlighter") {
  325. str += "[光]" + item.Content[j].value + "[/光]";
  326. }
  327. }
  328. } else if (item.Type == "sound") {
  329. if (item.SoundMark)
  330. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  331. else
  332. str = "[读]" + item.Content + "[/读]";
  333. } else if (item.Type == "recorder") {
  334. if (item.SoundMark)
  335. str = "[音 url='" + item.SoundMark + "'][/音]";
  336. } else if (item.Type == "normal") {
  337. str = item.Content;
  338. } else if (item.Type == "return") {
  339. str = "\n";
  340. }
  341. result["Field" + i] += str;
  342. }
  343. }
  344. result["Field" + i] = main.changeViewToString(result["Field" + i]);
  345. }
  346. return result;
  347. },
  348. checkImageCount: function (arr) {
  349. var count = 0;
  350. for (var i = 0; i < arr.length; i++) {
  351. for (var j = 0; j < arr[i].length; j++) {
  352. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  353. count++;
  354. }
  355. }
  356. }
  357. if (count > 3) {
  358. wx.showToast({
  359. title: '只能上传三张图片',
  360. });
  361. return false;
  362. } else
  363. return true;
  364. },
  365. uploadImageAll: function (arr, callback) {
  366. var that = this;
  367. var b = false;
  368. var arrSource = [],
  369. arrResult = [];
  370. for (var i = 0; i < arr.length; i++) {
  371. for (var j = 0; j < arr[i].length; j++) {
  372. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  373. arrSource.push(arr[i][j].Content);
  374. if (arr[i][j].ContentServer.indexOf(app.globalData.uploadImageUrl) >= 0 ||
  375. arr[i][j].ContentServer.indexOf("baidu.com") >= 0 ||
  376. arr[i][j].ContentServer.indexOf("bcebos.com") >= 0) {
  377. var result = {};
  378. result.Source = arr[i][j].ContentServer;
  379. result.Target = arr[i][j].ContentServer;
  380. arrResult.push(result);
  381. } else {
  382. var source = arr[i][j].Content;
  383. that.uploadFileToServer(source, function (data) {
  384. if (data) {
  385. data = JSON.parse(data);
  386. var result = data.result;
  387. result.Target = app.globalData.uploadImageUrl + result.Target;
  388. arrResult.push(result);
  389. }
  390. });
  391. }
  392. b = true;
  393. }
  394. }
  395. }
  396. if (b) {
  397. wx.showLoading({
  398. title: '上传图片请稍候',
  399. mask: true,
  400. });
  401. timeoutUploadImage = setTimeout(function () {
  402. wx.hideLoading();
  403. }, 30000);
  404. }
  405. interval = setInterval(function () {
  406. //console.log(arrResult.length);
  407. if (arrResult.length >= arrSource.length) {
  408. wx.hideLoading();
  409. //console.log("arrResult:" + JSON.stringify(arrResult));
  410. clearInterval(interval);
  411. var success = true;
  412. var ari = 0;
  413. for (var i = 0; i < arr.length; i++) {
  414. for (var j = 0; j < arr[i].length; j++) {
  415. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  416. var tempUrl = arr[i][j].Content;
  417. var serverUrl = "";
  418. for (var k = 0; k < arrResult.length; k++) {
  419. if (tempUrl.indexOf(arrResult[k].Source) >= 0) {
  420. serverUrl = arrResult[k].Target;
  421. break;
  422. }
  423. }
  424. //console.log("serverUrl:" + serverUrl);
  425. //console.log("tempUrl:" + tempUrl);
  426. if (serverUrl == "")
  427. serverUrl = main.getServerImage(tempUrl);
  428. main.saveTempImage(serverUrl, tempUrl);
  429. arr[i][j].Content = serverUrl;
  430. arr[i][j].ContentServer = serverUrl;
  431. if (serverUrl == "") {
  432. success = false;
  433. break;
  434. }
  435. }
  436. }
  437. }
  438. //console.log(JSON.stringify(arr));
  439. callback(success, arr);
  440. }
  441. }, 500);
  442. },
  443. uploadFileToServer: function (file, callback) {
  444. var url = common.Encrypt("MiaoguoUploadFile2");
  445. wx.uploadFile({
  446. url: app.globalData.serverUrl + url,
  447. filePath: file,
  448. name: 'file',
  449. success(res) {
  450. callback(res.data);
  451. },
  452. fail: function (err) {
  453. wx.hideLoading();
  454. wx.showModal({
  455. title: '上传文件失败',
  456. showCancel: false,
  457. content: JSON.stringify(err),
  458. });
  459. }
  460. });
  461. },
  462. saveLocalCardList: function (param1) {
  463. var that = this;
  464. var list = app.globalData.CardList;
  465. for (var i = 0; i < list.length; i++) {
  466. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  467. for (var j = 0; j < 4; j++) {
  468. if (j == 0) {
  469. if (param1.tags && param1.tags.length > 0)
  470. list[i].Content[j].Content = param1.tags.join(",");
  471. } else
  472. list[i].Content[j].Content = param1["Field" + j];
  473. }
  474. if (param1.LimitTime)
  475. list[i].LimitTime = common.formatTime(param1.LimitTime);
  476. if (param1.IsTodayStudy == 1) {
  477. list[i].LimitTime = common.formatTime(new Date());
  478. main.getTaskTodayList(function () { });
  479. }
  480. app.globalData.CardList = list;
  481. break;
  482. }
  483. }
  484. },
  485. initAddCard: function () {
  486. var card = {};
  487. card.MiaoguoCardID = 0;
  488. card.Content = [];
  489. for (var i = 0; i < 4; i++) {
  490. var obj = {};
  491. obj.ContentType = i;
  492. obj.Content = [];
  493. card.Content.push(obj);
  494. }
  495. app.globalData.CardList = [card];
  496. this.setData({
  497. MiaoguoCardID: 0,
  498. Field: [
  499. [],
  500. [],
  501. [],
  502. []
  503. ],
  504. Tags: [],
  505. UpdateType: "add2",
  506. });
  507. },
  508. onBindError: function (e) {
  509. for (var i = 1; i < this.data.Field.length; i++) {
  510. for (var j = 0; j < this.data.Field[i].length; j++) {
  511. if (this.data.Field[i][j].Type == "image") {
  512. this.data.Field[i][j].Url = this.data.Field[i][j].Content;
  513. }
  514. }
  515. }
  516. this.setData({
  517. Field: this.data.Field,
  518. });
  519. },
  520. deleteItem: function (e) {
  521. var that = this;
  522. var index = e.currentTarget.dataset.id;
  523. wx.showModal({
  524. title: '提醒',
  525. content: '记号“' + that.data.Tags[index] + '”要删除吗?',
  526. success(res) {
  527. if (res.confirm) {
  528. that.data.Tags.splice(index, 1);
  529. that.setData({
  530. Tags: that.data.Tags,
  531. });
  532. var list = app.globalData.CardList;
  533. for (var i = 0; i < list.length; i++) {
  534. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  535. list[i].Content[0].Content = that.data.Tags;
  536. break;
  537. }
  538. }
  539. app.globalData.CardList = list;
  540. }
  541. }
  542. });
  543. },
  544. onGotoList: function () {
  545. var that = this;
  546. if (isFirstAdd == true || !that.data.Field) {
  547. wx.showModal({
  548. title: '无法查看上一张',
  549. content: '本功能是在批量添加题卡时快速回看上一张题卡。现在是本批的第一张,没有上一张。',
  550. confirmText: '知道了',
  551. showCancel: false,
  552. });
  553. }
  554. else if (that.data.Field[1].length > 0 || that.data.Field[2].length > 0 || that.data.Field[2].length > 0) {
  555. wx.showModal({
  556. title: '尚未保存',
  557. content: '即将“查看上一张题卡”,但当前题卡尚未保存,按继续将放弃保存。',
  558. confirmText: '继续',
  559. success(res) {
  560. if (res.confirm) {
  561. goto();
  562. setTimeout(function () {
  563. wx.removeStorageSync("TempCardNoSaved");
  564. }, 1000);
  565. }
  566. }
  567. });
  568. }
  569. else {
  570. goto();
  571. }
  572. function goto() {
  573. wx.showLoading({
  574. title: '请稍候',
  575. });
  576. setTimeout(function () {
  577. wx.hideLoading();
  578. }, 5000);
  579. var url = 'GetMiaoguoCardList?UserID=' + app.globalData.userInfo.UserID;
  580. main.getData(url, function (data) {
  581. wx.hideLoading();
  582. if (data) {
  583. app.globalData.CardList = data.List;
  584. that.setData({
  585. UpdateType: "add",
  586. });
  587. wx.navigateTo({
  588. url: './searchCardList?type=2&Count=' + data.Count,
  589. })
  590. }
  591. });
  592. }
  593. },
  594. getLimitTimeStr: function () {
  595. var that = this;
  596. if (!that.data.LimitTime)
  597. that.data.LimitTime = common.formatTime(new Date());
  598. var LimitTime = common.formatTime(new Date(that.data.LimitTime));
  599. if (that.data.PracticeTimeStr == PracticeTimeArr[1].Name)
  600. LimitTime = common.formatTime(new Date());
  601. else if (that.data.PracticeTimeStr == PracticeTimeArr[2].Name)
  602. LimitTime = common.formatTime(common.addDate("w", 1, new Date(that.data.LimitTime)));
  603. else if (that.data.PracticeTimeStr == PracticeTimeArr[3].Name)
  604. LimitTime = common.formatTime(common.addDate("m", 1, new Date(that.data.LimitTime)));
  605. else if (that.data.PracticeTimeStr == PracticeTimeArr[4].Name)
  606. LimitTime = common.formatTime(common.addDate("m", 3, new Date(that.data.LimitTime)));
  607. //console.log(that.data.LimitTime);
  608. //console.log(new Date(that.data.LimitTime));
  609. //console.log(common.addDate("w", 1, new Date(that.data.LimitTime)));
  610. //console.log(LimitTime);
  611. return LimitTime
  612. },
  613. //段落编辑**************************
  614. //字段输入
  615. bindinputField: function (e) {
  616. //console.log("bindinputField:" + e.detail.value + " isEdit:" + isEdit);
  617. var that = this;
  618. if (app.globalData.IsAndroid && !isEdit) {
  619. return;
  620. }
  621. this.setData({
  622. FieldContent: e.detail.value,
  623. });
  624. },
  625. //加符号
  626. addSymbol: function (e) {
  627. //console.log("addSymbol");
  628. isEdit = true;
  629. var that = this;
  630. btnName = e.currentTarget.dataset.id;
  631. if (btnName == "[读]") {
  632. this.setData({
  633. SoundSign: "[/读]",
  634. });
  635. } else if (btnName == "[/读]") {
  636. this.setData({
  637. SoundSign: "[读]",
  638. });
  639. } else if (btnName == "[线]") {
  640. this.setData({
  641. LineSign: "[/线]",
  642. });
  643. } else if (btnName == "[/线]") {
  644. this.setData({
  645. LineSign: "[线]",
  646. });
  647. } else if (btnName == "[光]") {
  648. this.setData({
  649. HighlighterSign: "[/光]",
  650. });
  651. } else if (btnName == "[/光]") {
  652. this.setData({
  653. HighlighterSign: "[光]",
  654. });
  655. }
  656. if (btnName == "( )")
  657. btnName = "( )";
  658. else if (btnName == "_")
  659. btnName = "_____";
  660. //console.log("addSymbol_btnName:" + btnName);
  661. if (!this.data.Focus) {
  662. var obj = { detail: { cursor: tempCursor } };
  663. this.onBindblur(obj);
  664. }
  665. //console.log("addSymbol:" + this.data.FieldContent);
  666. setTimeout(function () {
  667. that.setData({
  668. Focus: true,
  669. });
  670. }, 300);
  671. },
  672. //焦点聚焦
  673. onBindFocus: function () {
  674. //console.log("onBindFocus");
  675. btnName = "";
  676. this.setData({
  677. Focus: true,
  678. });
  679. },
  680. //失焦
  681. onBindblur: function (e) {
  682. var that = this;
  683. //console.log("onBindblur:" + isEdit + " Filed:" + this.data.FieldContent);
  684. if (app.globalData.IsAndroid && !isEdit) {
  685. setTimeout(function () {
  686. isEdit = true;
  687. //console.log("onBindblur2:" + isEdit);
  688. }, 500);
  689. return;
  690. }
  691. isEdit = false;
  692. if (app.globalData.IsAndroid && !isEdit) {
  693. setTimeout(function () {
  694. isEdit = true;
  695. //console.log("onBindblur2:" + isEdit);
  696. }, 500);
  697. }
  698. //console.log("onBindblur:"+isEdit);
  699. this.updateField();
  700. tempCursor = e.detail.cursor;
  701. //console.log("tempCursor:" + tempCursor);
  702. if (tempCursor == undefined)
  703. tempCursor = this.data["FieldContent"].length;
  704. var str1 = "",
  705. str2 = "";
  706. if (this.data.FieldContent.length > 0) {
  707. str1 = this.data.FieldContent.substr(0, tempCursor);
  708. str2 = this.data.FieldContent.substring(tempCursor, this.data.FieldContent.length);
  709. }
  710. //console.log("str1:" + str1);
  711. //console.log("btnName:" + btnName);
  712. //console.log("str2:" + str2);
  713. var cur = 0;
  714. if (btnName) {
  715. cur = 1;
  716. if (btnName == "[读]" || btnName == "[线]" || btnName == "[光]") {
  717. cur = 3;
  718. } else if (btnName == "[/读]" || btnName == "[/线]" || btnName == "[/光]") {
  719. cur = 4;
  720. } else if (btnName === "( )") {
  721. cur = 7;
  722. } else if (btnName === "_____") {
  723. cur = 5;
  724. }
  725. }
  726. this.data.FieldContent = str1 + btnName + str2;
  727. this.setData({
  728. FieldContent: this.data.FieldContent,
  729. Focus: false,
  730. Cursor: tempCursor + cur,
  731. });
  732. btnName = "";
  733. },
  734. bindscrollHandler: function () {
  735. //console.log("bindscrollHandler");
  736. btnName = "";
  737. },
  738. onSearchField: function (e) {
  739. app.globalData.TempFieldNumber = this.data.FieldNumber;
  740. wx.navigateTo({
  741. url: './searchWeb',
  742. });
  743. this.updateField();
  744. setTimeout(function () {
  745. isEdit = true;
  746. //console.log("onSearchEnd");
  747. }, 1000);
  748. },
  749. clear: function () {
  750. var that = this;
  751. //console.log("clear");
  752. this.setData({
  753. FieldContent: "",
  754. Focus: true,
  755. Cursor: 0,
  756. });
  757. btnName = "";
  758. isEdit = false;
  759. this.updateField();
  760. },
  761. closeAddItem: function (e) {
  762. var that = this;
  763. var isSave = e.currentTarget.dataset.idsave;
  764. if (isSave == "true") {
  765. isUnload = false;
  766. if (that.data.FieldContent) {
  767. var content = that.data.FieldContent;
  768. main.postData("MsgSecCheck2",
  769. { Content: content, },
  770. function (data) {
  771. if (data && data.errcode == 0) {
  772. next(that);
  773. } else {
  774. if (data.errmsg) {
  775. wx.showToast({
  776. title: data.errmsg,
  777. duration: 2000,
  778. image: "../images/universalpic_wrong_white_120x120.png",
  779. });
  780. isViolate = true;
  781. }
  782. }
  783. });
  784. } else {
  785. next(that);
  786. }
  787. } else if (isSave == "false") {
  788. var content = wx.getStorageSync("TempCardInfoAddItem");
  789. this.setData({
  790. FieldContent: content,
  791. });
  792. next(that);
  793. }
  794. function next(obj) {
  795. isViolate = false;
  796. obj.updateField();
  797. obj.setData({
  798. HiddenFieldEdit: true,
  799. });
  800. var title = "编辑题卡";
  801. if (obj.data.UpdateType == "add2") {
  802. title = "添加题卡";
  803. }
  804. wx.setNavigationBarTitle({
  805. title: title,
  806. });
  807. }
  808. },
  809. updateField: function () {
  810. var str = this.data.FieldContent;
  811. var list = app.globalData.CardList;
  812. var card = {};
  813. for (var i = 0; i < list.length; i++) {
  814. if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  815. list[i].Content[this.data.FieldNumber].Content = str;
  816. card = main.changeStringToView(list[i].Content);
  817. break;
  818. }
  819. }
  820. app.globalData.CardList = list;
  821. this.setData({
  822. Field: card.Field,
  823. Tags: card.Tags,
  824. });
  825. },
  826. //选择图片上传
  827. uploadImageField: function () {
  828. //console.log("uploadImageStart");
  829. var that = this;
  830. //若是安卓机
  831. if (app.globalData.IsAndroid) {
  832. selectImage(that);
  833. } else {
  834. wx.showActionSheet({
  835. itemList: ['拍照', '从手机相册选择'],
  836. success(res) {
  837. if (res.tapIndex == 0) {
  838. wx.chooseImage({
  839. count: 1,
  840. sizeType: ['compressed'],
  841. sourceType: ['camera'],
  842. success(res2) {
  843. wx.showLoading({
  844. title: '请秒候',
  845. mask: true,
  846. });
  847. setTimeout(function () {
  848. wx.hideLoading();
  849. selectImage(that);
  850. }, 2000);
  851. },
  852. });
  853. } else if (res.tapIndex == 1) {
  854. selectImage(that);
  855. }
  856. },
  857. fail(res) {
  858. console.log(res.errMsg)
  859. }
  860. });
  861. }
  862. function selectImage(that) {
  863. var sizeType = ['album'];
  864. //若是安卓机
  865. if (app.globalData.IsAndroid)
  866. sizeType = ['album', 'camera'];
  867. wx.chooseImage({
  868. count: 1,
  869. sizeType: ['compressed'],
  870. sourceType: sizeType,
  871. success(res) {
  872. // tempFilePath可以作为img标签的src属性显示图片
  873. const tempFilePaths = res.tempFilePaths;
  874. //console.log(tempFilePaths[0]);
  875. //that.data.FieldContent = that.data.FieldContent + "[图 url='" + tempFilePaths[0] + "']" + tempFilePaths[0] + "[/图]";
  876. wx.getImageInfo({
  877. src: res.tempFilePaths[0],
  878. success(res) {
  879. //console.log(res.width)
  880. //console.log(res.height)
  881. if (tempCursor == undefined)
  882. tempCursor = that.data.FieldContent.length;
  883. var str1 = "",
  884. str2 = "";
  885. if (that.data.FieldContent.length > 0) {
  886. str1 = that.data.FieldContent.substr(0, tempCursor);
  887. str2 = that.data.FieldContent.substring(tempCursor, that.data.FieldContent.length);
  888. }
  889. var width = res.width;
  890. if (isNaN(width))
  891. width = 650;
  892. var height = res.height;
  893. if (isNaN(height))
  894. height = 650;
  895. var str0 = "[图 w='" + width + "' h='" + height + "']" + tempFilePaths[0] + "[/图]";
  896. that.data.FieldContent = str1 + str0 + str2;
  897. tempCursor = that.data.FieldContent.length;
  898. //console.log("uploadImageEnd:" + that.data.FieldContent);
  899. that.setData({
  900. FieldContent: that.data.FieldContent,
  901. Focus: false,
  902. });
  903. that.updateField();
  904. if (!wx.getStorageSync("NoRemindImage")) {
  905. wx.showModal({
  906. title: '图片已插到段落中',
  907. showCancel: true,
  908. content: "图片显示为[图...][/图]。如要移动到别的段落,剪切时请确保其完整性。",
  909. confirmText: "知道了",
  910. cancelText: "不再提示",
  911. confirmColor: "#0071EF",
  912. success(res) {
  913. if (res.confirm) { } else {
  914. wx.setStorageSync("NoRemindImage", true);
  915. }
  916. },
  917. });
  918. }
  919. }
  920. });
  921. },
  922. fail: function () {
  923. }
  924. });
  925. }
  926. },
  927. onPracticeTime: function (e) {
  928. var that = this;
  929. var value = e.currentTarget.dataset.value;
  930. that.data.IsShowPracticeTimeStart = true;
  931. if (that.data.IsShowPracticeTimeStart && value != "还原") {
  932. that.data.IsShowPracticeTimeStart = false;
  933. }
  934. that.setData({
  935. IsPracticeTime: false,
  936. PracticeTimeStr: value,
  937. IsShowPracticeTimeStart: that.data.IsShowPracticeTimeStart,
  938. });
  939. var PracticeTimeStr2 = common.formatDateCHS(common.formatTime(that.data.LimitTime));
  940. if (value != "还原")
  941. PracticeTimeStr2 = common.formatDateCHS(common.formatTime(that.getLimitTimeStr(value)));
  942. else
  943. if (that.data.UpdateType === "add" || that.data.UpdateType === "add2")
  944. PracticeTimeStr2 = "智能安排";
  945. that.setData({
  946. PracticeTimeStr2: PracticeTimeStr2,
  947. });
  948. },
  949. showPracticeTime: function () {
  950. this.setData({
  951. IsPracticeTime: true,
  952. });
  953. },
  954. closePracticeTime: function () {
  955. this.setData({
  956. IsPracticeTime: false,
  957. });
  958. },
  959. //录音授权
  960. recorderAccredit: function () {
  961. var that = this;
  962. if (app.globalData.IsRecorderAccredit == 1)
  963. that.showRecorder();
  964. else if (app.globalData.IsRecorderAccredit == 0) {
  965. recorderManager.stop();
  966. app.globalData.IsRecorderAccredit = 1;
  967. that.showRecorder();
  968. } else if (app.globalData.IsRecorderAccredit == -1) {
  969. wx.getSetting({
  970. success(res) {
  971. if (res.authSetting['scope.record'] === true) {
  972. app.globalData.IsRecorderAccredit = 1;
  973. that.showRecorder();
  974. } else if (res.authSetting['scope.record'] === false) {
  975. wx.navigateTo({
  976. url: '../index/openSetting',
  977. });
  978. }
  979. }
  980. });
  981. }
  982. },
  983. showRecorder: function () {
  984. var that = this;
  985. if (that.checkRecorderCount()) {
  986. that.recorderInit();
  987. tempRecorderFile = "";
  988. wx.setNavigationBarTitle({
  989. title: '录音',
  990. });
  991. that.setData({
  992. IsRecorder: true,
  993. IsRecorderFinished: false,
  994. BtnRecorderName: "按住录音",
  995. RecorderTime: "00:00",
  996. RecorderTimeCss: "",
  997. RecorderPlayName: "播放",
  998. });
  999. innerAudioContext = wx.createInnerAudioContext();
  1000. innerAudioContext.onPlay(() => {
  1001. console.log('开始播放');
  1002. that.setData({
  1003. RecorderTimeCss: "RecorderPanel1121",
  1004. RecorderTime: "00:00",
  1005. RecorderPlayName: "停止",
  1006. });
  1007. });
  1008. innerAudioContext.onEnded(() => {
  1009. console.log('结束播放');
  1010. clearInterval(intervalRecorder);
  1011. that.setData({
  1012. RecorderTime: "00:00",
  1013. RecorderTimeCss: "",
  1014. RecorderPlayName: "播放",
  1015. });
  1016. });
  1017. }
  1018. },
  1019. closeRecorder: function () {
  1020. var that = this;
  1021. this.recorderInit();
  1022. if (tempRecorderFile) {
  1023. wx.showModal({
  1024. title: '提醒',
  1025. content: '录音还没上传,要继续退出并放弃录音吗?',
  1026. showCancel: true,
  1027. confirmText: "取消",
  1028. cancelColor: "#000000",
  1029. cancelText: "继续",
  1030. confirmColor: "#000000",
  1031. success(res) {
  1032. if (res.cancel) {
  1033. closeRecorder2();
  1034. }
  1035. },
  1036. })
  1037. } else {
  1038. closeRecorder2();
  1039. }
  1040. function closeRecorder2() {
  1041. wx.setNavigationBarTitle({
  1042. title: '编辑 段落' + that.data.FieldNumber,
  1043. });
  1044. that.setData({
  1045. IsRecorder: false,
  1046. IsRecorderFinished: false,
  1047. });
  1048. tempRecorderFile = "";
  1049. }
  1050. },
  1051. //录音初始化
  1052. recorderInit: function () {
  1053. if (innerAudioContext)
  1054. innerAudioContext.stop();
  1055. if (recorderManager)
  1056. recorderManager.stop();
  1057. clearInterval(intervalRecorder);
  1058. },
  1059. checkRecorderCount: function (arr) {
  1060. var that = this;
  1061. var count = 0;
  1062. if (that.data.FieldContent.indexOf("[音 url=") >= 0 ||
  1063. that.data.FieldContent.indexOf("[/音]") >= 0) {
  1064. count = 1;
  1065. }
  1066. if (count > 0) {
  1067. wx.showToast({
  1068. title: '仅能上传一段',
  1069. });
  1070. return false;
  1071. } else
  1072. return true;
  1073. },
  1074. btnRecorderStart: function () {
  1075. var that = this;
  1076. if (app.globalData.IsRecorderAccredit == 1) {
  1077. that.setData({
  1078. BtnRecorderName: "松手结束",
  1079. RecorderTimeCss: "RecorderPanel1121",
  1080. });
  1081. that.showRecorderTime();
  1082. recorderManager.start();
  1083. }
  1084. },
  1085. btnRecorderEnd: function () {
  1086. var that = this;
  1087. if (app.globalData.IsRecorderAccredit == 1) {
  1088. if (that.data.RecorderTime == "00:00") {
  1089. //小于1秒处理
  1090. wx.showToast({
  1091. title: '时间过短',
  1092. image: "../images/universalpic_wrong_white_120x120.png",
  1093. });
  1094. that.showRecorder();
  1095. } else {
  1096. that.setData({
  1097. IsRecorderFinished: true,
  1098. RecorderTimeCss: "",
  1099. });
  1100. that.recorderInit();
  1101. }
  1102. } else {
  1103. that.recorderAccredit();
  1104. }
  1105. },
  1106. showRecorderTime: function () {
  1107. var that = this;
  1108. var second = 0;
  1109. clearInterval(intervalRecorder);
  1110. intervalRecorder = setInterval(function () {
  1111. second++;
  1112. var secondStr = second.toString();
  1113. if (second < 10)
  1114. secondStr = "0" + secondStr;
  1115. that.setData({
  1116. RecorderTime: "00:" + secondStr,
  1117. });
  1118. if (second >= 59) {
  1119. that.setData({
  1120. IsRecorderFinished: true,
  1121. RecorderTimeCss: "",
  1122. });
  1123. that.recorderInit();
  1124. if (that.data.RecorderPlayName == "播放") {
  1125. wx.showToast({
  1126. title: '录音超时',
  1127. image: "../images/universalpic_wrong_white_120x120.png",
  1128. });
  1129. }
  1130. }
  1131. }, 1000);
  1132. },
  1133. btnRecorderPlay: function () {
  1134. var that = this;
  1135. if (tempRecorderFile && this.data.RecorderPlayName == "播放") {
  1136. innerAudioContext.src = tempRecorderFile;
  1137. innerAudioContext.play();
  1138. this.showRecorderTime();
  1139. } else if (this.data.RecorderPlayName == "停止") {
  1140. if (innerAudioContext)
  1141. innerAudioContext.stop();
  1142. clearInterval(intervalRecorder);
  1143. that.setData({
  1144. RecorderTime: "00:00",
  1145. RecorderTimeCss: "",
  1146. RecorderPlayName: "播放",
  1147. });
  1148. }
  1149. },
  1150. btnRecorderSave: function () {
  1151. var that = this;
  1152. this.recorderInit();
  1153. wx.showLoading({
  1154. title: '上传中请稍候',
  1155. });
  1156. setTimeout(function () {
  1157. wx.hideLoading();
  1158. }, 60000);
  1159. that.uploadFileToServer(tempRecorderFile, function (data) {
  1160. if (data) {
  1161. data = JSON.parse(data);
  1162. //console.log(data);
  1163. wx.hideLoading();
  1164. var result = data.result;
  1165. result.Target = app.globalData.uploadImageUrl + result.Target;
  1166. that.data.FieldContent = that.data.FieldContent + "[音 url='" + result.Target + "'][/音]";
  1167. that.data.FieldContent = main.encryptUrl(that.data.FieldContent);
  1168. that.setData({
  1169. FieldContent: that.data.FieldContent,
  1170. });
  1171. tempRecorderFile = "";
  1172. that.closeRecorder();
  1173. if (!wx.getStorageSync("NoRemindRecorder")) {
  1174. wx.showModal({
  1175. title: '录音已插到段落中',
  1176. showCancel: true,
  1177. content: "录音显示为[音...][/音]。如要移动到别的段落,剪切时请确保其完整性。",
  1178. confirmText: "知道了",
  1179. cancelText: "不再提示",
  1180. confirmColor: "#0071EF",
  1181. success(res) {
  1182. if (res.confirm) { } else {
  1183. wx.setStorageSync("NoRemindRecorder", true);
  1184. }
  1185. },
  1186. });
  1187. }
  1188. }
  1189. });
  1190. },
  1191. gotoSymbol: function (e) {
  1192. wx.navigateTo({
  1193. url: '../main/symbolsetting',
  1194. });
  1195. },
  1196. gotoTest: function () {
  1197. var that=this;
  1198. if (that.data.Field[1].length > 0 || that.data.Field[2].length > 0 || that.data.Field[2].length > 0) {
  1199. wx.showModal({
  1200. title: '尚未保存',
  1201. content: '即将打开“知识检验”功能,但当前题卡尚未保存,按继续将放弃保存。',
  1202. confirmText: '继续',
  1203. success(res) {
  1204. if (res.confirm) {
  1205. wx.redirectTo({
  1206. url: '../test/index',
  1207. });
  1208. setTimeout(function(){
  1209. wx.removeStorageSync("TempCardNoSaved");
  1210. },1000);
  1211. }
  1212. }
  1213. });
  1214. }
  1215. else {
  1216. wx.redirectTo({
  1217. url: '../test/index',
  1218. });
  1219. }
  1220. },
  1221. onShareAppMessage: function () {
  1222. return {
  1223. title: app.globalData.ShareTitle,
  1224. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  1225. imageUrl: app.globalData.ShareImage,
  1226. }
  1227. },
  1228. })