Sakai Vue Documentation

repository·master·Indexed 22 days ago

https://github.com/primefaces/sakai-vue

A professional Vue application template powered by Vite and PrimeVue. It features the useLayout composable for managing global layout state, themes, and menus, as well as integrated services like CustomerService, ProductService, and NodeService for mock data retrieval. The template utilizes vue-router for layout-wrapped and standalone routing and is configured with the Aura theme preset.

Tokens
5.7K
Snippets
18
Records
19
Agent score
78%

What's inside Sakai Vue

  1. Get started with Sakai Vue

    master

    Sakai is an application template for Vue projects powered by Vite. It is built using the recommended create-vue approach. For comprehensive setup instructions, detailed guides, and component documentation, visit the official Sakai documentation website.

    https://sakai.primevue.org/documentation
  2. Initialize the Sakai Vue application

    master

    The application is initialized using the standard Vue createApp pattern. It integrates vue-router for navigation, PrimeVue for UI components, and PrimeVue services for feedback mechanisms.

    Key integrations include:

    • PrimeVue Configuration: Configured with the Aura theme preset. The darkModeSelector is set to .app-dark, meaning dark mode is toggled by applying this class to a parent element.
    • Services: ToastService (for notifications) and ConfirmationService (for confirmation dialogs) are registered globally.
    • Styles: The application imports Tailwind CSS and custom SCSS styles.
    import { createApp } from 'vue';
    import App from './App.vue';
    import router from './router';
    
    import Aura from '@primeuix/themes/aura';
    import PrimeVue from 'primevue/config';
    import ConfirmationService from 'primevue/confirmationservice';
    import ToastService from 'primevue/toastservice';
    
    import '@/assets/tailwind.css';
    import '@/assets/styles.scss';
    
    const app = createApp(App);
    
    app.use(router);
    app.use(PrimeVue, {
        theme: {
            preset: Aura,
            options: {
                darkModeSelector: '.app-dark'
            }
        }
    });
    app.use(ToastService);
    app.use(ConfirmationService);
    
    app.mount('#app');
  3. Configure routing in Sakai-Vue

    master

    Sakai-Vue uses vue-router to manage application navigation. The routing structure is organized into two main types of routes:

    1. Layout-wrapped routes: Routes defined as children of the / path use AppLayout.vue as their parent component. These routes typically include the main application dashboard, UI kit documentation, and utility pages. They inherit the application's shell (sidebar, topbar, etc.).
    2. Standalone routes: Routes defined outside the AppLayout children array, such as /landing, /pages/notfound, and authentication pages (/auth/login, /auth/access, /auth/error). These are used for pages that do not require the standard application layout.

    To add a new page that uses the application layout, add a new object to the children array of the / path. To add a page that stands alone (like a custom landing page), add it to the top-level routes array.

    import AppLayout from '@/layout/AppLayout.vue';
    import { createRouter, createWebHistory } from 'vue-router';
    
    const router = createRouter({
        history: createWebHistory(),
        routes: [
            {
                path: '/',
                component: AppLayout,
                children: [
                    // Add layout-wrapped routes here
                ]
            },
            {
                path: '/standalone-path',
                name: 'standalone',
                component: () => import('@/views/Standalone.vue')
            }
        ]
    });
    
    export default router;
  4. Use CountryService to retrieve country data

    master

    The CountryService object provides methods to access a list of country information. Each country object in the returned array contains a name (string) and a code (ISO country code string).

    Use getCountries() to retrieve the data asynchronously, which returns a Promise that resolves to the array of countries.

    import { CountryService } from '@/service/CountryService';
    
    // Fetching countries asynchronously
    CountryService.getCountries().then(data => {
        console.log(data);
        // data is an array of { name: string, code: string }
    });
  5. Use the useLayout composable to manage application state

    master

    The useLayout composable provides access to the global layout configuration and state, allowing you to control themes, menus, and sidebars across your Sakai Vue application. It returns reactive objects for configuration and state, along with helper methods to trigger UI transitions.

    Configuration (layoutConfig)

    Use layoutConfig to manage the visual appearance:

    • preset: The UI preset (e.g., 'Aura').
    • primary: The primary color theme (e.g., 'emerald').
    • surface: The surface color theme.
    • darkTheme: Boolean indicating if dark mode is active.
    • menuMode: The menu behavior, typically 'static' or 'overlay'.

    State (layoutState)

    Use layoutState to track the current UI status:

    • staticMenuInactive: Whether the static menu is collapsed.
    • overlayMenuActive: Whether the overlay menu is open.
    • configSidebarVisible: Whether the configuration sidebar is visible.
    • sidebarExpanded: Whether the sidebar is expanded.
    • activeMenuItem: The currently active menu item.
    • activePath: The current application path.
    import { useLayout } from '@/layout/composables/layout';
    
    const { layoutConfig, layoutState, toggleDarkMode, toggleMenu } = useLayout();
    
    // Example: Accessing state in a component
    // <div v-if="layoutState.configSidebarVisible">...</div>
    
    // Example: Triggering actions
    // <button @click="toggleDarkMode">Toggle Dark Mode</button>
  6. Use NodeService to fetch tree data

    master

    The NodeService provides methods to retrieve hierarchical node data, typically used for populating tree or treeTable components. It supports both synchronous data retrieval and asynchronous Promise-based retrieval.

    Available Methods

    • getTreeNodes(): Returns a Promise that resolves to an array of tree nodes. Each node contains key, label, data, icon, and an optional children array.
    • getTreeTableNodes(): Returns a Promise that resolves to an array of tree table nodes. Each node contains a key, a data object (containing properties like name, size, and type), and an optional children array.

    Node Structure

    For standard trees, nodes follow this shape:

    {
        key: string;
        label: string;
        data?: string;
        icon?: string;
        children?: Array<Node>;
    }

    For tree tables, nodes follow this shape:

    {
        key: string;
        data: {
            name: string;
            size: string;
            type: string;
        };
        children?: Array<Node>;
    }
    import { NodeService } from '@/service/NodeService';
    
    // Fetching tree nodes
    const nodes = await NodeService.getTreeNodes();
    
    // Fetching tree table nodes
    const tableNodes = await NodeService.getTreeTableNodes();
  7. Use PhotoService to retrieve image data

    master

    The PhotoService provides methods to fetch photo-related information, typically used for populating image galleries or carousels. It returns an array of photo objects, each containing source URLs for full images and thumbnails, along with metadata like titles and alt text.

    Photo Object Schema

    Each photo object in the returned array contains:

    • itemImageSrc: URL of the full-size image.
    • thumbnailImageSrc: URL of the thumbnail image.
    • alt: Alternative text description for the image.
    • title: The title of the photo.
    import { PhotoService } from '@/service/PhotoService';
    
    // Using the asynchronous method (recommended for consistency with real APIs)
    PhotoService.getImages().then((images) => {
        console.log(images);
    });
    
    // Or using the synchronous method
    const data = PhotoService.getData();
    console.log(data);
  8. Use ProductService to fetch product data

    master

    The ProductService object provides several methods to retrieve product information, simulating API calls by returning Promises. These methods allow you to fetch different subsets of data, including products with or without associated order history.

    Available methods:

    • getProducts(): Returns all products.
    • getProductsMini(): Returns a small subset (first 5) of products.
    • getProductsSmall(): Returns a small subset (first 10) of products.
    • getProductsWithOrders(): Returns all products, including an orders array for each product.
    • getProductsWithOrdersSmall(): Returns a small subset (first 10) of products including their orders array.
    • getProductsWithOrdersData(): Returns the raw array of products with order data (synchronous).
    import { ProductService } from 'src/service/ProductService';
    
    // Example: Fetching all products
    ProductService.getProducts().then(products => {
        console.log(products);
    });
    
    // Example: Fetching products with their order history
    ProductService.getProductsWithOrders().then(productsWithOrders => {
        console.log(productsWithOrders);
    });
  9. Manage theme and menu interactions with useLayout methods

    master

    The useLayout composable exports several methods to programmatically control the application layout:

    • toggleDarkMode(): Toggles the darkTheme configuration and updates the app-dark class on the document element. It uses document.startViewTransition for smooth transitions if supported by the browser.
    • toggleMenu(): Toggles the menu based on the current menuMode and device type (desktop vs mobile).
    • toggleConfigSidebar(): Toggles the visibility of the configuration sidebar.
    • hideMobileMenu(): Specifically closes the mobile menu.
    • changeMenuMode(event): Updates the menuMode (e.g., switching from 'static' to 'overlay') and resets various menu-related states like staticMenuInactive and sidebarExpanded.
    const { 
        toggleDarkMode, 
        toggleMenu, 
        toggleConfigSidebar, 
        hideMobileMenu, 
        changeMenuMode 
    } = useLayout();
    
    // To change menu mode via an event (e.g., from a Select component)
    // changeMenuMode({ value: 'overlay' });
  10. Check layout status with useLayout computed properties

    master

    Use the following computed properties from useLayout to reactively check the current layout status in your components:

    • isDarkTheme: A computed boolean that returns true if layoutConfig.darkTheme is active.
    • hasOpenOverlay: A computed boolean that returns true if layoutState.overlayMenuActive is active.
    • isDesktop(): A helper function that returns true if the window width is greater than 991 pixels.
    const { isDarkTheme, hasOpenOverlay, isDesktop } = useLayout();
    
    // Usage in template
    // <div v-if="isDarkTheme">Dark Mode Active</div>
    // <div v-if="hasOpenOverlay">Overlay is open</div>
  11. Use CustomerService to retrieve customer data

    master

    The CustomerService object provides a method to retrieve a mock dataset of customer information. This is useful for populating UI components like tables or lists during development. The getData() method returns an array of customer objects containing details such as ID, name, country, company, status, and representative information.

    import { CustomerService } from 'src/service/CustomerService';
    
    const customers = CustomerService.getData();
    console.log(customers);
  12. Retrieve product data using ProductService.getProductsData()

    master

    The ProductService object provides a method getProductsData() which returns an array of mock product objects. This is useful for populating UI components like product lists, tables, or grids within the Sakai template. Each product object contains details such as id, code, name, description, image, price, category, quantity, inventoryStatus, and rating.

    import { ProductService } from '@/service/ProductService';
    
    const products = ProductService.getProductsData();
    console.log(products);