searchWeb2.js 9.1 KB

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