icongroup.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* DIY组件:Searchbar
  2. */
  3. var Parse = getApp().Parse;
  4. var Nova = getApp().Nova;
  5. Component({
  6. behaviors: [],
  7. // 属性定义(详情参见下文)
  8. properties: {
  9. options: null,
  10. },
  11. data: {
  12. list: [],
  13. }, // 私有数据,可用于模板渲染
  14. lifetimes: {
  15. // 生命周期函数,可以为函数,或一个在methods段中定义的方法名
  16. attached: function () {
  17. console.log("diy-icongroup", this.data);
  18. },
  19. moved: function () { },
  20. detached: function () { },
  21. },
  22. ready: function () {
  23. // 在组件布局完成后执行,确保options参数中有data信息
  24. console.log("ready");
  25. this.loadData();
  26. },
  27. pageLifetimes: {
  28. // 组件所在页面的生命周期函数
  29. show: function () { },
  30. hide: function () { },
  31. resize: function () { },
  32. },
  33. methods: {
  34. /*********************************
  35. * 重要方法:加载数据
  36. * ******************************/
  37. async loadData() {
  38. await Nova.checkComponentsDataProperties(this);
  39. let list = await Nova.getBlockData(this.data.options.data);
  40. let { options } = this.data;
  41. console.log("图标组", options);
  42. console.log(list);
  43. let { data, src, style } = options;
  44. let { className, filter } = data;
  45. this.setData({
  46. list,
  47. style,
  48. className,
  49. filter,
  50. });
  51. },
  52. /*********************************
  53. * 重要方法:链接跳转
  54. * ******************************/
  55. goNovaURL: async function (ev) {
  56. let item = ev.currentTarget.dataset.item;
  57. let url = "";
  58. if (item.url) {
  59. console.log(item.url);
  60. if (item.name) {
  61. url = item.url + '?title=' + item.name;
  62. } else {
  63. url = item.url
  64. }
  65. Nova.goNovaURL(url);
  66. return;
  67. }
  68. if (item.type == "shop") {
  69. url = `/nova-shop/pages/shop-list/index?title=${item.name}&cid=${item.objectId}`;
  70. } else if (item.type == "article") {
  71. let Article = new Parse.Query("Article");
  72. Article.select('objectId')
  73. Article.equalTo("category", item.objectId);
  74. let articles = await Article.find();
  75. if (articles && articles.length == 1) {
  76. url = `/common-page/pages/cates/article-detail/index?title=${item.name}&aid=${articles[0].objectId}`;
  77. } else if (articles && articles.length > 1) {
  78. url = `/common-page/pages/cates/article-list/index?title=${item.name}&cid=${item.objectId}`;
  79. }
  80. }
  81. Nova.goNovaURL(url);
  82. },
  83. },
  84. });