searchWeb2.js 6.2 KB

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