vue-element-plus-admin

repository·master·Indexed 25 days ago

https://github.com/kailong321200875/vue-element-plus-admin

A backend integration solution based on Vue 3, Element Plus, TypeScript, and Vite 4. It features an admin dashboard with a routing system supporting static and dynamic routes, permission-based access control, and multi-tab management. The project includes a comprehensive set of APIs for dashboard analysis, user and department management, role-based access, and a configured Axios instance for HTTP requests.

Tokens
17.1K
Snippets
29
Records
183
Agent score
87%

What's inside vue-element-plus-admin

  1. Initialize the Vue application

    master

    The application is initialized using an asynchronous setupAll function that orchestrates the mounting of various plugins, stores, and core services. To replicate the application setup or understand the initialization sequence, ensure the following plugins are applied to the Vue app instance in order:

    1. i18n: setupI18n(app)
    2. State Management: setupStore(app)
    3. Global Components: setupGlobCom(app)
    4. UI Framework: setupElementPlus(app)
    5. Routing: setupRouter(app)
    6. Permissions/Directives: setupPermission(app)

    Finally, call app.mount('#app') to mount the application to the DOM element with ID app.

    import { createApp } from 'vue'
    import App from './App.vue'
    
    const setupAll = async () => {
      const app = createApp(App)
    
      await setupI18n(app)
      setupStore(app)
      setupGlobCom(app)
      setupElementPlus(app)
      setupRouter(app)
      setupPermission(app)
    
      app.mount('#app')
    }
    
    setupAll()
  2. Initialize Element Plus with setupElementPlus

    master

    Use setupElementPlus to register necessary Element Plus plugins (like ElLoading) and components (like ElScrollbar) globally in your Vue application. This ensures that components used in dropdowns or overlays have the correct styles and functionality.

    To optimize development speed, you can instruct the plugin to import all Element Plus styles at once by setting the VITE_USE_ALL_ELEMENT_PLUS_STYLE environment variable to 'true'.

  3. Configure UnoCSS in vue-element-plus-admin

    master

    The project uses UnoCSS for utility-first CSS. The configuration includes presetUno with dark mode support via the class strategy and transformerVariantGroup to allow grouping of variants.

    Custom utility rules are available for specific layout and styling needs:

    • overflow-ellipsis: Applies text-overflow: ellipsis.
    • custom-hover: Applies flex layout, height, padding, cursor, and transition, with specific hover background colors for light and dark modes.
    • layout-border__left, layout-border__right, layout-border__top, layout-border__bottom: Apply absolute positioned pseudo-elements to create borders using CSS variables like --el-border-color.
  4. Configure Stylelint for the project

    master

    The project uses stylelint with postcss-html custom syntax to support linting CSS within .vue and .html files. It extends stylelint-config-standard and uses stylelint-order for property and rule ordering.

    Key configuration details:

    • Plugins: stylelint-order is used to enforce specific property and rule sequences.
    • Ignored Files: JavaScript and TypeScript files (.js, .jsx, .tsx, .ts) are ignored by Stylelint.
    • Vue/HTML Support: Specific overrides are applied to .vue and .html files to allow Vue-specific pseudo-elements like v-deep, v-global, and v-slotted.
  5. Configure TreeHelperConfig for tree utilities

    master

    When using tree utility functions, you can provide a configuration object to specify the property names used for identifying nodes and their hierarchy. If no config is provided, the following defaults are used:

    • id: 'id'
    • children: 'children'
    • pid: 'pid'
    interface TreeHelperConfig {
      id: string
      children: string
      pid: string
    }
  6. Configure ESLint for Vue and TypeScript

    master

    The project uses a flat configuration file (eslint.config.mjs) that integrates TypeScript, Vue, and Prettier. It targets .ts, .tsx, and .vue files within the src directory.

    Key configuration features include:

    • Parsers: Uses vue-eslint-parser for .vue files and typescript-eslint for TypeScript syntax.
    • Presets: Extends eslint.configs.recommended, tseslint.configs.recommended, and pluginVue.configs['flat/essential'].
    • Prettier Integration: Uses eslint-plugin-prettier to treat Prettier formatting issues as ESLint errors.
    import pluginVue from 'eslint-plugin-vue'
    import eslint from '@eslint/js'
    import tseslint from 'typescript-eslint'
    import vueParser from 'vue-eslint-parser'
    import prettier from 'eslint-plugin-prettier'
    
    export default tseslint.config({
      files: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.vue'],
      extends: [
        eslint.configs.recommended,
        ...tseslint.configs.recommended,
        ...pluginVue.configs['flat/essential']
      ],
      plugins: {
        prettier
      },
      languageOptions: {
        parser: vueParser,
        parserOptions: {
          parser: tseslint.parser,
          sourceType: 'module',
          ecmaVersion: 2020,
          ecmaFeatures: {
            jsx: true
          }
        }
      },
      rules: {
        'prettier/prettier': 'error',
        // ... other rules
      }
    })
  7. Configure Prettier settings

    master

    The project uses Prettier for code formatting. The following configuration is applied to maintain consistent code style across the repository:

    • printWidth: 100
    • tabWidth: 2
    • useTabs: false
    • semi: false
    • vueIndentScriptAndStyle: false
    • singleQuote: true
    • quoteProps: 'as-needed'
    • bracketSpacing: true
    • trailingComma: 'none'
    • jsxSingleQuote: false
    • arrowParens: 'always'
    • insertPragma: false
    • requirePragma: false
    • proseWrap: 'never'
    • htmlWhitespaceSensitivity: 'strict'
    • endOfLine: 'auto'
    • rangeStart: 0
    module.exports = {
      printWidth: 100,
      tabWidth: 2,
      useTabs: false,
      semi: false,
      vueIndentScriptAndStyle: false,
      singleQuote: true,
      quoteProps: 'as-needed',
      bracketSpacing: true,
      trailingComma: 'none',
      jsxSingleQuote: false,
      arrowParens: 'always',
      insertPragma: false,
      requirePragma: false,
      proseWrap: 'never',
      htmlWhitespaceSensitivity: 'strict',
      endOfLine: 'auto',
      rangeStart: 0
    }
  8. Toggle Icon Presets via VITE_USE_ONLINE_ICON

    master

    The UnoCSS icon preset behavior is controlled by an environment variable.

    • If VITE_USE_ONLINE_ICON is set to 'true', the presetIcons is disabled (returns an empty array).
    • If VITE_USE_ONLINE_ICON is not 'true', presetIcons is enabled with autoInstall: false and uses the project's defined ICON_PREFIX.