add.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  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)
  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. }
  323. });
  324. }
  325. else{
  326. wx.showToast({
  327. title: '已保存',
  328. image: "../images/universalpic_saved_white_120x120.png",
  329. });
  330. }
  331. isFirstAdd = false;
  332. that.initAddCard();
  333. }
  334. else{
  335. wx.showToast({
  336. title: '已保存',
  337. image: "../images/universalpic_saved_white_120x120.png",
  338. });
  339. }
  340. }
  341. wx.removeStorageSync("TempCardInfo");
  342. if (that.data.CardType==1){
  343. var cardType=wx.getStorageSync('CardType');
  344. if (cardType==0 && app.globalData.TaskToday.CardNumberUrgent==1){
  345. wx.navigateTo({
  346. url: "../other/menu?Type=0",
  347. });
  348. }
  349. }
  350. });
  351. } else {
  352. wx.showToast({
  353. title: '图片上传失败1',
  354. mask: true,
  355. });
  356. }
  357. });
  358. }
  359. } else {
  360. wx.showToast({
  361. title: '点击太频繁',
  362. mask: true,
  363. });
  364. }
  365. }
  366. },
  367. formatField: function (field) {
  368. var result = {};
  369. for (var i = 1; i <= 3; i++) {
  370. result["Field" + i] = "";
  371. if (field.length>0 && field[i]) {
  372. for (var key in field[i]) {
  373. var item = field[i][key];
  374. var str = "";
  375. if (item.Type == "image") {
  376. str = "[图 w='" + item.Width + "' h='" + item.Height + "']" + item.Content + "[/图]";
  377. } else if (item.Type == "line") {
  378. for (var j = 0; j < item.Content.length; j++) {
  379. if (item.Content[j].key == "normal")
  380. str += item.Content[j].value;
  381. if (item.Content[j].key == "line") {
  382. str += "[线]" + item.Content[j].value + "[/线]";
  383. }
  384. if (item.Content[j].key == "highlighter") {
  385. str += "[光]" + item.Content[j].value + "[/光]";
  386. }
  387. }
  388. } else if (item.Type == "sound") {
  389. if (item.SoundMark)
  390. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  391. else
  392. str = "[读]" + item.Content + "[/读]";
  393. } else if (item.Type == "recorder") {
  394. if (item.SoundMark)
  395. str = "[音 url='" + item.SoundMark + "'][/音]";
  396. } else if (item.Type == "normal") {
  397. str = item.Content;
  398. } else if (item.Type == "return") {
  399. str = "\n";
  400. }
  401. result["Field" + i] += str;
  402. }
  403. }
  404. result["Field" + i] = main.changeViewToString(result["Field" + i]);
  405. }
  406. return result;
  407. },
  408. checkImageCount: function (arr) {
  409. var count = 0;
  410. for (var i = 0; i < arr.length; i++) {
  411. for (var j = 0; j < arr[i].length; j++) {
  412. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  413. count++;
  414. }
  415. }
  416. }
  417. if (count > 3) {
  418. wx.showToast({
  419. title: '只能上传三张图片',
  420. });
  421. return false;
  422. } else
  423. return true;
  424. },
  425. uploadImageAll: function (arr, callback) {
  426. var that = this;
  427. var b = false;
  428. var arrSource = [],
  429. arrResult = [];
  430. for (var i = 0; i < arr.length; i++) {
  431. for (var j = 0; j < arr[i].length; j++) {
  432. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  433. arrSource.push(arr[i][j].Content);
  434. if (arr[i][j].ContentServer.indexOf(app.globalData.uploadImageUrl) >= 0 ||
  435. arr[i][j].ContentServer.indexOf("baidu.com") >= 0 ||
  436. arr[i][j].ContentServer.indexOf("bcebos.com") >= 0) {
  437. var result = {};
  438. result.Source = arr[i][j].ContentServer;
  439. result.Target = arr[i][j].ContentServer;
  440. arrResult.push(result);
  441. } else {
  442. var source = arr[i][j].Content;
  443. that.uploadFileToServer(source, function (data) {
  444. if (data) {
  445. data = JSON.parse(data);
  446. var result = data.result;
  447. result.Target = app.globalData.uploadImageUrl + result.Target;
  448. arrResult.push(result);
  449. }
  450. });
  451. }
  452. b = true;
  453. }
  454. }
  455. }
  456. if (b) {
  457. wx.showLoading({
  458. title: '正在上传',
  459. mask: true,
  460. });
  461. timeoutUploadImage = setTimeout(function () {
  462. wx.hideLoading();
  463. }, 30000);
  464. }
  465. interval = setInterval(function () {
  466. //console.log(arrResult.length);
  467. if (arrResult.length >= arrSource.length) {
  468. wx.hideLoading();
  469. //console.log("arrResult:" + JSON.stringify(arrResult));
  470. clearInterval(interval);
  471. var success = true;
  472. var ari = 0;
  473. for (var i = 0; i < arr.length; i++) {
  474. for (var j = 0; j < arr[i].length; j++) {
  475. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  476. var tempUrl = arr[i][j].Content;
  477. var serverUrl = "";
  478. for (var k = 0; k < arrResult.length; k++) {
  479. if (tempUrl.indexOf(arrResult[k].Source) >= 0) {
  480. serverUrl = arrResult[k].Target;
  481. break;
  482. }
  483. }
  484. //console.log("serverUrl:" + serverUrl);
  485. //console.log("tempUrl:" + tempUrl);
  486. if (serverUrl == "")
  487. serverUrl = main.getServerImage(tempUrl);
  488. main.saveTempImage(serverUrl, tempUrl);
  489. arr[i][j].Content = serverUrl;
  490. arr[i][j].ContentServer = serverUrl;
  491. if (serverUrl == "") {
  492. success = false;
  493. break;
  494. }
  495. }
  496. }
  497. }
  498. //console.log(JSON.stringify(arr));
  499. callback(success, arr);
  500. }
  501. }, 500);
  502. },
  503. uploadFileToServer: function (file, callback) {
  504. var url = common.Encrypt("MiaoguoUploadFile2");
  505. wx.uploadFile({
  506. url: app.globalData.serverUrl + url,
  507. filePath: file,
  508. name: 'file',
  509. success(res) {
  510. callback(res.data);
  511. },
  512. fail: function (err) {
  513. wx.hideLoading();
  514. wx.showModal({
  515. title: '上传文件失败',
  516. showCancel: false,
  517. content: JSON.stringify(err),
  518. });
  519. }
  520. });
  521. },
  522. saveLocalCardList: function (param1) {
  523. var that = this;
  524. var list = app.globalData.CardList;
  525. for (var i = 0; i < list.length; i++) {
  526. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  527. for (var j = 0; j < 4; j++) {
  528. if (j == 0) {
  529. if (param1.tags && param1.tags.length > 0)
  530. list[i].Content[j].Content = param1.tags.join(",");
  531. } else
  532. list[i].Content[j].Content = param1["Field" + j];
  533. }
  534. if (param1.LimitTime)
  535. list[i].LimitTime = common.formatTime(param1.LimitTime);
  536. if (param1.IsTodayStudy == 1) {
  537. list[i].LimitTime = common.formatTime(new Date());
  538. main.getTaskTodayList(function () { });
  539. }
  540. app.globalData.CardList = list;
  541. break;
  542. }
  543. }
  544. },
  545. initAddCard: function () {
  546. var card = {};
  547. card.MiaoguoCardID = 0;
  548. card.Content = [];
  549. for (var i = 0; i < 4; i++) {
  550. var obj = {};
  551. obj.ContentType = i;
  552. obj.Content = [];
  553. card.Content.push(obj);
  554. }
  555. app.globalData.CardList = [card];
  556. this.setData({
  557. MiaoguoCardID: 0,
  558. Field: [
  559. [],
  560. [],
  561. [],
  562. []
  563. ],
  564. Tags: [],
  565. UpdateType: "add2",
  566. });
  567. },
  568. onBindError: function (e) {
  569. for (var i = 1; i < this.data.Field.length; i++) {
  570. for (var j = 0; j < this.data.Field[i].length; j++) {
  571. if (this.data.Field[i][j].Type == "image") {
  572. this.data.Field[i][j].Url = this.data.Field[i][j].Content;
  573. }
  574. }
  575. }
  576. this.setData({
  577. Field: this.data.Field,
  578. });
  579. },
  580. deleteItem: function (e) {
  581. var that = this;
  582. var index = e.currentTarget.dataset.id;
  583. if (e.currentTarget.dataset.type==1){
  584. that.setData({
  585. TagIndex: index,
  586. });
  587. }
  588. else if (e.currentTarget.dataset.type==2){
  589. that.data.TagTemp.splice(index, 1);
  590. that.setData({
  591. TagTemp: that.data.TagTemp,
  592. TagIndex: -1,
  593. });
  594. }
  595. else if (e.currentTarget.dataset.type==3){
  596. that.setData({
  597. Tags: that.data.TagTemp,
  598. TagsStr:that.data.TagTemp.join("、"),
  599. TagIndex: -1,
  600. });
  601. var list = app.globalData.CardList;
  602. for (var i = 0; i < list.length; i++) {
  603. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  604. list[i].Content[0].Content = that.data.Tags;
  605. break;
  606. }
  607. }
  608. app.globalData.CardList = list;
  609. that.closeTagShow();
  610. }
  611. },
  612. onGotoList: function () {
  613. var that = this;
  614. if (isFirstAdd == true || !that.data.Field) {
  615. wx.showModal({
  616. title: '提醒',
  617. content: '无法复查,因为没有上一张。从连续新建第二张题卡起可一键查看上一张题卡。',
  618. confirmText: '知道了',
  619. showCancel: false,
  620. });
  621. }
  622. else if (that.data.Field[1].length > 0 || that.data.Field[2].length > 0 || that.data.Field[2].length > 0) {
  623. wx.showModal({
  624. title: '提醒',
  625. content: '将离开编辑状态,请先保存题卡。',
  626. confirmText: '不保存',
  627. success(res) {
  628. if (res.confirm) {
  629. goto();
  630. setTimeout(function () {
  631. wx.removeStorageSync("TempCardNoSaved");
  632. }, 1000);
  633. }
  634. }
  635. });
  636. }
  637. else {
  638. goto();
  639. }
  640. function goto() {
  641. wx.showLoading({
  642. title: '请稍候',
  643. });
  644. setTimeout(function () {
  645. wx.hideLoading();
  646. }, 5000);
  647. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
  648. main.getData(url, function (data) {
  649. wx.hideLoading();
  650. if (data) {
  651. app.globalData.CardList = data.List;
  652. that.setData({
  653. UpdateType: "add",
  654. });
  655. wx.navigateTo({
  656. url: './searchCardList?type=3&Count=' + data.Count,
  657. })
  658. }
  659. });
  660. }
  661. },
  662. //段落编辑**************************
  663. //字段输入
  664. bindinputField: function (e) {
  665. //console.log("bindinputField:" + e.detail.value + " isEdit:" + isEdit);
  666. var that = this;
  667. if (app.globalData.IsAndroid && !isEdit) {
  668. return;
  669. }
  670. this.setData({
  671. FieldContent: e.detail.value,
  672. });
  673. },
  674. //加符号
  675. addSymbol: function (e) {
  676. //console.log("addSymbol");
  677. isEdit = true;
  678. var that = this;
  679. btnName = e.currentTarget.dataset.id;
  680. if (btnName == "[读]") {
  681. this.setData({
  682. SoundSign: "[/读]",
  683. });
  684. } else if (btnName == "[/读]") {
  685. this.setData({
  686. SoundSign: "[读]",
  687. });
  688. } else if (btnName == "[线]") {
  689. this.setData({
  690. LineSign: "[/线]",
  691. });
  692. } else if (btnName == "[/线]") {
  693. this.setData({
  694. LineSign: "[线]",
  695. });
  696. } else if (btnName == "[光]") {
  697. this.setData({
  698. HighlighterSign: "[/光]",
  699. });
  700. } else if (btnName == "[/光]") {
  701. this.setData({
  702. HighlighterSign: "[光]",
  703. });
  704. }
  705. if (btnName == "( )")
  706. btnName = "( )";
  707. else if (btnName == "_")
  708. btnName = "_____";
  709. //console.log("addSymbol_btnName:" + btnName);
  710. if (!this.data.Focus) {
  711. var obj = { detail: { cursor: tempCursor } };
  712. this.onBindblur(obj);
  713. }
  714. //console.log("addSymbol:" + this.data.FieldContent);
  715. setTimeout(function () {
  716. that.setData({
  717. Focus: true,
  718. });
  719. }, 300);
  720. },
  721. //焦点聚焦
  722. onBindFocus: function () {
  723. //console.log("onBindFocus");
  724. btnName = "";
  725. this.setData({
  726. Focus: true,
  727. });
  728. },
  729. //失焦
  730. onBindblur: function (e) {
  731. var that = this;
  732. //console.log("onBindblur:" + isEdit + " Filed:" + this.data.FieldContent);
  733. if (app.globalData.IsAndroid && !isEdit) {
  734. setTimeout(function () {
  735. isEdit = true;
  736. //console.log("onBindblur2:" + isEdit);
  737. }, 500);
  738. return;
  739. }
  740. isEdit = false;
  741. if (app.globalData.IsAndroid && !isEdit) {
  742. setTimeout(function () {
  743. isEdit = true;
  744. //console.log("onBindblur2:" + isEdit);
  745. }, 500);
  746. }
  747. //console.log("onBindblur:"+isEdit);
  748. this.updateField();
  749. tempCursor = e.detail.cursor;
  750. //console.log("tempCursor:" + tempCursor);
  751. if (tempCursor == undefined)
  752. tempCursor = this.data["FieldContent"].length;
  753. var str1 = "",
  754. str2 = "";
  755. if (this.data.FieldContent.length > 0) {
  756. str1 = this.data.FieldContent.substr(0, tempCursor);
  757. str2 = this.data.FieldContent.substring(tempCursor, this.data.FieldContent.length);
  758. }
  759. //console.log("str1:" + str1);
  760. //console.log("btnName:" + btnName);
  761. //console.log("str2:" + str2);
  762. var cur = 0;
  763. if (btnName) {
  764. cur = 1;
  765. if (btnName == "[读]" || btnName == "[线]" || btnName == "[光]") {
  766. cur = 3;
  767. } else if (btnName == "[/读]" || btnName == "[/线]" || btnName == "[/光]") {
  768. cur = 4;
  769. } else if (btnName === "( )") {
  770. cur = 7;
  771. } else if (btnName === "_____") {
  772. cur = 5;
  773. }
  774. }
  775. this.data.FieldContent = str1 + btnName + str2;
  776. this.setData({
  777. FieldContent: this.data.FieldContent,
  778. Focus: false,
  779. Cursor: tempCursor + cur,
  780. });
  781. btnName = "";
  782. },
  783. bindscrollHandler: function () {
  784. //console.log("bindscrollHandler");
  785. btnName = "";
  786. },
  787. onSearchField: function (e) {
  788. app.globalData.TempFieldNumber = this.data.FieldNumber;
  789. wx.navigateTo({
  790. url: './searchWeb',
  791. });
  792. this.updateField();
  793. setTimeout(function () {
  794. isEdit = true;
  795. //console.log("onSearchEnd");
  796. }, 1000);
  797. },
  798. clear: function () {
  799. var that = this;
  800. //console.log("clear");
  801. this.setData({
  802. FieldContent: "",
  803. Focus: true,
  804. Cursor: 0,
  805. });
  806. btnName = "";
  807. isEdit = false;
  808. this.updateField();
  809. },
  810. closeAddItem: function (e) {
  811. var that = this;
  812. var isSave = e.currentTarget.dataset.idsave;
  813. if (isSave == "true") {
  814. isUnload = false;
  815. if (that.data.FieldContent) {
  816. var content = that.data.FieldContent;
  817. main.postData("MsgSecCheck2",
  818. { Content: content, },
  819. function (data) {
  820. if (data && data.errcode == 0) {
  821. next(that);
  822. } else {
  823. if (data.errmsg) {
  824. wx.showToast({
  825. title: data.errmsg,
  826. duration: 2000,
  827. image: "../images/universalpic_wrong_white_120x120.png",
  828. });
  829. isViolate = true;
  830. }
  831. }
  832. });
  833. } else {
  834. next(that);
  835. }
  836. } else if (isSave == "false") {
  837. var content = wx.getStorageSync("TempCardInfoAddItem");
  838. this.setData({
  839. FieldContent: content,
  840. });
  841. next(that);
  842. }
  843. function next(obj) {
  844. isViolate = false;
  845. obj.updateField();
  846. obj.setData({
  847. HiddenFieldEdit: true,
  848. });
  849. var title = "编辑题卡";
  850. if (obj.data.UpdateType == "add2") {
  851. title = "新建题卡";
  852. }
  853. that.setData({
  854. PageTitle: title,
  855. });
  856. }
  857. },
  858. updateField: function () {
  859. var str = this.data.FieldContent;
  860. var list = app.globalData.CardList;
  861. var card = {};
  862. for (var i = 0; i < list.length; i++) {
  863. if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  864. list[i].Content[this.data.FieldNumber].Content = str;
  865. card = main.changeStringToView(list[i].Content);
  866. break;
  867. }
  868. }
  869. app.globalData.CardList = list;
  870. this.setData({
  871. Field: card.Field,
  872. Tags: card.Tags,
  873. });
  874. },
  875. //选择图片上传
  876. uploadImageField: function () {
  877. //console.log("uploadImageStart");
  878. var that = this;
  879. //若是安卓机
  880. if (app.globalData.IsAndroid) {
  881. selectImage(that);
  882. } else {
  883. wx.showActionSheet({
  884. itemList: ['拍照', '从手机相册选择'],
  885. success(res) {
  886. if (res.tapIndex == 0) {
  887. wx.chooseImage({
  888. count: 1,
  889. sizeType: ['compressed'],
  890. sourceType: ['camera'],
  891. success(res2) {
  892. wx.showLoading({
  893. title: '请稍候',
  894. mask: true,
  895. });
  896. setTimeout(function () {
  897. wx.hideLoading();
  898. selectImage(that);
  899. }, 2000);
  900. },
  901. });
  902. } else if (res.tapIndex == 1) {
  903. selectImage(that);
  904. }
  905. },
  906. fail(res) {
  907. console.log(res.errMsg)
  908. }
  909. });
  910. }
  911. function selectImage(that) {
  912. var sizeType = ['album'];
  913. //若是安卓机
  914. if (app.globalData.IsAndroid)
  915. sizeType = ['album', 'camera'];
  916. wx.chooseImage({
  917. count: 1,
  918. sizeType: ['compressed'],
  919. sourceType: sizeType,
  920. success(res) {
  921. // tempFilePath可以作为img标签的src属性显示图片
  922. const tempFilePaths = res.tempFilePaths;
  923. //console.log(tempFilePaths[0]);
  924. //that.data.FieldContent = that.data.FieldContent + "[图 url='" + tempFilePaths[0] + "']" + tempFilePaths[0] + "[/图]";
  925. wx.getImageInfo({
  926. src: res.tempFilePaths[0],
  927. success(res) {
  928. //console.log(res.width)
  929. //console.log(res.height)
  930. if (tempCursor == undefined)
  931. tempCursor = that.data.FieldContent.length;
  932. var str1 = "",
  933. str2 = "";
  934. if (that.data.FieldContent.length > 0) {
  935. str1 = that.data.FieldContent.substr(0, tempCursor);
  936. str2 = that.data.FieldContent.substring(tempCursor, that.data.FieldContent.length);
  937. }
  938. var width = res.width;
  939. if (isNaN(width))
  940. width = 650;
  941. var height = res.height;
  942. if (isNaN(height))
  943. height = 650;
  944. var str0 = "[图 w='" + width + "' h='" + height + "']" + tempFilePaths[0] + "[/图]";
  945. that.data.FieldContent = str1 + str0 + str2;
  946. tempCursor = that.data.FieldContent.length;
  947. //console.log("uploadImageEnd:" + that.data.FieldContent);
  948. that.setData({
  949. FieldContent: that.data.FieldContent,
  950. Focus: false,
  951. });
  952. that.updateField();
  953. if (!wx.getStorageSync("NoRemindImage")) {
  954. wx.showModal({
  955. title: '提醒',
  956. showCancel: true,
  957. content: "“图片记号”以符号[图]开始…以符号[/图]结尾。如要剪切请确保完整性。",
  958. confirmText: "好的",
  959. cancelText: "不再提醒",
  960. success(res) {
  961. if (res.confirm) { } else {
  962. wx.setStorageSync("NoRemindImage", true);
  963. }
  964. },
  965. });
  966. }
  967. }
  968. });
  969. },
  970. fail: function () {
  971. }
  972. });
  973. }
  974. },
  975. showPracticeTime: function () {
  976. if (this.data.MiaoguoCardID){
  977. wx.navigateTo({
  978. url: './previewMenu?IsSave=0&ID='+this.data.MiaoguoCardID+'&CardType='+this.data.CardType+"&LimitTime="+this.data.LimitTime,
  979. });
  980. }
  981. else{
  982. var limitTime=common.formatTime(new Date(),"-",true);
  983. if (this.data.LimitTime)
  984. limitTime=this.data.LimitTime;
  985. var cardType=0;
  986. if (this.data.CardType)
  987. cardType=this.data.CardType;
  988. wx.navigateTo({
  989. url: './previewMenu?IsSave=0&ID=0&CardType='+cardType+'&LimitTime='+limitTime,
  990. });
  991. }
  992. },
  993. //录音授权
  994. recorderAccredit: function () {
  995. var that = this;
  996. if (app.globalData.IsRecorderAccredit == 1)
  997. that.showRecorder();
  998. else if (app.globalData.IsRecorderAccredit == 0) {
  999. recorderManager.stop();
  1000. app.globalData.IsRecorderAccredit = 1;
  1001. that.showRecorder();
  1002. } else if (app.globalData.IsRecorderAccredit == -1) {
  1003. wx.getSetting({
  1004. success(res) {
  1005. if (res.authSetting['scope.record'] === true) {
  1006. app.globalData.IsRecorderAccredit = 1;
  1007. that.showRecorder();
  1008. } else if (res.authSetting['scope.record'] === false) {
  1009. wx.navigateTo({
  1010. url: '../index/openSetting',
  1011. });
  1012. }
  1013. }
  1014. });
  1015. }
  1016. },
  1017. showRecorder: function () {
  1018. var that = this;
  1019. if (that.checkRecorderCount()) {
  1020. that.recorderInit();
  1021. tempRecorderFile = "";
  1022. that.setData({
  1023. PageTitle: '录音',
  1024. });
  1025. that.setData({
  1026. IsRecorder: true,
  1027. IsRecorderFinished: false,
  1028. BtnRecorderName: "按住录音1分钟",
  1029. RecorderTime: "00:00",
  1030. RecorderTimeCss: "",
  1031. RecorderPlayName: "播放",
  1032. });
  1033. innerAudioContext = wx.createInnerAudioContext();
  1034. innerAudioContext.onPlay(() => {
  1035. console.log('开始播放');
  1036. that.setData({
  1037. RecorderTimeCss: "RecorderPanel1121",
  1038. RecorderTime: "00:00",
  1039. RecorderPlayName: "停止",
  1040. });
  1041. });
  1042. innerAudioContext.onEnded(() => {
  1043. console.log('结束播放');
  1044. clearInterval(intervalRecorder);
  1045. that.setData({
  1046. RecorderTime: "00:00",
  1047. RecorderTimeCss: "",
  1048. RecorderPlayName: "播放",
  1049. });
  1050. });
  1051. }
  1052. },
  1053. closeRecorder: function () {
  1054. var that = this;
  1055. this.recorderInit();
  1056. if (tempRecorderFile) {
  1057. wx.showModal({
  1058. title: '提醒',
  1059. content: '录音文件还未上传,要放弃录音吗?',
  1060. showCancel: true,
  1061. confirmText: "取消",
  1062. cancelText: "不上传",
  1063. success(res) {
  1064. if (res.cancel) {
  1065. closeRecorder2();
  1066. }
  1067. },
  1068. })
  1069. } else {
  1070. closeRecorder2();
  1071. }
  1072. function closeRecorder2() {
  1073. that.setData({
  1074. PageTitle: '编辑 段落' + that.data.FieldNumber,
  1075. });
  1076. that.setData({
  1077. IsRecorder: false,
  1078. IsRecorderFinished: false,
  1079. });
  1080. tempRecorderFile = "";
  1081. }
  1082. },
  1083. //录音初始化
  1084. recorderInit: function () {
  1085. if (innerAudioContext)
  1086. innerAudioContext.stop();
  1087. if (recorderManager)
  1088. recorderManager.stop();
  1089. clearInterval(intervalRecorder);
  1090. },
  1091. checkRecorderCount: function (arr) {
  1092. var that = this;
  1093. var count = 0;
  1094. if (that.data.FieldContent.indexOf("[音 url=") >= 0 ||
  1095. that.data.FieldContent.indexOf("[/音]") >= 0) {
  1096. count = 1;
  1097. }
  1098. if (count > 0) {
  1099. wx.showToast({
  1100. title: '仅能上传一段',
  1101. });
  1102. return false;
  1103. } else
  1104. return true;
  1105. },
  1106. btnRecorderStart: function () {
  1107. var that = this;
  1108. if (app.globalData.IsRecorderAccredit == 1) {
  1109. that.setData({
  1110. BtnRecorderName: "松手结束",
  1111. RecorderTimeCss: "RecorderPanel1121",
  1112. });
  1113. that.showRecorderTime();
  1114. recorderManager.start();
  1115. }
  1116. },
  1117. btnRecorderEnd: function () {
  1118. var that = this;
  1119. if (app.globalData.IsRecorderAccredit == 1) {
  1120. if (that.data.RecorderTime == "00:00") {
  1121. //小于1秒处理
  1122. wx.showToast({
  1123. title: '时间过短',
  1124. image: "../images/universalpic_warning_white_126x120.png",
  1125. });
  1126. that.showRecorder();
  1127. } else {
  1128. that.setData({
  1129. IsRecorderFinished: true,
  1130. RecorderTimeCss: "",
  1131. });
  1132. that.recorderInit();
  1133. }
  1134. } else {
  1135. that.recorderAccredit();
  1136. }
  1137. },
  1138. showRecorderTime: function () {
  1139. var that = this;
  1140. var second = 0;
  1141. clearInterval(intervalRecorder);
  1142. intervalRecorder = setInterval(function () {
  1143. second++;
  1144. var secondStr = second.toString();
  1145. if (second < 10)
  1146. secondStr = "0" + secondStr;
  1147. that.setData({
  1148. RecorderTime: "00:" + secondStr,
  1149. });
  1150. if (second >= 59) {
  1151. that.setData({
  1152. IsRecorderFinished: true,
  1153. RecorderTimeCss: "",
  1154. });
  1155. that.recorderInit();
  1156. if (that.data.RecorderPlayName == "播放") {
  1157. wx.showToast({
  1158. title: '录音超时',
  1159. image: "../images/universalpic_warning_white_126x120.png",
  1160. });
  1161. }
  1162. }
  1163. }, 1000);
  1164. },
  1165. btnRecorderPlay: function () {
  1166. var that = this;
  1167. if (tempRecorderFile && this.data.RecorderPlayName == "播放") {
  1168. innerAudioContext.src = tempRecorderFile;
  1169. innerAudioContext.play();
  1170. this.showRecorderTime();
  1171. } else if (this.data.RecorderPlayName == "停止") {
  1172. if (innerAudioContext)
  1173. innerAudioContext.stop();
  1174. clearInterval(intervalRecorder);
  1175. that.setData({
  1176. RecorderTime: "00:00",
  1177. RecorderTimeCss: "",
  1178. RecorderPlayName: "播放",
  1179. });
  1180. }
  1181. },
  1182. btnRecorderSave: function () {
  1183. var that = this;
  1184. this.recorderInit();
  1185. wx.showLoading({
  1186. title: '正在上传',
  1187. });
  1188. setTimeout(function () {
  1189. wx.hideLoading();
  1190. }, 60000);
  1191. that.uploadFileToServer(tempRecorderFile, function (data) {
  1192. if (data) {
  1193. data = JSON.parse(data);
  1194. //console.log(data);
  1195. wx.hideLoading();
  1196. var result = data.result;
  1197. result.Target = app.globalData.uploadImageUrl + result.Target;
  1198. that.data.FieldContent = that.data.FieldContent + "[音 url='" + result.Target + "'][/音]";
  1199. that.data.FieldContent = main.encryptUrl(that.data.FieldContent);
  1200. that.setData({
  1201. FieldContent: that.data.FieldContent,
  1202. });
  1203. tempRecorderFile = "";
  1204. that.closeRecorder();
  1205. if (!wx.getStorageSync("NoRemindRecorder")) {
  1206. wx.showModal({
  1207. title: '提醒',
  1208. showCancel: true,
  1209. content: "“录音记号”以符号[录]开始…以符号[/录]结尾。如要剪切请确保完整性。",
  1210. confirmText: "好的",
  1211. cancelText: "不再提醒",
  1212. success(res) {
  1213. if (res.confirm) { } else {
  1214. wx.setStorageSync("NoRemindRecorder", true);
  1215. }
  1216. },
  1217. });
  1218. }
  1219. }
  1220. });
  1221. },
  1222. gotoSymbol: function (e) {
  1223. wx.navigateTo({
  1224. url: '../main/symbolsetting',
  1225. });
  1226. },
  1227. gotoTest: function () {
  1228. var that=this;
  1229. if (that.data.Field[1].length > 0 || that.data.Field[2].length > 0 || that.data.Field[2].length > 0) {
  1230. wx.showModal({
  1231. title: '尚未保存',
  1232. content: '即将打开“知识检验”功能,但当前题卡尚未保存,按继续将放弃保存。',
  1233. confirmText: '继续',
  1234. success(res) {
  1235. if (res.confirm) {
  1236. wx.redirectTo({
  1237. url: '../test/index',
  1238. });
  1239. setTimeout(function(){
  1240. wx.removeStorageSync("TempCardNoSaved");
  1241. },1000);
  1242. }
  1243. }
  1244. });
  1245. }
  1246. else {
  1247. wx.redirectTo({
  1248. url: '../test/index',
  1249. });
  1250. }
  1251. },
  1252. showTagShow:function(){
  1253. var tagTemp=this.data.Tags.join(",");
  1254. this.setData({
  1255. IsTagShow:true,
  1256. TagTemp:tagTemp.split(","),
  1257. TagIndex:-1,
  1258. });
  1259. this.setData({
  1260. PageTitle: '自动记号',
  1261. });
  1262. },
  1263. closeTagShow:function(){
  1264. this.setData({
  1265. IsTagShow:false,
  1266. });
  1267. this.setData({
  1268. PageTitle: '编辑题卡',
  1269. });
  1270. },
  1271. setCardTypeInit:function(){
  1272. this.setData({
  1273. CardType:0,
  1274. PracticeCardType:"日常",
  1275. PracticeTimeStr:"",
  1276. LimitTime:common.formatTime(new Date(),"-",true),
  1277. IsEditCardType:"",
  1278. });
  1279. wx.showToast({
  1280. title: '已恢复默认',
  1281. image: "../images/universalpic_restore_white_120x120.png",
  1282. });
  1283. },
  1284. onShareAppMessage: function () {
  1285. return {
  1286. title: app.globalData.ShareTitle,
  1287. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  1288. imageUrl: app.globalData.ShareImage,
  1289. }
  1290. },
  1291. })