add.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938
  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. wx.showToast({
  484. title: '图片上传失败1',
  485. image: "../images/universalpic_exclamation_white_120x120.png",
  486. mask: true,
  487. });
  488. }
  489. });
  490. }
  491. } else {
  492. wx.showToast({
  493. title: '点击太频繁',
  494. image: "../images/universalpic_exclamation_white_120x120.png",
  495. mask: true,
  496. });
  497. }
  498. }
  499. function changePattern(obj) {
  500. if (obj.data.CardType == 1) {
  501. var cardType = wx.getStorageSync('CardType');
  502. if (cardType == 0 && app.globalData.TaskToday.CardNumberUrgent == 1) {
  503. wx.navigateTo({
  504. url: "../other/menu?Type=0",
  505. });
  506. }
  507. }
  508. }
  509. },
  510. formatField: function (field) {
  511. var result = {};
  512. for (var i = 1; i <= 3; i++) {
  513. result["Field" + i] = "";
  514. if (field.length > 0 && field[i]) {
  515. for (var key in field[i]) {
  516. var item = field[i][key];
  517. var str = "";
  518. if (item.Type == "image") {
  519. str = "[图 w='" + item.Width + "' h='" + item.Height + "']" + item.Content + "[/图]";
  520. } else if (item.Type == "line") {
  521. for (var j = 0; j < item.Content.length; j++) {
  522. if (item.Content[j].key == "normal")
  523. str += item.Content[j].value;
  524. if (item.Content[j].key == "line") {
  525. str += "[线]" + item.Content[j].value + "[/线]";
  526. }
  527. if (item.Content[j].key == "highlighter") {
  528. str += "[光]" + item.Content[j].value + "[/光]";
  529. }
  530. }
  531. } else if (item.Type == "sound") {
  532. if (item.SoundMark)
  533. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  534. else
  535. str = "[读]" + item.Content + "[/读]";
  536. } else if (item.Type == "bigword") {
  537. str = "[特 FS=\""+item.FontSize+"\"]"+item.Content+"[/特]";
  538. } else if (item.Type == "latex") {
  539. str = "[公式";
  540. if (item.LatexName)
  541. str+=" N=\""+item.LatexName+"\" ";
  542. if (item.FontSize)
  543. str+=" FS=\""+item.FontSize+"\" ";
  544. str += "]"+item.Content+"[/公式]";
  545. str = str.replace("$$", "");
  546. str = str.replace("$$", "");
  547. } else if (item.Type == "recorder") {
  548. if (item.SoundMark)
  549. str = "[音 url='" + item.SoundMark + "'][/音]";
  550. } else if (item.Type == "normal") {
  551. str = item.Content;
  552. } else if (item.Type == "return") {
  553. str = "\n";
  554. }
  555. result["Field" + i] += str;
  556. }
  557. }
  558. result["Field" + i] = main.changeViewToString(result["Field" + i]);
  559. }
  560. return result;
  561. },
  562. checkImageCount: function (arr) {
  563. var count = 0;
  564. for (var i = 0; i < arr.length; i++) {
  565. for (var j = 0; j < arr[i].length; j++) {
  566. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  567. count++;
  568. }
  569. }
  570. }
  571. if (count > 4) {
  572. wx.showToast({
  573. title: '只能上传四张图片',
  574. image: "../images/universalpic_exclamation_white_120x120.png",
  575. });
  576. return false;
  577. } else
  578. return true;
  579. },
  580. uploadImageAll: function (arr, callback) {
  581. var that = this;
  582. var b = false;
  583. var arrSource = [],
  584. arrResult = [];
  585. for (var i = 0; i < arr.length; i++) {
  586. for (var j = 0; j < arr[i].length; j++) {
  587. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  588. arrSource.push(arr[i][j].Content);
  589. if (arr[i][j].ContentServer.indexOf(app.globalData.uploadImageUrl) >= 0 ||
  590. arr[i][j].ContentServer.indexOf("baidu.com") >= 0 ||
  591. arr[i][j].ContentServer.indexOf("bcebos.com") >= 0) {
  592. var result = {};
  593. result.Source = arr[i][j].ContentServer;
  594. result.Target = arr[i][j].ContentServer;
  595. arrResult.push(result);
  596. } else {
  597. var source = arr[i][j].Content;
  598. that.uploadFileToServer(source, function (data) {
  599. if (data) {
  600. var result = data;
  601. result.Target = app.globalData.uploadImageUrl + result.Target;
  602. arrResult.push(result);
  603. }
  604. });
  605. }
  606. }
  607. }
  608. }
  609. //检查是否上传成功
  610. setTimeout(function () {
  611. console.log(arrResult.length);
  612. console.log(arrSource.length);
  613. if (arrResult.length >= arrSource.length) {
  614. //console.log("arrResult:" + JSON.stringify(arrResult));
  615. var success = true;
  616. var ari = 0;
  617. for (var i = 0; i < arr.length; i++) {
  618. for (var j = 0; j < arr[i].length; j++) {
  619. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  620. var tempUrl = arr[i][j].Content;
  621. var serverUrl = "";
  622. for (var k = 0; k < arrResult.length; k++) {
  623. if (tempUrl.indexOf(arrResult[k].Source) >= 0) {
  624. serverUrl = arrResult[k].Target;
  625. break;
  626. }
  627. }
  628. console.log("serverUrl:" + serverUrl);
  629. arr[i][j].Content = serverUrl;
  630. arr[i][j].ContentServer = serverUrl;
  631. if (serverUrl == "") {
  632. success = false;
  633. break;
  634. }
  635. }
  636. }
  637. }
  638. //console.log(JSON.stringify(arr));
  639. callback(success, arr);
  640. }
  641. }, 2000);
  642. },
  643. uploadFileToServer: function (file, callback) {
  644. var url = common.Encrypt("MiaoguoUploadFile2");
  645. wx.showLoading({
  646. title: '上传中',
  647. mask: true,
  648. });
  649. wx.uploadFile({
  650. url: app.globalData.serverUrl + url,
  651. filePath: file,
  652. name: 'file',
  653. success(res) {
  654. var err = JSON.parse(res.data);
  655. if (err.errcode == 10000) {
  656. wx.hideLoading();
  657. callback(err.result);
  658. // setTimeout(function () {
  659. // wx.downloadFile({
  660. // url: err.result.Target,
  661. // success(res) {
  662. // wx.hideLoading();
  663. // if (res.statusCode != 200) {
  664. // wx.showModal({
  665. // title: '上传图片可能失败',
  666. // showCancel: false,
  667. // confirmText: '知道了',
  668. // content: "请点左下角“复查”后编辑上一张题卡重新上传图片。"
  669. // });
  670. // } else {
  671. // console.log("上传成功");
  672. // }
  673. // }
  674. // });
  675. // }, 5000);
  676. } else {
  677. wx.hideLoading();
  678. wx.showModal({
  679. title: '上传文件失败',
  680. showCancel: false,
  681. content: JSON.stringify(err.errMsg),
  682. });
  683. }
  684. },
  685. fail: function (err) {
  686. wx.hideLoading();
  687. wx.showModal({
  688. title: '上传文件失败',
  689. showCancel: false,
  690. content: JSON.stringify(err),
  691. });
  692. }
  693. });
  694. },
  695. saveLocalCardList: function (param1) {
  696. var that = this;
  697. var list = app.globalData.CardList;
  698. for (var i = 0; i < list.length; i++) {
  699. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  700. for (var j = 0; j < 4; j++) {
  701. if (j == 0) {
  702. if (param1.tags && param1.tags.length > 0)
  703. list[i].Content[j].Content = param1.tags.join(",");
  704. } else
  705. list[i].Content[j].Content = param1["Field" + j];
  706. }
  707. if (param1.LimitTime)
  708. list[i].LimitTime = common.formatTime(param1.LimitTime);
  709. app.globalData.CardList = list;
  710. break;
  711. }
  712. }
  713. },
  714. initAddCard: function () {
  715. var card = {};
  716. card.MiaoguoCardID = 0;
  717. card.Content = [];
  718. for (var i = 0; i < 4; i++) {
  719. var obj = {};
  720. obj.ContentType = i;
  721. obj.Content = [];
  722. card.Content.push(obj);
  723. }
  724. app.globalData.CardList = [card];
  725. this.setData({
  726. MiaoguoCardID: 0,
  727. Field: [
  728. [],
  729. [],
  730. [],
  731. []
  732. ],
  733. Tags: [],
  734. UpdateType: "add2",
  735. BtnSaveSelectCss: "",
  736. });
  737. },
  738. onBindError: function (e) {
  739. for (var i = 1; i < this.data.Field.length; i++) {
  740. for (var j = 0; j < this.data.Field[i].length; j++) {
  741. if (this.data.Field[i][j].Type == "image") {
  742. this.data.Field[i][j].Url = this.data.Field[i][j].Content;
  743. }
  744. }
  745. }
  746. this.setData({
  747. Field: this.data.Field,
  748. });
  749. },
  750. deleteItem: function (e) {
  751. var that = this;
  752. var index = e.currentTarget.dataset.id;
  753. if (e.currentTarget.dataset.type == 1) {
  754. that.setData({
  755. TagIndex: index,
  756. });
  757. } else if (e.currentTarget.dataset.type == 2) {
  758. that.data.TagTemp.splice(index, 1);
  759. that.setData({
  760. TagTemp: that.data.TagTemp,
  761. TagIndex: -1,
  762. });
  763. } else if (e.currentTarget.dataset.type == 3) {
  764. that.setData({
  765. Tags: that.data.TagTemp,
  766. TagsStr: that.data.TagTemp.join("、"),
  767. TagIndex: -1,
  768. });
  769. var list = app.globalData.CardList;
  770. for (var i = 0; i < list.length; i++) {
  771. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  772. list[i].Content[0].Content = that.data.Tags;
  773. break;
  774. }
  775. }
  776. app.globalData.CardList = list;
  777. that.closeTagShow();
  778. }
  779. },
  780. onGotoList: function () {
  781. var that = this;
  782. if (isFirstAdd == true || !that.data.Field) {
  783. wx.showModal({
  784. title: '提醒',
  785. content: '本功能用于在连续新建题卡时一键复查「上一张题卡」。请在连续新建到第二张时再来试一试。',
  786. confirmText: '知道了',
  787. showCancel: false,
  788. });
  789. } else if (that.data.Field[1].length > 0 || that.data.Field[2].length > 0 || that.data.Field[2].length > 0) {
  790. wx.showModal({
  791. title: '提醒',
  792. content: '您所做的编辑还没有保存,要放弃保存吗?',
  793. confirmText: '取消',
  794. cancelText: "不保存",
  795. success(res) {
  796. if (!res.confirm) {
  797. goto();
  798. setTimeout(function () {
  799. wx.removeStorageSync("TempCardNoSaved");
  800. }, 1000);
  801. }
  802. }
  803. });
  804. } else {
  805. goto();
  806. }
  807. function goto() {
  808. wx.showLoading({
  809. title: '请稍候',
  810. });
  811. setTimeout(function () {
  812. wx.hideLoading();
  813. }, 5000);
  814. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
  815. main.getData(url, function (data) {
  816. wx.hideLoading();
  817. if (data) {
  818. app.globalData.CardList = data.List;
  819. that.setData({
  820. UpdateType: "add",
  821. });
  822. var url='./mainlist?type=3&Count=' + data.Count;
  823. wx.navigateTo({
  824. url: url,
  825. })
  826. }
  827. });
  828. }
  829. },
  830. //段落编辑**************************
  831. //字段输入
  832. bindinputField: function (e) {
  833. //console.log("bindinputField:" + e.detail.value + " isEdit:" + isEdit);
  834. var that = this;
  835. if (app.globalData.IsAndroid && !isEdit) {
  836. return;
  837. }
  838. this.setData({
  839. FieldContent: e.detail.value,
  840. });
  841. },
  842. //加符号
  843. addSymbol: function (e) {
  844. //console.log("addSymbol");
  845. isEdit = true;
  846. var that = this;
  847. btnName = e.currentTarget.dataset.id;
  848. if (btnName == "[读]") {
  849. this.setData({
  850. SoundSign: "[/读]",
  851. });
  852. } else if (btnName == "[/读]") {
  853. this.setData({
  854. SoundSign: "[读]",
  855. });
  856. } else if (btnName == "[线]") {
  857. this.setData({
  858. LineSign: "[/线]",
  859. });
  860. } else if (btnName == "[/线]") {
  861. this.setData({
  862. LineSign: "[线]",
  863. });
  864. } else if (btnName == "[光]") {
  865. this.setData({
  866. HighlighterSign: "[/光]",
  867. });
  868. } else if (btnName == "[/光]") {
  869. this.setData({
  870. HighlighterSign: "[光]",
  871. });
  872. }
  873. if (btnName == "( )")
  874. btnName = "( )";
  875. else if (btnName == "_")
  876. btnName = "_____";
  877. //console.log("addSymbol_btnName:" + btnName);
  878. if (!this.data.Focus) {
  879. var obj = {
  880. detail: {
  881. cursor: tempCursor
  882. }
  883. };
  884. this.onBindblur(obj);
  885. }
  886. //console.log("addSymbol:" + this.data.FieldContent);
  887. setTimeout(function () {
  888. that.setData({
  889. Focus: true,
  890. });
  891. }, 300);
  892. },
  893. //焦点聚焦
  894. onBindFocus: function () {
  895. //console.log("onBindFocus");
  896. btnName = "";
  897. this.setData({
  898. Focus: true,
  899. });
  900. },
  901. //失焦
  902. onBindblur: function (e) {
  903. var that = this;
  904. //console.log("onBindblur:" + isEdit + " Filed:" + this.data.FieldContent);
  905. if (app.globalData.IsAndroid && !isEdit) {
  906. setTimeout(function () {
  907. isEdit = true;
  908. //console.log("onBindblur2:" + isEdit);
  909. }, 500);
  910. return;
  911. }
  912. isEdit = false;
  913. if (app.globalData.IsAndroid && !isEdit) {
  914. setTimeout(function () {
  915. isEdit = true;
  916. //console.log("onBindblur2:" + isEdit);
  917. }, 500);
  918. }
  919. //console.log("onBindblur:"+isEdit);
  920. this.updateField();
  921. tempCursor = e.detail.cursor;
  922. //console.log("tempCursor:" + tempCursor);
  923. if (tempCursor == undefined)
  924. tempCursor = this.data["FieldContent"].length;
  925. var str1 = "",
  926. str2 = "";
  927. if (this.data.FieldContent.length > 0) {
  928. str1 = this.data.FieldContent.substr(0, tempCursor);
  929. str2 = this.data.FieldContent.substring(tempCursor, this.data.FieldContent.length);
  930. }
  931. //console.log("str1:" + str1);
  932. //console.log("btnName:" + btnName);
  933. //console.log("str2:" + str2);
  934. var cur = 0;
  935. if (btnName) {
  936. cur = 1;
  937. if (btnName == "[读]" || btnName == "[线]" || btnName == "[光]") {
  938. cur = 3;
  939. } else if (btnName == "[/读]" || btnName == "[/线]" || btnName == "[/光]") {
  940. cur = 4;
  941. } else if (btnName === "( )") {
  942. cur = 7;
  943. } else if (btnName === "_____") {
  944. cur = 5;
  945. }
  946. }
  947. this.data.FieldContent = str1 + btnName + str2;
  948. this.setData({
  949. FieldContent: this.data.FieldContent,
  950. Focus: false,
  951. Cursor: tempCursor + cur,
  952. });
  953. btnName = "";
  954. },
  955. bindscrollHandler: function () {
  956. //console.log("bindscrollHandler");
  957. btnName = "";
  958. },
  959. onSearchField: function (e) {
  960. app.globalData.TempFieldNumber = this.data.FieldNumber;
  961. wx.navigateTo({
  962. url: './addInfomation',
  963. });
  964. this.updateField();
  965. setTimeout(function () {
  966. isEdit = true;
  967. //console.log("onSearchEnd");
  968. }, 1000);
  969. },
  970. clear: function () {
  971. var that = this;
  972. //console.log("clear");
  973. this.setData({
  974. FieldContent: "",
  975. Focus: true,
  976. Cursor: 0,
  977. });
  978. btnName = "";
  979. isEdit = false;
  980. this.updateField();
  981. },
  982. closeAddItem: function (e) {
  983. var that = this;
  984. var isSave = e.currentTarget.dataset.idsave;
  985. if (isSave == "true") {
  986. isUnload = false;
  987. if (that.data.FieldContent) {
  988. var content = that.data.FieldContent;
  989. main.postData("MsgSecCheck2", {
  990. Content: content,
  991. UserID:app.globalData.userInfo.UserID,
  992. },
  993. function (data) {
  994. if (data && data.errcode == 0) {
  995. next(that);
  996. } else {
  997. if (data.errmsg) {
  998. wx.showToast({
  999. title: data.errmsg,
  1000. duration: 2000,
  1001. image: "../images/universalpic_wrong_white_120x120.png",
  1002. });
  1003. isViolate = true;
  1004. }
  1005. }
  1006. });
  1007. } else {
  1008. next(that);
  1009. }
  1010. } else if (isSave == "false") {
  1011. var content = wx.getStorageSync("TempCardInfoAddItem");
  1012. this.setData({
  1013. FieldContent: content,
  1014. });
  1015. next(that);
  1016. }
  1017. function next(obj) {
  1018. isViolate = false;
  1019. obj.updateField();
  1020. obj.setData({
  1021. HiddenFieldEdit: true,
  1022. });
  1023. var title = "编辑题卡";
  1024. if (obj.data.UpdateType == "add2") {
  1025. title = "新建题卡";
  1026. }
  1027. that.setData({
  1028. PageTitle: title,
  1029. });
  1030. that.setBtnSaveCss();
  1031. }
  1032. },
  1033. setBtnSaveCss: function () {
  1034. var that = this;
  1035. if (that.data.Field && that.data.Field[1] && that.data.Field[1] != "") {
  1036. that.setData({
  1037. BtnSaveSelectCss: "MenuBtnSelect",
  1038. });
  1039. } else {
  1040. that.setData({
  1041. BtnSaveSelectCss: "",
  1042. });
  1043. }
  1044. },
  1045. updateField: function () {
  1046. var str = this.data.FieldContent;
  1047. var list = app.globalData.CardList;
  1048. var card = {};
  1049. for (var i = 0; i < list.length; i++) {
  1050. if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  1051. list[i].Content[this.data.FieldNumber].Content = str;
  1052. card = main.changeStringToView(list[i].Content);
  1053. //debugger;
  1054. break;
  1055. }
  1056. }
  1057. app.globalData.CardList = list;
  1058. this.setData({
  1059. Field: card.Field,
  1060. Tags: card.Tags,
  1061. });
  1062. },
  1063. //选择图片上传
  1064. uploadImageField: function () {
  1065. //console.log("uploadImageStart");
  1066. var that = this;
  1067. //若是安卓机
  1068. if (app.globalData.IsAndroid) {
  1069. selectImage(that);
  1070. } else {
  1071. wx.showActionSheet({
  1072. itemList: ['拍照', '从手机相册选择'],
  1073. success(res) {
  1074. if (res.tapIndex == 0) {
  1075. wx.chooseImage({
  1076. count: 1,
  1077. sizeType: ['compressed'],
  1078. sourceType: ['camera'],
  1079. success(res2) {
  1080. wx.showLoading({
  1081. title: '请稍候',
  1082. mask: true,
  1083. });
  1084. setTimeout(function () {
  1085. wx.hideLoading();
  1086. selectImage(that);
  1087. }, 2000);
  1088. },
  1089. });
  1090. } else if (res.tapIndex == 1) {
  1091. selectImage(that);
  1092. }
  1093. },
  1094. fail(res) {
  1095. console.log(res.errMsg)
  1096. }
  1097. });
  1098. }
  1099. function selectImage(that) {
  1100. var sizeType = ['album'];
  1101. //若是安卓机
  1102. if (app.globalData.IsAndroid)
  1103. sizeType = ['album', 'camera'];
  1104. wx.chooseImage({
  1105. count: 1,
  1106. sizeType: ['compressed'],
  1107. sourceType: sizeType,
  1108. success(res) {
  1109. // tempFilePath可以作为img标签的src属性显示图片
  1110. const tempFilePaths = res.tempFilePaths;
  1111. //console.log(tempFilePaths[0]);
  1112. //that.data.FieldContent = that.data.FieldContent + "[图 url='" + tempFilePaths[0] + "']" + tempFilePaths[0] + "[/图]";
  1113. wx.getImageInfo({
  1114. src: res.tempFilePaths[0],
  1115. success(res) {
  1116. //console.log(res.width)
  1117. //console.log(res.height)
  1118. if (tempCursor == undefined)
  1119. tempCursor = that.data.FieldContent.length;
  1120. var str1 = "",
  1121. str2 = "";
  1122. if (that.data.FieldContent.length > 0) {
  1123. str1 = that.data.FieldContent.substr(0, tempCursor);
  1124. str2 = that.data.FieldContent.substring(tempCursor, that.data.FieldContent.length);
  1125. }
  1126. var width = res.width;
  1127. if (isNaN(width))
  1128. width = 650;
  1129. var height = res.height;
  1130. if (isNaN(height))
  1131. height = 650;
  1132. var str0 = "[图 w='" + width + "' h='" + height + "']" + tempFilePaths[0] + "[/图]";
  1133. that.data.FieldContent = str1 + str0 + str2;
  1134. tempCursor = that.data.FieldContent.length;
  1135. //console.log("uploadImageEnd:" + that.data.FieldContent);
  1136. that.setData({
  1137. FieldContent: that.data.FieldContent,
  1138. Focus: false,
  1139. });
  1140. that.updateField();
  1141. if (!wx.getStorageSync("NoRemindImage")) {
  1142. wx.showModal({
  1143. title: '提醒',
  1144. showCancel: true,
  1145. content: "“图片记号”以符号[图]开始…以符号[/图]结尾。如要剪切请确保完整性。",
  1146. confirmText: "好的",
  1147. cancelText: "不再提醒",
  1148. success(res) {
  1149. if (res.confirm) {} else {
  1150. wx.setStorageSync("NoRemindImage", true);
  1151. }
  1152. },
  1153. });
  1154. }
  1155. }
  1156. });
  1157. },
  1158. fail: function () {
  1159. }
  1160. });
  1161. }
  1162. },
  1163. showPracticeTime: function () {
  1164. if (this.data.MiaoguoCardID) {
  1165. wx.navigateTo({
  1166. url: './previewMenu?IsSave=0&ID=' + this.data.MiaoguoCardID + '&CardType=' + this.data.CardType + "&LimitTime=" + this.data.LimitTime,
  1167. });
  1168. } else {
  1169. var limitTime = common.formatTime(new Date(), "-", true);
  1170. if (this.data.LimitTime)
  1171. limitTime = this.data.LimitTime;
  1172. var cardType = 0;
  1173. if (this.data.CardType)
  1174. cardType = this.data.CardType;
  1175. wx.navigateTo({
  1176. url: './previewMenu?IsSave=0&ID=0&CardType=' + cardType + '&LimitTime=' + limitTime,
  1177. });
  1178. }
  1179. },
  1180. //录音授权
  1181. recorderAccredit: function () {
  1182. var that = this;
  1183. if (app.globalData.IsRecorderAccredit == 1)
  1184. that.showRecorder();
  1185. else if (app.globalData.IsRecorderAccredit == 0) {
  1186. recorderManager.stop();
  1187. app.globalData.IsRecorderAccredit = 1;
  1188. that.showRecorder();
  1189. } else if (app.globalData.IsRecorderAccredit == -1) {
  1190. wx.getSetting({
  1191. success(res) {
  1192. if (res.authSetting['scope.record'] === true) {
  1193. app.globalData.IsRecorderAccredit = 1;
  1194. that.showRecorder();
  1195. } else if (res.authSetting['scope.record'] === false) {
  1196. wx.navigateTo({
  1197. url: '../other/openSetting',
  1198. });
  1199. }
  1200. }
  1201. });
  1202. }
  1203. },
  1204. showRecorder: function () {
  1205. var that = this;
  1206. if (that.checkRecorderCount()) {
  1207. that.recorderInit();
  1208. tempRecorderFile = "";
  1209. that.setData({
  1210. PageTitle: '录音',
  1211. });
  1212. that.setData({
  1213. IsRecorder: true,
  1214. IsRecorderFinished: false,
  1215. BtnRecorderName: "按住录音1分钟",
  1216. RecorderTime: "00:00",
  1217. RecorderTimeCss: "",
  1218. RecorderPlayName: "播放",
  1219. });
  1220. innerAudioContext = wx.createInnerAudioContext();
  1221. innerAudioContext.onPlay(() => {
  1222. console.log('开始播放');
  1223. that.setData({
  1224. RecorderTimeCss: "RecorderPanel1121",
  1225. RecorderTime: "00:00",
  1226. RecorderPlayName: "停止",
  1227. });
  1228. });
  1229. innerAudioContext.onEnded(() => {
  1230. console.log('结束播放');
  1231. clearInterval(intervalRecorder);
  1232. that.setData({
  1233. RecorderTime: "00:00",
  1234. RecorderTimeCss: "",
  1235. RecorderPlayName: "播放",
  1236. });
  1237. });
  1238. }
  1239. },
  1240. closeRecorder: function () {
  1241. var that = this;
  1242. this.recorderInit();
  1243. if (tempRecorderFile) {
  1244. wx.showModal({
  1245. title: '提醒',
  1246. content: '这段录音还没有上传,要放弃录音吗?',
  1247. showCancel: true,
  1248. confirmText: "取消",
  1249. cancelText: "不上传",
  1250. success(res) {
  1251. if (res.cancel) {
  1252. closeRecorder2();
  1253. }
  1254. },
  1255. })
  1256. } else {
  1257. closeRecorder2();
  1258. }
  1259. function closeRecorder2() {
  1260. that.setData({
  1261. PageTitle: '编辑 段落' + that.data.FieldNumber,
  1262. });
  1263. that.setData({
  1264. IsRecorder: false,
  1265. IsRecorderFinished: false,
  1266. });
  1267. tempRecorderFile = "";
  1268. }
  1269. },
  1270. //录音初始化
  1271. recorderInit: function () {
  1272. if (innerAudioContext)
  1273. innerAudioContext.stop();
  1274. if (recorderManager)
  1275. recorderManager.stop();
  1276. clearInterval(intervalRecorder);
  1277. },
  1278. checkRecorderCount: function (arr) {
  1279. var that = this;
  1280. var count = 0;
  1281. if (that.data.FieldContent.indexOf("[音 url=") >= 0 ||
  1282. that.data.FieldContent.indexOf("[/音]") >= 0) {
  1283. count = 1;
  1284. }
  1285. if (count > 0) {
  1286. wx.showToast({
  1287. title: '仅能上传一段',
  1288. image: "../images/universalpic_exclamation_white_120x120.png",
  1289. });
  1290. return false;
  1291. } else
  1292. return true;
  1293. },
  1294. btnRecorderStart: function () {
  1295. var that = this;
  1296. if (app.globalData.IsRecorderAccredit == 1) {
  1297. that.setData({
  1298. BtnRecorderName: "松手结束",
  1299. RecorderTimeCss: "RecorderPanel1121",
  1300. });
  1301. that.showRecorderTime();
  1302. recorderManager.start();
  1303. }
  1304. },
  1305. btnRecorderEnd: function () {
  1306. var that = this;
  1307. if (app.globalData.IsRecorderAccredit == 1) {
  1308. if (that.data.RecorderTime == "00:00") {
  1309. //小于1秒处理
  1310. wx.showToast({
  1311. title: '时间过短',
  1312. image: "../images/universalpic_exclamation_white_120x120.png",
  1313. });
  1314. that.showRecorder();
  1315. } else {
  1316. that.setData({
  1317. IsRecorderFinished: true,
  1318. RecorderTimeCss: "",
  1319. });
  1320. that.recorderInit();
  1321. }
  1322. } else {
  1323. that.recorderAccredit();
  1324. }
  1325. },
  1326. showRecorderTime: function () {
  1327. var that = this;
  1328. var second = 0;
  1329. clearInterval(intervalRecorder);
  1330. intervalRecorder = setInterval(function () {
  1331. second++;
  1332. var secondStr = second.toString();
  1333. if (second < 10)
  1334. secondStr = "0" + secondStr;
  1335. that.setData({
  1336. RecorderTime: "00:" + secondStr,
  1337. });
  1338. if (second >= 59) {
  1339. that.setData({
  1340. IsRecorderFinished: true,
  1341. RecorderTimeCss: "",
  1342. });
  1343. that.recorderInit();
  1344. if (that.data.RecorderPlayName == "播放") {
  1345. wx.showToast({
  1346. title: '录音超时',
  1347. image: "../images/universalpic_exclamation_white_120x120.png",
  1348. });
  1349. }
  1350. }
  1351. }, 1000);
  1352. },
  1353. btnRecorderPlay: function () {
  1354. var that = this;
  1355. if (tempRecorderFile && this.data.RecorderPlayName == "播放") {
  1356. innerAudioContext.src = tempRecorderFile;
  1357. innerAudioContext.play();
  1358. this.showRecorderTime();
  1359. } else if (this.data.RecorderPlayName == "停止") {
  1360. if (innerAudioContext)
  1361. innerAudioContext.stop();
  1362. clearInterval(intervalRecorder);
  1363. that.setData({
  1364. RecorderTime: "00:00",
  1365. RecorderTimeCss: "",
  1366. RecorderPlayName: "播放",
  1367. });
  1368. }
  1369. },
  1370. btnRecorderSave: function () {
  1371. var that = this;
  1372. if (tempRecorderFile) {
  1373. this.recorderInit();
  1374. wx.showLoading({
  1375. title: '正在上传',
  1376. });
  1377. setTimeout(function () {
  1378. wx.hideLoading();
  1379. }, 60000);
  1380. that.uploadFileToServer(tempRecorderFile, function (data) {
  1381. if (data) {
  1382. wx.hideLoading();
  1383. var result = data;
  1384. result.Target = app.globalData.uploadImageUrl + result.Target;
  1385. that.data.FieldContent = that.data.FieldContent + "[音 url='" + result.Target + "'][/音]";
  1386. that.data.FieldContent = main.encryptUrl(that.data.FieldContent);
  1387. that.setData({
  1388. FieldContent: that.data.FieldContent,
  1389. });
  1390. tempRecorderFile = "";
  1391. that.closeRecorder();
  1392. if (!wx.getStorageSync("NoRemindRecorder")) {
  1393. wx.showModal({
  1394. title: '提醒',
  1395. showCancel: true,
  1396. content: "“录音记号”以符号[录]开始…以符号[/录]结尾。如要剪切请确保完整性。",
  1397. confirmText: "好的",
  1398. cancelText: "不再提醒",
  1399. success(res) {
  1400. if (res.confirm) {} else {
  1401. wx.setStorageSync("NoRemindRecorder", true);
  1402. }
  1403. },
  1404. });
  1405. }
  1406. }
  1407. });
  1408. } else {
  1409. wx.showToast({
  1410. title: '没有录音',
  1411. image: "../images/universalpic_exclamation_white_120x120.png",
  1412. });
  1413. }
  1414. },
  1415. goto: function (e) {
  1416. var url = e.currentTarget.dataset.url;
  1417. if (url == "../index/index?type=helpAddInfomation") {
  1418. wx.setStorageSync('IsHelpAddInfomation', 1);
  1419. wx.redirectTo({
  1420. url: './default',
  1421. });
  1422. }
  1423. else{
  1424. wx.navigateTo({
  1425. url: url,
  1426. });
  1427. if (url == "./folderEdit?type=add") {
  1428. isAddFolder = true;
  1429. }
  1430. }
  1431. },
  1432. showTagShow: function () {
  1433. var tagTemp = this.data.Tags.join(",");
  1434. this.setData({
  1435. IsTagShow: true,
  1436. TagTemp: tagTemp.split(","),
  1437. TagIndex: -1,
  1438. });
  1439. this.setData({
  1440. PageTitle: '自动记号',
  1441. });
  1442. },
  1443. closeTagShow: function () {
  1444. this.setData({
  1445. IsTagShow: false,
  1446. });
  1447. this.setData({
  1448. PageTitle: '编辑题卡',
  1449. });
  1450. },
  1451. setCardTypeInit: function () {
  1452. this.setData({
  1453. CardType: 0,
  1454. PracticeCardType: constant1.arrStudyPattern[0] + "题卡",
  1455. PracticeTimeStr: "",
  1456. LimitTime: common.formatTime(new Date(), "-", true),
  1457. });
  1458. wx.showToast({
  1459. title: '已恢复默认',
  1460. image: "../images/universalpic_restore_white_120x120.png",
  1461. });
  1462. },
  1463. gotoAddInfomationDetail: function (param) {
  1464. main.searchInfomation(param.Word, param.SearchType, param.Author, app.globalData.TempStr, function (list, obj) {
  1465. main.updateSearchList(obj, function () {
  1466. app.globalData.TempSearchBackNumber = 0;
  1467. wx.navigateTo({
  1468. url: './addInfomationDetail',
  1469. });
  1470. });
  1471. });
  1472. },
  1473. showPanel: function (e) {
  1474. var that = this;
  1475. that.hiddenPanel(true);
  1476. switch (e.currentTarget.dataset.type) {
  1477. case "help":
  1478. that.setData({
  1479. IsHelp: true,
  1480. });
  1481. break;
  1482. case "menu":
  1483. that.setData({
  1484. IsShowMenu: true,
  1485. IsShowAddHelp: 1,
  1486. });
  1487. wx.setStorageSync("IsShowAddHelp", that.data.IsShowAddHelp);
  1488. break;
  1489. case "folder":
  1490. that.setData({
  1491. IsFolder: true,
  1492. });
  1493. that.getFolderList();
  1494. break;
  1495. case "limittime":
  1496. var arrLimitTime = constant1.arrLimitTime;
  1497. for (var i = 0; i < arrLimitTime.length; i++) {
  1498. arrLimitTime[i].Selected = "";
  1499. }
  1500. //arrLimitTime[0].Selected="MenuBtnSelect";
  1501. that.setData({
  1502. Today: common.formatTime(new Date()),
  1503. IsLimitTime: true,
  1504. LimitTimeTemp: that.data.LimitTime,
  1505. PracticeTimeStrTemp: common.formatDateCHS(that.data.LimitTime),
  1506. LimitTimeArr: arrLimitTime,
  1507. });
  1508. break;
  1509. case "fontsize":
  1510. if (!that.data.FontSize)
  1511. that.data.FontSize = 48;
  1512. var fontSize = constant1.arrFontSize;
  1513. var fontSizeName = "";
  1514. for (var i = 0; i < fontSize.length; i++) {
  1515. fontSize[i].Selected = "";
  1516. if (fontSize[i].Value == that.data.FontSize) {
  1517. fontSize[i].Selected = "MenuBtnSelect";
  1518. fontSizeName = fontSize[i].Name;
  1519. }
  1520. }
  1521. that.setData({
  1522. IsFontsize: true,
  1523. FontSizeArr: fontSize,
  1524. FontSizeTemp: that.data.FontSize,
  1525. FontSizeName: fontSizeName,
  1526. });
  1527. break;
  1528. case "cardtype":
  1529. var obj = {};
  1530. if (!that.data.CardType)
  1531. that.data.CardType = 0;
  1532. if (that.data.CardType == 0) {
  1533. obj.NormalCss = "MenuBtnSelect";
  1534. obj.UrgentCss = "";
  1535. } else if (that.data.CardType == 1) {
  1536. obj.NormalCss = "";
  1537. obj.UrgentCss = "MenuBtnSelect";
  1538. } else if (that.data.CardType == -1) {
  1539. obj.NormalCss = "MenuBtnDisabled";
  1540. obj.UrgentCss = "MenuBtnDisabled";
  1541. }
  1542. that.setData({
  1543. IsCardType: true,
  1544. CardTypeCss: obj,
  1545. CardTypeTemp: that.data.CardType,
  1546. CardNumberUrgent: app.globalData.TaskToday.CardNumberUrgent,
  1547. });
  1548. break;
  1549. }
  1550. },
  1551. hiddenPanel: function (e) {
  1552. var that = this;
  1553. that.setData({
  1554. IsShowMenu: false,
  1555. IsHelp: false,
  1556. IsFontsize: false,
  1557. IsFolder: false,
  1558. IsLimitTime: false,
  1559. IsCardType: false,
  1560. });
  1561. if (that.data.IsFolder) {
  1562. for (var i = 0; i < that.data.FolderArr.length; i++) {
  1563. that.data.FolderArr[i].Selected = "";
  1564. }
  1565. that.setData({
  1566. FolderArr: that.data.FolderArr,
  1567. });
  1568. }
  1569. },
  1570. setFontSize: function (e) {
  1571. var that = this;
  1572. var fontSize = constant1.arrFontSize;
  1573. var fontSizeName;
  1574. for (var i = 0; i < fontSize.length; i++) {
  1575. fontSize[i].Selected = "";
  1576. if (fontSize[i].Value == e.currentTarget.dataset.fontsize) {
  1577. fontSize[i].Selected = "MenuBtnSelect";
  1578. fontSizeName = fontSize[i].Name;
  1579. }
  1580. }
  1581. that.setData({
  1582. FontSizeTemp: e.currentTarget.dataset.fontsize,
  1583. FontSizeArr: fontSize,
  1584. FontSizeNameTemp: fontSizeName,
  1585. });
  1586. },
  1587. saveFontSize: function () {
  1588. var fontSizeName;
  1589. var fontSize = constant1.arrFontSize;
  1590. for (var i = 0; i < fontSize.length; i++) {
  1591. if (fontSize[i].Value == this.data.FontSizeTemp) {
  1592. fontSizeName = fontSize[i].Name;
  1593. }
  1594. }
  1595. this.setData({
  1596. FontSize: this.data.FontSizeTemp,
  1597. FontSizeName: fontSizeName,
  1598. });
  1599. this.hiddenPanel();
  1600. },
  1601. getFolderList: function (e) {
  1602. var that = this;
  1603. if (app.globalData.FolderList.length == 0) {
  1604. var url = "GetUserFolderList?UserID=" + app.globalData.userInfo.UserID;
  1605. main.getData(url, function (data) {
  1606. if (data) {
  1607. if (isAddFolder) {
  1608. that.setData({
  1609. FolderID: data[0].ID,
  1610. });
  1611. isAddFolder = false;
  1612. }
  1613. update(data);
  1614. }
  1615. });
  1616. } else {
  1617. update(app.globalData.FolderList);
  1618. }
  1619. function update(arr) {
  1620. for (var i = 0; i < arr.length; i++) {
  1621. arr[i].Selected = "";
  1622. if (that.data.FolderID) {
  1623. if (arr[i].ID == that.data.FolderID) {
  1624. arr[i].Selected = "MenuBtnSelect";
  1625. }
  1626. }
  1627. }
  1628. that.setData({
  1629. FolderArr: arr,
  1630. });
  1631. app.globalData.FolderList = arr;
  1632. }
  1633. },
  1634. selectFolder: function (e) {
  1635. var that = this;
  1636. var id = e.currentTarget.dataset.id;
  1637. for (var i = 0; i < that.data.FolderArr.length; i++) {
  1638. if (id == that.data.FolderArr[i].ID)
  1639. that.data.FolderArr[i].Selected = "MenuBtnSelect";
  1640. else
  1641. that.data.FolderArr[i].Selected = "";
  1642. }
  1643. var nullFolder = "";
  1644. if (id == 0) {
  1645. nullFolder = "MenuBtnSelect";
  1646. }
  1647. that.setData({
  1648. FolderArr: that.data.FolderArr,
  1649. NullFolder: nullFolder,
  1650. });
  1651. },
  1652. setFolder: function () {
  1653. var that = this;
  1654. var id = 0;
  1655. var FolderName = "";
  1656. for (var i = 0; i < that.data.FolderArr.length; i++) {
  1657. if (that.data.FolderArr[i].Selected == "MenuBtnSelect") {
  1658. id = that.data.FolderArr[i].ID;
  1659. FolderName = that.data.FolderArr[i].Name;
  1660. }
  1661. }
  1662. that.setData({
  1663. FolderID: id,
  1664. FolderName: FolderName,
  1665. });
  1666. that.hiddenPanel();
  1667. },
  1668. selectLimitTime: function (e) {
  1669. var that = this;
  1670. var limitTime = "";
  1671. var daynumber = e.currentTarget.dataset.daynumber;
  1672. for (var i = 0; i < that.data.LimitTimeArr.length; i++) {
  1673. if (daynumber == that.data.LimitTimeArr[i].DayNumber) {
  1674. that.data.LimitTimeArr[i].Selected = "MenuBtnSelect";
  1675. limitTime = common.formatTime(common.addDate("d", daynumber, new Date()), "-", true);
  1676. } else
  1677. that.data.LimitTimeArr[i].Selected = "";
  1678. }
  1679. that.setData({
  1680. LimitTimeTemp: limitTime,
  1681. PracticeTimeStrTemp: common.formatDateCHS(limitTime),
  1682. LimitTimeArr: that.data.LimitTimeArr,
  1683. });
  1684. },
  1685. selectLimitTime2: function (e) {
  1686. var that = this;
  1687. var limitTime = e.detail.value;
  1688. var today = common.formatTime(new Date(), "-", true);
  1689. console.log(today);
  1690. if (limitTime < today) {
  1691. wx.showModal({
  1692. title: '提醒',
  1693. content: '指定日期只能是今天或未来某日,您可重新选择。',
  1694. confirmText: "知道了",
  1695. showCancel: false,
  1696. });
  1697. } else {
  1698. for (var i = 0; i < that.data.LimitTimeArr.length; i++) {
  1699. that.data.LimitTimeArr[i].Selected = "";
  1700. }
  1701. that.setData({
  1702. LimitTimeTemp: limitTime,
  1703. PracticeTimeStrTemp: common.formatDateCHS(limitTime),
  1704. LimitTimeArr: that.data.LimitTimeArr,
  1705. });
  1706. }
  1707. },
  1708. setLimitTime: function (e) {
  1709. var that = this;
  1710. that.setData({
  1711. LimitTime: that.data.LimitTimeTemp,
  1712. PracticeTimeStr: common.formatDateCHS(that.data.LimitTimeTemp),
  1713. });
  1714. that.hiddenPanel();
  1715. },
  1716. setCollect: function () {
  1717. var that = this;
  1718. var IsCollectStr = "";
  1719. if (that.data.IsCollect == 1) {
  1720. that.data.IsCollect = 0;
  1721. } else {
  1722. that.data.IsCollect = 1;
  1723. }
  1724. that.setData({
  1725. IsCollect: that.data.IsCollect,
  1726. });
  1727. that.hiddenPanel();
  1728. },
  1729. setLimitTime: function (e) {
  1730. var that = this;
  1731. that.setData({
  1732. LimitTime: that.data.LimitTimeTemp,
  1733. PracticeTimeStr: common.formatDateCHS(that.data.LimitTimeTemp),
  1734. });
  1735. that.hiddenPanel();
  1736. },
  1737. selectCardType: function (e) {
  1738. var that = this;
  1739. var cardtype = 0;
  1740. if (!e.currentTarget.dataset.disabled) {
  1741. if (e.currentTarget.dataset.cardtype) {
  1742. cardtype = e.currentTarget.dataset.cardtype;
  1743. }
  1744. if (e.detail.value === true)
  1745. cardtype = -1;
  1746. else if (e.detail.value === false)
  1747. cardtype = 0;
  1748. var obj = {};
  1749. if (cardtype == 0) {
  1750. obj.NormalCss = "MenuBtnSelect";
  1751. }
  1752. if (cardtype == 1) {
  1753. obj.UrgentCss = "MenuBtnSelect";
  1754. }
  1755. if (cardtype == -1) {
  1756. obj.NormalCss = "MenuBtnDisabled";
  1757. obj.UrgentCss = "MenuBtnDisabled";
  1758. }
  1759. if (that.data.CardType == 1 && (cardtype == 0 || cardtype == -1))
  1760. app.globalData.TaskToday.CardNumberUrgent--;
  1761. if (app.globalData.TaskToday.CardNumberUrgent + 1 > 200) {
  1762. obj.UrgentCss = "MenuBtnDisabled";
  1763. }
  1764. that.setData({
  1765. CardTypeTemp: cardtype,
  1766. CardTypeCss: obj,
  1767. });
  1768. }
  1769. },
  1770. setCardType: function (e) {
  1771. var that = this;
  1772. if (that.data.CardTypeTemp == 1 || that.data.CardType == -1) {
  1773. var limittime = common.formatTime(new Date(), "-", true);
  1774. that.setData({
  1775. LimitTime: limittime,
  1776. PracticeTimeStr: common.formatDateCHS(limittime),
  1777. });
  1778. }
  1779. that.setData({
  1780. CardType: Number(that.data.CardTypeTemp),
  1781. PracticeCardType: constant1.arrStudyPattern[that.data.CardTypeTemp] + "题卡",
  1782. });
  1783. that.hiddenPanel();
  1784. },
  1785. deleteCard: function () {
  1786. app.globalData.TempStr = "deleteCard";
  1787. this.onClose();
  1788. },
  1789. closeHelp:function(){
  1790. this.setData({
  1791. IsShowHelp:false,
  1792. });
  1793. wx.setStorageSync('IsHelpAddInfomation', 0);
  1794. },
  1795. onShareAppMessage: function () {
  1796. return {
  1797. title: app.globalData.ShareTitle,
  1798. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  1799. imageUrl: app.globalData.ShareImage,
  1800. }
  1801. },
  1802. })