add.js 54 KB

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