add.js 54 KB

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