IntroductionUpdate.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div class="parent-container">
  3. <div class="button-group">
  4. <el-button
  5. v-for="(button, index) in buttons"
  6. :key="index"
  7. type="primary"
  8. :class="{ 'is-active': currentTargetId === parseInt(button.targetId) }"
  9. @click="showComponent(parseInt(button.targetId))"
  10. >
  11. {{ button.label }}
  12. </el-button>
  13. </div>
  14. <IntroUpdateModal
  15. :targetId="currentTargetId"
  16. :isVisible="!!currentTargetId"
  17. @updateSuccess="handleUpdateSuccess"
  18. />
  19. </div>
  20. </template>
  21. <script setup lang="ts">
  22. import { ref, onMounted } from 'vue';
  23. import IntroUpdateModal from './IntroUpdateModal.vue';
  24. const buttons = [
  25. { label: '软件简介更新', targetId: '1' },
  26. { label: '项目简介更新', targetId: '2' },
  27. { label: '研究成果更新', targetId: '3' },
  28. { label: '团队信息更新', targetId: '4' }
  29. ];
  30. const currentTargetId = ref<number | null>(null);
  31. const showComponent = (id: number) => {
  32. currentTargetId.value = id;
  33. };
  34. const handleUpdateSuccess = () => {
  35. console.log('子组件更新成功事件已接收');
  36. };
  37. // 页面加载时默认选中第一个按钮
  38. onMounted(() => {
  39. showComponent(parseInt(buttons[0].targetId));
  40. });
  41. </script>
  42. <style scoped>
  43. .parent-container {
  44. padding: 10px;
  45. width: 80%;
  46. max-width: 1200px;
  47. margin: 0 auto;
  48. background: #f0f8ff;
  49. border-radius: 15px;
  50. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  51. }
  52. .button-group {
  53. margin-bottom: 15px;
  54. display: flex;
  55. flex-wrap: wrap;
  56. gap: 15px;
  57. }
  58. .el-button {
  59. padding: 8px 15px;
  60. border-radius: 8px;
  61. font-size: 16px;
  62. font-weight: 500;
  63. background-color: #e0f2ff; /* 正常状态背景色 */
  64. color: #007bff; /* 正常状态文字颜色 */
  65. border: none;
  66. box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  67. transition: all 0.3s ease;
  68. }
  69. .el-button:hover {
  70. background-color: #b3d9ff; /* 悬停状态背景色 */
  71. color: #0056b3; /* 悬停状态文字颜色 */
  72. transform: translateY(-2px);
  73. box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  74. }
  75. .is-active {
  76. background-color: #007bff; /* 选中状态背景色 */
  77. color: white; /* 选中状态文字颜色 */
  78. transform: scale(1.05);
  79. box-shadow: 0 4px 15px rgba(0, 123, 255, 0.2);
  80. }
  81. </style>