Spaces:
Running
Running
| // Shared JavaScript across all pages | |
| // Code generation function | |
| function generateCode() { | |
| const codeOutput = document.getElementById('code-output'); | |
| // Sample generated code (in real implementation, this would come from API) | |
| const sampleCode = `package com.example.entity; | |
| import com.mybatisflex.annotation.Id; | |
| import com.mybatisflex.annotation.Table; | |
| import java.time.LocalDateTime; | |
| @Table("user") | |
| public class User { | |
| @Id | |
| private Long id; | |
| private String username; | |
| private String email; | |
| private LocalDateTime createTime; | |
| private LocalDateTime updateTime; | |
| // Getters and Setters | |
| public Long getId() { return id; } | |
| public void setId(Long id) { this.id = id; } | |
| public String getUsername() { return username; } | |
| public void setUsername(String username) { this.username = username; } | |
| public String getEmail() { return email; } | |
| public void setEmail(String email) { this.email = email; } | |
| public LocalDateTime getCreateTime() { return createTime; } | |
| public void setCreateTime(LocalDateTime createTime) { this.createTime = createTime; } | |
| public LocalDateTime getUpdateTime() { return updateTime; } | |
| public void setUpdateTime(LocalDateTime updateTime) { this.updateTime = updateTime; } | |
| }`; | |
| codeOutput.textContent = sampleCode; | |
| codeOutput.classList.add('code-highlight'); | |
| setTimeout(() => codeOutput.classList.remove('code-highlight'), 2000); | |
| // Show success notification | |
| showNotification('代码生成成功!', 'success'); | |
| } | |
| // Copy code to clipboard | |
| function copyCode() { | |
| const codeOutput = document.getElementById('code-output'); | |
| const textArea = document.createElement('textarea'); | |
| textArea.value = codeOutput.textContent; | |
| document.body.appendChild(textArea); | |
| textArea.select(); | |
| document.execCommand('copy'); | |
| document.body.removeChild(textArea); | |
| showNotification('代码已复制到剪贴板!', 'success'); | |
| } | |
| // Download generated code | |
| function downloadCode() { | |
| const codeOutput = document.getElementById('code-output'); | |
| const blob = new Blob([codeOutput.textContent], { type: 'text/plain' }); | |
| const url = URL.createObjectURL(blob); | |
| const a = document.createElement('a'); | |
| a.href = url; | |
| a.download = 'MyBatisFlexGeneratedCode.java'; | |
| document.body.appendChild(a); | |
| a.click(); | |
| document.body.removeChild(a); | |
| URL.revokeObjectURL(url); | |
| showNotification('代码下载成功!', 'success'); | |
| } | |
| // Notification system | |
| function showNotification(message, type = 'info') { | |
| const notification = document.createElement('div'); | |
| notification.className = `fixed top-4 right-4 z-50 px-6 py-4 rounded-lg shadow-lg transform transition-all duration-300 ${ | |
| type === 'success' ? 'bg-green-500 text-white' : | |
| type === 'error' ? 'bg-red-500 text-white' : | |
| 'bg-blue-500 text-white' | |
| }`; | |
| notification.textContent = message; | |
| document.body.appendChild(notification); | |
| // Animate in | |
| setTimeout(() => { | |
| notification.classList.add('translate-x-0', 'opacity-100'); | |
| notification.classList.remove('translate-x-full', 'opacity-0'); | |
| }, 100); | |
| // Auto remove after 3 seconds | |
| setTimeout(() => { | |
| notification.classList.add('translate-x-full', 'opacity-0'); | |
| setTimeout(() => { | |
| if (notification.parentNode) { | |
| notification.parentNode.removeChild(notification); | |
| } | |
| }, 300); | |
| }, 3000); | |
| } | |
| // Initialize app when DOM is loaded | |
| document.addEventListener('DOMContentLoaded', function() { | |
| console.log('FlexGen Studio loaded successfully!'); | |
| // Add smooth scrolling for anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function (e) { | |
| e.preventDefault(); | |
| const target = document.querySelector(this.getAttribute('href')); | |
| if (target) { | |
| target.scrollIntoView({ | |
| behavior: 'smooth', | |
| block: 'start' | |
| }); | |
| } | |
| }); | |
| }); | |
| }); |