App.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. }
  38. const navAction = (actionCode:string) => {
  39. if(editMode){
  40. return console.log('is edit mode')
  41. }
  42. console.log(`action: ${actionCode}`);
  43. // 寻找actionCode对应的 index
  44. let index = navItems.findIndex((item) => item.actionCode === actionCode);
  45. if (index === -1) {
  46. return console.warn(`找不到actionCode: ${actionCode}`);
  47. }
  48. // 更改动画
  49. if (index < activeIndex.value) {
  50. transitionName.value = 'slide-left';
  51. }else{
  52. transitionName.value = 'slide-right';
  53. }
  54. activeIndex.value = index;
  55. pageKey.value = navItems[index].actionCode;
  56. switch (actionCode) {
  57. case settingPageKey:
  58. title.value = navItems[index].name;
  59. break;
  60. default:
  61. pageKey.value = homePageKey;
  62. title.value = 'fc-ele';
  63. break;
  64. }
  65. console.log(`pageKey: ${pageKey.value}`);
  66. }
  67. </script>
  68. <template>
  69. <mac-window :title="title" :icon="'home'">
  70. <div class="image-bg">
  71. <img src="./assets/images/bg.jpg" alt="">
  72. </div>
  73. <Transition :name="transitionName">
  74. <div class="full" v-if="pageKey === homePageKey">
  75. <div class="app-content">
  76. <magnet-view
  77. :edit-mode="editMode"
  78. @edit-mode-change="editModeChange"
  79. />
  80. </div>
  81. </div>
  82. <setting-view v-else-if="pageKey === settingPageKey"></setting-view>
  83. </Transition>
  84. <div class="app-bar">
  85. <apple-bar
  86. :nav-items="navItems"
  87. :active="pageKey"
  88. :hide-time="3000"
  89. @action="navAction"
  90. >
  91. <bar-icon-btn
  92. icon-name="edit"
  93. :active="editMode"
  94. @click.native="editModeChange"
  95. >
  96. </bar-icon-btn>
  97. </apple-bar>
  98. </div>
  99. </mac-window>
  100. </template>
  101. <style scoped>
  102. .app-content {
  103. width: 100%;
  104. height: 100%;
  105. background-color: var(--color-background-soft);
  106. overflow: auto;
  107. }
  108. .app-bar{
  109. width: 100%;
  110. height: 70px;
  111. display: flex;
  112. justify-content: center;
  113. position: absolute;
  114. left: 0;
  115. bottom: 0;
  116. z-index: 1000;
  117. }
  118. @media screen and (max-width: 768px) {
  119. .app-content {
  120. height: calc(100% - 50px);
  121. }
  122. .app-bar {
  123. position: relative;
  124. bottom: 0;
  125. }
  126. }
  127. </style>