add.js 33 KB

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