searchCardList.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. that.setData({
  11. });
  12. var Search="",IsToday=0;
  13. if (options.search) {
  14. Search=options.search;
  15. wx.setNavigationBarTitle({
  16. title: options.search
  17. });
  18. }
  19. else if (options.type==1) {
  20. IsToday = 1;
  21. wx.setNavigationBarTitle({
  22. title: "今日的任务"
  23. });
  24. }
  25. that.setData({
  26. Search: Search,
  27. IsToday: IsToday,
  28. Containnerheight: main.getWindowHeight(),
  29. });
  30. },
  31. onPullDownRefresh:function(){
  32. var that = this;
  33. that.getList();
  34. wx.stopPullDownRefresh();
  35. },
  36. onShow:function(){
  37. var that = this;
  38. that.getList();
  39. },
  40. getList: function () {
  41. var list=wx.getStorageSync("CardList");
  42. var len=20;
  43. for(var i=0;i<list.length;i++){
  44. var item=list[i];
  45. item.Content[1].ContentStr = replaceString(item.Content[1].Content);
  46. if (item.Content[1].ContentStr.length > len)
  47. item.Content[1].ContentStr = replaceString(item.Content[1].ContentStr.substr(0, len)) + "...";
  48. item.Content[2].ContentStr = replaceString(item.Content[2].Content);
  49. if (item.Content[2].ContentStr.length > len)
  50. item.Content[2].ContentStr = replaceString(item.Content[2].ContentStr.substr(0, len)) + "...";
  51. var imageUrl = getImage(item.Content[1].Content);
  52. if (!imageUrl && item.Content[2].Content)
  53. imageUrl = getImage(item.Content[2].Content);
  54. if (!imageUrl && item.Content[3].Content)
  55. imageUrl = getImage(item.Content[3].Content);
  56. if (imageUrl)
  57. item.ImageUrl=imageUrl;
  58. }
  59. this.setData({
  60. List:list,
  61. });
  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. var id = e.currentTarget.dataset.id;
  99. var that = this;
  100. var url = 'GetMiaoguoCard?UserID=' + app.globalData.userInfo.UserID+"&IsToday="+that.data.IsToday + "&PageID=" + id;
  101. if (that.data.Search)
  102. url += "&Key=" + that.data.Search;
  103. main.getData(url, function (data) {
  104. if (data) {
  105. var list = wx.getStorageSync("CardList");
  106. for(var i=0;i<data.length;i++){
  107. list.push(data[i]);
  108. }
  109. wx.setStorageSync("CardList", list);
  110. that.getList();
  111. }
  112. });
  113. },
  114. onShareAppMessage: function () {
  115. return {
  116. title: app.globalData.ShareTitle,
  117. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  118. imageUrl: app.globalData.ShareImage,
  119. }
  120. },
  121. })