searchCardList.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. wx.hideLoading();
  63. function getImage(str){
  64. var result="";
  65. if (str.indexOf("[图]")>=0){
  66. result = str.substring(str.indexOf("[图]") + 3, str.indexOf("[/图]"));
  67. }
  68. return result;
  69. }
  70. function replaceString(str){
  71. str = str.replace(/\[读]/g, "");
  72. str = str.replace(/\[\/读\]/g, "");
  73. str = str.replace(/\[图]/g, "");
  74. str = str.replace(/\[\/图\]/g, "");
  75. var str2="";
  76. if (str.indexOf("[读") >= 0) {
  77. str2 = str.substr(str.indexOf("[读"));
  78. str2 = str2.substring(0, str2.indexOf("]") + 1);
  79. }
  80. str = str.replace(str2, "");
  81. if (str.indexOf("[读") >= 0) {
  82. str2 = str.substr(str.indexOf("[读"));
  83. str2 = str2.substring(0, str2.indexOf("]") + 1);
  84. }
  85. str = str.replace(str2, "");
  86. str = str.replace(/\[线]/g, "");
  87. str = str.replace(/\[\/线\]/g, "");
  88. str = main.encryptUrl(str);
  89. return str;
  90. }
  91. },
  92. onPreview: function (e) {
  93. var id = e.currentTarget.dataset.id;
  94. wx.navigateTo({
  95. url: './preview?type=show&id='+id,
  96. })
  97. },
  98. gotoNextPage: function (e) {
  99. wx.showLoading({
  100. title: '请稍候',
  101. });
  102. var that = this;
  103. var id = e.currentTarget.dataset.id;
  104. var url = 'GetMiaoguoCardList?UserID=' + app.globalData.userInfo.UserID+"&IsToday="+that.data.IsToday + "&PageID=" + id;
  105. if (that.data.Search)
  106. url += "&Key=" + that.data.Search;
  107. main.getData(url, function (data) {
  108. if (data) {
  109. var list = wx.getStorageSync("CardList");
  110. for(var i=0;i<data.length;i++){
  111. list.push(data[i]);
  112. }
  113. wx.setStorageSync("CardList", list);
  114. that.getList();
  115. }
  116. });
  117. },
  118. onShareAppMessage: function () {
  119. return {
  120. title: app.globalData.ShareTitle,
  121. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  122. imageUrl: app.globalData.ShareImage,
  123. }
  124. },
  125. })