searchCardList.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. var that = this;
  9. that.setData({
  10. Containnerheight: main.getWindowHeight(),
  11. });
  12. if (options.search) {
  13. wx.setNavigationBarTitle({
  14. title: options.search
  15. });
  16. }
  17. else if (options.type==1) {
  18. wx.setNavigationBarTitle({
  19. title: "今日的任务"
  20. });
  21. }
  22. },
  23. onPullDownRefresh:function(){
  24. var that = this;
  25. that.getList();
  26. wx.stopPullDownRefresh();
  27. },
  28. onShow:function(){
  29. var that = this;
  30. that.getList();
  31. },
  32. getList: function () {
  33. var list=wx.getStorageSync("CardList");
  34. var len=20;
  35. for(var i=0;i<list.length;i++){
  36. var item=list[i];
  37. item.Content[1].ContentStr = replaceString(item.Content[1].Content);
  38. if (item.Content[1].ContentStr.length > len)
  39. item.Content[1].ContentStr = replaceString(item.Content[1].ContentStr.substr(0, len)) + "...";
  40. item.Content[2].ContentStr = replaceString(item.Content[2].Content);
  41. if (item.Content[2].ContentStr.length > len)
  42. item.Content[2].ContentStr = replaceString(item.Content[2].ContentStr.substr(0, len)) + "...";
  43. var imageUrl = getImage(item.Content[1].Content);
  44. if (!imageUrl && item.Content[2].Content)
  45. imageUrl = getImage(item.Content[2].Content);
  46. if (!imageUrl && item.Content[3].Content)
  47. imageUrl = getImage(item.Content[3].Content);
  48. if (imageUrl)
  49. item.ImageUrl=imageUrl;
  50. }
  51. this.setData({
  52. List:list,
  53. });
  54. function getImage(str){
  55. var result="";
  56. if (str.indexOf("[图]")>=0){
  57. result = str.substring(str.indexOf("[图]") + 3, str.indexOf("[/图]"));
  58. }
  59. return result;
  60. }
  61. function replaceString(str){
  62. str = str.replace(/\[读]/g, "");
  63. str = str.replace(/\[\/读\]/g, "");
  64. str = str.replace(/\[图]/g, "");
  65. str = str.replace(/\[\/图\]/g, "");
  66. var str2="";
  67. if (str.indexOf("[读") >= 0) {
  68. str2 = str.substr(str.indexOf("[读"));
  69. str2 = str2.substring(0, str2.indexOf("]") + 1);
  70. }
  71. str = str.replace(str2, "");
  72. if (str.indexOf("[读") >= 0) {
  73. str2 = str.substr(str.indexOf("[读"));
  74. str2 = str2.substring(0, str2.indexOf("]") + 1);
  75. }
  76. str = str.replace(str2, "");
  77. str = str.replace(/\[线]/g, "");
  78. str = str.replace(/\[\/线\]/g, "");
  79. str = main.encryptUrl(str);
  80. return str;
  81. }
  82. },
  83. onPreview: function (e) {
  84. var id = e.currentTarget.dataset.id;
  85. wx.navigateTo({
  86. url: './preview?type=show&id='+id,
  87. })
  88. },
  89. onShareAppMessage: function () {
  90. return {
  91. title: app.globalData.ShareTitle,
  92. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  93. imageUrl: app.globalData.ShareImage,
  94. }
  95. },
  96. })