mywords.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. import animation from '../../utils/animation';
  4. const app = getApp();
  5. Page({
  6. data: {
  7. IsShowSelect:false,
  8. IsShowRemind:false,
  9. AlertClass:"",
  10. Sort1:"panel112",
  11. Sort2:"",
  12. RemindArr:[
  13. {
  14. "Title":"取消收藏",
  15. "Content":"确定删除这条收藏记录吗?删除后无法恢复。",
  16. "BtnName":"删除",
  17. },{
  18. "Title":"取消收藏",
  19. "Content":"确定删除这些收藏记录吗?删除后无法恢复。",
  20. "BtnName":"删除",
  21. },{
  22. "Title":"生成文章",
  23. "Content":"要用这些单词生成新文章吗?",
  24. "BtnName":"继续",
  25. },{
  26. "Title":"导出到秒过",
  27. "Content":"要把这些单词做成秒过题卡吗?\n\n该功能需要切换到「秒过 - 错题记忆卡」小程序中实现。",
  28. "BtnName":"继续",
  29. },
  30. ],
  31. RemindIndex:0,
  32. },
  33. onLoad: function (options) {
  34. let that = this;
  35. that.setData({
  36. Containnerheight: main.getWindowHeight(),
  37. List:app.globalData.UserCollect,
  38. Count:0,
  39. });
  40. },
  41. sortWord:function(e){
  42. let isSort=e.currentTarget.dataset.issort;
  43. let list=[];
  44. let sort1="",sort2="";
  45. if (isSort=="1"){
  46. list=common.sort(this.data.List,"ASC","Word","String");
  47. sort1="";
  48. sort2="panel112";
  49. }
  50. else{
  51. list=common.sort(this.data.List,"DESC","ID","Number");
  52. sort1="panel112";
  53. sort2="";
  54. }
  55. //debugger;
  56. this.setData({
  57. List:list,
  58. Sort1:sort1,
  59. Sort2:sort2,
  60. });
  61. },
  62. selecItem:function(e){
  63. let index=e.currentTarget.dataset.index;
  64. let list=this.data.List;
  65. for(let i=0;i<list.length;i++){
  66. if (index=="all")
  67. list[i].Selected=1;
  68. else if (index==i)
  69. list[i].Selected=list[i].Selected==1?0:1;
  70. }
  71. let count=0;
  72. for(let i=0;i<list.length;i++){
  73. if (list[i].Selected==1)
  74. count++;
  75. }
  76. this.setData({
  77. List:list,
  78. Count:count,
  79. });
  80. },
  81. setDataBoolean:function(e){
  82. if (e.currentTarget.dataset.name=="IsShowSelect"){
  83. this.cancelSelected();
  84. }
  85. this.setData({
  86. IsShowSelect:!this.data.IsShowSelect,
  87. });
  88. },
  89. showRemindStart:function(e){
  90. let that=this;
  91. let remindIndex=e.currentTarget.dataset.type;
  92. this.setData({
  93. RemindIndex:remindIndex,
  94. });
  95. let arr=that.getSelectedWord();
  96. if (arr){
  97. if (arr.length==0){
  98. // 使用组件显示提示
  99. this.selectComponent('#alertTip').showAlert("请至少选择1个单词");
  100. return null;
  101. }
  102. else if (remindIndex==2 && arr.length>10){
  103. // 使用组件显示提示
  104. this.selectComponent('#alertTip').showAlert("一篇文章最多可选10个单词");
  105. return null;
  106. }
  107. }
  108. if (e.currentTarget.dataset.word)
  109. that.Word=e.currentTarget.dataset.word;
  110. animation.toggleRemindWithAnimation(this, {
  111. hideColor: 'rgba(0,0,0,0)',
  112. showColor: 'rgba(277,277,277,0.5)',
  113. panelAnimationKey: 'panelAnimation', // 控制内容面板的动画
  114. animationKey: 'parentAnimation' // 控制父容器的动画(如果需要)
  115. });
  116. },
  117. showRemindEnd:function(e){
  118. let that=this;
  119. const confirm=e.currentTarget.dataset.confirm;
  120. animation.toggleRemindWithAnimation(this, {
  121. hideColor: 'rgba(0,0,0,0)',
  122. showColor: 'rgba(277,277,277,0.5)'
  123. });
  124. if (confirm=="1") {
  125. switch(Number(that.data.RemindIndex)){
  126. case 0:
  127. that.deleteItem(that.Word);
  128. break;
  129. case 1:
  130. that.deleteMany();
  131. break;
  132. case 2:
  133. that.setClipboard();
  134. break;
  135. case 3:
  136. that.gotoMiaoguo();
  137. break;
  138. }
  139. }
  140. },
  141. deleteItem:function(word){
  142. let that=this;
  143. main.getData('AddOrDeleteYJBDCUserCollect?UserID='+app.globalData.userInfo.UserID+'&Word='+word, function (data) {
  144. if (data){
  145. app.globalData.UserCollect=data;
  146. that.setData({
  147. List:app.globalData.UserCollect,
  148. });
  149. wx.showToast({
  150. title: '删除完成',
  151. });
  152. }
  153. });
  154. },
  155. deleteMany:function(){
  156. let that=this;
  157. let arr=that.getSelectedWord();
  158. main.getData('DeleteYJBDCUserCollect?UserID='+app.globalData.userInfo.UserID+'&WordArr='+arr.join(","), function (data) {
  159. if (data){
  160. app.globalData.UserCollect=data;
  161. that.setData({
  162. List:app.globalData.UserCollect,
  163. });
  164. wx.showToast({
  165. title: '批量删除完成',
  166. });
  167. }
  168. });
  169. },
  170. setClipboard:function(e){
  171. let that=this;
  172. let arr=that.getSelectedWord(true);
  173. app.globalData.SelectedWords=arr;
  174. wx.redirectTo({
  175. url: 'wordsinput',
  176. });
  177. },
  178. gotoMiaoguo:function(e){
  179. let that=this;
  180. let arr=that.getSelectedWord();
  181. var appid="wx84b3feac6069eec3";
  182. var path="pages/index/index?SourceID="+app.globalData.ProgramID+"&goto=buildcard&Words="+arr.join(",");
  183. wx.navigateToMiniProgram({
  184. appId: appid,
  185. path: path,
  186. });
  187. },
  188. getSelectedWord:function(selectTen){
  189. let that=this;
  190. let list=that.data.List;
  191. let arr=[];
  192. for(let i=0;i<list.length;i++){
  193. if (list[i].Selected==1)
  194. arr.push(list[i].Word);
  195. }
  196. return arr;
  197. },
  198. cancelSelected:function(){
  199. let list=this.data.List;
  200. for(let i=0;i<list.length;i++)
  201. list[i].Selected=0;
  202. this.setData({
  203. List:list,
  204. Count:0,
  205. });
  206. },
  207. goto: function (e) {
  208. let that=this;
  209. var url=e.currentTarget.dataset.url;
  210. wx.navigateTo({
  211. url: url,
  212. });
  213. },
  214. onShareAppMessage: function () {
  215. return {
  216. title: app.globalData.ShareTitle,
  217. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  218. imageUrl: app.globalData.ShareImage,
  219. }
  220. },
  221. })