add.js 33 KB

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