add.js 35 KB

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