index.ux 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <import name="bookshelf" src="../../components/bookshelf"></import>
  2. <import name="library" src="../../components/library"></import>
  3. <import name="search-book" src="../../components/search-book"></import>
  4. <template>
  5. <div class="page-wrapper">
  6. <tabs index="{{selectedTab}}" onchange="changeTab">
  7. <tab-content>
  8. <bookshelf
  9. shelf-list="{{shelfList}}"
  10. onupdate-shelf="updateShelf"
  11. ></bookshelf>
  12. <library></library>
  13. <search-book></search-book>
  14. </tab-content>
  15. <tab-bar mode="fixed" class="tab-bar">
  16. <div class="tab-item" for="tabList">
  17. <text class="iconfont">{{
  18. selectedTab === $idx ? $item.activatedIcon : $item.icon
  19. }}</text>
  20. <text class="tab-title">{{ $item.title }}</text>
  21. </div>
  22. </tab-bar>
  23. </tabs>
  24. </div>
  25. </template>
  26. <script>
  27. import { bookListData } from '../../assets/data/book-list.js'
  28. export default {
  29. private: {
  30. tabList: [
  31. {
  32. title: '书架',
  33. icon: '\ue602',
  34. activatedIcon: '\ue601'
  35. },
  36. {
  37. title: '书城',
  38. icon: '\ue681',
  39. activatedIcon: '\ue67d'
  40. },
  41. {
  42. title: '查找',
  43. icon: '\ue603',
  44. activatedIcon: '\ue604'
  45. },
  46. {
  47. title: '工具广场',
  48. icon: '\ue603',
  49. activatedIcon: '\ue604'
  50. }
  51. ],
  52. selectedTab: 1,
  53. defaultShelfList: bookListData.slice(0, 2),
  54. shelfList: []
  55. },
  56. onInit() {
  57. $utils.getStorage('bookshelf').then(value => {
  58. // 从storage获取
  59. if (!value) {
  60. this.shelfList = this.defaultShelfList
  61. $utils.setShelfList(this.shelfList, true) // 保存到全局变量和storage
  62. } else {
  63. this.shelfList = JSON.parse(value)
  64. $utils.setShelfList(this.shelfList) // 保存到全局变量
  65. }
  66. })
  67. },
  68. /* -------------------SelfCustomEvent------------------ */
  69. changeTab(e) {
  70. let index = e.index === undefined ? 1 : e.index
  71. this.selectedTab = index
  72. },
  73. updateShelf(param) {
  74. this.shelfList = param.detail.shelfList
  75. $utils.setShelfList(this.shelfList, true) // 保存到全局变量和storage
  76. }
  77. }
  78. </script>
  79. <style lang="less">
  80. @import '../../assets/styles/index.less';
  81. .tab-bar {
  82. background-color: @white;
  83. .border-top-mixins();
  84. padding: 15px 0;
  85. height: 110px;
  86. .tab-item {
  87. flex: 1;
  88. .flex-box-mixins(column, center, center);
  89. .iconfont {
  90. font-size: 50px;
  91. color: @text-grey;
  92. &:active {
  93. color: @brand;
  94. }
  95. }
  96. .g22kjdgy {
  97. color: #ffffff;
  98. }
  99. .tab-title {
  100. font-size: 20px;
  101. color: @text-grey;
  102. &:active {
  103. color: @brand;
  104. }
  105. }
  106. }
  107. }
  108. </style>