add.js 51 KB

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