addItem.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var tempCursor = 0,
  5. btnName = "";
  6. var arrSoundMark = [];
  7. var isUnload = true;
  8. var isEdit = true;
  9. Page({
  10. data: {
  11. Field: "",
  12. SoundSign: "[读]",
  13. LineSign: "[线]",
  14. BtnArray: ["+", "-", "×", "÷", "=", "<", ">"],
  15. },
  16. onLoad: function (options) {
  17. wx.hideShareMenu();
  18. var id = options.id;
  19. var fieldid = options.fieldid;
  20. tempCursor = 0, btnName = "", arrSoundMark = [];
  21. var that = this;
  22. that.setData({
  23. MiaoguoCardID: id,
  24. Focus: true,
  25. FieldNumber: fieldid,
  26. Containnerheight: main.getWindowHeight(),
  27. });
  28. wx.setNavigationBarTitle({
  29. title: '编辑 段落' + fieldid,
  30. });
  31. },
  32. onShow: function () {
  33. //console.log("onShow");
  34. var that = this;
  35. //console.log("onShow:" + isEdit);
  36. if (app.globalData.IsAndroid && !isEdit) {
  37. return;
  38. }
  39. var list = app.globalData.CardList;
  40. var card = {};
  41. for (var i = 0; i < list.length; i++) {
  42. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  43. var content = main.encryptUrl(list[i].Content[this.data.FieldNumber].Content);
  44. this.setData({
  45. Field: content,
  46. });
  47. if (!wx.getStorageSync("TempCardInfoAddItem")) {
  48. wx.setStorageSync("TempCardInfoAddItem", content);
  49. }
  50. break;
  51. }
  52. }
  53. isUnload = true;
  54. },
  55. onUnload: function () {
  56. if (isUnload) {
  57. var content = wx.getStorageSync("TempCardInfoAddItem");
  58. if (content != undefined) {
  59. this.updateField(content);
  60. wx.removeStorageSync("TempCardInfoAddItem");
  61. }
  62. }
  63. isEdit = true;
  64. },
  65. bindinputField: function (e) {
  66. console.log("bindinputField:" + e.detail.value + " isEdit:" + isEdit);
  67. var that = this;
  68. if (app.globalData.IsAndroid && !isEdit) {
  69. return;
  70. }
  71. this.setData({
  72. Field: e.detail.value,
  73. });
  74. //this.updateField();
  75. },
  76. addSymbol: function (e) {
  77. //console.log("addSymbol");
  78. isEdit = true;
  79. var that = this;
  80. btnName = e.currentTarget.dataset.id;
  81. if (btnName == "[读]") {
  82. this.setData({
  83. SoundSign: "[/读]",
  84. });
  85. } else if (btnName == "[/读]") {
  86. this.setData({
  87. SoundSign: "[读]",
  88. });
  89. } else if (btnName == "[线]") {
  90. this.setData({
  91. LineSign: "[/线]",
  92. });
  93. } else if (btnName == "[/线]") {
  94. this.setData({
  95. LineSign: "[线]",
  96. });
  97. }
  98. if (!this.data.Focus) {
  99. this.data.Field = this.data.Field + btnName;
  100. this.setData({
  101. Field: this.data.Field,
  102. });
  103. }
  104. //console.log("addSymbol:" + this.data.Field);
  105. setTimeout(function () {
  106. that.setData({
  107. Focus: true,
  108. });
  109. }, 300);
  110. },
  111. onBindFocus: function () {
  112. this.setData({
  113. Focus: true,
  114. });
  115. },
  116. onBindblur: function (e) {
  117. var that = this;
  118. //console.log("onBindblur:" + isEdit + " Filed:" + this.data.Field);
  119. if (app.globalData.IsAndroid && !isEdit) {
  120. setTimeout(function () {
  121. isEdit = true;
  122. console.log("onBindblur2:" + isEdit);
  123. }, 500);
  124. return;
  125. }
  126. isEdit = false;
  127. if (app.globalData.IsAndroid && !isEdit) {
  128. setTimeout(function () {
  129. isEdit = true;
  130. console.log("onBindblur2:" + isEdit);
  131. }, 500);
  132. }
  133. //console.log("onBindblur:"+isEdit);
  134. this.updateField();
  135. tempCursor = e.detail.cursor;
  136. //console.log("tempCursor:" + tempCursor);
  137. if (tempCursor == undefined)
  138. tempCursor = this.data["Field"].length;
  139. var str1 = "",
  140. str2 = "";
  141. if (this.data.Field.length > 0) {
  142. str1 = this.data.Field.substr(0, tempCursor);
  143. str2 = this.data.Field.substring(tempCursor, this.data.Field.length);
  144. }
  145. //console.log("str1:" + str1);
  146. //console.log("str2:" + str2);
  147. var cur = 1;
  148. if (btnName == "[读]" || btnName == "[线]") {
  149. cur = 3;
  150. } else if (btnName == "[/读]" || btnName == "[/线]") {
  151. cur = 4;
  152. } else if (btnName == "(   )") {
  153. cur = 5;
  154. } else if (btnName == "_____") {
  155. cur = 5;
  156. }
  157. this.data.Field = str1 + btnName + str2;
  158. this.setData({
  159. Field: this.data.Field,
  160. Focus: false,
  161. Cursor: tempCursor + cur,
  162. });
  163. btnName = "";
  164. },
  165. onSearch: function (e) {
  166. wx.setStorageSync("TempFieldNumber", this.data.FieldNumber);
  167. wx.navigateTo({
  168. url: './searchWeb',
  169. });
  170. this.updateField();
  171. setTimeout(function () {
  172. isEdit = true;
  173. //console.log("onSearchEnd");
  174. }, 1000);
  175. },
  176. clear: function () {
  177. var that = this;
  178. //console.log("clear");
  179. this.setData({
  180. Field: "",
  181. Focus: true,
  182. Cursor: 0,
  183. });
  184. btnName = "";
  185. isEdit = false;
  186. this.updateField();
  187. },
  188. closeAddItem: function (e) {
  189. var isSave = e.currentTarget.dataset.idsave;
  190. if (isSave == "true") {
  191. isUnload = false;
  192. wx.removeStorageSync("TempCardInfoAddItem");
  193. this.updateField();
  194. }
  195. wx.navigateBack({
  196. delta: 1,
  197. });
  198. },
  199. uploadImage: function () {
  200. //console.log("uploadImageStart");
  201. var that = this;
  202. wx.chooseImage({
  203. count: 1,
  204. sizeType: ['compressed'],
  205. sourceType: ['album', 'camera'],
  206. success(res) {
  207. // tempFilePath可以作为img标签的src属性显示图片
  208. const tempFilePaths = res.tempFilePaths;
  209. //console.log(tempFilePaths[0]);
  210. //that.data.Field = that.data.Field + "[图 url='" + tempFilePaths[0] + "']" + tempFilePaths[0] + "[/图]";
  211. if (tempCursor == undefined)
  212. tempCursor = that.data.Field.length;
  213. var str1 = "",
  214. str2 = "";
  215. if (that.data.Field.length > 0) {
  216. str1 = that.data.Field.substr(0, tempCursor);
  217. str2 = that.data.Field.substring(tempCursor, that.data.Field.length);
  218. }
  219. var str0 = "[图]" + tempFilePaths[0] + "[/图]";
  220. that.data.Field = str1 + str0 + str2;
  221. //console.log("uploadImageEnd:" + that.data.Field);
  222. that.setData({
  223. Field: that.data.Field,
  224. Focus: false,
  225. });
  226. that.updateField();
  227. },
  228. fail: function () {
  229. }
  230. });
  231. },
  232. updateField: function (history) {
  233. var str = this.data.Field;
  234. str = main.decryptUrl(str);
  235. str = str.replace(/\[读\]/g, "\n[读]");
  236. str = str.replace(/\[图\]/g, "\n[图]");
  237. str = str.replace(/\[\/读\]/g, "[\/读]\n");
  238. str = str.replace(/\[\/图\]/g, "[\/图]\n");
  239. str = str.replace(/\n\n/g, "\n");
  240. var list = app.globalData.CardList;
  241. for (var i = 0; i < list.length; i++) {
  242. if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  243. if (history != undefined)
  244. list[i].Content[this.data.FieldNumber].Content = history;
  245. else
  246. list[i].Content[this.data.FieldNumber].Content = str;
  247. break;
  248. }
  249. }
  250. app.globalData.CardList=list;
  251. },
  252. onShareAppMessage: function () {
  253. return {
  254. title: app.globalData.ShareTitle,
  255. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  256. imageUrl: app.globalData.ShareImage,
  257. }
  258. },
  259. })