addInfomationDetail.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. var sound=this.data.Result.CHN.HanZi;
  171. sound=main.GetSoundError(sound);
  172. str = "[读 src='" + sound + "']" + item.Content + "[/读]";
  173. }
  174. else
  175. str = "[读 src='" + item.SoundMark + "']" + item.Content + "[/读]";
  176. }
  177. else{
  178. var sound=this.data.Result.CHN.HanZi+"("+ main.getPinyinNormal(item.Content) +")";
  179. sound=main.GetSoundError(sound);
  180. str = "[读 src='"+sound+"']" + item.Content + "[/读]";
  181. }
  182. }
  183. }
  184. else {
  185. if (item.Tag == "诗词" || item.Tag == "译文"){
  186. if (common.checkIsArray(item.Content)
  187. && common.checkIsArray(item.Content[0])){
  188. for (var j = 0; j < item.Content.length; j++) {
  189. if (common.checkIsArray(item.Content[j])){
  190. item.Content[j] = item.Content[j].join("");
  191. }
  192. }
  193. if (common.checkIsArray(item.Content))
  194. str = item.Content.join("\n");
  195. else
  196. str = item.Content;
  197. }
  198. else{
  199. if (common.checkIsArray(item.Content))
  200. str = item.Content.join("");
  201. else
  202. str = item.Content;
  203. }
  204. if (item.Tag == "诗词" && this.data.IsPoemRead==1){
  205. var arr=str.split("\n");
  206. var arr2=[];
  207. for(var j=0;j<arr.length;j++){
  208. arr2.push("[读]" +arr[j]+ "[/读]");
  209. }
  210. str=arr2.join("\n");
  211. }
  212. }
  213. else
  214. str = item.Content;
  215. }
  216. if (this.data.Result && this.data.Result.CHN && this.data.Result.CHN.PinYin && this.data.Result.CHN.PinYin.length == 1){
  217. if (item.Tag=="释义"){
  218. str=str.substr(str.indexOf("[/读]")+4);
  219. }
  220. }
  221. if (list[i].Content[item.Number].Content){
  222. if (item.Tag == "组词" || item.Tag == "近义词" || item.Tag == "反义词"){
  223. str = " " + str;
  224. }
  225. else{
  226. str = "\n\n" + str;
  227. }
  228. }
  229. list[i].Content[item.Number].Content += str;
  230. if (list[i].Content[item.Number].Content.indexOf("\n\n")==0)
  231. list[i].Content[item.Number].Content=list[i].Content[item.Number].Content.substr(2);
  232. if (item.Tag == "诗词"){
  233. if (list[i].Content[item.Number].Content.indexOf("\n")>0 && list[i].Content[item.Number].Content.indexOf("[")!=0){
  234. list[i].Content[item.Number].Content="\n\n"+list[i].Content[item.Number].Content;
  235. }
  236. }
  237. }
  238. break;
  239. }
  240. }
  241. app.globalData.CardList = list;
  242. wx.navigateBack({
  243. delta: app.globalData.TempSearchBackNumber,
  244. });
  245. }
  246. else {
  247. wx.showToast({
  248. title: '请选择内容',
  249. })
  250. }
  251. },
  252. changeBishun:function(e){
  253. var id=e.currentTarget.dataset.id;
  254. if (id === "0"){
  255. for (var i = 0; i < 6; i++) {
  256. delete this.data.CSS["CHN_BiShunArr2_" + i];
  257. }
  258. }
  259. else if (id === "1") {
  260. for (var i = 0; i < 6; i++) {
  261. delete this.data.CSS["CHN_KaitiArr_" + i];
  262. }
  263. }
  264. this.setData({
  265. ShowKaiti: id,
  266. CSS:this.data.CSS,
  267. });
  268. },
  269. changeSoundMark:function(e){
  270. var id=e.currentTarget.dataset.id;
  271. this.setData({
  272. ShowSoundMark: id,
  273. });
  274. },
  275. changeRead: function (e) {
  276. var id = e.currentTarget.dataset.id;
  277. var count=Object.getOwnPropertyNames(this.data.CSS).length;
  278. for (var i=0;i<count;i++) {
  279. delete this.data.CSS["CHN_PeomContent_" + i];
  280. }
  281. delete this.data.CSS["CHN_PeomContent"];
  282. this.setData({
  283. IsPoemRead: id,
  284. CSS:this.data.CSS,
  285. });
  286. },
  287. changeInfomation:function(e){
  288. var word=e.currentTarget.dataset.word;
  289. if (word.indexOf(";")>0){
  290. word=word.substr(0,word.indexOf(";"));
  291. }
  292. var url = 'GetMiaoguoAISearch2?UserID=' + app.globalData.userInfo.UserID;
  293. url += "&Word=" + word;
  294. if (!e.currentTarget.dataset.ischn)
  295. url += "&SearchType=zici";
  296. wx.showLoading();
  297. main.getData(url, function (data) {
  298. wx.hideLoading();
  299. if (data && (data.CHN || data.ENG)){
  300. var obj={};
  301. var len = 26;
  302. obj.Value=data;
  303. if (data.CHN){
  304. obj.Key=data.CHN.HanZi;
  305. obj.Content=data.CHN.PinYin[0].explain;
  306. if (obj.Key.length==1)
  307. obj.TypeName="Z";
  308. else
  309. obj.TypeName="C";
  310. obj.Url="&UserID="+app.globalData.userInfo.UserID+"&Word="+obj.Key;
  311. }
  312. else if (data.ENG){
  313. obj.Key=data.ENG.Word;
  314. obj.TypeName="D";
  315. if (data.ENG.Soundmark)
  316. obj.Remark=data.ENG.Soundmark.Eng;
  317. obj.Content=data.ENG.Paraphrase[0].ParaphraseList;
  318. obj.Url="&UserID="+app.globalData.userInfo.UserID+"&Word="+obj.Key;
  319. }
  320. if (data.CHN && data.CHN.PinYin && data.CHN.PinYin.length>0){
  321. obj.Remark=data.CHN.PinYin[0].pinyin;
  322. }
  323. if (obj.Content && obj.Content.length > len)
  324. obj.Content = obj.Content.substr(0, len) + "...";
  325. main.updateSearchList(obj);
  326. if (app.globalData.TempSearchBackNumber==0)
  327. app.globalData.TempSearchBackNumber=1;
  328. else if (app.globalData.TempSearchBackNumber>=1)
  329. app.globalData.TempSearchBackNumber=2;
  330. wx.redirectTo({
  331. url: './addInfomationDetail',
  332. });
  333. }
  334. else{
  335. wx.showToast({
  336. title: '无资料',
  337. image: "../images/universalpic_exclamation_white_120x120.png",
  338. });
  339. }
  340. });
  341. },
  342. openHelp: function () {
  343. this.setData({
  344. IsShowHelp: 0,
  345. });
  346. },
  347. showHelp: function () {
  348. var that = this;
  349. that.setData({
  350. IsHelp: true,
  351. });
  352. },
  353. closeHelp: function () {
  354. this.setData({
  355. IsHelp: false,
  356. });
  357. },
  358. onShareAppMessage: function () {
  359. return {
  360. title: app.globalData.ShareTitle,
  361. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  362. imageUrl: app.globalData.ShareImage,
  363. }
  364. },
  365. })