addInfomationDetail.js 12 KB

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