add.js 54 KB

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