mywords.js 5.8 KB

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