add.js 51 KB

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