add.js 51 KB

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