addInfomationDetail.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. 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
  239. str = item.Content;
  240. }
  241. if (this.data.Result && this.data.Result.CHN && this.data.Result.CHN.PinYin && this.data.Result.CHN.PinYin.length == 1) {
  242. if (item.Tag == "释义") {
  243. str = str.substr(str.indexOf("[/读]") + 4);
  244. }
  245. }
  246. if (list[i].Content[item.Number].Content) {
  247. if (item.Tag == "组词" || item.Tag == "近义词" || item.Tag == "反义词") {
  248. str = "\n" + str;
  249. } else {
  250. str = "\n\n" + str;
  251. }
  252. }
  253. list[i].Content[item.Number].Content += str;
  254. if (list[i].Content[item.Number].Content.indexOf("\n\n") == 0)
  255. list[i].Content[item.Number].Content = list[i].Content[item.Number].Content.substr(2);
  256. if (item.Tag == "诗词") {
  257. if (list[i].Content[item.Number].Content.indexOf("\n") > 0 && list[i].Content[item.Number].Content.indexOf("[") != 0) {
  258. list[i].Content[item.Number].Content = "\n\n" + list[i].Content[item.Number].Content;
  259. }
  260. }
  261. }
  262. break;
  263. }
  264. }
  265. app.globalData.CardList = list;
  266. wx.navigateBack({
  267. delta: app.globalData.TempSearchBackNumber,
  268. });
  269. } else {
  270. wx.showToast({
  271. title: '请选择内容',
  272. })
  273. }
  274. },
  275. changeBishun: function (e) {
  276. var id = e.currentTarget.dataset.id;
  277. if (id === "0") {
  278. for (var i = 0; i < 6; i++) {
  279. delete this.data.CSS["CHN_BiShunArr2_" + i];
  280. }
  281. } else if (id === "1") {
  282. for (var i = 0; i < 6; i++) {
  283. delete this.data.CSS["CHN_KaitiArr_" + i];
  284. }
  285. }
  286. this.setData({
  287. ShowKaiti: id,
  288. CSS: this.data.CSS,
  289. });
  290. },
  291. changeSoundMark: function (e) {
  292. var id = e.currentTarget.dataset.id;
  293. this.setData({
  294. ShowSoundMark: id,
  295. });
  296. },
  297. changeRead: function (e) {
  298. var id = e.currentTarget.dataset.id;
  299. var count = Object.getOwnPropertyNames(this.data.CSS).length;
  300. for (var i = 0; i < count; i++) {
  301. delete this.data.CSS["CHN_PeomContent_" + i];
  302. }
  303. delete this.data.CSS["CHN_PeomContent"];
  304. this.setData({
  305. IsPoemRead: id,
  306. CSS: this.data.CSS,
  307. });
  308. },
  309. changeInfomation: function (e) {
  310. var word = e.currentTarget.dataset.word;
  311. if (word.indexOf(";") > 0) {
  312. word = word.substr(0, word.indexOf(";"));
  313. }
  314. var url = 'GetMiaoguoAISearch2?UserID=' + app.globalData.userInfo.UserID;
  315. url += "&Word=" + word;
  316. if (!e.currentTarget.dataset.ischn)
  317. url += "&SearchType=zici";
  318. wx.showLoading();
  319. main.getData(url, function (data) {
  320. wx.hideLoading();
  321. if (data && (data.CHN || data.ENG)) {
  322. var obj = {};
  323. var len = 26;
  324. obj.Value = data;
  325. if (data.CHN) {
  326. obj.Key = data.CHN.HanZi;
  327. obj.Content = data.CHN.PinYin[0].explain;
  328. if (obj.Key.length == 1)
  329. obj.TypeName = "Z";
  330. else
  331. obj.TypeName = "C";
  332. obj.Url = "&UserID=" + app.globalData.userInfo.UserID + "&Word=" + obj.Key;
  333. } else if (data.ENG) {
  334. obj.Key = data.ENG.Word;
  335. obj.TypeName = "D";
  336. if (data.ENG.Soundmark)
  337. obj.Remark = data.ENG.Soundmark.Eng;
  338. if (data.ENG.Paraphrase && data.ENG.Paraphrase[0] && data.ENG.Paraphrase[0].ParaphraseList)
  339. obj.Content = data.ENG.Paraphrase[0].ParaphraseList;
  340. obj.Url = "&UserID=" + app.globalData.userInfo.UserID + "&Word=" + obj.Key;
  341. }
  342. if (data.CHN && data.CHN.PinYin && data.CHN.PinYin.length > 0) {
  343. obj.Remark = data.CHN.PinYin[0].pinyin;
  344. }
  345. if (obj.Content && obj.Content.length > len)
  346. obj.Content = obj.Content.substr(0, len) + "...";
  347. main.updateSearchList(obj);
  348. if (app.globalData.TempSearchBackNumber == 0)
  349. app.globalData.TempSearchBackNumber = 1;
  350. else if (app.globalData.TempSearchBackNumber >= 1)
  351. app.globalData.TempSearchBackNumber = 2;
  352. wx.redirectTo({
  353. url: './addInfomationDetail',
  354. });
  355. } else {
  356. wx.showToast({
  357. title: '无资料',
  358. image: "../images/universalpic_exclamation_white_120x120.png",
  359. });
  360. }
  361. });
  362. },
  363. showHelp0: function () {
  364. var that = this;
  365. that.setData({
  366. IsHelp: true,
  367. });
  368. },
  369. closeHelp0: function () {
  370. this.setData({
  371. IsHelp: false,
  372. });
  373. },
  374. closeHelp: function () {
  375. this.setData({
  376. IsShowHelp: false,
  377. });
  378. wx.setStorageSync('IsHelpAddInfomation', 0);
  379. },
  380. onShareAppMessage: function () {
  381. return {
  382. title: app.globalData.ShareTitle,
  383. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  384. imageUrl: app.globalData.ShareImage,
  385. }
  386. },
  387. })