mall-admin-web

repository·master·Indexed 11 days ago

https://github.com/macrozheng/mall-admin-web

A Vue 3 and Element Plus based frontend administration dashboard for the 'mall' e-commerce ecosystem. Version 3.0.0 provides comprehensive management for products (PMS), orders (OMS), users (UMS), and promotions (SMS), featuring a dual-map routing strategy for permission-based access and Pinia for state management.

Tokens
13.3K
Snippets
50
Records
61
Agent score
95%

What's inside mall-admin-web

  1. Overview of mall-admin-web

    master

    mall-admin-web is a frontend e-commerce administration system built with Vue 3 and Element Plus. It provides comprehensive management capabilities including product management, order management, member management, promotion management, operations management, content management, statistical reports, financial management, permission management, and settings.

    Key Features:

    • Product (PMS), Order (OMS), and User (UMS) modules.
    • Statistical reporting and financial management.
    • Permission and settings management.
  2. Install and Run mall-admin-web locally

    master

    Follow these steps to set up the development environment:

    1. Prerequisites:

      • Install Node.js (v20 or higher recommended, e.g., v20 LTS).
      • Ensure you have a backend environment running (refer to the mall backend repository).
    2. Configure API URL: Edit the .env.development file to set VITE_BASE_SERVER_URL based on your backend:

      • Local Backend: Use your local backend API address.
      • Online API (No backend setup required): Set VITE_BASE_SERVER_URL to https://admin-api.macrozheng.com.
      • Microservices (mall-swarm): Set VITE_BASE_SERVER_URL to http://localhost:8201/mall-admin (requires gateway access).
    3. Execution:

      # Install dependencies
      npm install
      
      # Run the development server
      npm run dev
    4. Access: Open http://localhost:5173 in your browser.

    npm install
    npm run dev
  3. Understand the routing structure in mall-admin-web

    master

    The application uses a dual-map routing strategy to manage access control and navigation. Routes are split into two main categories:

    1. constantRouterMap: These are static routes that are always available to the user, regardless of permissions. This typically includes the login page, 404 error page, and the basic layout/home structure.
    2. asyncRouterMap: These are dynamic routes that are loaded based on user permissions (e.g., PMS for products, OMS for orders, SMS for marketing, UMS for user management). These routes are usually fetched or injected after authentication.

    Routes can be hidden from the sidebar/menu by setting the hidden: true property in their configuration.

  4. How SVG icon automatic loading works

    master
    The icon system uses Vite's import.meta.glob to automatically discover and load all .svg files located in the ./svg/ directory relative to the icon entry point. When the module is executed, the SVG content is loaded into the application, making the icons available for use via the svg-icon component. To add a new icon, simply place the .svg file into the src/icons/svg/ folder.
  5. Enable additional languages in .vue files

    master

    If you need to support languages other than standard TypeScript (e.g., tsx) within your .vue files, you must use configureVueProject from @vue/eslint-config-typescript before the default export.

    import { configureVueProject } from '@vue/eslint-config-typescript'
    
    configureVueProject({ scriptLangs: ['ts', 'tsx'] })
  6. Initialize the mall-admin-web application

    master

    The application entrypoint src/main.ts initializes the Vue application by integrating Pinia for state management, Vue Router for navigation, and a custom SVG icon system.

    Key initialization steps include:

    • State Management: Uses pinia with the pinia-plugin-persistedstate plugin to enable automatic state persistence.
    • Routing: Uses vue-router with pre-defined navigation guards imported from @/router/guard.
    • Icon System: Uses setupSvgIcon to register SVG icons, which relies on the virtual:svg-icons-register module for icon registration.
    • Styling: Loads global SCSS styles and normalize.css for cross-browser consistency.
    import { createApp } from 'vue'
    import App from './App.vue'
    import { createPinia } from 'pinia'
    import router from './router'
    import '@/styles/index.scss'
    import 'normalize.css/normalize.css'
    import { setupSvgIcon } from './icons'
    import 'virtual:svg-icons-register'
    import '@/router/guard'
    import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
    
    const app = createApp(App)
    const pinia = createPinia()
    
    // Enable state persistence
    pinia.use(piniaPluginPersistedstate)
    
    app.use(pinia)
    app.use(router)
    setupSvgIcon(app)
    app.mount('#app')
  7. Configure ESLint for Vue and TypeScript

    master

    The project uses a flat configuration format for ESLint, specifically optimized for Vue and TypeScript via @vue/eslint-config-typescript.

    By default, the configuration targets files with the following extensions:

    • .ts
    • .mts
    • .tsx
    • .vue

    It applies the following rule sets:

    1. pluginVue.configs['flat/essential']: Essential Vue linting rules.
    2. vueTsConfigs.recommended: Recommended TypeScript rules for Vue.
    3. Custom rules: Currently disables 'vue/multi-word-component-names' to allow single-word component names.
    import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
    import pluginVue from 'eslint-plugin-vue'
    
    export default defineConfigWithVueTs(
      {
        name: 'app/files-to-lint',
        files: ['**/*.{ts,mts,tsx,vue}'],
      },
    
      // Global ignores
      // pluginVue.configs['flat/essential'],
      // vueTsConfigs.recommended,
      {
        name: 'app/custom-rules',
        rules: {
          'vue/multi-word-component-names': 'off',
        },
      },
    )
  8. Project Directory Structure

    master

    The source code is organized as follows:

    • src/apis: Axios network request definitions.
    • src/assets: Static image resources.
    • src/components: Encapsulated common components.
    • src/icons: SVG vector icons.
    • src/router: Vue Router configurations.
    • src/store: Pinia state management.
    • src/styles: Global CSS styles.
    • src/types: Type definitions.
    • src/utils: Utility functions.
    • src/views: Frontend page components, categorized by module:
      • home: Home page.
      • layout: Common page layouts.
      • normal: Common pages (e.g., login, 404).
      • oms: Order module pages.
      • pms: Product module pages.
      • sms: Message/Content module pages.
      • ums: User module pages.
  9. Technical Stack of mall-admin-web

    master

    The project utilizes the following core technologies:

    TechnologyDescription
    VueFrontend framework
    Element PlusUI framework
    Vue RouterRouting framework
    PiniaGlobal state management
    Pinia Plugin PersistedstatePinia persistence plugin
    AxiosHTTP client
    vue-chartsChart framework based on Echarts
    TinyMCE VueRich text editor
    Js-cookieCookie management
    vue-element-adminProject scaffolding
  10. Register SVG icons globally with setupSvgIcon

    master

    The setupSvgIcon function allows you to register the svg-icon component globally within a Vue application. This is typically called in your main.ts or main.js file to ensure the icon component is available throughout your entire application without manual imports in every component.

    import { createApp } from 'vue'
    import App from './App.vue'
    import { setupSvgIcon } from '@/icons/index'
    
    const app = createApp(App)
    
    // Register the svg-icon component globally
    setupSvgIcon(app)
    
    app.mount('#app')
  11. Order Query and Parameter types

    master

    These types are used for filtering order lists and providing data for specific order actions:

    • OrderQueryParam: Used for searching/filtering orders. Extends PageParam and includes orderSn, receiverKeyword, status, orderType, sourceType, and createTime.
    • OmsOrderDeliveryParam: Used when shipping an order. Requires orderId and optional deliveryCompany and deliverySn.
    • OmsReceiverInfoParam: Used for updating or managing receiver details. Requires orderId and status.
    • OmsMoneyInfoParam: Used for managing order financial adjustments. Requires orderId, freightAmount, discountAmount, and status.
    export type OrderQueryParam = PageParam & {
      orderSn?: string
      receiverKeyword?: string
      status?: number
      orderType?: number
      sourceType?: number
      createTime?: string
    }
    
    export type OmsOrderDeliveryParam = {
      orderId: number
      deliveryCompany?: string
      deliverySn?: string
    }
    
    export type OmsReceiverInfoParam = {
      orderId: number
      receiverName?: string
      receiverPhone?: string
      receiverPostCode?: string
      receiverDetailAddress?: string
      receiverProvince?: string
      receiverCity?: string
      receiverRegion?: string
      status: number
    }
    
    export type OmsMoneyInfoParam = {
      orderId: number
      freightAmount: number
      discountAmount: number
      status: number
    }