addInfomationDetail.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. var hasStart = {};
  5. Page({
  6. data: {
  7. ImagePath: app.globalData.uploadImageUrl,
  8. IsShowHelp: 1,
  9. IsPoemRead: 0,
  10. ShowKaiti: 0,
  11. ShowSoundMark:1,
  12. CSS: {},
  13. IsHelp:false,
  14. HelpArr:["help_board_tips_zhidingduanluo","help_board_tips_tiaozhuanchaxun"],
  15. },
  16. onLoad: function (options) {
  17. var that = this;
  18. that.setData({
  19. Containnerheight: main.getWindowHeight(),
  20. });
  21. this.getList();
  22. hasStart = {};
  23. },
  24. getList: function () {
  25. if (app.globalData.SearchItem) {
  26. this.getListFinished(app.globalData.SearchItem);
  27. }
  28. },
  29. getListFinished: function (data) {
  30. var that = this;
  31. if (data.CHN) {
  32. if (data.CHN.PeomContent)
  33. data.TypeName = "S";
  34. else if (data.CHN.HanZi.length == 1)
  35. data.TypeName = "Z";
  36. else
  37. data.TypeName = "C";
  38. } else if (data.ENG) {
  39. data.TypeName = "D";
  40. }
  41. if (data.CHN && data.CHN.KaitiArr) {
  42. if (data.CHN.KaitiArr.length==1){
  43. data.CHN.KaitiWidth="";
  44. }
  45. else{
  46. data.CHN.KaitiWidth="panelItemSmall";
  47. }
  48. if (data.CHN.BiShunArr2.length==1){
  49. data.CHN.BiShunWidth="";
  50. }
  51. else{
  52. data.CHN.BiShunWidth="panelItemSmall";
  53. }
  54. }
  55. if (data.ENG && data.ENG.Paraphrase && common.checkIsArray(data.ENG.Paraphrase)) {
  56. for (var i = 0; i < data.ENG.Paraphrase.length; i++) {
  57. var item = data.ENG.Paraphrase[i];
  58. item.PartOfSpeech = common.ReplaceAllString(item.PartOfSpeech, "释义", "");
  59. }
  60. }
  61. if (data.ENG && data.ENG.ExamplesSentences){
  62. for (var i = 0; i < data.ENG.ExamplesSentences.length; i++) {
  63. var item = data.ENG.ExamplesSentences[i];
  64. var obj=[{ContentType:0,Content:""},{ContentType:1,Content:item[0]},{ContentType:2,Content:""},{ContentType:3,Content:""}];
  65. var obj2=main.changeStringToView(obj);
  66. var str=obj2.Field[1][0].Content;
  67. item.push(str);
  68. item[1]=common.ReplaceAllString(item[1],"<b>","");
  69. item[1]=common.ReplaceAllString(item[1],"</b>","");
  70. }
  71. }
  72. that.setData({
  73. Result: data,
  74. })
  75. },
  76. getInputData: function (e) {
  77. //console.log("time1:"+new Date().getTime());
  78. common.getStorageValue(this, "IsShowHelp", 0, function () {
  79. });
  80. var type = e.currentTarget.dataset.type;
  81. var css = e.currentTarget.dataset.css;
  82. var tag = e.currentTarget.dataset.tag;
  83. var content = e.currentTarget.dataset.content;
  84. var soundmark = e.currentTarget.dataset.soundmark;
  85. //console.log(content);
  86. //console.log("time2:" + new Date().getTime());
  87. if (!this.data.CSS[css] || this.data.CSS[css].Number == "") {
  88. if (!this.data.CSS[css])
  89. this.data.CSS[css] = {};
  90. this.data.CSS[css].Css1 = "Select1";
  91. this.data.CSS[css].Css2 = "Select2";
  92. this.data.CSS[css].Content = content;
  93. this.data.CSS[css].Type = type;
  94. this.data.CSS[css].Tag = tag;
  95. if (tag == "发音")
  96. this.data.CSS[css].SoundMark = soundmark;
  97. if (tag == "默写" || tag=="拼音") {
  98. var soundmark = e.currentTarget.dataset.soundmark;
  99. if (soundmark)
  100. this.data.CSS[css].SoundMark = e.currentTarget.dataset.soundmark;
  101. }
  102. this.data.CSS[css].Number = "1";
  103. if (app.globalData.TempFieldNumber > 0 && !hasStart[css]) {
  104. this.data.CSS[css].Number = app.globalData.TempFieldNumber;
  105. hasStart[css] = true;
  106. }
  107. }
  108. else if (this.data.CSS[css].Number == "3") {
  109. this.data.CSS[css].Css1 = "";
  110. this.data.CSS[css].Css2 = "";
  111. this.data.CSS[css].Number = "";
  112. this.data.CSS[css].Content = "";
  113. this.data.CSS[css].Type = "";
  114. this.data.CSS[css].Tag = "";
  115. }
  116. else {
  117. this.data.CSS[css].Number = Number(this.data.CSS[css].Number) + 1;
  118. }
  119. //console.log("time3:" + new Date().getTime());
  120. this.setData({
  121. CSS: this.data.CSS,
  122. });
  123. //console.log("time4:" + new Date().getTime());
  124. },
  125. addData: function () {
  126. if (JSON.stringify(this.data.CSS) != "{}") {
  127. for (var item in this.data.CSS) {
  128. if (this.data.CSS[item].Number == "") {
  129. delete this.data.CSS[item];
  130. }
  131. }
  132. app.globalData.TempFieldNumber = 0;
  133. var id = app.globalData.TempMiaoguoCardID;
  134. var list = app.globalData.CardList;
  135. for (var i = 0; i < list.length; i++) {
  136. if (id == list[i].MiaoguoCardID) {
  137. for (var key in this.data.CSS) {
  138. var item = this.data.CSS[key];
  139. if (item.Tag) {
  140. var strArrTag = list[i].Content[0].Content + ",";
  141. if (list[i].Content[0].Content.constructor == Array)
  142. strArrTag = list[i].Content[0].Content.join(",") + ",";
  143. else
  144. list[i].Content[0].Content = list[i].Content[0].Content.split(",");
  145. var tags = item.Tag.split(",");
  146. for (var j = 0; j < tags.length; j++) {
  147. if (tags[i]) {
  148. if (strArrTag.indexOf(tags[i] + ",") < 0)
  149. list[i].Content[0].Content.push(tags[i]);
  150. }
  151. }
  152. }
  153. var str = "";
  154. if (item.Type == "image") {
  155. item.Content = main.encryptUrl(item.Content);
  156. str = "[图]" + item.Content + "[/图]";
  157. }
  158. else if (item.Type == "sound") {
  159. str = "[读]" + item.Content + "[/读]";
  160. if (item.Tag == "发音") {
  161. var strTemp=item.Content.substr(0,1);
  162. if (this.data.ShowSoundMark=="1")
  163. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  164. else
  165. str = "[读 src='" + item.SoundMark + "']"+strTemp+"式[/读]";
  166. }
  167. else if (item.Tag == "拼音" || item.Tag == "默写") {
  168. if (item.SoundMark){
  169. if (this.data.Result.CHN.HanZi)
  170. str = "[读 src='" + this.data.Result.CHN.HanZi + "']" + item.Content + "[/读]";
  171. else
  172. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  173. }
  174. else
  175. str = "[读 src='"+this.data.Result.CHN.HanZi+"("+ main.getPinyinNormal(item.Content) +")"+"']" + item.Content + "[/读]";
  176. }
  177. }
  178. else {
  179. if (item.Tag == "诗词" || item.Tag == "译文"){
  180. if (common.checkIsArray(item.Content)
  181. && common.checkIsArray(item.Content[0])){
  182. for (var j = 0; j < item.Content.length; j++) {
  183. if (common.checkIsArray(item.Content[j])){
  184. item.Content[j] = item.Content[j].join("");
  185. }
  186. }
  187. if (common.checkIsArray(item.Content))
  188. str = item.Content.join("\n");
  189. else
  190. str = item.Content;
  191. }
  192. else{
  193. if (common.checkIsArray(item.Content))
  194. str = item.Content.join("");
  195. else
  196. str = item.Content;
  197. }
  198. if (item.Tag == "诗词" && this.data.IsPoemRead==1){
  199. var arr=str.split("\n");
  200. var arr2=[];
  201. for(var j=0;j<arr.length;j++){
  202. arr2.push("[读]" +arr[j]+ "[/读]");
  203. }
  204. str=arr2.join("\n");
  205. }
  206. }
  207. else
  208. str = item.Content;
  209. }
  210. if (this.data.Result && this.data.Result.CHN && this.data.Result.CHN.PinYin && this.data.Result.CHN.PinYin.length == 1){
  211. if (item.Tag=="释义"){
  212. str=str.substr(str.indexOf("[/读]")+4);
  213. }
  214. }
  215. if (list[i].Content[item.Number].Content){
  216. if (item.Tag == "组词" || item.Tag == "近义词" || item.Tag == "反义词"){
  217. str = " " + str;
  218. }
  219. else{
  220. str = "\n\n" + str;
  221. }
  222. }
  223. list[i].Content[item.Number].Content += str;
  224. if (list[i].Content[item.Number].Content.indexOf("\n\n")==0)
  225. list[i].Content[item.Number].Content=list[i].Content[item.Number].Content.substr(2);
  226. if (item.Tag == "诗词"){
  227. if (list[i].Content[item.Number].Content.indexOf("\n")>0 && list[i].Content[item.Number].Content.indexOf("[")!=0){
  228. list[i].Content[item.Number].Content="\n\n"+list[i].Content[item.Number].Content;
  229. }
  230. }
  231. }
  232. break;
  233. }
  234. }
  235. app.globalData.CardList = list;
  236. wx.navigateBack({
  237. delta: app.globalData.TempSearchBackNumber,
  238. });
  239. }
  240. else {
  241. wx.showToast({
  242. title: '请选择内容',
  243. })
  244. }
  245. },
  246. changeBishun:function(e){
  247. var id=e.currentTarget.dataset.id;
  248. if (id === "0"){
  249. for (var i = 0; i < 6; i++) {
  250. delete this.data.CSS["CHN_BiShunArr2_" + i];
  251. }
  252. }
  253. else if (id === "1") {
  254. for (var i = 0; i < 6; i++) {
  255. delete this.data.CSS["CHN_KaitiArr_" + i];
  256. }
  257. }
  258. this.setData({
  259. ShowKaiti: id,
  260. CSS:this.data.CSS,
  261. });
  262. },
  263. changeSoundMark:function(e){
  264. var id=e.currentTarget.dataset.id;
  265. this.setData({
  266. ShowSoundMark: id,
  267. });
  268. },
  269. changeRead: function (e) {
  270. var id = e.currentTarget.dataset.id;
  271. var count=Object.getOwnPropertyNames(this.data.CSS).length;
  272. for (var i=0;i<count;i++) {
  273. delete this.data.CSS["CHN_PeomContent_" + i];
  274. }
  275. delete this.data.CSS["CHN_PeomContent"];
  276. this.setData({
  277. IsPoemRead: id,
  278. CSS:this.data.CSS,
  279. });
  280. },
  281. changeInfomation:function(e){
  282. var word=e.currentTarget.dataset.word;
  283. if (word.indexOf(";")>0){
  284. word=word.substr(0,word.indexOf(";"));
  285. }
  286. var url = 'GetMiaoguoAISearch2?UserID=' + app.globalData.userInfo.UserID;
  287. url += "&Word=" + word;
  288. if (!e.currentTarget.dataset.ischn)
  289. url += "&SearchType=zici";
  290. wx.showLoading();
  291. main.getData(url, function (data) {
  292. wx.hideLoading();
  293. if (data && (data.CHN || data.ENG)){
  294. var obj={};
  295. var len = 26;
  296. obj.Value=data;
  297. if (data.CHN){
  298. obj.Key=data.CHN.HanZi;
  299. obj.Content=data.CHN.PinYin[0].explain;
  300. if (obj.Key.length==1)
  301. obj.TypeName="Z";
  302. else
  303. obj.TypeName="C";
  304. obj.Url="&UserID="+app.globalData.userInfo.UserID+"&Word="+obj.Key;
  305. }
  306. else if (data.ENG){
  307. obj.Key=data.ENG.Word;
  308. obj.TypeName="D";
  309. if (data.ENG.Soundmark)
  310. obj.Remark=data.ENG.Soundmark.Eng;
  311. obj.Content=data.ENG.Paraphrase[0].ParaphraseList;
  312. obj.Url="&UserID="+app.globalData.userInfo.UserID+"&Word="+obj.Key;
  313. }
  314. if (data.CHN && data.CHN.PinYin && data.CHN.PinYin.length>0){
  315. obj.Remark=data.CHN.PinYin[0].pinyin;
  316. }
  317. if (obj.Content && obj.Content.length > len)
  318. obj.Content = obj.Content.substr(0, len) + "...";
  319. main.updateSearchList(obj);
  320. if (app.globalData.TempSearchBackNumber==0)
  321. app.globalData.TempSearchBackNumber=1;
  322. else if (app.globalData.TempSearchBackNumber>=1)
  323. app.globalData.TempSearchBackNumber=2;
  324. wx.redirectTo({
  325. url: './addInfomationDetail',
  326. });
  327. }
  328. else{
  329. wx.showToast({
  330. title: '无资料',
  331. image: "../images/universalpic_exclamation_white_120x120.png",
  332. });
  333. }
  334. });
  335. },
  336. openHelp: function () {
  337. this.setData({
  338. IsShowHelp: 0,
  339. });
  340. },
  341. showHelp: function () {
  342. var that = this;
  343. that.setData({
  344. IsHelp: true,
  345. });
  346. },
  347. closeHelp: function () {
  348. this.setData({
  349. IsHelp: false,
  350. });
  351. },
  352. onShareAppMessage: function () {
  353. return {
  354. title: app.globalData.ShareTitle,
  355. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  356. imageUrl: app.globalData.ShareImage,
  357. }
  358. },
  359. })