searchWeb2.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. if (this.data.Result.CHN.HanZi)
  126. str = "[读 src='" + this.data.Result.CHN.HanZi + "']" + item.Content + "[/读]";
  127. else
  128. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  129. }
  130. else
  131. str = "[读]" + item.Content + "[/读]";
  132. }
  133. }
  134. else {
  135. if (item.Tag == "诗词" || item.Tag == "译文"){
  136. if (common.checkIsArray(item.Content)
  137. && common.checkIsArray(item.Content[0])){
  138. for (var j = 0; j < item.Content.length; j++) {
  139. if (common.checkIsArray(item.Content[j])){
  140. item.Content[j] = item.Content[j].join("");
  141. }
  142. }
  143. if (common.checkIsArray(item.Content))
  144. str = item.Content.join("\n");
  145. else
  146. str = item.Content;
  147. }
  148. else{
  149. if (common.checkIsArray(item.Content))
  150. str = item.Content.join("");
  151. else
  152. str = item.Content;
  153. }
  154. }
  155. else
  156. str = item.Content;
  157. }
  158. if (list[i].Content[item.Number].Content)
  159. str = "\n\n" + str;
  160. list[i].Content[item.Number].Content += str;
  161. }
  162. break;
  163. }
  164. }
  165. app.globalData.CardList = list;
  166. wx.navigateBack({
  167. delta: app.globalData.TempSearcchBackNumber,
  168. });
  169. }
  170. else {
  171. wx.showToast({
  172. title: '请选择内容',
  173. })
  174. }
  175. },
  176. changeBishun:function(e){
  177. var id=e.currentTarget.dataset.id;
  178. if (id === "0"){
  179. for (var i = 0; i < 6; i++) {
  180. delete this.data.CSS["CHN_BiShunArr2_" + i];
  181. }
  182. }
  183. else if (id === "1") {
  184. for (var i = 0; i < 6; i++) {
  185. delete this.data.CSS["CHN_KaitiArr_" + i];
  186. }
  187. }
  188. this.setData({
  189. ShowKaiti: id,
  190. CSS:this.data.CSS,
  191. });
  192. },
  193. openHelp: function () {
  194. this.setData({
  195. IsShowHelp: 0,
  196. });
  197. },
  198. close: function () {
  199. this.setData({
  200. IsShowHelp: 1,
  201. });
  202. wx.setStorageSync("IsShowHelp", 1);
  203. },
  204. onShareAppMessage: function () {
  205. return {
  206. title: app.globalData.ShareTitle,
  207. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  208. imageUrl: app.globalData.ShareImage,
  209. }
  210. },
  211. })