add.js 53 KB

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