searchCardList.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. },
  7. onLoad: function (options) {
  8. wx.hideShareMenu();
  9. var that = this;
  10. var Search="",IsToday=0;
  11. if (options.search) {
  12. Search=options.search;
  13. wx.setNavigationBarTitle({
  14. title: options.search
  15. });
  16. }
  17. else if (options.type==1) {
  18. IsToday = 1;
  19. wx.setNavigationBarTitle({
  20. title: "今日的任务"
  21. });
  22. }
  23. that.setData({
  24. Search: Search,
  25. IsToday: IsToday,
  26. Count:options.Count,
  27. Containnerheight: main.getWindowHeight(),
  28. });
  29. },
  30. onPullDownRefresh:function(){
  31. var that = this;
  32. that.getList();
  33. wx.stopPullDownRefresh();
  34. },
  35. onShow:function(){
  36. var that = this;
  37. that.getList();
  38. },
  39. getList: function () {
  40. var list=wx.getStorageSync("CardList");
  41. var len=20;
  42. for(var i=0;i<list.length;i++){
  43. var item=list[i];
  44. item.Content[1].ContentStr = replaceString(item.Content[1].Content);
  45. if (item.Content[1].ContentStr.length > len)
  46. item.Content[1].ContentStr = replaceString(item.Content[1].ContentStr.substr(0, len)) + "...";
  47. item.Content[2].ContentStr = replaceString(item.Content[2].Content);
  48. if (item.Content[2].ContentStr.length > len)
  49. item.Content[2].ContentStr = replaceString(item.Content[2].ContentStr.substr(0, len)) + "...";
  50. var imageUrl = getImage(item.Content[1].Content);
  51. if (!imageUrl && item.Content[2].Content)
  52. imageUrl = getImage(item.Content[2].Content);
  53. if (!imageUrl && item.Content[3].Content)
  54. imageUrl = getImage(item.Content[3].Content);
  55. if (imageUrl)
  56. item.ImageUrl=imageUrl;
  57. }
  58. this.setData({
  59. List:list,
  60. });
  61. wx.hideLoading();
  62. function getImage(str){
  63. var result="";
  64. if (str.indexOf("[图]")>=0){
  65. result = str.substring(str.indexOf("[图]") + 3, str.indexOf("[/图]"));
  66. }
  67. return result;
  68. }
  69. function replaceString(str){
  70. str = str.replace(/\[读]/g, "");
  71. str = str.replace(/\[\/读\]/g, "");
  72. str = str.replace(/\[图]/g, "");
  73. str = str.replace(/\[\/图\]/g, "");
  74. var str2="";
  75. if (str.indexOf("[读") >= 0) {
  76. str2 = str.substr(str.indexOf("[读"));
  77. str2 = str2.substring(0, str2.indexOf("]") + 1);
  78. }
  79. str = str.replace(str2, "");
  80. if (str.indexOf("[读") >= 0) {
  81. str2 = str.substr(str.indexOf("[读"));
  82. str2 = str2.substring(0, str2.indexOf("]") + 1);
  83. }
  84. str = str.replace(str2, "");
  85. str = str.replace(/\[线]/g, "");
  86. str = str.replace(/\[\/线\]/g, "");
  87. str = main.encryptUrl(str);
  88. return str;
  89. }
  90. },
  91. onPreview: function (e) {
  92. var id = e.currentTarget.dataset.id;
  93. wx.navigateTo({
  94. url: './preview?type=show&id='+id,
  95. })
  96. },
  97. gotoNextPage: function (e) {
  98. wx.showLoading({
  99. title: '请稍候',
  100. });
  101. var that = this;
  102. var id = e.currentTarget.dataset.id;
  103. var url = 'GetMiaoguoCardList?UserID=' + app.globalData.userInfo.UserID+"&IsToday="+that.data.IsToday + "&PageID=" + id;
  104. if (that.data.Search)
  105. url += "&Key=" + that.data.Search;
  106. main.getData(url, function (data) {
  107. if (data) {
  108. var list = wx.getStorageSync("CardList");
  109. for(var i=0;i<data.List.length;i++){
  110. list.push(data.List[i]);
  111. }
  112. wx.setStorageSync("CardList", list);
  113. that.getList();
  114. }
  115. });
  116. },
  117. addCard:function(){
  118. wx.redirectTo({
  119. url: './add?type=add&id=0',
  120. });
  121. },
  122. onShareAppMessage: function () {
  123. return {
  124. title: app.globalData.ShareTitle,
  125. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  126. imageUrl: app.globalData.ShareImage,
  127. }
  128. },
  129. })