index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <!-- 虚拟实验室 -->
  3. <div class="home-container">
  4. <!-- 展开收起侧边栏 -->
  5. <div
  6. class="icon-expand"
  7. :style="{
  8. backgroundColor: drawerVisible ? '#44449c' : '#7F70C840',
  9. left: drawerVisible ? '18%' : '0'
  10. }"
  11. @click="toggleDrawer"
  12. >
  13. <span
  14. class="vertical-lines"
  15. :style="{
  16. color: drawerVisible ? '#8a78d0' : 'white'
  17. }"
  18. >||</span
  19. >
  20. </div>
  21. <!-- 侧边栏组件 -->
  22. <LeftPanel ref="leftPanelRef" v-show="drawerVisible" />
  23. <!-- 右侧内容区 -->
  24. <div class="number-people">
  25. <div class="title-box">
  26. <div class="box-icon" @click="goBack">
  27. <el-icon class="left-icon"><ArrowLeftBold /></el-icon>
  28. 虚拟实验室
  29. </div>
  30. </div>
  31. <!-- 内容区域 -->
  32. <div class="content-box">
  33. <div @click="handleLabClick(item)" v-for="(item, index) in laboratoryList" :key="index" class="small-box">
  34. <div
  35. class="nested-box"
  36. :style="{
  37. backgroundImage: `url(${item.image})`,
  38. backgroundSize: 'cover'
  39. }"
  40. ></div>
  41. <div class="additional-text">
  42. {{item.name}}
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <script setup>
  50. import { ref } from 'vue'
  51. import { useRouter } from 'vue-router'
  52. import { ArrowLeftBold } from '@element-plus/icons-vue'
  53. import LeftPanel from '@/components/LeftPanel.vue'
  54. import desklamp from '@/assets/images/desklamp.png'
  55. const leftPanelRef = ref(null)
  56. // 侧边栏始终显示
  57. const drawerVisible = ref(true)
  58. // 切换抽屉显示状态的函数
  59. const toggleDrawer = () => {
  60. drawerVisible.value = !drawerVisible.value
  61. }
  62. const router = useRouter()
  63. // 返回上一页
  64. const goBack = () => {
  65. try {
  66. // 直接使用window.location.href确保页面立即跳转并刷新
  67. window.location.href = '/home';
  68. } catch (error) {
  69. console.error('返回home页面失败:', error);
  70. // 备用方案
  71. router.replace('/home');
  72. window.location.reload();
  73. }
  74. }
  75. const laboratoryList = ref([
  76. {
  77. name: '智能台灯',
  78. image: desklamp
  79. },
  80. ])
  81. const handleLabClick = (item) => {
  82. if (item.name === '智能台灯') {
  83. try {
  84. // 立即修改URL,不经过Vue Router的队列处理
  85. window.location.href = '/blockly2';
  86. } catch (error) {
  87. console.error('直接跳转失败:', error);
  88. // 备用方案:强制Vue Router进行跳转
  89. router.replace('/blockly2');
  90. // 强制刷新页面以确保视图更新
  91. window.location.reload();
  92. }
  93. }
  94. }
  95. </script>
  96. <style scoped lang="scss">
  97. @use 'sass:math';
  98. // 定义rpx转换函数
  99. @function rpx($px) {
  100. @return math.div($px, 750) * 100vw;
  101. }
  102. /* 过渡样式 */
  103. .drawer-slide-enter-active,
  104. .drawer-slide-leave-active {
  105. transition: all 0.3s ease;
  106. }
  107. .drawer-slide-enter-from,
  108. .drawer-slide-leave-to {
  109. transform: translateX(-100%);
  110. opacity: 0;
  111. transition: all 0.3s ease;
  112. }
  113. .home-container {
  114. position: fixed;
  115. top: 0;
  116. left: 0;
  117. right: 0;
  118. bottom: 0;
  119. display: flex;
  120. flex-direction: row;
  121. gap: rpx(0);
  122. background: linear-gradient(to bottom, #e2ddfc, #f1effd);
  123. }
  124. .icon-expand {
  125. width: rpx(8);
  126. height: rpx(35);
  127. border-top-right-radius: rpx(5);
  128. border-bottom-right-radius: rpx(5);
  129. z-index: 9999;
  130. position: absolute;
  131. top: 50%;
  132. left: 18%;
  133. transform: translateY(-50%);
  134. background-color: #44449c;
  135. cursor: pointer;
  136. clip-path: polygon(0 0, 100% 15%, 100% 85%, 0 100%);
  137. display: flex;
  138. justify-content: center;
  139. align-items: center;
  140. transition: all 0.3s ease;
  141. }
  142. .icon-expand .vertical-lines {
  143. color: #8a78d0;
  144. font-size: rpx(10);
  145. }
  146. // 右侧内容区
  147. .number-people {
  148. flex: 1;
  149. height: 100%;
  150. display: flex;
  151. flex-direction: column;
  152. background: linear-gradient(to bottom, #e2ddfc, #f1effd);
  153. }
  154. // 标题样式
  155. .title-box {
  156. height: rpx(35);
  157. }
  158. .box-icon {
  159. width: 100%;
  160. height: 100%;
  161. flex: 1;
  162. display: flex;
  163. align-items: center;
  164. color: black;
  165. padding-left: rpx(15);
  166. font-size: rpx(10);
  167. cursor: pointer;
  168. }
  169. .box-icon .left-icon {
  170. margin-left: rpx(10);
  171. margin-right: rpx(5);
  172. }
  173. // 内容样式
  174. .content-box {
  175. box-sizing: border-box;
  176. flex: 1;
  177. display: flex;
  178. flex-wrap: wrap;
  179. overflow-y: auto;
  180. }
  181. .content-box::-webkit-scrollbar {
  182. width: rpx(2);
  183. }
  184. .content-box::-webkit-scrollbar-track {
  185. background: transparent;
  186. border-radius: rpx(3);
  187. }
  188. .content-box::-webkit-scrollbar-thumb {
  189. background: linear-gradient(to bottom, hsl(230, 100%, 21%), #8a78d0);
  190. border-radius: rpx(3);
  191. }
  192. .content-box::-webkit-scrollbar-thumb:hover {
  193. background: linear-gradient(to bottom, hsl(230, 100%, 21%), #8a78d0);
  194. }
  195. .small-box {
  196. flex: 0 0 calc(33.333% - rpx(10)); // 每个小盒子占三分之一宽度,减去间距
  197. margin-left: rpx(10); // 设置小盒子间距
  198. margin-top: rpx(3); // 设置小盒子间距
  199. display: flex;
  200. flex-direction: column;
  201. justify-content: flex-start;
  202. align-items: center;
  203. color: black;
  204. font-size: rpx(8);
  205. cursor: pointer; // 鼠标指针样式
  206. }
  207. .nested-box {
  208. width: rpx(150);
  209. height: rpx(80);
  210. border-radius: rpx(10);
  211. margin-top: rpx(5);
  212. display: flex;
  213. border: 1px solid white; // 添加边框;
  214. justify-content: center;
  215. align-items: center;
  216. }
  217. .nested-box:hover,
  218. .nested-box:active {
  219. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
  220. }
  221. .additional-text {
  222. margin-bottom: rpx(4);
  223. font-size: rpx(8);
  224. }
  225. </style>