addInfomationDetail.js 14 KB

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