add.js 54 KB

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