add.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. const PracticeTimeArr = [{
  5. Name: "还原",
  6. CSS: "numberContainerFooter1121Select"
  7. },
  8. {
  9. Name: "推迟一周",
  10. },
  11. {
  12. Name: "推迟一个月",
  13. },
  14. {
  15. Name: "推迟三个月",
  16. }
  17. ];
  18. var arrTag = [];
  19. var tempCursor = undefined,
  20. btnName = "";
  21. var arrSoundMark = [];
  22. var isUnload = true;
  23. var isEdit = true;
  24. var isSave = true;
  25. var interval;
  26. var timeoutUploadImage = 0;
  27. var intervalRecorder = 0; //录音计时器
  28. var recorderManager;
  29. var tempRecorderFile = "";
  30. var innerAudioContext;
  31. var isViolate = false; //是否是违禁词
  32. var isFirstAdd = true;//是第一个填加
  33. Page({
  34. data: {
  35. HiddenFieldEdit: true,
  36. FieldContent: "",
  37. SoundSign: "[读]",
  38. LineSign: "[线]",
  39. HighlighterSign: "[光]",
  40. IsPracticeTime: false,
  41. IsRecorder: false,
  42. PracticeTimeArr: PracticeTimeArr,
  43. IsIPhoneX: app.globalData.IsIPhoneX,
  44. },
  45. onReady: function () {
  46. recorderManager = wx.getRecorderManager();
  47. recorderManager.onStart(() => {
  48. console.log('recorder start')
  49. });
  50. recorderManager.onStop((res) => {
  51. console.log('recorder stop', res);
  52. tempRecorderFile = res.tempFilePath;
  53. });
  54. recorderManager.onError((err) => {
  55. // console.log('err', err);
  56. // if (err.errMsg =="operateRecorder:fail auth deny"){
  57. // wx.navigateTo({
  58. // url: '../index/openSetting',
  59. // })
  60. // }
  61. });
  62. },
  63. onLoad: function (options) {
  64. var that = this;
  65. var fieldNumber = 0;
  66. if (options.fieldid)
  67. fieldNumber = options.fieldid;
  68. that.setData({
  69. Containnerheight: main.getWindowHeight(),
  70. UpdateType: options.type,
  71. MiaoguoCardID: options.id,
  72. FieldNumber: fieldNumber,
  73. PracticeTimeStr: PracticeTimeArr[0].Name,
  74. IsShow: app.globalData.userInfo.IsShow,
  75. IsShowPracticeTimeStart: true,
  76. });
  77. var list = app.globalData.CardList;
  78. for (var i = 0; i < list.length; i++) {
  79. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  80. wx.setStorageSync("TempCardInfo", list[i]);
  81. break;
  82. }
  83. }
  84. app.globalData.TempFieldNumber = 0;
  85. app.globalData.TempMiaoguoCardID = that.data.MiaoguoCardID;
  86. isViolate = false;
  87. isFirstAdd = true;
  88. },
  89. onShow: function () {
  90. var that = this;
  91. if (that.data.UpdateType == "add") {
  92. that.initAddCard();
  93. that.setData({
  94. PracticeTimeStr2: "智能安排",
  95. });
  96. } else {
  97. var card = {},
  98. content = "";
  99. var list = app.globalData.CardList;
  100. for (var i = 0; i < list.length; i++) {
  101. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  102. card = main.changeStringToView(list[i].Content);
  103. card.MiaoguoCardID = list[i].MiaoguoCardID;
  104. card.LimitTime = list[i].LimitTime;
  105. if (that.data.FieldNumber && that.data.FieldNumber > 0)
  106. content = main.encryptUrl(list[i].Content[that.data.FieldNumber].Content);
  107. break;
  108. }
  109. }
  110. that.setData({
  111. MiaoguoCardID: card.MiaoguoCardID,
  112. LimitTime: common.formatTime(card.LimitTime),
  113. PracticeTimeStr2: common.formatDateCHS(common.formatTime(card.LimitTime)),
  114. Field: card.Field,
  115. Tags: card.Tags,
  116. FieldContent: content,
  117. });
  118. if (that.data.UpdateType != "add2") {
  119. wx.setNavigationBarTitle({
  120. title: '编辑题卡'
  121. });
  122. }
  123. if (that.data.UpdateType == "edit3") {
  124. that.gotoAddItem({
  125. currentTarget: {
  126. dataset: {
  127. fieldid: that.data.FieldNumber
  128. }
  129. }
  130. });
  131. }
  132. }
  133. common.getStorageValue(that, "SymbolMain", app.globalData.SymbolMain, function () { });
  134. },
  135. onHide: function () {
  136. //用于恢复未保存的新题卡
  137. //console.log("onHide");
  138. var that = this;
  139. if (!that.data.HiddenFieldEdit) {
  140. that.updateField();
  141. }
  142. if (!(that.data && that.data.Field && that.data.Field[1].length == 0 &&
  143. that.data.Field[2].length == 0 &&
  144. that.data.Field[3].length == 0)) {
  145. if (!isViolate && (that.data.UpdateType == "add" || that.data.UpdateType == "add2")) {
  146. var card = {};
  147. card.MiaoguoCardID = that.data.MiaoguoCardID;
  148. card.Content = [];
  149. var param1 = {};
  150. param1 = that.formatField(that.data.Field);
  151. for (var i = 0; i < 4; i++) {
  152. var obj = {};
  153. obj.ContentType = i;
  154. if (i == 0)
  155. obj.Content = that.data.Tags;
  156. else
  157. obj.Content = param1["Field" + i];
  158. card.Content.push(obj);
  159. }
  160. wx.setStorageSync("TempCardNoSaved", card);
  161. }
  162. }
  163. },
  164. onUnload: function () {
  165. this.onHide();
  166. var card = wx.getStorageSync("TempCardInfo");
  167. if (card) {
  168. var list = app.globalData.CardList;
  169. for (var i = 0; i < list.length; i++) {
  170. if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  171. list[i] = card;
  172. break;
  173. }
  174. }
  175. app.globalData.CardList = list;
  176. wx.removeStorageSync("TempCardInfo");
  177. }
  178. clearInterval(interval);
  179. clearTimeout(timeoutUploadImage);
  180. clearInterval(intervalRecorder);
  181. if (this.data.IsRecorder)
  182. this.closeRecorder();
  183. },
  184. onClose: function () {
  185. wx.navigateBack({
  186. delta: 1,
  187. });
  188. clearInterval(intervalRecorder);
  189. },
  190. gotoAddItem: function (e) {
  191. var that = this;
  192. var fieldid = e.currentTarget.dataset.fieldid;
  193. var content;
  194. var list = app.globalData.CardList;
  195. for (var i = 0; i < list.length; i++) {
  196. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  197. content = main.encryptUrl(list[i].Content[fieldid].Content);
  198. break;
  199. }
  200. }
  201. wx.setStorageSync("TempCardInfoAddItem", content);
  202. that.setData({
  203. HiddenFieldEdit: false,
  204. Focus: true,
  205. FieldNumber: fieldid,
  206. FieldContent: content,
  207. });
  208. wx.setNavigationBarTitle({
  209. title: '编辑 段落' + fieldid,
  210. });
  211. },
  212. onSearch: function (e) {
  213. app.globalData.TempFieldNumber = 0;
  214. wx.navigateTo({
  215. url: './searchWeb',
  216. })
  217. },
  218. onPreview: function (e) {
  219. var that = this;
  220. if (that.data.Field[1] == "") {
  221. wx.showToast({
  222. title: '第一段必填',
  223. image: "../images/universalpic_wrong_white_120x120.png",
  224. });
  225. } else {
  226. wx.navigateTo({
  227. url: './preview?type=preview&id=' + this.data.MiaoguoCardID,
  228. });
  229. }
  230. },
  231. saveCard: function () {
  232. var that = this;
  233. if (that.data.Field[1] == "") {
  234. wx.showToast({
  235. title: '第一段必填',
  236. image: "../images/universalpic_wrong_white_120x120.png",
  237. });
  238. } else {
  239. if (isSave) {
  240. isSave = false;
  241. setTimeout(function () {
  242. isSave = true;
  243. }, 5000);
  244. if (that.checkImageCount(that.data.Field)) {
  245. that.uploadImageAll(that.data.Field, function (success, field) {
  246. if (success) {
  247. that.data.Field = field;
  248. var userid = app.globalData.userInfo.UserID;
  249. var tags = [];
  250. for (var i = 0; i < that.data.Tags.length; i++) {
  251. if (that.data.Tags[i])
  252. tags.push(that.data.Tags[i]);
  253. }
  254. var param1 = {};
  255. param1 = that.formatField(that.data.Field);
  256. param1.Tags = tags;
  257. param1.LimitTime = that.getLimitTimeStr();
  258. param1.ID = that.data.MiaoguoCardID;
  259. that.saveLocalCardList(param1);
  260. wx.hideLoading();
  261. wx.showLoading({
  262. title: '保存数据请稍候',
  263. mask: true,
  264. });
  265. timeoutUploadImage = setTimeout(function () {
  266. wx.hideLoading();
  267. }, 15000);
  268. main.postData('AddMiaoguoCard?Type=' + that.data.UpdateType + '&UserID=' + userid, param1, function (data) {
  269. wx.removeStorageSync("TempCardNoSaved");
  270. if (that.data.UpdateType == "edit" || that.data.UpdateType == "edit2" || that.data.UpdateType == "edit3") {
  271. that.onClose();
  272. } else {
  273. wx.hideLoading();
  274. wx.showToast({
  275. title: '已保存!',
  276. image: "../images/universalpic_saved_white_120x120.png",
  277. });
  278. if (that.data.UpdateType == "add2") {
  279. isFirstAdd = false;
  280. that.initAddCard();
  281. }
  282. }
  283. wx.removeStorageSync("TempCardInfo");
  284. });
  285. } else {
  286. wx.showToast({
  287. title: '图片上传失败1',
  288. mask: true,
  289. });
  290. }
  291. });
  292. }
  293. } else {
  294. wx.showToast({
  295. title: '点击太频繁',
  296. mask: true,
  297. });
  298. }
  299. }
  300. },
  301. formatField: function (field) {
  302. var result = {};
  303. for (var i = 1; i <= 3; i++) {
  304. result["Field" + i] = "";
  305. if (field[i]) {
  306. for (var key in field[i]) {
  307. var item = field[i][key];
  308. var str = "";
  309. if (item.Type == "image") {
  310. str = "[图 w='" + item.Width + "' h='" + item.Height + "']" + item.Content + "[/图]";
  311. } else if (item.Type == "line") {
  312. for (var j = 0; j < item.Content.length; j++) {
  313. if (item.Content[j].key == "normal")
  314. str += item.Content[j].value;
  315. if (item.Content[j].key == "line") {
  316. str += "[线]" + item.Content[j].value + "[/线]";
  317. }
  318. if (item.Content[j].key == "highlighter") {
  319. str += "[光]" + item.Content[j].value + "[/光]";
  320. }
  321. }
  322. } else if (item.Type == "sound") {
  323. if (item.SoundMark)
  324. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  325. else
  326. str = "[读]" + item.Content + "[/读]";
  327. } else if (item.Type == "recorder") {
  328. if (item.SoundMark)
  329. str = "[音 url='" + item.SoundMark + "'][/音]";
  330. } else if (item.Type == "normal") {
  331. str = item.Content;
  332. } else if (item.Type == "return") {
  333. str = "\n";
  334. }
  335. result["Field" + i] += str;
  336. }
  337. }
  338. result["Field" + i] = main.changeViewToString(result["Field" + i]);
  339. }
  340. return result;
  341. },
  342. checkImageCount: function (arr) {
  343. var count = 0;
  344. for (var i = 0; i < arr.length; i++) {
  345. for (var j = 0; j < arr[i].length; j++) {
  346. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  347. count++;
  348. }
  349. }
  350. }
  351. if (count > 3) {
  352. wx.showToast({
  353. title: '只能上传三张图片',
  354. });
  355. return false;
  356. } else
  357. return true;
  358. },
  359. uploadImageAll: function (arr, callback) {
  360. var that = this;
  361. var b = false;
  362. var arrSource = [],
  363. arrResult = [];
  364. for (var i = 0; i < arr.length; i++) {
  365. for (var j = 0; j < arr[i].length; j++) {
  366. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  367. arrSource.push(arr[i][j].Content);
  368. if (arr[i][j].ContentServer.indexOf(app.globalData.uploadImageUrl) >= 0 ||
  369. arr[i][j].ContentServer.indexOf("baidu.com") >= 0 ||
  370. arr[i][j].ContentServer.indexOf("bcebos.com") >= 0) {
  371. var result = {};
  372. result.Source = arr[i][j].ContentServer;
  373. result.Target = arr[i][j].ContentServer;
  374. arrResult.push(result);
  375. } else {
  376. var source = arr[i][j].Content;
  377. that.uploadFileToServer(source, function (data) {
  378. if (data) {
  379. data = JSON.parse(data);
  380. var result = data.result;
  381. result.Target = app.globalData.uploadImageUrl + result.Target;
  382. arrResult.push(result);
  383. }
  384. });
  385. }
  386. b = true;
  387. }
  388. }
  389. }
  390. if (b) {
  391. wx.showLoading({
  392. title: '上传图片请稍候',
  393. mask: true,
  394. });
  395. timeoutUploadImage = setTimeout(function () {
  396. wx.hideLoading();
  397. }, 30000);
  398. }
  399. interval = setInterval(function () {
  400. //console.log(arrResult.length);
  401. if (arrResult.length >= arrSource.length) {
  402. wx.hideLoading();
  403. //console.log("arrResult:" + JSON.stringify(arrResult));
  404. clearInterval(interval);
  405. var success = true;
  406. var ari = 0;
  407. for (var i = 0; i < arr.length; i++) {
  408. for (var j = 0; j < arr[i].length; j++) {
  409. if (arr[i][j].Type == "image" && arr[i][j].Content) {
  410. var tempUrl = arr[i][j].Content;
  411. var serverUrl = "";
  412. for (var k = 0; k < arrResult.length; k++) {
  413. if (tempUrl.indexOf(arrResult[k].Source) >= 0) {
  414. serverUrl = arrResult[k].Target;
  415. break;
  416. }
  417. }
  418. //console.log("serverUrl:" + serverUrl);
  419. //console.log("tempUrl:" + tempUrl);
  420. if (serverUrl == "")
  421. serverUrl = main.getServerImage(tempUrl);
  422. main.saveTempImage(serverUrl, tempUrl);
  423. arr[i][j].Content = serverUrl;
  424. arr[i][j].ContentServer = serverUrl;
  425. if (serverUrl == "") {
  426. success = false;
  427. break;
  428. }
  429. }
  430. }
  431. }
  432. //console.log(JSON.stringify(arr));
  433. callback(success, arr);
  434. }
  435. }, 500);
  436. },
  437. uploadFileToServer: function (file, callback) {
  438. var url = common.Encrypt("MiaoguoUploadFile2");
  439. wx.uploadFile({
  440. url: app.globalData.serverUrl + url,
  441. filePath: file,
  442. name: 'file',
  443. success(res) {
  444. callback(res.data);
  445. },
  446. fail: function (err) {
  447. wx.hideLoading();
  448. wx.showModal({
  449. title: '上传文件失败',
  450. showCancel: false,
  451. content: JSON.stringify(err),
  452. });
  453. }
  454. });
  455. },
  456. saveLocalCardList: function (param1) {
  457. var that = this;
  458. var list = app.globalData.CardList;
  459. for (var i = 0; i < list.length; i++) {
  460. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  461. for (var j = 0; j < 4; j++) {
  462. if (j == 0) {
  463. if (param1.tags && param1.tags.length > 0)
  464. list[i].Content[j].Content = param1.tags.join(",");
  465. } else
  466. list[i].Content[j].Content = param1["Field" + j];
  467. }
  468. if (param1.LimitTime)
  469. list[i].LimitTime = common.formatTime(param1.LimitTime);
  470. if (param1.IsTodayStudy == 1) {
  471. list[i].LimitTime = common.formatTime(new Date());
  472. main.getTaskTodayList(function () { });
  473. }
  474. app.globalData.CardList = list;
  475. break;
  476. }
  477. }
  478. },
  479. initAddCard: function () {
  480. var card = {};
  481. card.MiaoguoCardID = 0;
  482. card.Content = [];
  483. for (var i = 0; i < 4; i++) {
  484. var obj = {};
  485. obj.ContentType = i;
  486. obj.Content = [];
  487. card.Content.push(obj);
  488. }
  489. app.globalData.CardList = [card];
  490. this.setData({
  491. MiaoguoCardID: 0,
  492. Field: [
  493. [],
  494. [],
  495. [],
  496. []
  497. ],
  498. Tags: [],
  499. UpdateType: "add2",
  500. });
  501. },
  502. onBindError: function (e) {
  503. for (var i = 1; i < this.data.Field.length; i++) {
  504. for (var j = 0; j < this.data.Field[i].length; j++) {
  505. if (this.data.Field[i][j].Type == "image") {
  506. this.data.Field[i][j].Url = this.data.Field[i][j].Content;
  507. }
  508. }
  509. }
  510. this.setData({
  511. Field: this.data.Field,
  512. });
  513. },
  514. deleteItem: function (e) {
  515. var that = this;
  516. var index = e.currentTarget.dataset.id;
  517. wx.showModal({
  518. title: '提醒',
  519. content: '记号“' + that.data.Tags[index] + '”要删除吗?',
  520. success(res) {
  521. if (res.confirm) {
  522. that.data.Tags.splice(index, 1);
  523. that.setData({
  524. Tags: that.data.Tags,
  525. });
  526. var list = app.globalData.CardList;
  527. for (var i = 0; i < list.length; i++) {
  528. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  529. list[i].Content[0].Content = that.data.Tags;
  530. break;
  531. }
  532. }
  533. app.globalData.CardList = list;
  534. }
  535. }
  536. });
  537. },
  538. onGotoList: function () {
  539. var that = this;
  540. if (isFirstAdd == true || !that.data.Field) {
  541. wx.showModal({
  542. title: '无法查看上一张',
  543. content: '本功能是在批量添加题卡时快速回看上一张题卡。现在是本批的第一张,没有上一张。',
  544. confirmText: '知道了',
  545. showCancel: false,
  546. });
  547. }
  548. else if (that.data.Field[1].length > 0 || that.data.Field[2].length > 0 || that.data.Field[2].length > 0) {
  549. wx.showModal({
  550. title: '尚未保存',
  551. content: '即将“查看上一张题卡”,但当前题卡尚未保存,按继续将放弃保存。',
  552. confirmText: '继续',
  553. success(res) {
  554. if (res.confirm) {
  555. goto();
  556. setTimeout(function () {
  557. wx.removeStorageSync("TempCardNoSaved");
  558. }, 1000);
  559. }
  560. }
  561. });
  562. }
  563. else {
  564. goto();
  565. }
  566. function goto() {
  567. wx.showLoading({
  568. title: '请稍候',
  569. });
  570. setTimeout(function () {
  571. wx.hideLoading();
  572. }, 5000);
  573. var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
  574. main.getData(url, function (data) {
  575. wx.hideLoading();
  576. if (data) {
  577. app.globalData.CardList = data.List;
  578. that.setData({
  579. UpdateType: "add",
  580. });
  581. wx.navigateTo({
  582. url: './searchCardList?type=2&Count=' + data.Count,
  583. })
  584. }
  585. });
  586. }
  587. },
  588. getLimitTimeStr: function () {
  589. var that = this;
  590. if (!that.data.LimitTime)
  591. that.data.LimitTime = common.formatTime(new Date());
  592. var LimitTime = common.formatTime(new Date(that.data.LimitTime),"-");
  593. if (that.data.PracticeTimeStr == PracticeTimeArr[1].Name)
  594. LimitTime = common.formatTime(common.addDate("w", 1, new Date(that.data.LimitTime)));
  595. else if (that.data.PracticeTimeStr == PracticeTimeArr[2].Name)
  596. LimitTime = common.formatTime(common.addDate("m", 1, new Date(that.data.LimitTime)));
  597. else if (that.data.PracticeTimeStr == PracticeTimeArr[3].Name)
  598. LimitTime = common.formatTime(common.addDate("m", 3, new Date(that.data.LimitTime)));
  599. //console.log(that.data.LimitTime);
  600. //console.log(new Date(that.data.LimitTime));
  601. //console.log(common.addDate("w", 1, new Date(that.data.LimitTime)));
  602. //console.log(LimitTime);
  603. return LimitTime
  604. },
  605. //段落编辑**************************
  606. //字段输入
  607. bindinputField: function (e) {
  608. //console.log("bindinputField:" + e.detail.value + " isEdit:" + isEdit);
  609. var that = this;
  610. if (app.globalData.IsAndroid && !isEdit) {
  611. return;
  612. }
  613. this.setData({
  614. FieldContent: e.detail.value,
  615. });
  616. },
  617. //加符号
  618. addSymbol: function (e) {
  619. //console.log("addSymbol");
  620. isEdit = true;
  621. var that = this;
  622. btnName = e.currentTarget.dataset.id;
  623. if (btnName == "[读]") {
  624. this.setData({
  625. SoundSign: "[/读]",
  626. });
  627. } else if (btnName == "[/读]") {
  628. this.setData({
  629. SoundSign: "[读]",
  630. });
  631. } else if (btnName == "[线]") {
  632. this.setData({
  633. LineSign: "[/线]",
  634. });
  635. } else if (btnName == "[/线]") {
  636. this.setData({
  637. LineSign: "[线]",
  638. });
  639. } else if (btnName == "[光]") {
  640. this.setData({
  641. HighlighterSign: "[/光]",
  642. });
  643. } else if (btnName == "[/光]") {
  644. this.setData({
  645. HighlighterSign: "[光]",
  646. });
  647. }
  648. if (btnName == "( )")
  649. btnName = "( )";
  650. else if (btnName == "_")
  651. btnName = "_____";
  652. //console.log("addSymbol_btnName:" + btnName);
  653. if (!this.data.Focus) {
  654. var obj = { detail: { cursor: tempCursor } };
  655. this.onBindblur(obj);
  656. }
  657. //console.log("addSymbol:" + this.data.FieldContent);
  658. setTimeout(function () {
  659. that.setData({
  660. Focus: true,
  661. });
  662. }, 300);
  663. },
  664. //焦点聚焦
  665. onBindFocus: function () {
  666. //console.log("onBindFocus");
  667. btnName = "";
  668. this.setData({
  669. Focus: true,
  670. });
  671. },
  672. //失焦
  673. onBindblur: function (e) {
  674. var that = this;
  675. //console.log("onBindblur:" + isEdit + " Filed:" + this.data.FieldContent);
  676. if (app.globalData.IsAndroid && !isEdit) {
  677. setTimeout(function () {
  678. isEdit = true;
  679. //console.log("onBindblur2:" + isEdit);
  680. }, 500);
  681. return;
  682. }
  683. isEdit = false;
  684. if (app.globalData.IsAndroid && !isEdit) {
  685. setTimeout(function () {
  686. isEdit = true;
  687. //console.log("onBindblur2:" + isEdit);
  688. }, 500);
  689. }
  690. //console.log("onBindblur:"+isEdit);
  691. this.updateField();
  692. tempCursor = e.detail.cursor;
  693. //console.log("tempCursor:" + tempCursor);
  694. if (tempCursor == undefined)
  695. tempCursor = this.data["FieldContent"].length;
  696. var str1 = "",
  697. str2 = "";
  698. if (this.data.FieldContent.length > 0) {
  699. str1 = this.data.FieldContent.substr(0, tempCursor);
  700. str2 = this.data.FieldContent.substring(tempCursor, this.data.FieldContent.length);
  701. }
  702. //console.log("str1:" + str1);
  703. //console.log("btnName:" + btnName);
  704. //console.log("str2:" + str2);
  705. var cur = 0;
  706. if (btnName) {
  707. cur = 1;
  708. if (btnName == "[读]" || btnName == "[线]" || btnName == "[光]") {
  709. cur = 3;
  710. } else if (btnName == "[/读]" || btnName == "[/线]" || btnName == "[/光]") {
  711. cur = 4;
  712. } else if (btnName === "( )") {
  713. cur = 7;
  714. } else if (btnName === "_____") {
  715. cur = 5;
  716. }
  717. }
  718. this.data.FieldContent = str1 + btnName + str2;
  719. this.setData({
  720. FieldContent: this.data.FieldContent,
  721. Focus: false,
  722. Cursor: tempCursor + cur,
  723. });
  724. btnName = "";
  725. },
  726. bindscrollHandler: function () {
  727. //console.log("bindscrollHandler");
  728. btnName = "";
  729. },
  730. onSearchField: function (e) {
  731. app.globalData.TempFieldNumber = this.data.FieldNumber;
  732. wx.navigateTo({
  733. url: './searchWeb',
  734. });
  735. this.updateField();
  736. setTimeout(function () {
  737. isEdit = true;
  738. //console.log("onSearchEnd");
  739. }, 1000);
  740. },
  741. clear: function () {
  742. var that = this;
  743. //console.log("clear");
  744. this.setData({
  745. FieldContent: "",
  746. Focus: true,
  747. Cursor: 0,
  748. });
  749. btnName = "";
  750. isEdit = false;
  751. this.updateField();
  752. },
  753. closeAddItem: function (e) {
  754. var that = this;
  755. var isSave = e.currentTarget.dataset.idsave;
  756. if (isSave == "true") {
  757. isUnload = false;
  758. if (that.data.FieldContent) {
  759. var content = that.data.FieldContent;
  760. main.postData("MsgSecCheck2",
  761. { Content: content, },
  762. function (data) {
  763. if (data && data.errcode == 0) {
  764. next(that);
  765. } else {
  766. if (data.errmsg) {
  767. wx.showToast({
  768. title: data.errmsg,
  769. duration: 2000,
  770. image: "../images/universalpic_wrong_white_120x120.png",
  771. });
  772. isViolate = true;
  773. }
  774. }
  775. });
  776. } else {
  777. next(that);
  778. }
  779. } else if (isSave == "false") {
  780. var content = wx.getStorageSync("TempCardInfoAddItem");
  781. this.setData({
  782. FieldContent: content,
  783. });
  784. next(that);
  785. }
  786. function next(obj) {
  787. isViolate = false;
  788. obj.updateField();
  789. obj.setData({
  790. HiddenFieldEdit: true,
  791. });
  792. var title = "编辑题卡";
  793. if (obj.data.UpdateType == "add2") {
  794. title = "添加题卡";
  795. }
  796. wx.setNavigationBarTitle({
  797. title: title,
  798. });
  799. }
  800. },
  801. updateField: function () {
  802. var str = this.data.FieldContent;
  803. var list = app.globalData.CardList;
  804. var card = {};
  805. for (var i = 0; i < list.length; i++) {
  806. if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  807. list[i].Content[this.data.FieldNumber].Content = str;
  808. card = main.changeStringToView(list[i].Content);
  809. break;
  810. }
  811. }
  812. app.globalData.CardList = list;
  813. this.setData({
  814. Field: card.Field,
  815. Tags: card.Tags,
  816. });
  817. },
  818. //选择图片上传
  819. uploadImageField: function () {
  820. //console.log("uploadImageStart");
  821. var that = this;
  822. //若是安卓机
  823. if (app.globalData.IsAndroid) {
  824. selectImage(that);
  825. } else {
  826. wx.showActionSheet({
  827. itemList: ['拍照', '从手机相册选择'],
  828. success(res) {
  829. if (res.tapIndex == 0) {
  830. wx.chooseImage({
  831. count: 1,
  832. sizeType: ['compressed'],
  833. sourceType: ['camera'],
  834. success(res2) {
  835. wx.showLoading({
  836. title: '请秒候',
  837. mask: true,
  838. });
  839. setTimeout(function () {
  840. wx.hideLoading();
  841. selectImage(that);
  842. }, 2000);
  843. },
  844. });
  845. } else if (res.tapIndex == 1) {
  846. selectImage(that);
  847. }
  848. },
  849. fail(res) {
  850. console.log(res.errMsg)
  851. }
  852. });
  853. }
  854. function selectImage(that) {
  855. var sizeType = ['album'];
  856. //若是安卓机
  857. if (app.globalData.IsAndroid)
  858. sizeType = ['album', 'camera'];
  859. wx.chooseImage({
  860. count: 1,
  861. sizeType: ['compressed'],
  862. sourceType: sizeType,
  863. success(res) {
  864. // tempFilePath可以作为img标签的src属性显示图片
  865. const tempFilePaths = res.tempFilePaths;
  866. //console.log(tempFilePaths[0]);
  867. //that.data.FieldContent = that.data.FieldContent + "[图 url='" + tempFilePaths[0] + "']" + tempFilePaths[0] + "[/图]";
  868. wx.getImageInfo({
  869. src: res.tempFilePaths[0],
  870. success(res) {
  871. //console.log(res.width)
  872. //console.log(res.height)
  873. if (tempCursor == undefined)
  874. tempCursor = that.data.FieldContent.length;
  875. var str1 = "",
  876. str2 = "";
  877. if (that.data.FieldContent.length > 0) {
  878. str1 = that.data.FieldContent.substr(0, tempCursor);
  879. str2 = that.data.FieldContent.substring(tempCursor, that.data.FieldContent.length);
  880. }
  881. var width = res.width;
  882. if (isNaN(width))
  883. width = 650;
  884. var height = res.height;
  885. if (isNaN(height))
  886. height = 650;
  887. var str0 = "[图 w='" + width + "' h='" + height + "']" + tempFilePaths[0] + "[/图]";
  888. that.data.FieldContent = str1 + str0 + str2;
  889. tempCursor = that.data.FieldContent.length;
  890. //console.log("uploadImageEnd:" + that.data.FieldContent);
  891. that.setData({
  892. FieldContent: that.data.FieldContent,
  893. Focus: false,
  894. });
  895. that.updateField();
  896. if (!wx.getStorageSync("NoRemindImage")) {
  897. wx.showModal({
  898. title: '图片已插到段落中',
  899. showCancel: true,
  900. content: "图片显示为[图...][/图]。如要移动到别的段落,剪切时请确保其完整性。",
  901. confirmText: "知道了",
  902. cancelText: "不再提示",
  903. confirmColor: "#0071EF",
  904. success(res) {
  905. if (res.confirm) { } else {
  906. wx.setStorageSync("NoRemindImage", true);
  907. }
  908. },
  909. });
  910. }
  911. }
  912. });
  913. },
  914. fail: function () {
  915. }
  916. });
  917. }
  918. },
  919. onPracticeTime: function (e) {
  920. var that = this;
  921. var value = e.currentTarget.dataset.value;
  922. that.data.IsShowPracticeTimeStart = true;
  923. if (that.data.IsShowPracticeTimeStart && value != "还原") {
  924. that.data.IsShowPracticeTimeStart = false;
  925. }
  926. that.setData({
  927. IsPracticeTime: false,
  928. PracticeTimeStr: value,
  929. IsShowPracticeTimeStart: that.data.IsShowPracticeTimeStart,
  930. });
  931. var PracticeTimeStr2 = common.formatDateCHS(common.formatTime(that.data.LimitTime));
  932. if (value != "还原")
  933. PracticeTimeStr2 = common.formatDateCHS(common.formatTime(that.getLimitTimeStr(value)));
  934. else
  935. if (that.data.UpdateType === "add" || that.data.UpdateType === "add2")
  936. PracticeTimeStr2 = "智能安排";
  937. that.setData({
  938. PracticeTimeStr2: PracticeTimeStr2,
  939. });
  940. },
  941. showPracticeTime: function () {
  942. this.setData({
  943. IsPracticeTime: true,
  944. });
  945. },
  946. closePracticeTime: function () {
  947. this.setData({
  948. IsPracticeTime: false,
  949. });
  950. },
  951. //录音授权
  952. recorderAccredit: function () {
  953. var that = this;
  954. if (app.globalData.IsRecorderAccredit == 1)
  955. that.showRecorder();
  956. else if (app.globalData.IsRecorderAccredit == 0) {
  957. recorderManager.stop();
  958. app.globalData.IsRecorderAccredit = 1;
  959. that.showRecorder();
  960. } else if (app.globalData.IsRecorderAccredit == -1) {
  961. wx.getSetting({
  962. success(res) {
  963. if (res.authSetting['scope.record'] === true) {
  964. app.globalData.IsRecorderAccredit = 1;
  965. that.showRecorder();
  966. } else if (res.authSetting['scope.record'] === false) {
  967. wx.navigateTo({
  968. url: '../index/openSetting',
  969. });
  970. }
  971. }
  972. });
  973. }
  974. },
  975. showRecorder: function () {
  976. var that = this;
  977. if (that.checkRecorderCount()) {
  978. that.recorderInit();
  979. tempRecorderFile = "";
  980. wx.setNavigationBarTitle({
  981. title: '录音',
  982. });
  983. that.setData({
  984. IsRecorder: true,
  985. IsRecorderFinished: false,
  986. BtnRecorderName: "按住录音",
  987. RecorderTime: "00:00",
  988. RecorderTimeCss: "",
  989. RecorderPlayName: "播放",
  990. });
  991. innerAudioContext = wx.createInnerAudioContext();
  992. innerAudioContext.onPlay(() => {
  993. console.log('开始播放');
  994. that.setData({
  995. RecorderTimeCss: "RecorderPanel1121",
  996. RecorderTime: "00:00",
  997. RecorderPlayName: "停止",
  998. });
  999. });
  1000. innerAudioContext.onEnded(() => {
  1001. console.log('结束播放');
  1002. clearInterval(intervalRecorder);
  1003. that.setData({
  1004. RecorderTime: "00:00",
  1005. RecorderTimeCss: "",
  1006. RecorderPlayName: "播放",
  1007. });
  1008. });
  1009. }
  1010. },
  1011. closeRecorder: function () {
  1012. var that = this;
  1013. this.recorderInit();
  1014. if (tempRecorderFile) {
  1015. wx.showModal({
  1016. title: '提醒',
  1017. content: '录音还没上传,要继续退出并放弃录音吗?',
  1018. showCancel: true,
  1019. confirmText: "取消",
  1020. cancelColor: "#000000",
  1021. cancelText: "继续",
  1022. confirmColor: "#000000",
  1023. success(res) {
  1024. if (res.cancel) {
  1025. closeRecorder2();
  1026. }
  1027. },
  1028. })
  1029. } else {
  1030. closeRecorder2();
  1031. }
  1032. function closeRecorder2() {
  1033. wx.setNavigationBarTitle({
  1034. title: '编辑 段落' + that.data.FieldNumber,
  1035. });
  1036. that.setData({
  1037. IsRecorder: false,
  1038. IsRecorderFinished: false,
  1039. });
  1040. tempRecorderFile = "";
  1041. }
  1042. },
  1043. //录音初始化
  1044. recorderInit: function () {
  1045. if (innerAudioContext)
  1046. innerAudioContext.stop();
  1047. if (recorderManager)
  1048. recorderManager.stop();
  1049. clearInterval(intervalRecorder);
  1050. },
  1051. checkRecorderCount: function (arr) {
  1052. var that = this;
  1053. var count = 0;
  1054. if (that.data.FieldContent.indexOf("[音 url=") >= 0 ||
  1055. that.data.FieldContent.indexOf("[/音]") >= 0) {
  1056. count = 1;
  1057. }
  1058. if (count > 0) {
  1059. wx.showToast({
  1060. title: '仅能上传一段',
  1061. });
  1062. return false;
  1063. } else
  1064. return true;
  1065. },
  1066. btnRecorderStart: function () {
  1067. var that = this;
  1068. if (app.globalData.IsRecorderAccredit == 1) {
  1069. that.setData({
  1070. BtnRecorderName: "松手结束",
  1071. RecorderTimeCss: "RecorderPanel1121",
  1072. });
  1073. that.showRecorderTime();
  1074. recorderManager.start();
  1075. }
  1076. },
  1077. btnRecorderEnd: function () {
  1078. var that = this;
  1079. if (app.globalData.IsRecorderAccredit == 1) {
  1080. if (that.data.RecorderTime == "00:00") {
  1081. //小于1秒处理
  1082. wx.showToast({
  1083. title: '时间过短',
  1084. image: "../images/universalpic_wrong_white_120x120.png",
  1085. });
  1086. that.showRecorder();
  1087. } else {
  1088. that.setData({
  1089. IsRecorderFinished: true,
  1090. RecorderTimeCss: "",
  1091. });
  1092. that.recorderInit();
  1093. }
  1094. } else {
  1095. that.recorderAccredit();
  1096. }
  1097. },
  1098. showRecorderTime: function () {
  1099. var that = this;
  1100. var second = 0;
  1101. clearInterval(intervalRecorder);
  1102. intervalRecorder = setInterval(function () {
  1103. second++;
  1104. var secondStr = second.toString();
  1105. if (second < 10)
  1106. secondStr = "0" + secondStr;
  1107. that.setData({
  1108. RecorderTime: "00:" + secondStr,
  1109. });
  1110. if (second >= 59) {
  1111. that.setData({
  1112. IsRecorderFinished: true,
  1113. RecorderTimeCss: "",
  1114. });
  1115. that.recorderInit();
  1116. if (that.data.RecorderPlayName == "播放") {
  1117. wx.showToast({
  1118. title: '录音超时',
  1119. image: "../images/universalpic_wrong_white_120x120.png",
  1120. });
  1121. }
  1122. }
  1123. }, 1000);
  1124. },
  1125. btnRecorderPlay: function () {
  1126. var that = this;
  1127. if (tempRecorderFile && this.data.RecorderPlayName == "播放") {
  1128. innerAudioContext.src = tempRecorderFile;
  1129. innerAudioContext.play();
  1130. this.showRecorderTime();
  1131. } else if (this.data.RecorderPlayName == "停止") {
  1132. if (innerAudioContext)
  1133. innerAudioContext.stop();
  1134. clearInterval(intervalRecorder);
  1135. that.setData({
  1136. RecorderTime: "00:00",
  1137. RecorderTimeCss: "",
  1138. RecorderPlayName: "播放",
  1139. });
  1140. }
  1141. },
  1142. btnRecorderSave: function () {
  1143. var that = this;
  1144. this.recorderInit();
  1145. wx.showLoading({
  1146. title: '上传中请稍候',
  1147. });
  1148. setTimeout(function () {
  1149. wx.hideLoading();
  1150. }, 60000);
  1151. that.uploadFileToServer(tempRecorderFile, function (data) {
  1152. if (data) {
  1153. data = JSON.parse(data);
  1154. //console.log(data);
  1155. wx.hideLoading();
  1156. var result = data.result;
  1157. result.Target = app.globalData.uploadImageUrl + result.Target;
  1158. that.data.FieldContent = that.data.FieldContent + "[音 url='" + result.Target + "'][/音]";
  1159. that.data.FieldContent = main.encryptUrl(that.data.FieldContent);
  1160. that.setData({
  1161. FieldContent: that.data.FieldContent,
  1162. });
  1163. tempRecorderFile = "";
  1164. that.closeRecorder();
  1165. if (!wx.getStorageSync("NoRemindRecorder")) {
  1166. wx.showModal({
  1167. title: '录音已插到段落中',
  1168. showCancel: true,
  1169. content: "录音显示为[音...][/音]。如要移动到别的段落,剪切时请确保其完整性。",
  1170. confirmText: "知道了",
  1171. cancelText: "不再提示",
  1172. confirmColor: "#0071EF",
  1173. success(res) {
  1174. if (res.confirm) { } else {
  1175. wx.setStorageSync("NoRemindRecorder", true);
  1176. }
  1177. },
  1178. });
  1179. }
  1180. }
  1181. });
  1182. },
  1183. gotoSymbol: function (e) {
  1184. wx.navigateTo({
  1185. url: '../main/symbolsetting',
  1186. });
  1187. },
  1188. gotoTest: function () {
  1189. var that=this;
  1190. if (that.data.Field[1].length > 0 || that.data.Field[2].length > 0 || that.data.Field[2].length > 0) {
  1191. wx.showModal({
  1192. title: '尚未保存',
  1193. content: '即将打开“知识检验”功能,但当前题卡尚未保存,按继续将放弃保存。',
  1194. confirmText: '继续',
  1195. success(res) {
  1196. if (res.confirm) {
  1197. wx.redirectTo({
  1198. url: '../test/index',
  1199. });
  1200. setTimeout(function(){
  1201. wx.removeStorageSync("TempCardNoSaved");
  1202. },1000);
  1203. }
  1204. }
  1205. });
  1206. }
  1207. else {
  1208. wx.redirectTo({
  1209. url: '../test/index',
  1210. });
  1211. }
  1212. },
  1213. onShareAppMessage: function () {
  1214. return {
  1215. title: app.globalData.ShareTitle,
  1216. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  1217. imageUrl: app.globalData.ShareImage,
  1218. }
  1219. },
  1220. })