addInfomationDetail.js 14 KB

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