add.js 38 KB

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