add.js 36 KB

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