add.js 50 KB

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