searchWeb2.js 7.8 KB

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