searchWeb2.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. IsPoemRead: 0,
  9. ShowKaiti: 0,
  10. CSS: {},
  11. },
  12. onLoad: function (options) {
  13. var that = this;
  14. that.setData({
  15. Containnerheight: main.getWindowHeight(),
  16. });
  17. this.getList();
  18. hasStart = {};
  19. },
  20. getList: function () {
  21. if (app.globalData.SearchItem) {
  22. this.getListFinished(app.globalData.SearchItem);
  23. }
  24. },
  25. getListFinished: function (data) {
  26. var that = this;
  27. if (data.ENG && data.ENG.Paraphrase && common.checkIsArray(data.ENG.Paraphrase)) {
  28. for (var i = 0; i < data.ENG.Paraphrase.length; i++) {
  29. var item = data.ENG.Paraphrase[i];
  30. item.PartOfSpeech = common.ReplaceAllString(item.PartOfSpeech, "释义", "");
  31. }
  32. }
  33. if (data.ENG && data.ENG.ExamplesSentences){
  34. for (var i = 0; i < data.ENG.ExamplesSentences.length; i++) {
  35. var item = data.ENG.ExamplesSentences[i];
  36. var obj=[{ContentType:0,Content:""},{ContentType:1,Content:item[0]},{ContentType:2,Content:""},{ContentType:3,Content:""}];
  37. var obj2=main.changeStringToView(obj);
  38. var str=obj2.Field[1][0].Content;
  39. item.push(str);
  40. item[1]=common.ReplaceAllString(item[1],"<b>","");
  41. item[1]=common.ReplaceAllString(item[1],"</b>","");
  42. }
  43. }
  44. that.setData({
  45. Result: data,
  46. })
  47. },
  48. getInputData: function (e) {
  49. //console.log("time1:"+new Date().getTime());
  50. common.getStorageValue(this, "IsShowHelp", 0, function () {
  51. });
  52. var type = e.currentTarget.dataset.type;
  53. var css = e.currentTarget.dataset.css;
  54. var tag = e.currentTarget.dataset.tag;
  55. var content = e.currentTarget.dataset.content;
  56. var soundmark = e.currentTarget.dataset.soundmark;
  57. //console.log(content);
  58. //console.log("time2:" + new Date().getTime());
  59. if (!this.data.CSS[css] || this.data.CSS[css].Number == "") {
  60. if (!this.data.CSS[css])
  61. this.data.CSS[css] = {};
  62. this.data.CSS[css].Css1 = "Select1";
  63. this.data.CSS[css].Css2 = "Select2";
  64. this.data.CSS[css].Content = content;
  65. this.data.CSS[css].Type = type;
  66. this.data.CSS[css].Tag = tag;
  67. if (tag == "发音")
  68. this.data.CSS[css].SoundMark = soundmark;
  69. if (tag == "默写" || tag=="拼音") {
  70. var soundmark = e.currentTarget.dataset.soundmark;
  71. if (soundmark)
  72. this.data.CSS[css].SoundMark = e.currentTarget.dataset.soundmark;
  73. }
  74. this.data.CSS[css].Number = "1";
  75. if (app.globalData.TempFieldNumber > 0 && !hasStart[css]) {
  76. this.data.CSS[css].Number = app.globalData.TempFieldNumber;
  77. hasStart[css] = true;
  78. }
  79. }
  80. else if (this.data.CSS[css].Number == "3") {
  81. this.data.CSS[css].Css1 = "";
  82. this.data.CSS[css].Css2 = "";
  83. this.data.CSS[css].Number = "";
  84. this.data.CSS[css].Content = "";
  85. this.data.CSS[css].Type = "";
  86. this.data.CSS[css].Tag = "";
  87. }
  88. else {
  89. this.data.CSS[css].Number = Number(this.data.CSS[css].Number) + 1;
  90. }
  91. //console.log("time3:" + new Date().getTime());
  92. this.setData({
  93. CSS: this.data.CSS,
  94. });
  95. //console.log("time4:" + new Date().getTime());
  96. },
  97. addData: function () {
  98. if (JSON.stringify(this.data.CSS) != "{}") {
  99. for (var item in this.data.CSS) {
  100. if (this.data.CSS[item].Number == "") {
  101. delete this.data.CSS[item];
  102. }
  103. }
  104. app.globalData.TempFieldNumber = 0;
  105. var id = app.globalData.TempMiaoguoCardID;
  106. var list = app.globalData.CardList;
  107. for (var i = 0; i < list.length; i++) {
  108. if (id == list[i].MiaoguoCardID) {
  109. for (var key in this.data.CSS) {
  110. var item = this.data.CSS[key];
  111. if (item.Tag) {
  112. var strArrTag = list[i].Content[0].Content + ",";
  113. if (list[i].Content[0].Content.constructor == Array)
  114. strArrTag = list[i].Content[0].Content.join(",") + ",";
  115. else
  116. list[i].Content[0].Content = list[i].Content[0].Content.split(",");
  117. var tags = item.Tag.split(",");
  118. for (var j = 0; j < tags.length; j++) {
  119. if (tags[i]) {
  120. if (strArrTag.indexOf(tags[i] + ",") < 0)
  121. list[i].Content[0].Content.push(tags[i]);
  122. }
  123. }
  124. }
  125. var str = "";
  126. if (item.Type == "image") {
  127. item.Content = main.encryptUrl(item.Content);
  128. str = "[图]" + item.Content + "[/图]";
  129. }
  130. else if (item.Type == "sound") {
  131. str = "[读]" + item.Content + "[/读]";
  132. if (item.Tag == "发音") {
  133. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  134. }
  135. else if (item.Tag == "拼音" || item.Tag == "默写") {
  136. if (item.SoundMark){
  137. if (this.data.Result.CHN.HanZi)
  138. str = "[读 src='" + this.data.Result.CHN.HanZi + "']" + item.Content + "[/读]";
  139. else
  140. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  141. }
  142. else
  143. str = "[读]" + item.Content + "[/读]";
  144. }
  145. }
  146. else {
  147. if (item.Tag == "诗词" || item.Tag == "译文"){
  148. if (common.checkIsArray(item.Content)
  149. && common.checkIsArray(item.Content[0])){
  150. for (var j = 0; j < item.Content.length; j++) {
  151. if (common.checkIsArray(item.Content[j])){
  152. item.Content[j] = item.Content[j].join("");
  153. }
  154. }
  155. if (common.checkIsArray(item.Content))
  156. str = item.Content.join("\n");
  157. else
  158. str = item.Content;
  159. }
  160. else{
  161. if (common.checkIsArray(item.Content))
  162. str = item.Content.join("");
  163. else
  164. str = item.Content;
  165. }
  166. if (item.Tag == "诗词" && this.data.IsPoemRead==1){
  167. var arr=str.split("\n");
  168. var arr2=[];
  169. for(var j=0;j<arr.length;j++){
  170. arr2.push("[读]" +arr[j]+ "[/读]");
  171. }
  172. str=arr2.join("\n");
  173. }
  174. }
  175. else
  176. str = item.Content;
  177. }
  178. if (this.data.Result && this.data.Result.CHN && this.data.Result.CHN.PinYin && this.data.Result.CHN.PinYin.length == 1){
  179. if (item.Tag=="释义"){
  180. str=str.substr(str.indexOf("[/读]")+4);
  181. }
  182. }
  183. if (list[i].Content[item.Number].Content){
  184. if (item.Tag == "组词" || item.Tag == "近义词" || item.Tag == "反义词"){
  185. str = " " + str;
  186. }
  187. else{
  188. str = "\n\n" + str;
  189. }
  190. }
  191. list[i].Content[item.Number].Content += str;
  192. if (list[i].Content[item.Number].Content.indexOf("\n\n")==0)
  193. list[i].Content[item.Number].Content=list[i].Content[item.Number].Content.substr(2);
  194. if (item.Tag == "诗词"){
  195. if (list[i].Content[item.Number].Content.indexOf("\n")>0 && list[i].Content[item.Number].Content.indexOf("[")!=0){
  196. list[i].Content[item.Number].Content="\n\n"+list[i].Content[item.Number].Content;
  197. }
  198. }
  199. }
  200. break;
  201. }
  202. }
  203. app.globalData.CardList = list;
  204. wx.navigateBack({
  205. delta: app.globalData.TempSearchBackNumber,
  206. });
  207. }
  208. else {
  209. wx.showToast({
  210. title: '请选择内容',
  211. })
  212. }
  213. },
  214. changeBishun:function(e){
  215. var id=e.currentTarget.dataset.id;
  216. if (id === "0"){
  217. for (var i = 0; i < 6; i++) {
  218. delete this.data.CSS["CHN_BiShunArr2_" + i];
  219. }
  220. }
  221. else if (id === "1") {
  222. for (var i = 0; i < 6; i++) {
  223. delete this.data.CSS["CHN_KaitiArr_" + i];
  224. }
  225. }
  226. this.setData({
  227. ShowKaiti: id,
  228. CSS:this.data.CSS,
  229. });
  230. },
  231. changeRead: function (e) {
  232. var id = e.currentTarget.dataset.id;
  233. this.setData({
  234. IsPoemRead: id,
  235. });
  236. },
  237. openHelp: function () {
  238. this.setData({
  239. IsShowHelp: 0,
  240. });
  241. },
  242. close: function () {
  243. this.setData({
  244. IsShowHelp: 1,
  245. });
  246. wx.setStorageSync("IsShowHelp", 1);
  247. },
  248. onShareAppMessage: function () {
  249. return {
  250. title: app.globalData.ShareTitle,
  251. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  252. imageUrl: app.globalData.ShareImage,
  253. }
  254. },
  255. })