add.js 36 KB

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