add.js 35 KB

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