searchWeb2.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var hasStart = {};
  5. Page({
  6. data: {
  7. IsShowHelp: 1,
  8. ShowKaiti:0,
  9. CSS: {},
  10. },
  11. onLoad: function (options) {
  12. var that = this;
  13. that.setData({
  14. Containnerheight: main.getWindowHeight(),
  15. });
  16. this.getList();
  17. hasStart = {};
  18. },
  19. getList: function () {
  20. if (app.globalData.SearchItem) {
  21. this.getListFinished(app.globalData.SearchItem);
  22. }
  23. },
  24. getListFinished: function (data) {
  25. var that = this;
  26. if (data.ENG && data.ENG.Paraphrase && common.checkIsArray(data.ENG.Paraphrase)) {
  27. for (var i = 0; i < data.ENG.Paraphrase.length; i++) {
  28. var item = data.ENG.Paraphrase[i];
  29. item.PartOfSpeech = common.ReplaceAllString(item.PartOfSpeech, "释义", "");
  30. }
  31. }
  32. that.setData({
  33. Result: data,
  34. })
  35. },
  36. getInputData: function (e) {
  37. //console.log("time1:"+new Date().getTime());
  38. common.getStorageValue(this, "IsShowHelp", 0, function () {
  39. });
  40. var type = e.currentTarget.dataset.type;
  41. var css = e.currentTarget.dataset.css;
  42. var tag = e.currentTarget.dataset.tag;
  43. var content = e.currentTarget.dataset.content;
  44. var soundmark = e.currentTarget.dataset.soundmark;
  45. //console.log(content);
  46. //console.log("time2:" + new Date().getTime());
  47. if (!this.data.CSS[css] || this.data.CSS[css].Number == "") {
  48. if (!this.data.CSS[css])
  49. this.data.CSS[css] = {};
  50. this.data.CSS[css].Css1 = "Select1";
  51. this.data.CSS[css].Css2 = "Select2";
  52. this.data.CSS[css].Content = content;
  53. this.data.CSS[css].Type = type;
  54. this.data.CSS[css].Tag = tag;
  55. if (tag == "发音")
  56. this.data.CSS[css].SoundMark = soundmark;
  57. if (tag == "默写" || tag=="拼音") {
  58. var soundmark = e.currentTarget.dataset.soundmark;
  59. if (soundmark)
  60. this.data.CSS[css].SoundMark = e.currentTarget.dataset.soundmark;
  61. }
  62. this.data.CSS[css].Number = "1";
  63. if (app.globalData.TempFieldNumber > 0 && !hasStart[css]) {
  64. this.data.CSS[css].Number = app.globalData.TempFieldNumber;
  65. hasStart[css] = true;
  66. }
  67. }
  68. else if (this.data.CSS[css].Number == "3") {
  69. this.data.CSS[css].Css1 = "";
  70. this.data.CSS[css].Css2 = "";
  71. this.data.CSS[css].Number = "";
  72. this.data.CSS[css].Content = "";
  73. this.data.CSS[css].Type = "";
  74. this.data.CSS[css].Tag = "";
  75. }
  76. else {
  77. this.data.CSS[css].Number = Number(this.data.CSS[css].Number) + 1;
  78. }
  79. //console.log("time3:" + new Date().getTime());
  80. this.setData({
  81. CSS: this.data.CSS,
  82. });
  83. //console.log("time4:" + new Date().getTime());
  84. },
  85. addData: function () {
  86. if (JSON.stringify(this.data.CSS) != "{}") {
  87. for (var item in this.data.CSS) {
  88. if (this.data.CSS[item].Number == "") {
  89. delete this.data.CSS[item];
  90. }
  91. }
  92. app.globalData.TempFieldNumber = 0;
  93. var id = app.globalData.TempMiaoguoCardID;
  94. var list = app.globalData.CardList;
  95. for (var i = 0; i < list.length; i++) {
  96. if (id == list[i].MiaoguoCardID) {
  97. for (var key in this.data.CSS) {
  98. var item = this.data.CSS[key];
  99. if (item.Tag) {
  100. var strArrTag = list[i].Content[0].Content + ",";
  101. if (list[i].Content[0].Content.constructor == Array)
  102. strArrTag = list[i].Content[0].Content.join(",") + ",";
  103. else
  104. list[i].Content[0].Content = list[i].Content[0].Content.split(",");
  105. var tags = item.Tag.split(",");
  106. for (var j = 0; j < tags.length; j++) {
  107. if (tags[i]) {
  108. if (strArrTag.indexOf(tags[i] + ",") < 0)
  109. list[i].Content[0].Content.push(tags[i]);
  110. }
  111. }
  112. }
  113. var str = "";
  114. if (item.Type == "image") {
  115. item.Content = main.encryptUrl(item.Content);
  116. str = "[图]" + item.Content + "[/图]";
  117. }
  118. else if (item.Type == "sound") {
  119. str = "[读]" + item.Content + "[/读]";
  120. if (item.Tag == "发音") {
  121. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  122. }
  123. else if (item.Tag == "拼音" || item.Tag == "默写") {
  124. if (item.SoundMark)
  125. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  126. else
  127. str = "[读]" + item.Content + "[/读]";
  128. }
  129. }
  130. else {
  131. if (item.Tag == "诗词" || item.Tag == "译文"){
  132. if (common.checkIsArray(item.Content)
  133. && common.checkIsArray(item.Content[0])){
  134. for (var j = 0; j < item.Content.length; j++) {
  135. if (common.checkIsArray(item.Content[j])){
  136. item.Content[j] = item.Content[j].join("");
  137. }
  138. }
  139. if (common.checkIsArray(item.Content))
  140. str = item.Content.join("\n");
  141. else
  142. str = item.Content;
  143. }
  144. else{
  145. if (common.checkIsArray(item.Content))
  146. str = item.Content.join("");
  147. else
  148. str = item.Content;
  149. }
  150. }
  151. else
  152. str = item.Content;
  153. }
  154. if (list[i].Content[item.Number].Content)
  155. str = "\n\n" + str;
  156. list[i].Content[item.Number].Content += str;
  157. }
  158. break;
  159. }
  160. }
  161. app.globalData.CardList = list;
  162. wx.navigateBack({
  163. delta: app.globalData.TempSearcchBackNumber,
  164. });
  165. }
  166. else {
  167. wx.showToast({
  168. title: '请选择内容',
  169. })
  170. }
  171. },
  172. changeBishun:function(e){
  173. var id=e.currentTarget.dataset.id;
  174. this.setData({
  175. ShowKaiti: id,
  176. });
  177. },
  178. openHelp: function () {
  179. this.setData({
  180. IsShowHelp: 0,
  181. });
  182. },
  183. close: function () {
  184. this.setData({
  185. IsShowHelp: 1,
  186. });
  187. wx.setStorageSync("IsShowHelp", 1);
  188. },
  189. onShareAppMessage: function () {
  190. return {
  191. title: app.globalData.ShareTitle,
  192. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  193. imageUrl: app.globalData.ShareImage,
  194. }
  195. },
  196. })