add.js 35 KB

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