App.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <script setup lang="ts">
  2. // import HelloWorld from './components/HelloWorld.vue'
  3. import {onMounted, ref} from "vue";
  4. import MacWindow from "./components/window/macWindow.vue";
  5. import MagnetView from "./components/magnets/magnetView.vue";
  6. import AppleBar from "@/components/appleBar/appleBar.vue";
  7. import BarIconBtn from "@/components/appleBar/barIconBtn.vue";
  8. import SettingView from "@/components/settingView.vue";
  9. import {NavItem} from "@/components/appleBar/appleBar.ts";
  10. onMounted(() => {
  11. });
  12. let transitionName = ref("slide-right");
  13. const settingPageKey = 'setting';
  14. const activeIndex = ref(0);
  15. const homePageKey = 'home';
  16. let navItems:NavItem[] = [
  17. {
  18. id: 1,
  19. name: '首页',
  20. actionCode: homePageKey,
  21. description: '返回首页',
  22. icon: 'home',
  23. },
  24. {
  25. id: 2,
  26. name: '设置',
  27. actionCode: settingPageKey,
  28. description: '软件设置',
  29. icon: 'setting',
  30. },
  31. ]
  32. const title = ref("fc-ele");
  33. const pageKey = ref(homePageKey);
  34. const editMode = ref(false);
  35. function editModeChange() {
  36. editMode.value = !editMode.value;
  37. if(!editMode.value){
  38. // 重新加载磁贴数据
  39. }
  40. }
  41. const navAction = (actionCode:string) => {
  42. if(editMode){
  43. return console.log('is edit mode')
  44. }
  45. console.log(`action: ${actionCode}`);
  46. // 寻找actionCode对应的 index
  47. let index = navItems.findIndex((item) => item.actionCode === actionCode);
  48. if (index === -1) {
  49. return console.warn(`找不到actionCode: ${actionCode}`);
  50. }
  51. // 更改动画
  52. if (index < activeIndex.value) {
  53. transitionName.value = 'slide-left';
  54. }else{
  55. transitionName.value = 'slide-right';
  56. }
  57. activeIndex.value = index;
  58. pageKey.value = navItems[index].actionCode;
  59. switch (actionCode) {
  60. case settingPageKey:
  61. title.value = navItems[index].name;
  62. break;
  63. default:
  64. pageKey.value = homePageKey;
  65. title.value = 'fc-ele';
  66. break;
  67. }
  68. console.log(`pageKey: ${pageKey.value}`);
  69. }
  70. </script>
  71. <template>
  72. <mac-window :title="title" :icon="'home'">
  73. <div class="image-bg">
  74. <img src="./assets/images/bg.jpg" alt="">
  75. </div>
  76. <Transition :name="transitionName">
  77. <div class="full" v-if="pageKey === homePageKey">
  78. <div class="app-content">
  79. <magnet-view
  80. :edit-mode="editMode"
  81. @edit-mode-change="editModeChange"
  82. />
  83. </div>
  84. </div>
  85. <setting-view v-else-if="pageKey === settingPageKey"></setting-view>
  86. </Transition>
  87. <div class="app-bar">
  88. <apple-bar
  89. :nav-items="navItems"
  90. :active="pageKey"
  91. :hide-time="3000"
  92. @action="navAction"
  93. >
  94. <bar-icon-btn
  95. icon-name="edit"
  96. :active="editMode"
  97. @click.native="editModeChange"
  98. >
  99. </bar-icon-btn>
  100. </apple-bar>
  101. </div>
  102. </mac-window>
  103. </template>
  104. <style scoped>
  105. .app-content {
  106. width: 100%;
  107. height: 100%;
  108. background-color: var(--color-background-soft);
  109. overflow: auto;
  110. }
  111. .app-bar{
  112. width: 100%;
  113. height: 70px;
  114. display: flex;
  115. justify-content: center;
  116. position: absolute;
  117. left: 0;
  118. bottom: 0;
  119. z-index: 1000;
  120. }
  121. @media screen and (max-width: 768px) {
  122. .app-content {
  123. height: calc(100% - 50px);
  124. }
  125. .app-bar {
  126. position: relative;
  127. bottom: 0;
  128. }
  129. }
  130. </style>