add.js 54 KB

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