add.js 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. import constant1 from '../../utils/constant';
  4. const app = getApp();
  5. var arrTag = [];
  6. var tempCursor = undefined,
  7. btnName = "";
  8. var arrSoundMark = [];
  9. var isUnload = true;
  10. var isEdit = true;
  11. var isSave = true;
  12. var interval;
  13. var timeoutUploadImage = 0;
  14. var intervalRecorder = 0; //录音计时器
  15. var recorderManager;
  16. var tempRecorderFile = "";
  17. var innerAudioContext;
  18. var isViolate = false; //是否是违禁词
  19. var isFirstAdd = true; //是第一个填加
  20. var isAddFolder = false; //用于新增卡单时用
  21. var isCancel = false; //是否放弃题卡内容
  22. Page({
  23. data: {
  24. ImagePath: app.globalData.uploadImageUrl,
  25. HiddenFieldEdit: true,
  26. FieldContent: "",
  27. SoundSign: "[读]",
  28. LineSign: "[线]",
  29. HighlighterSign: "[光]",
  30. IsPracticeTime: false,
  31. IsRecorder: false,
  32. IsIPhoneX: app.globalData.IsIPhoneX,
  33. IsAndroid: app.globalData.IsAndroid,
  34. IsTagShow: false,
  35. PageTitle: "新建题卡",
  36. InputHeight: 315,
  37. IsShowMenu: false,
  38. IsHelp: false,
  39. HelpArr: ["help_board_tips_jiaziliao", "help_board_tips_diankaigengduo", "help_board_tips_lianxvxinjian", "help_board_tips_meihua", "help_board_tips_geshi"],
  40. IsFontsize: false,
  41. IsCollect: 0,
  42. BtnSaveSelectCss: "",
  43. },
  44. onReady: function () {
  45. recorderManager = wx.getRecorderManager();
  46. recorderManager.onStart(() => {
  47. console.log('recorder start')
  48. });
  49. recorderManager.onStop((res) => {
  50. console.log('recorder stop', res);
  51. tempRecorderFile = res.tempFilePath;
  52. });
  53. recorderManager.onError((err) => {});
  54. },
  55. //获取导航栏高度
  56. getBarInfo(e) {
  57. var h = e.detail.topBarHeight;
  58. h = h * 2;
  59. var h2 = 0;
  60. var h3 = 0;
  61. if (app.globalData.IsIPad) {
  62. h2 = -68;
  63. h3 = -100;
  64. }
  65. this.setData({
  66. topBarHeight: h,
  67. topBarHeightIPad: h2,
  68. topBarHeightIPad2: h3,
  69. })
  70. },
  71. onLoad: function (options) {
  72. var that = this;
  73. var fieldNumber = 0;
  74. if (options.fieldid)
  75. fieldNumber = options.fieldid;
  76. var cardtype = options.CardType;
  77. if (!cardtype)
  78. cardtype = 0;
  79. else
  80. cardtype = Number(cardtype);
  81. var folderid = options.FolderID;
  82. var foldername = "";
  83. if (!folderid)
  84. folderid = 0;
  85. else {
  86. folderid = Number(folderid);
  87. foldername = options.FolderName;
  88. }
  89. that.setData({
  90. Containnerheight: main.getWindowHeight(),
  91. UpdateType: options.type,
  92. MiaoguoCardID: options.id,
  93. FieldNumber: fieldNumber,
  94. IsShow: app.globalData.userInfo.IsShow,
  95. CardType: cardtype,
  96. PracticeCardType: constant1.arrStudyPattern[cardtype] + "题卡",
  97. FolderID: folderid,
  98. FolderName: foldername,
  99. LimitTime: common.formatTime(new Date()),
  100. PracticeTimeStr: common.formatDateCHS(common.formatTime(new Date())),
  101. FontSize: 48,
  102. FontSizeName: "标准",
  103. OpenType: options.opentype,
  104. });
  105. var list = app.globalData.CardList;
  106. for (var i = 0; i < list.length; i++) {
  107. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  108. wx.setStorageSync("TempCardInfo", list[i]);
  109. break;
  110. }
  111. }
  112. app.globalData.TempFieldNumber = 0;
  113. app.globalData.TempMiaoguoCardID = that.data.MiaoguoCardID;
  114. isViolate = false;
  115. isFirstAdd = true;
  116. if (app.globalData.IsIPhoneX) {
  117. that.setData({
  118. InputHeight: 480,
  119. });
  120. }
  121. if (options.type == "add3") {
  122. that.gotoAddInfomationDetail(options);
  123. }
  124. if (options.type.indexOf("add") >= 0)
  125. common.getStorageValue(that, "IsShowAddHelp", 0, function () {});
  126. },
  127. onShow: function () {
  128. var that = this;
  129. if (that.data.UpdateType == "add" || that.data.UpdateType == "add3") {
  130. that.initAddCard();
  131. } else {
  132. var card = {},
  133. content = "";
  134. var list = app.globalData.CardList;
  135. for (var i = 0; i < list.length; i++) {
  136. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  137. card = main.changeStringToView(list[i].Content);
  138. card.MiaoguoCardID = list[i].MiaoguoCardID;
  139. if (list[i].CardType == 0 || list[i].CardType == 1 || list[i].CardType == -1)
  140. card.CardType = list[i].CardType;
  141. else if (that.data.CardType)
  142. card.CardType = that.data.CardType;
  143. else
  144. card.CardType = 0;
  145. card.IsCollect = list[i].IsCollect;
  146. if (that.data.IsCollect)
  147. card.IsCollect = that.data.IsCollect;
  148. else if (!card.IsCollect)
  149. card.IsCollect = 0;
  150. card.FontSize = list[i].FontSize;
  151. if (that.data.FontSize)
  152. card.FontSize = that.data.FontSize;
  153. else if (!card.FontSize)
  154. card.FontSize = 48;
  155. card.FolderID = list[i].FolderID;
  156. if (that.data.FolderID) {
  157. card.FolderID = that.data.FolderID;
  158. card.FolderName = that.data.FolderName;
  159. } else if (!card.FolderID) {
  160. card.FolderID = 0;
  161. }
  162. if (list[i].LimitTime)
  163. card.LimitTime = list[i].LimitTime;
  164. else if (that.data.LimitTime)
  165. card.LimitTime = that.data.LimitTime;
  166. if (that.data.FieldNumber && that.data.FieldNumber > 0)
  167. content = main.encryptUrl(list[i].Content[that.data.FieldNumber].Content);
  168. break;
  169. }
  170. }
  171. var arrTagTemp = [];
  172. if (card.Tags && card.Tags.length > 0) {
  173. for (var j = 0; j < card.Tags.length; j++) {
  174. if (card.Tags[j])
  175. arrTagTemp.push(card.Tags[j]);
  176. }
  177. }
  178. card.Tags = arrTagTemp;
  179. var fontSize = constant1.arrFontSize;
  180. var fontSizeName = "";
  181. for (var j = 0; j < fontSize.length; j++) {
  182. if (fontSize[j].Value == card.FontSize) {
  183. fontSizeName = fontSize[j].Name;
  184. break;
  185. }
  186. }
  187. that.setData({
  188. MiaoguoCardID: card.MiaoguoCardID,
  189. LimitTime: common.formatTime(card.LimitTime),
  190. PracticeCardType: constant1.arrStudyPattern[card.CardType] + "题卡",
  191. PracticeTimeStr: common.formatDateCHS(common.formatTime(card.LimitTime)),
  192. Field: card.Field,
  193. Tags: card.Tags,
  194. TagsStr: card.Tags.join("、"),
  195. FieldContent: content,
  196. CardType: card.CardType,
  197. IsCollect: card.IsCollect,
  198. FolderID: card.FolderID,
  199. FolderName: card.FolderName,
  200. FontSize: card.FontSize,
  201. FontSizeName: fontSizeName,
  202. });
  203. if (that.data.UpdateType != "add2") {
  204. that.setData({
  205. PageTitle: '编辑题卡',
  206. });
  207. }
  208. if (that.data.UpdateType == "edit3") {
  209. that.gotoAddItem({
  210. currentTarget: {
  211. dataset: {
  212. fieldid: that.data.FieldNumber
  213. }
  214. }
  215. });
  216. }
  217. if (that.data.OpenType) {
  218. that.showPanel({
  219. currentTarget: {
  220. dataset: {
  221. type: that.data.OpenType
  222. }
  223. }
  224. });
  225. }
  226. }
  227. if (that.data.IsFolder) {
  228. that.getFolderList();
  229. }
  230. that.setBtnSaveCss();
  231. common.getStorageValue(that, "SymbolMain", app.globalData.SymbolMain, function () {});
  232. },
  233. onHide: function () {
  234. //用于恢复未保存的新题卡
  235. //console.log("onHide");
  236. var that = this;
  237. if (!that.data.HiddenFieldEdit) {
  238. that.updateField();
  239. }
  240. if (!(that.data && that.data.Field && that.data.Field[1].length == 0 &&
  241. that.data.Field[2].length == 0 &&
  242. that.data.Field[3].length == 0) && !isCancel) {
  243. if (!isViolate && (that.data.UpdateType == "add" || that.data.UpdateType == "add2")) {
  244. var card = {};
  245. card.MiaoguoCardID = that.data.MiaoguoCardID;
  246. card.Content = [];
  247. var param1 = {};
  248. param1 = that.formatField(that.data.Field);
  249. for (var i = 0; i < 4; i++) {
  250. var obj = {};
  251. obj.ContentType = i;
  252. if (i == 0)
  253. obj.Content = that.data.Tags;
  254. else
  255. obj.Content = param1["Field" + i];
  256. card.Content.push(obj);
  257. }
  258. wx.setStorageSync("TempCardNoSaved", card);
  259. }
  260. }
  261. isCancel = false;
  262. },
  263. onUnload: function () {
  264. this.onHide();
  265. var card = wx.getStorageSync("TempCardInfo");
  266. if (card) {
  267. var list = app.globalData.CardList;
  268. for (var i = 0; i < list.length; i++) {
  269. if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  270. list[i] = card;
  271. break;
  272. }
  273. }
  274. app.globalData.CardList = list;
  275. wx.removeStorageSync("TempCardInfo");
  276. }
  277. clearInterval(interval);
  278. clearTimeout(timeoutUploadImage);
  279. clearInterval(intervalRecorder);
  280. if (this.data.IsRecorder)
  281. this.closeRecorder();
  282. if (wx.getStorageSync("IsRemindContinuousNew") == 1) {
  283. wx.removeStorageSync('IsRemindContinuousNew');
  284. }
  285. },
  286. onClose: function () {
  287. wx.navigateBack({
  288. delta: 1,
  289. });
  290. isCancel = true;
  291. wx.removeStorageSync('TempCardNoSaved');
  292. clearInterval(intervalRecorder);
  293. },
  294. gotoAddItem: function (e) {
  295. var that = this;
  296. var fieldid = e.currentTarget.dataset.fieldid;
  297. var content;
  298. var list = app.globalData.CardList;
  299. for (var i = 0; i < list.length; i++) {
  300. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  301. content = main.encryptUrl(list[i].Content[fieldid].Content);
  302. break;
  303. }
  304. }
  305. wx.setStorageSync("TempCardInfoAddItem", content);
  306. that.setData({
  307. HiddenFieldEdit: false,
  308. Focus: true,
  309. FieldNumber: fieldid,
  310. FieldContent: content,
  311. });
  312. that.setData({
  313. PageTitle: '编辑 段落' + fieldid,
  314. });
  315. },
  316. onSearch: function (e) {
  317. app.globalData.TempFieldNumber = 0;
  318. wx.navigateTo({
  319. url: './addInfomation',
  320. })
  321. },
  322. onPreview: function (e) {
  323. var that = this;
  324. if (that.data.Field[1] == "") {
  325. wx.showToast({
  326. title: '填写段落1',
  327. image: "../images/universalpic_exclamation_white_120x120.png",
  328. });
  329. } else {
  330. var list = app.globalData.CardList;
  331. for (var i = 0; i < list.length; i++) {
  332. if (list[i].MiaoguoCardID == this.data.MiaoguoCardID) {
  333. list[i].FontSize = this.data.FontSize;
  334. }
  335. }
  336. app.globalData.CardList = list;
  337. wx.navigateTo({
  338. url: './preview?type=preview&id=' + this.data.MiaoguoCardID,
  339. });
  340. }
  341. },
  342. saveCard: function () {
  343. var that = this;
  344. if (that.data.Field[1] == "") {
  345. wx.showToast({
  346. title: '填写段落1',
  347. image: "../images/universalpic_exclamation_white_120x120.png",
  348. });
  349. } else {
  350. if (isSave) {
  351. isSave = false;
  352. setTimeout(function () {
  353. isSave = true;
  354. }, 5000);
  355. if (that.checkImageCount(that.data.Field)) {
  356. that.uploadImageAll(that.data.Field, function (success, field) {
  357. if (success) {
  358. that.data.Field = field;
  359. var userid = app.globalData.userInfo.UserID;
  360. var tags = [];
  361. for (var i = 0; i < that.data.Tags.length; i++) {
  362. if (that.data.Tags[i])
  363. tags.push(that.data.Tags[i]);
  364. }
  365. var param1 = {};
  366. param1 = that.formatField(that.data.Field);
  367. param1.Tags = tags;
  368. param1.IsCollect = that.data.IsCollect;
  369. param1.LimitTime = that.data.LimitTime;
  370. if (!param1.LimitTime)
  371. param1.LimitTime = common.formatTime(new Date(), "-", true);
  372. param1.CardType = that.data.CardType;
  373. if (!param1.CardType)
  374. param1.CardType = 0;
  375. if (that.data.FolderID)
  376. param1.FolderID = that.data.FolderID;
  377. if (that.data.FontSize)
  378. param1.FontSize = that.data.FontSize;
  379. param1.ID = that.data.MiaoguoCardID;
  380. that.saveLocalCardList(param1);
  381. wx.hideLoading();
  382. wx.showLoading({
  383. title: '保存中',
  384. mask: true,
  385. });
  386. timeoutUploadImage = setTimeout(function () {
  387. wx.hideLoading();
  388. }, 15000);
  389. main.postData('AddMiaoguoCard?Type=' + that.data.UpdateType + '&UserID=' + userid, param1, function (data) {
  390. wx.removeStorageSync("TempCardNoSaved");
  391. if (that.data.UpdateType.indexOf("edit") >= 0) {
  392. var list = app.globalData.CardList;
  393. for (var i = 0; i < list.length; i++) {
  394. if (list[i].MiaoguoCardID == that.data.MiaoguoCardID) {
  395. list[i].CardType = that.data.CardType;
  396. list[i].IsCollect = that.data.IsCollect;
  397. list[i].FontSize = that.data.FontSize;
  398. list[i].FolderID = that.data.FolderID;
  399. list[i].FolderName = that.data.FolderName;
  400. list[i].LimitTime = that.data.LimitTime;
  401. list[i].LimitTimeStr = common.formatDateCHS(that.data.LimitTime);
  402. list[i].UpdateTime = common.formatTime(new Date());
  403. delete list[i].IsNullImage;
  404. }
  405. }
  406. app.globalData.CardList = list;
  407. app.globalData.IsUpdateStudyPlan = 1;
  408. if (that.data.CardType == 1) {
  409. app.globalData.TaskToday.CardNumberUrgent++;
  410. }
  411. that.onClose();
  412. } else {
  413. wx.hideLoading();
  414. if (that.data.UpdateType == "add2") {
  415. var remind = wx.getStorageSync("IsRemindContinuousNew")
  416. if (!remind) {
  417. wx.showModal({
  418. title: '提醒',
  419. showCancel: true,
  420. cancelText: "不再提醒",
  421. content: '已进入连续新建状态,此时会保留上一张题卡的练习模式、到期时间、卡单、字号的设置,以方便您创建大量有相同属性的新题卡。另外,还能一键「复查」上一张题卡。',
  422. confirmText: '知道了',
  423. success(res) {
  424. if (res.confirm) {
  425. wx.setStorageSync("IsRemindContinuousNew", 1);
  426. } else {
  427. wx.setStorageSync("IsRemindContinuousNew", 2);
  428. }
  429. changePattern(that);
  430. }
  431. });
  432. } else {
  433. wx.showToast({
  434. title: '已保存',
  435. image: "../images/universalpic_save_white_120x120.png",
  436. });
  437. changePattern(that);
  438. }
  439. isFirstAdd = false;
  440. that.initAddCard();
  441. } else {
  442. wx.showToast({
  443. title: '已保存',
  444. image: "../images/universalpic_save_white_120x120.png",
  445. });
  446. changePattern(that);
  447. }
  448. if (that.data.FolderID > 0) {
  449. app.globalData.FolderList = [];
  450. }
  451. }
  452. wx.removeStorageSync("TempCardInfo");
  453. });
  454. } else {
  455. wx.showToast({
  456. title: '图片上传失败1',
  457. image: "../images/universalpic_exclamation_white_120x120.png",
  458. mask: true,
  459. });
  460. }
  461. });
  462. }
  463. } else {
  464. wx.showToast({
  465. title: '点击太频繁',
  466. image: "../images/universalpic_exclamation_white_120x120.png",
  467. mask: true,
  468. });
  469. }
  470. }
  471. function changePattern(obj) {
  472. if (obj.data.CardType == 1) {
  473. var cardType = wx.getStorageSync('CardType');
  474. if (cardType == 0 && app.globalData.TaskToday.CardNumberUrgent == 1) {
  475. wx.navigateTo({
  476. url: "../other/menu?Type=0",
  477. });
  478. }
  479. }
  480. }
  481. },
  482. formatField: function (field) {
  483. var result = {};
  484. for (var i = 1; i <= 3; i++) {
  485. result["Field" + i] = "";
  486. if (field.length > 0 && field[i]) {
  487. for (var key in field[i]) {
  488. var item = field[i][key];
  489. var str = "";
  490. if (item.Type == "image") {
  491. str = "[图 w='" + item.Width + "' h='" + item.Height + "']" + item.Content + "[/图]";
  492. } else if (item.Type == "line") {
  493. for (var j = 0; j < item.Content.length; j++) {
  494. if (item.Content[j].key == "normal")
  495. str += item.Content[j].value;
  496. if (item.Content[j].key == "line") {
  497. str += "[线]" + item.Content[j].value + "[/线]";
  498. }
  499. if (item.Content[j].key == "highlighter") {
  500. str += "[光]" + item.Content[j].value + "[/光]";
  501. }
  502. }
  503. } else if (item.Type == "sound") {
  504. if (item.SoundMark)
  505. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  506. else
  507. str = "[读]" + item.Content + "[/读]";
  508. } else if (item.Type == "recorder") {
  509. if (item.SoundMark)
  510. str = "[音 url='" + item.SoundMark + "'][/音]";
  511. } else if (item.Type == "normal") {
  512. str = item.Content;
  513. } else if (item.Type == "return") {
  514. str = "\n";
  515. }
  516. result["Field" + i] += str;
  517. }
  518. }
  519. result["Field" + i] = main.changeViewToString(result["Field" + i]);
  520. }
  521. return result;
  522. },
  523. checkImageCount: function (arr) {
  524. var count = 0;
  525. for (var i = 0; i < arr.length; i++) {
  526. for (var j = 0; j < arr[i].length; j++) {
  527. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  528. count++;
  529. }
  530. }
  531. }
  532. if (count > 4) {
  533. wx.showToast({
  534. title: '只能上传四张图片',
  535. image: "../images/universalpic_exclamation_white_120x120.png",
  536. });
  537. return false;
  538. } else
  539. return true;
  540. },
  541. uploadImageAll: function (arr, callback) {
  542. var that = this;
  543. var b = false;
  544. var arrSource = [],
  545. arrResult = [];
  546. for (var i = 0; i < arr.length; i++) {
  547. for (var j = 0; j < arr[i].length; j++) {
  548. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  549. arrSource.push(arr[i][j].Content);
  550. if (arr[i][j].ContentServer.indexOf(app.globalData.uploadImageUrl) >= 0 ||
  551. arr[i][j].ContentServer.indexOf("baidu.com") >= 0 ||
  552. arr[i][j].ContentServer.indexOf("bcebos.com") >= 0) {
  553. var result = {};
  554. result.Source = arr[i][j].ContentServer;
  555. result.Target = arr[i][j].ContentServer;
  556. arrResult.push(result);
  557. } else {
  558. var source = arr[i][j].Content;
  559. that.uploadFileToServer(source, function (data) {
  560. if (data) {
  561. var result = data;
  562. result.Target = app.globalData.uploadImageUrl + result.Target;
  563. arrResult.push(result);
  564. }
  565. });
  566. }
  567. b = true;
  568. }
  569. }
  570. }
  571. if (b) {
  572. wx.showLoading({
  573. title: '正在上传',
  574. mask: true,
  575. });
  576. timeoutUploadImage = setTimeout(function () {
  577. wx.hideLoading();
  578. }, 30000);
  579. }
  580. interval = setInterval(function () {
  581. //console.log(arrResult.length);
  582. if (arrResult.length >= arrSource.length) {
  583. wx.hideLoading();
  584. //console.log("arrResult:" + JSON.stringify(arrResult));
  585. clearInterval(interval);
  586. var success = true;
  587. var ari = 0;
  588. for (var i = 0; i < arr.length; i++) {
  589. for (var j = 0; j < arr[i].length; j++) {
  590. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  591. var tempUrl = arr[i][j].Content;
  592. var serverUrl = "";
  593. for (var k = 0; k < arrResult.length; k++) {
  594. if (tempUrl.indexOf(arrResult[k].Source) >= 0) {
  595. serverUrl = arrResult[k].Target;
  596. break;
  597. }
  598. }
  599. console.log("serverUrl:" + serverUrl);
  600. //console.log("tempUrl:" + tempUrl);
  601. if (serverUrl == "")
  602. serverUrl = main.getServerImage(tempUrl);
  603. main.saveTempImage(serverUrl, tempUrl);
  604. arr[i][j].Content = serverUrl;
  605. arr[i][j].ContentServer = serverUrl;
  606. if (serverUrl == "") {
  607. success = false;
  608. break;
  609. }
  610. }
  611. }
  612. }
  613. //console.log(JSON.stringify(arr));
  614. callback(success, arr);
  615. }
  616. }, 500);
  617. },
  618. uploadFileToServer: function (file, callback) {
  619. var url = common.Encrypt("MiaoguoUploadFile2");
  620. wx.uploadFile({
  621. url: app.globalData.serverUrl + url,
  622. filePath: file,
  623. name: 'file',
  624. success(res) {
  625. var err = JSON.parse(res.data);
  626. if (err.errcode == 10000) {
  627. callback(err.result);
  628. setTimeout(function () {
  629. wx.downloadFile({
  630. url: err.result.Target,
  631. success(res) {
  632. if (res.statusCode != 200) {
  633. wx.hideLoading();
  634. wx.showModal({
  635. title: '上传图片可能失败',
  636. showCancel: false,
  637. confirmText: '知道了',
  638. content: "请点左下角“复查”后编辑上一张题卡重新上传图片。"
  639. });
  640. } else {
  641. console.log("上传成功");
  642. }
  643. }
  644. });
  645. }, 5000);
  646. } else {
  647. wx.hideLoading();
  648. wx.showModal({
  649. title: '上传文件失败',
  650. showCancel: false,
  651. content: JSON.stringify(err.errMsg),
  652. });
  653. }
  654. },
  655. fail: function (err) {
  656. wx.hideLoading();
  657. wx.showModal({
  658. title: '上传文件失败',
  659. showCancel: false,
  660. content: JSON.stringify(err),
  661. });
  662. }
  663. });
  664. },
  665. saveLocalCardList: function (param1) {
  666. var that = this;
  667. var list = app.globalData.CardList;
  668. for (var i = 0; i < list.length; i++) {
  669. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  670. for (var j = 0; j < 4; j++) {
  671. if (j == 0) {
  672. if (param1.tags && param1.tags.length > 0)
  673. list[i].Content[j].Content = param1.tags.join(",");
  674. } else
  675. list[i].Content[j].Content = param1["Field" + j];
  676. }
  677. if (param1.LimitTime)
  678. list[i].LimitTime = common.formatTime(param1.LimitTime);
  679. app.globalData.CardList = list;
  680. break;
  681. }
  682. }
  683. },
  684. initAddCard: function () {
  685. var card = {};
  686. card.MiaoguoCardID = 0;
  687. card.Content = [];
  688. for (var i = 0; i < 4; i++) {
  689. var obj = {};
  690. obj.ContentType = i;
  691. obj.Content = [];
  692. card.Content.push(obj);
  693. }
  694. app.globalData.CardList = [card];
  695. this.setData({
  696. MiaoguoCardID: 0,
  697. Field: [
  698. [],
  699. [],
  700. [],
  701. []
  702. ],
  703. Tags: [],
  704. UpdateType: "add2",
  705. BtnSaveSelectCss: "",
  706. });
  707. },
  708. onBindError: function (e) {
  709. for (var i = 1; i < this.data.Field.length; i++) {
  710. for (var j = 0; j < this.data.Field[i].length; j++) {
  711. if (this.data.Field[i][j].Type == "image") {
  712. this.data.Field[i][j].Url = this.data.Field[i][j].Content;
  713. }
  714. }
  715. }
  716. this.setData({
  717. Field: this.data.Field,
  718. });
  719. },
  720. deleteItem: function (e) {
  721. var that = this;
  722. var index = e.currentTarget.dataset.id;
  723. if (e.currentTarget.dataset.type == 1) {
  724. that.setData({
  725. TagIndex: index,
  726. });
  727. } else if (e.currentTarget.dataset.type == 2) {
  728. that.data.TagTemp.splice(index, 1);
  729. that.setData({
  730. TagTemp: that.data.TagTemp,
  731. TagIndex: -1,
  732. });
  733. } else if (e.currentTarget.dataset.type == 3) {
  734. that.setData({
  735. Tags: that.data.TagTemp,
  736. TagsStr: that.data.TagTemp.join("、"),
  737. TagIndex: -1,
  738. });
  739. var list = app.globalData.CardList;
  740. for (var i = 0; i < list.length; i++) {
  741. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  742. list[i].Content[0].Content = that.data.Tags;
  743. break;
  744. }
  745. }
  746. app.globalData.CardList = list;
  747. that.closeTagShow();
  748. }
  749. },
  750. onGotoList: function () {
  751. var that = this;
  752. if (isFirstAdd == true || !that.data.Field) {
  753. wx.showModal({
  754. title: '提醒',
  755. content: '本功能用于在连续新建题卡时一键复查「上一张题卡」。请在连续新建到第二张时再来试一试。',
  756. confirmText: '知道了',
  757. showCancel: false,
  758. });
  759. } else if (that.data.Field[1].length > 0 || that.data.Field[2].length > 0 || that.data.Field[2].length > 0) {
  760. wx.showModal({
  761. title: '提醒',
  762. content: '您所做的编辑还没有保存,要放弃保存吗?',
  763. confirmText: '取消',
  764. cancelText: "不保存",
  765. success(res) {
  766. if (!res.confirm) {
  767. goto();
  768. setTimeout(function () {
  769. wx.removeStorageSync("TempCardNoSaved");
  770. }, 1000);
  771. }
  772. }
  773. });
  774. } else {
  775. goto();
  776. }
  777. function goto() {
  778. wx.showLoading({
  779. title: '请稍候',
  780. });
  781. setTimeout(function () {
  782. wx.hideLoading();
  783. }, 5000);
  784. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
  785. main.getData(url, function (data) {
  786. wx.hideLoading();
  787. if (data) {
  788. app.globalData.CardList = data.List;
  789. that.setData({
  790. UpdateType: "add",
  791. });
  792. wx.navigateTo({
  793. url: './mainlist?type=3&Count=' + data.Count,
  794. })
  795. }
  796. });
  797. }
  798. },
  799. //段落编辑**************************
  800. //字段输入
  801. bindinputField: function (e) {
  802. //console.log("bindinputField:" + e.detail.value + " isEdit:" + isEdit);
  803. var that = this;
  804. if (app.globalData.IsAndroid && !isEdit) {
  805. return;
  806. }
  807. this.setData({
  808. FieldContent: e.detail.value,
  809. });
  810. },
  811. //加符号
  812. addSymbol: function (e) {
  813. //console.log("addSymbol");
  814. isEdit = true;
  815. var that = this;
  816. btnName = e.currentTarget.dataset.id;
  817. if (btnName == "[读]") {
  818. this.setData({
  819. SoundSign: "[/读]",
  820. });
  821. } else if (btnName == "[/读]") {
  822. this.setData({
  823. SoundSign: "[读]",
  824. });
  825. } else if (btnName == "[线]") {
  826. this.setData({
  827. LineSign: "[/线]",
  828. });
  829. } else if (btnName == "[/线]") {
  830. this.setData({
  831. LineSign: "[线]",
  832. });
  833. } else if (btnName == "[光]") {
  834. this.setData({
  835. HighlighterSign: "[/光]",
  836. });
  837. } else if (btnName == "[/光]") {
  838. this.setData({
  839. HighlighterSign: "[光]",
  840. });
  841. }
  842. if (btnName == "( )")
  843. btnName = "( )";
  844. else if (btnName == "_")
  845. btnName = "_____";
  846. //console.log("addSymbol_btnName:" + btnName);
  847. if (!this.data.Focus) {
  848. var obj = {
  849. detail: {
  850. cursor: tempCursor
  851. }
  852. };
  853. this.onBindblur(obj);
  854. }
  855. //console.log("addSymbol:" + this.data.FieldContent);
  856. setTimeout(function () {
  857. that.setData({
  858. Focus: true,
  859. });
  860. }, 300);
  861. },
  862. //焦点聚焦
  863. onBindFocus: function () {
  864. //console.log("onBindFocus");
  865. btnName = "";
  866. this.setData({
  867. Focus: true,
  868. });
  869. },
  870. //失焦
  871. onBindblur: function (e) {
  872. var that = this;
  873. //console.log("onBindblur:" + isEdit + " Filed:" + this.data.FieldContent);
  874. if (app.globalData.IsAndroid && !isEdit) {
  875. setTimeout(function () {
  876. isEdit = true;
  877. //console.log("onBindblur2:" + isEdit);
  878. }, 500);
  879. return;
  880. }
  881. isEdit = false;
  882. if (app.globalData.IsAndroid && !isEdit) {
  883. setTimeout(function () {
  884. isEdit = true;
  885. //console.log("onBindblur2:" + isEdit);
  886. }, 500);
  887. }
  888. //console.log("onBindblur:"+isEdit);
  889. this.updateField();
  890. tempCursor = e.detail.cursor;
  891. //console.log("tempCursor:" + tempCursor);
  892. if (tempCursor == undefined)
  893. tempCursor = this.data["FieldContent"].length;
  894. var str1 = "",
  895. str2 = "";
  896. if (this.data.FieldContent.length > 0) {
  897. str1 = this.data.FieldContent.substr(0, tempCursor);
  898. str2 = this.data.FieldContent.substring(tempCursor, this.data.FieldContent.length);
  899. }
  900. //console.log("str1:" + str1);
  901. //console.log("btnName:" + btnName);
  902. //console.log("str2:" + str2);
  903. var cur = 0;
  904. if (btnName) {
  905. cur = 1;
  906. if (btnName == "[读]" || btnName == "[线]" || btnName == "[光]") {
  907. cur = 3;
  908. } else if (btnName == "[/读]" || btnName == "[/线]" || btnName == "[/光]") {
  909. cur = 4;
  910. } else if (btnName === "( )") {
  911. cur = 7;
  912. } else if (btnName === "_____") {
  913. cur = 5;
  914. }
  915. }
  916. this.data.FieldContent = str1 + btnName + str2;
  917. this.setData({
  918. FieldContent: this.data.FieldContent,
  919. Focus: false,
  920. Cursor: tempCursor + cur,
  921. });
  922. btnName = "";
  923. },
  924. bindscrollHandler: function () {
  925. //console.log("bindscrollHandler");
  926. btnName = "";
  927. },
  928. onSearchField: function (e) {
  929. app.globalData.TempFieldNumber = this.data.FieldNumber;
  930. wx.navigateTo({
  931. url: './addInfomation',
  932. });
  933. this.updateField();
  934. setTimeout(function () {
  935. isEdit = true;
  936. //console.log("onSearchEnd");
  937. }, 1000);
  938. },
  939. clear: function () {
  940. var that = this;
  941. //console.log("clear");
  942. this.setData({
  943. FieldContent: "",
  944. Focus: true,
  945. Cursor: 0,
  946. });
  947. btnName = "";
  948. isEdit = false;
  949. this.updateField();
  950. },
  951. closeAddItem: function (e) {
  952. var that = this;
  953. var isSave = e.currentTarget.dataset.idsave;
  954. if (isSave == "true") {
  955. isUnload = false;
  956. if (that.data.FieldContent) {
  957. var content = that.data.FieldContent;
  958. main.postData("MsgSecCheck2", {
  959. Content: content,
  960. UserID:app.globalData.userInfo.UserID,
  961. },
  962. function (data) {
  963. if (data && data.errcode == 0) {
  964. next(that);
  965. } else {
  966. if (data.errmsg) {
  967. wx.showToast({
  968. title: data.errmsg,
  969. duration: 2000,
  970. image: "../images/universalpic_wrong_white_120x120.png",
  971. });
  972. isViolate = true;
  973. }
  974. }
  975. });
  976. } else {
  977. next(that);
  978. }
  979. } else if (isSave == "false") {
  980. var content = wx.getStorageSync("TempCardInfoAddItem");
  981. this.setData({
  982. FieldContent: content,
  983. });
  984. next(that);
  985. }
  986. function next(obj) {
  987. isViolate = false;
  988. obj.updateField();
  989. obj.setData({
  990. HiddenFieldEdit: true,
  991. });
  992. var title = "编辑题卡";
  993. if (obj.data.UpdateType == "add2") {
  994. title = "新建题卡";
  995. }
  996. that.setData({
  997. PageTitle: title,
  998. });
  999. that.setBtnSaveCss();
  1000. }
  1001. },
  1002. setBtnSaveCss: function () {
  1003. var that = this;
  1004. if (that.data.Field && that.data.Field[1] && that.data.Field[1] != "") {
  1005. that.setData({
  1006. BtnSaveSelectCss: "MenuBtnSelect",
  1007. });
  1008. } else {
  1009. that.setData({
  1010. BtnSaveSelectCss: "",
  1011. });
  1012. }
  1013. },
  1014. updateField: function () {
  1015. var str = this.data.FieldContent;
  1016. var list = app.globalData.CardList;
  1017. var card = {};
  1018. for (var i = 0; i < list.length; i++) {
  1019. if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  1020. list[i].Content[this.data.FieldNumber].Content = str;
  1021. card = main.changeStringToView(list[i].Content);
  1022. break;
  1023. }
  1024. }
  1025. app.globalData.CardList = list;
  1026. this.setData({
  1027. Field: card.Field,
  1028. Tags: card.Tags,
  1029. });
  1030. },
  1031. //选择图片上传
  1032. uploadImageField: function () {
  1033. //console.log("uploadImageStart");
  1034. var that = this;
  1035. //若是安卓机
  1036. if (app.globalData.IsAndroid) {
  1037. selectImage(that);
  1038. } else {
  1039. wx.showActionSheet({
  1040. itemList: ['拍照', '从手机相册选择'],
  1041. success(res) {
  1042. if (res.tapIndex == 0) {
  1043. wx.chooseImage({
  1044. count: 1,
  1045. sizeType: ['compressed'],
  1046. sourceType: ['camera'],
  1047. success(res2) {
  1048. wx.showLoading({
  1049. title: '请稍候',
  1050. mask: true,
  1051. });
  1052. setTimeout(function () {
  1053. wx.hideLoading();
  1054. selectImage(that);
  1055. }, 2000);
  1056. },
  1057. });
  1058. } else if (res.tapIndex == 1) {
  1059. selectImage(that);
  1060. }
  1061. },
  1062. fail(res) {
  1063. console.log(res.errMsg)
  1064. }
  1065. });
  1066. }
  1067. function selectImage(that) {
  1068. var sizeType = ['album'];
  1069. //若是安卓机
  1070. if (app.globalData.IsAndroid)
  1071. sizeType = ['album', 'camera'];
  1072. wx.chooseImage({
  1073. count: 1,
  1074. sizeType: ['compressed'],
  1075. sourceType: sizeType,
  1076. success(res) {
  1077. // tempFilePath可以作为img标签的src属性显示图片
  1078. const tempFilePaths = res.tempFilePaths;
  1079. //console.log(tempFilePaths[0]);
  1080. //that.data.FieldContent = that.data.FieldContent + "[图 url='" + tempFilePaths[0] + "']" + tempFilePaths[0] + "[/图]";
  1081. wx.getImageInfo({
  1082. src: res.tempFilePaths[0],
  1083. success(res) {
  1084. //console.log(res.width)
  1085. //console.log(res.height)
  1086. if (tempCursor == undefined)
  1087. tempCursor = that.data.FieldContent.length;
  1088. var str1 = "",
  1089. str2 = "";
  1090. if (that.data.FieldContent.length > 0) {
  1091. str1 = that.data.FieldContent.substr(0, tempCursor);
  1092. str2 = that.data.FieldContent.substring(tempCursor, that.data.FieldContent.length);
  1093. }
  1094. var width = res.width;
  1095. if (isNaN(width))
  1096. width = 650;
  1097. var height = res.height;
  1098. if (isNaN(height))
  1099. height = 650;
  1100. var str0 = "[图 w='" + width + "' h='" + height + "']" + tempFilePaths[0] + "[/图]";
  1101. that.data.FieldContent = str1 + str0 + str2;
  1102. tempCursor = that.data.FieldContent.length;
  1103. //console.log("uploadImageEnd:" + that.data.FieldContent);
  1104. that.setData({
  1105. FieldContent: that.data.FieldContent,
  1106. Focus: false,
  1107. });
  1108. that.updateField();
  1109. if (!wx.getStorageSync("NoRemindImage")) {
  1110. wx.showModal({
  1111. title: '提醒',
  1112. showCancel: true,
  1113. content: "“图片记号”以符号[图]开始…以符号[/图]结尾。如要剪切请确保完整性。",
  1114. confirmText: "好的",
  1115. cancelText: "不再提醒",
  1116. success(res) {
  1117. if (res.confirm) {} else {
  1118. wx.setStorageSync("NoRemindImage", true);
  1119. }
  1120. },
  1121. });
  1122. }
  1123. }
  1124. });
  1125. },
  1126. fail: function () {
  1127. }
  1128. });
  1129. }
  1130. },
  1131. showPracticeTime: function () {
  1132. if (this.data.MiaoguoCardID) {
  1133. wx.navigateTo({
  1134. url: './previewMenu?IsSave=0&ID=' + this.data.MiaoguoCardID + '&CardType=' + this.data.CardType + "&LimitTime=" + this.data.LimitTime,
  1135. });
  1136. } else {
  1137. var limitTime = common.formatTime(new Date(), "-", true);
  1138. if (this.data.LimitTime)
  1139. limitTime = this.data.LimitTime;
  1140. var cardType = 0;
  1141. if (this.data.CardType)
  1142. cardType = this.data.CardType;
  1143. wx.navigateTo({
  1144. url: './previewMenu?IsSave=0&ID=0&CardType=' + cardType + '&LimitTime=' + limitTime,
  1145. });
  1146. }
  1147. },
  1148. //录音授权
  1149. recorderAccredit: function () {
  1150. var that = this;
  1151. if (app.globalData.IsRecorderAccredit == 1)
  1152. that.showRecorder();
  1153. else if (app.globalData.IsRecorderAccredit == 0) {
  1154. recorderManager.stop();
  1155. app.globalData.IsRecorderAccredit = 1;
  1156. that.showRecorder();
  1157. } else if (app.globalData.IsRecorderAccredit == -1) {
  1158. wx.getSetting({
  1159. success(res) {
  1160. if (res.authSetting['scope.record'] === true) {
  1161. app.globalData.IsRecorderAccredit = 1;
  1162. that.showRecorder();
  1163. } else if (res.authSetting['scope.record'] === false) {
  1164. wx.navigateTo({
  1165. url: '../other/openSetting',
  1166. });
  1167. }
  1168. }
  1169. });
  1170. }
  1171. },
  1172. showRecorder: function () {
  1173. var that = this;
  1174. if (that.checkRecorderCount()) {
  1175. that.recorderInit();
  1176. tempRecorderFile = "";
  1177. that.setData({
  1178. PageTitle: '录音',
  1179. });
  1180. that.setData({
  1181. IsRecorder: true,
  1182. IsRecorderFinished: false,
  1183. BtnRecorderName: "按住录音1分钟",
  1184. RecorderTime: "00:00",
  1185. RecorderTimeCss: "",
  1186. RecorderPlayName: "播放",
  1187. });
  1188. innerAudioContext = wx.createInnerAudioContext();
  1189. innerAudioContext.onPlay(() => {
  1190. console.log('开始播放');
  1191. that.setData({
  1192. RecorderTimeCss: "RecorderPanel1121",
  1193. RecorderTime: "00:00",
  1194. RecorderPlayName: "停止",
  1195. });
  1196. });
  1197. innerAudioContext.onEnded(() => {
  1198. console.log('结束播放');
  1199. clearInterval(intervalRecorder);
  1200. that.setData({
  1201. RecorderTime: "00:00",
  1202. RecorderTimeCss: "",
  1203. RecorderPlayName: "播放",
  1204. });
  1205. });
  1206. }
  1207. },
  1208. closeRecorder: function () {
  1209. var that = this;
  1210. this.recorderInit();
  1211. if (tempRecorderFile) {
  1212. wx.showModal({
  1213. title: '提醒',
  1214. content: '这段录音还没有上传,要放弃录音吗?',
  1215. showCancel: true,
  1216. confirmText: "取消",
  1217. cancelText: "不上传",
  1218. success(res) {
  1219. if (res.cancel) {
  1220. closeRecorder2();
  1221. }
  1222. },
  1223. })
  1224. } else {
  1225. closeRecorder2();
  1226. }
  1227. function closeRecorder2() {
  1228. that.setData({
  1229. PageTitle: '编辑 段落' + that.data.FieldNumber,
  1230. });
  1231. that.setData({
  1232. IsRecorder: false,
  1233. IsRecorderFinished: false,
  1234. });
  1235. tempRecorderFile = "";
  1236. }
  1237. },
  1238. //录音初始化
  1239. recorderInit: function () {
  1240. if (innerAudioContext)
  1241. innerAudioContext.stop();
  1242. if (recorderManager)
  1243. recorderManager.stop();
  1244. clearInterval(intervalRecorder);
  1245. },
  1246. checkRecorderCount: function (arr) {
  1247. var that = this;
  1248. var count = 0;
  1249. if (that.data.FieldContent.indexOf("[音 url=") >= 0 ||
  1250. that.data.FieldContent.indexOf("[/音]") >= 0) {
  1251. count = 1;
  1252. }
  1253. if (count > 0) {
  1254. wx.showToast({
  1255. title: '仅能上传一段',
  1256. image: "../images/universalpic_exclamation_white_120x120.png",
  1257. });
  1258. return false;
  1259. } else
  1260. return true;
  1261. },
  1262. btnRecorderStart: function () {
  1263. var that = this;
  1264. if (app.globalData.IsRecorderAccredit == 1) {
  1265. that.setData({
  1266. BtnRecorderName: "松手结束",
  1267. RecorderTimeCss: "RecorderPanel1121",
  1268. });
  1269. that.showRecorderTime();
  1270. recorderManager.start();
  1271. }
  1272. },
  1273. btnRecorderEnd: function () {
  1274. var that = this;
  1275. if (app.globalData.IsRecorderAccredit == 1) {
  1276. if (that.data.RecorderTime == "00:00") {
  1277. //小于1秒处理
  1278. wx.showToast({
  1279. title: '时间过短',
  1280. image: "../images/universalpic_exclamation_white_120x120.png",
  1281. });
  1282. that.showRecorder();
  1283. } else {
  1284. that.setData({
  1285. IsRecorderFinished: true,
  1286. RecorderTimeCss: "",
  1287. });
  1288. that.recorderInit();
  1289. }
  1290. } else {
  1291. that.recorderAccredit();
  1292. }
  1293. },
  1294. showRecorderTime: function () {
  1295. var that = this;
  1296. var second = 0;
  1297. clearInterval(intervalRecorder);
  1298. intervalRecorder = setInterval(function () {
  1299. second++;
  1300. var secondStr = second.toString();
  1301. if (second < 10)
  1302. secondStr = "0" + secondStr;
  1303. that.setData({
  1304. RecorderTime: "00:" + secondStr,
  1305. });
  1306. if (second >= 59) {
  1307. that.setData({
  1308. IsRecorderFinished: true,
  1309. RecorderTimeCss: "",
  1310. });
  1311. that.recorderInit();
  1312. if (that.data.RecorderPlayName == "播放") {
  1313. wx.showToast({
  1314. title: '录音超时',
  1315. image: "../images/universalpic_exclamation_white_120x120.png",
  1316. });
  1317. }
  1318. }
  1319. }, 1000);
  1320. },
  1321. btnRecorderPlay: function () {
  1322. var that = this;
  1323. if (tempRecorderFile && this.data.RecorderPlayName == "播放") {
  1324. innerAudioContext.src = tempRecorderFile;
  1325. innerAudioContext.play();
  1326. this.showRecorderTime();
  1327. } else if (this.data.RecorderPlayName == "停止") {
  1328. if (innerAudioContext)
  1329. innerAudioContext.stop();
  1330. clearInterval(intervalRecorder);
  1331. that.setData({
  1332. RecorderTime: "00:00",
  1333. RecorderTimeCss: "",
  1334. RecorderPlayName: "播放",
  1335. });
  1336. }
  1337. },
  1338. btnRecorderSave: function () {
  1339. var that = this;
  1340. if (tempRecorderFile) {
  1341. this.recorderInit();
  1342. wx.showLoading({
  1343. title: '正在上传',
  1344. });
  1345. setTimeout(function () {
  1346. wx.hideLoading();
  1347. }, 60000);
  1348. that.uploadFileToServer(tempRecorderFile, function (data) {
  1349. if (data) {
  1350. wx.hideLoading();
  1351. var result = data;
  1352. result.Target = app.globalData.uploadImageUrl + result.Target;
  1353. that.data.FieldContent = that.data.FieldContent + "[音 url='" + result.Target + "'][/音]";
  1354. that.data.FieldContent = main.encryptUrl(that.data.FieldContent);
  1355. that.setData({
  1356. FieldContent: that.data.FieldContent,
  1357. });
  1358. tempRecorderFile = "";
  1359. that.closeRecorder();
  1360. if (!wx.getStorageSync("NoRemindRecorder")) {
  1361. wx.showModal({
  1362. title: '提醒',
  1363. showCancel: true,
  1364. content: "“录音记号”以符号[录]开始…以符号[/录]结尾。如要剪切请确保完整性。",
  1365. confirmText: "好的",
  1366. cancelText: "不再提醒",
  1367. success(res) {
  1368. if (res.confirm) {} else {
  1369. wx.setStorageSync("NoRemindRecorder", true);
  1370. }
  1371. },
  1372. });
  1373. }
  1374. }
  1375. });
  1376. } else {
  1377. wx.showToast({
  1378. title: '没有录音',
  1379. image: "../images/universalpic_exclamation_white_120x120.png",
  1380. });
  1381. }
  1382. },
  1383. goto: function (e) {
  1384. var url = e.currentTarget.dataset.url;
  1385. wx.navigateTo({
  1386. url: url,
  1387. });
  1388. if (url == "./folderEdit?type=add") {
  1389. isAddFolder = true;
  1390. }
  1391. },
  1392. showTagShow: function () {
  1393. var tagTemp = this.data.Tags.join(",");
  1394. this.setData({
  1395. IsTagShow: true,
  1396. TagTemp: tagTemp.split(","),
  1397. TagIndex: -1,
  1398. });
  1399. this.setData({
  1400. PageTitle: '自动记号',
  1401. });
  1402. },
  1403. closeTagShow: function () {
  1404. this.setData({
  1405. IsTagShow: false,
  1406. });
  1407. this.setData({
  1408. PageTitle: '编辑题卡',
  1409. });
  1410. },
  1411. setCardTypeInit: function () {
  1412. this.setData({
  1413. CardType: 0,
  1414. PracticeCardType: constant1.arrStudyPattern[0] + "题卡",
  1415. PracticeTimeStr: "",
  1416. LimitTime: common.formatTime(new Date(), "-", true),
  1417. });
  1418. wx.showToast({
  1419. title: '已恢复默认',
  1420. image: "../images/universalpic_restore_white_120x120.png",
  1421. });
  1422. },
  1423. gotoAddInfomationDetail: function (param) {
  1424. main.searchInfomation(param.Word, param.SearchType, param.Author, app.globalData.TempStr, function (list, obj) {
  1425. main.updateSearchList(obj, function () {
  1426. app.globalData.TempSearchBackNumber = 0;
  1427. wx.navigateTo({
  1428. url: './addInfomationDetail',
  1429. });
  1430. });
  1431. });
  1432. },
  1433. showPanel: function (e) {
  1434. var that = this;
  1435. that.hiddenPanel(true);
  1436. switch (e.currentTarget.dataset.type) {
  1437. case "help":
  1438. that.setData({
  1439. IsHelp: true,
  1440. });
  1441. break;
  1442. case "menu":
  1443. that.setData({
  1444. IsShowMenu: true,
  1445. IsShowAddHelp: 1,
  1446. });
  1447. wx.setStorageSync("IsShowAddHelp", that.data.IsShowAddHelp);
  1448. break;
  1449. case "folder":
  1450. that.setData({
  1451. IsFolder: true,
  1452. });
  1453. that.getFolderList();
  1454. break;
  1455. case "limittime":
  1456. var arrLimitTime = constant1.arrLimitTime;
  1457. for (var i = 0; i < arrLimitTime.length; i++) {
  1458. arrLimitTime[i].Selected = "";
  1459. }
  1460. //arrLimitTime[0].Selected="MenuBtnSelect";
  1461. that.setData({
  1462. Today: common.formatTime(new Date()),
  1463. IsLimitTime: true,
  1464. LimitTimeTemp: that.data.LimitTime,
  1465. PracticeTimeStrTemp: common.formatDateCHS(that.data.LimitTime),
  1466. LimitTimeArr: arrLimitTime,
  1467. });
  1468. break;
  1469. case "fontsize":
  1470. if (!that.data.FontSize)
  1471. that.data.FontSize = 48;
  1472. var fontSize = constant1.arrFontSize;
  1473. var fontSizeName = "";
  1474. for (var i = 0; i < fontSize.length; i++) {
  1475. fontSize[i].Selected = "";
  1476. if (fontSize[i].Value == that.data.FontSize) {
  1477. fontSize[i].Selected = "MenuBtnSelect";
  1478. fontSizeName = fontSize[i].Name;
  1479. }
  1480. }
  1481. that.setData({
  1482. IsFontsize: true,
  1483. FontSizeArr: fontSize,
  1484. FontSizeTemp: that.data.FontSize,
  1485. FontSizeName: fontSizeName,
  1486. });
  1487. break;
  1488. case "cardtype":
  1489. var obj = {};
  1490. if (!that.data.CardType)
  1491. that.data.CardType = 0;
  1492. if (that.data.CardType == 0) {
  1493. obj.NormalCss = "MenuBtnSelect";
  1494. obj.UrgentCss = "";
  1495. } else if (that.data.CardType == 1) {
  1496. obj.NormalCss = "";
  1497. obj.UrgentCss = "MenuBtnSelect";
  1498. } else if (that.data.CardType == -1) {
  1499. obj.NormalCss = "MenuBtnDisabled";
  1500. obj.UrgentCss = "MenuBtnDisabled";
  1501. }
  1502. that.setData({
  1503. IsCardType: true,
  1504. CardTypeCss: obj,
  1505. CardTypeTemp: that.data.CardType,
  1506. CardNumberUrgent: app.globalData.TaskToday.CardNumberUrgent,
  1507. });
  1508. break;
  1509. }
  1510. },
  1511. hiddenPanel: function (e) {
  1512. var that = this;
  1513. that.setData({
  1514. IsShowMenu: false,
  1515. IsHelp: false,
  1516. IsFontsize: false,
  1517. IsFolder: false,
  1518. IsLimitTime: false,
  1519. IsCardType: false,
  1520. });
  1521. if (that.data.IsFolder) {
  1522. for (var i = 0; i < that.data.FolderArr.length; i++) {
  1523. that.data.FolderArr[i].Selected = "";
  1524. }
  1525. that.setData({
  1526. FolderArr: that.data.FolderArr,
  1527. });
  1528. }
  1529. },
  1530. setFontSize: function (e) {
  1531. var that = this;
  1532. var fontSize = constant1.arrFontSize;
  1533. var fontSizeName;
  1534. for (var i = 0; i < fontSize.length; i++) {
  1535. fontSize[i].Selected = "";
  1536. if (fontSize[i].Value == e.currentTarget.dataset.fontsize) {
  1537. fontSize[i].Selected = "MenuBtnSelect";
  1538. fontSizeName = fontSize[i].Name;
  1539. }
  1540. }
  1541. that.setData({
  1542. FontSizeTemp: e.currentTarget.dataset.fontsize,
  1543. FontSizeArr: fontSize,
  1544. FontSizeNameTemp: fontSizeName,
  1545. });
  1546. },
  1547. saveFontSize: function () {
  1548. var fontSizeName;
  1549. var fontSize = constant1.arrFontSize;
  1550. for (var i = 0; i < fontSize.length; i++) {
  1551. if (fontSize[i].Value == this.data.FontSizeTemp) {
  1552. fontSizeName = fontSize[i].Name;
  1553. }
  1554. }
  1555. this.setData({
  1556. FontSize: this.data.FontSizeTemp,
  1557. FontSizeName: fontSizeName,
  1558. });
  1559. this.hiddenPanel();
  1560. },
  1561. getFolderList: function (e) {
  1562. var that = this;
  1563. if (app.globalData.FolderList.length == 0) {
  1564. var url = "GetUserFolderList?UserID=" + app.globalData.userInfo.UserID;
  1565. main.getData(url, function (data) {
  1566. if (data) {
  1567. if (isAddFolder) {
  1568. that.setData({
  1569. FolderID: data[0].ID,
  1570. });
  1571. isAddFolder = false;
  1572. }
  1573. update(data);
  1574. }
  1575. });
  1576. } else {
  1577. update(app.globalData.FolderList);
  1578. }
  1579. function update(arr) {
  1580. for (var i = 0; i < arr.length; i++) {
  1581. arr[i].Selected = "";
  1582. if (that.data.FolderID) {
  1583. if (arr[i].ID == that.data.FolderID) {
  1584. arr[i].Selected = "MenuBtnSelect";
  1585. }
  1586. }
  1587. }
  1588. that.setData({
  1589. FolderArr: arr,
  1590. });
  1591. app.globalData.FolderList = arr;
  1592. }
  1593. },
  1594. selectFolder: function (e) {
  1595. var that = this;
  1596. var id = e.currentTarget.dataset.id;
  1597. for (var i = 0; i < that.data.FolderArr.length; i++) {
  1598. if (id == that.data.FolderArr[i].ID)
  1599. that.data.FolderArr[i].Selected = "MenuBtnSelect";
  1600. else
  1601. that.data.FolderArr[i].Selected = "";
  1602. }
  1603. var nullFolder = "";
  1604. if (id == 0) {
  1605. nullFolder = "MenuBtnSelect";
  1606. }
  1607. that.setData({
  1608. FolderArr: that.data.FolderArr,
  1609. NullFolder: nullFolder,
  1610. });
  1611. },
  1612. setFolder: function () {
  1613. var that = this;
  1614. var id = 0;
  1615. var FolderName = "";
  1616. for (var i = 0; i < that.data.FolderArr.length; i++) {
  1617. if (that.data.FolderArr[i].Selected == "MenuBtnSelect") {
  1618. id = that.data.FolderArr[i].ID;
  1619. FolderName = that.data.FolderArr[i].Name;
  1620. }
  1621. }
  1622. that.setData({
  1623. FolderID: id,
  1624. FolderName: FolderName,
  1625. });
  1626. that.hiddenPanel();
  1627. },
  1628. selectLimitTime: function (e) {
  1629. var that = this;
  1630. var limitTime = "";
  1631. var daynumber = e.currentTarget.dataset.daynumber;
  1632. for (var i = 0; i < that.data.LimitTimeArr.length; i++) {
  1633. if (daynumber == that.data.LimitTimeArr[i].DayNumber) {
  1634. that.data.LimitTimeArr[i].Selected = "MenuBtnSelect";
  1635. limitTime = common.formatTime(common.addDate("d", daynumber, new Date()), "-", true);
  1636. } else
  1637. that.data.LimitTimeArr[i].Selected = "";
  1638. }
  1639. that.setData({
  1640. LimitTimeTemp: limitTime,
  1641. PracticeTimeStrTemp: common.formatDateCHS(limitTime),
  1642. LimitTimeArr: that.data.LimitTimeArr,
  1643. });
  1644. },
  1645. selectLimitTime2: function (e) {
  1646. var that = this;
  1647. var limitTime = e.detail.value;
  1648. var today = common.formatTime(new Date(), "-", true);
  1649. console.log(today);
  1650. if (limitTime < today) {
  1651. wx.showModal({
  1652. title: '提醒',
  1653. content: '指定日期只能是今天或未来某日,您可重新选择。',
  1654. confirmText: "知道了",
  1655. showCancel: false,
  1656. });
  1657. } else {
  1658. for (var i = 0; i < that.data.LimitTimeArr.length; i++) {
  1659. that.data.LimitTimeArr[i].Selected = "";
  1660. }
  1661. that.setData({
  1662. LimitTimeTemp: limitTime,
  1663. PracticeTimeStrTemp: common.formatDateCHS(limitTime),
  1664. LimitTimeArr: that.data.LimitTimeArr,
  1665. });
  1666. }
  1667. },
  1668. setLimitTime: function (e) {
  1669. var that = this;
  1670. that.setData({
  1671. LimitTime: that.data.LimitTimeTemp,
  1672. PracticeTimeStr: common.formatDateCHS(that.data.LimitTimeTemp),
  1673. });
  1674. that.hiddenPanel();
  1675. },
  1676. setCollect: function () {
  1677. var that = this;
  1678. var IsCollectStr = "";
  1679. if (that.data.IsCollect == 1) {
  1680. that.data.IsCollect = 0;
  1681. } else {
  1682. that.data.IsCollect = 1;
  1683. }
  1684. that.setData({
  1685. IsCollect: that.data.IsCollect,
  1686. });
  1687. that.hiddenPanel();
  1688. },
  1689. setLimitTime: function (e) {
  1690. var that = this;
  1691. that.setData({
  1692. LimitTime: that.data.LimitTimeTemp,
  1693. PracticeTimeStr: common.formatDateCHS(that.data.LimitTimeTemp),
  1694. });
  1695. that.hiddenPanel();
  1696. },
  1697. selectCardType: function (e) {
  1698. var that = this;
  1699. var cardtype = 0;
  1700. if (!e.currentTarget.dataset.disabled) {
  1701. if (e.currentTarget.dataset.cardtype) {
  1702. cardtype = e.currentTarget.dataset.cardtype;
  1703. }
  1704. if (e.detail.value === true)
  1705. cardtype = -1;
  1706. else if (e.detail.value === false)
  1707. cardtype = 0;
  1708. var obj = {};
  1709. if (cardtype == 0) {
  1710. obj.NormalCss = "MenuBtnSelect";
  1711. }
  1712. if (cardtype == 1) {
  1713. obj.UrgentCss = "MenuBtnSelect";
  1714. }
  1715. if (cardtype == -1) {
  1716. obj.NormalCss = "MenuBtnDisabled";
  1717. obj.UrgentCss = "MenuBtnDisabled";
  1718. }
  1719. if (that.data.CardType == 1 && (cardtype == 0 || cardtype == -1))
  1720. app.globalData.TaskToday.CardNumberUrgent--;
  1721. if (app.globalData.TaskToday.CardNumberUrgent + 1 > 200) {
  1722. obj.UrgentCss = "MenuBtnDisabled";
  1723. }
  1724. that.setData({
  1725. CardTypeTemp: cardtype,
  1726. CardTypeCss: obj,
  1727. });
  1728. }
  1729. },
  1730. setCardType: function (e) {
  1731. var that = this;
  1732. if (that.data.CardTypeTemp == 1 || that.data.CardType == -1) {
  1733. var limittime = common.formatTime(new Date(), "-", true);
  1734. that.setData({
  1735. LimitTime: limittime,
  1736. PracticeTimeStr: common.formatDateCHS(limittime),
  1737. });
  1738. }
  1739. that.setData({
  1740. CardType: Number(that.data.CardTypeTemp),
  1741. PracticeCardType: constant1.arrStudyPattern[that.data.CardTypeTemp] + "题卡",
  1742. });
  1743. that.hiddenPanel();
  1744. },
  1745. deleteCard: function () {
  1746. app.globalData.TempStr = "deleteCard";
  1747. this.onClose();
  1748. },
  1749. onShareAppMessage: function () {
  1750. return {
  1751. title: app.globalData.ShareTitle,
  1752. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  1753. imageUrl: app.globalData.ShareImage,
  1754. }
  1755. },
  1756. })