Base Dialog and Drawer Container Technical Documentation
Table of Contents
- Introduction
- Project Structure
- Core Component Architecture
- BaseDialog Component Detailed Explanation
- BaseDrawer Component Detailed Explanation
- Component Comparison and Application Scenarios
- Micro-Frontend Environment Best Practices
- Summary
Introduction
This document provides a detailed introduction to two core container components in the LME base UI library: BaseDialog (base dialog) and BaseDrawer (base drawer). These two components are built based on Vue 3 Composition API, providing complete dialog and drawer functionality, including mask layer management, z-index stacking level control, ESC key listening and closing functionality, and touch support.
Project Structure
Chart Source
Section Source
Core Component Architecture
Chart Source
BaseDialog Component Detailed Explanation
Component Features
BaseDialog is an advanced dialog component based on Element Plus el-dialog encapsulation, with the following core features:
- Props-driven Display Control: Control dialog display state through v-model or props
- Emits Event Communication Mechanism: Provides three core events: close, confirm, open
- Mask Layer Management: Intelligently manages mask layer display and hiding
- Z-index Stacking Level Control: Ensures dialog displays at the correct level
- ESC Key Listening and Closing Functionality: Automatically listens for ESC key to close dialog
- Slot Content Customization: Supports default slot and custom button slot
Implementation Principle
Chart Source
Core Code Analysis
Event Handling Mechanism
// Close dialog will call this method. Sometimes when clicking confirm, it cannot trigger close at the same time. Add a parameter to distinguish whether it is a button close event or a close event
const onClose = (isClose = true) => emit('close', isClose)
const onConfirm = () => emit('confirm')
const onOpen = () => emit('open')
Style Class Name Calculation
const className = computed(() => {
if (attrs.class) {
return `without-cs-dialog ${attrs.class}`
}
return 'without-cs-dialog'
})
Content Area Height Control
const currentHeight = computed(() => {
return attrs.height || 'auto'
})
Section Source
BaseDrawer Component Detailed Explanation
Component Features
BaseDrawer is an advanced drawer component based on Element Plus el-drawer encapsulation, with the following core features:
- SCSS Transition Animation: Based on CSS animation to implement smooth slide-in/slide-out effects
- Touch Support: Supports mobile touch gesture operations
- Gradient Background Effect: Unique visual effects enhance user experience
- Icon Animation: Dynamic icons enhance interactive experience
- Flexible Width Control: Supports custom width settings
Implementation Principle
Chart Source
Core Code Analysis
Animation Keyframe Definition
@keyframes iconFrames {
0% { opacity: 1; }
25% { opacity: 0.66; }
50% { opacity: 0.33; }
75% { opacity: 0.66; }
100% { opacity: 1; }
}
Icon Animation Application
.iconPosition {
position: absolute;
top: 38px;
right: 111px;
user-select: none;
-webkit-user-drag: none;
animation: iconFrames 2s infinite linear;
}
Event Handling
return () => {
const vSlots: {
footer: () => Component
title?: () => Component
} = {
footer() {
return (
<div class={styles.csDialogFooter}>
<el-button
onClick={() => emit('close')}
type="info"
plain
class={{
[styles.dialogBtn]: true,
[styles.csBaseBtn]: true,
}}
>
{_t('取消')}
</el-button>
<el-button
onClick={() => emit('confirm')}
type="primary"
disabled={props.submitDisabled}
class={{
[styles.csBaseBtn]: true,
}}
>
{_t('确认')}
</el-button>
</div>
)
},
}
}
Section Source
Component Comparison and Application Scenarios
Feature Comparison Table
| Feature | BaseDialog | BaseDrawer |
|---|---|---|
| Display Method | Center Popup | Slide from Side |
| Default Width | 525px | Customizable |
| Mask Behavior | Click to Close | Configurable Click Behavior |
| Animation Effect | None | Slide In/Out |
| Mobile Support | General | Excellent |
| Content Area | Adjustable Height | Fully Filled |
| Application Scenario | Brief Interaction | Long Content Display |
Usage Scenario Suggestions
Micro-Frontend Environment Best Practices
CSS Scope Isolation
In micro-frontend environments, CSS scope isolation is key to ensuring component independence. The LME base UI library adopts the following strategies:
- Namespace Prefix: Implements style isolation through
$namespace = 'cs' - Automatic Namespace Conversion: Automatically converts
el-tocs-during packaging - Scoped CSS: Uses SCSS modularization to avoid style pollution
// Namespace conversion in build script
str = str.replace(/el-/g, 'cs-')
Event Bubbling Handling
Best Practice Recommendations
- Unified Event Naming Convention: Use semantic event names
- Parameter Serialization: Ensure data passed across applications is serializable
- Error Boundary Handling: Set error capture at application boundaries
- Resource Loading Isolation: Avoid duplicate loading of the same resources
Section Source
Summary
The BaseDialog and BaseDrawer components of the LME base UI library provide developers with powerful and flexible dialog and drawer solutions. Through the use of Vue 3 Composition API, these two components achieve:
- High Configurability: Rich props and event interfaces meet various business requirements
- Good User Experience: Smooth animation effects and intuitive operation feedback
- Excellent Compatibility: Supports desktop and mobile devices
- Micro-Frontend Friendly: Complete CSS scope isolation and event handling mechanisms
In actual projects, developers should choose appropriate components based on specific interaction requirements and content characteristics, and make reasonable use of the various functional features they provide to build excellent user interface experiences.