# PressConvertExchangeTemplate Exchange Template Component
# π¦ Component Introduction
PressConvertExchangeTemplate is a template component that encapsulates exchange list and point consumption functionality, integrating press-convert-exchange-list and press-convert-point-cost sub-components to provide complete point exchange features.
β¨ Architecture Advantages:
- Mixin Shared Logic - Avoid code duplication
- Independent Template Files - Support different DOM structures
- Auto Props Pass-through - Using
v-bind="{ ...$props, ...$attrs }"and explicit event forwarding - Easy to Maintain and Extend - Modify logic only in mixin, modify structure only in corresponding template
# ποΈ Architecture Design
# File Structure
press-convert-exchange-template/
βββ press-convert-exchange-template.vue # Main component (routing dispatcher)
βββ template-mixin.js # Common logic Mixin
βββ pwd/
β βββ index.vue # PWD template (independent DOM structure)
βββ party/
β βββ index.vue # Party template (independent DOM structure)
βββ demo.vue # Example code
βββ README.md # Documentation
# Architecture Principle
βββββββββββββββββββββββββββββββββββββββββββββββ
β press-convert-exchange-template.vue β
β (Main component - dispatcher) β
β β
β <TemplatePwd v-if="type === 'pwd'" ... /> β
β <TemplateParty v-else ... /> β
ββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β
ββββ type="pwd" βββ pwd/index.vue (PWD template)
β ββ mixins: [templateMixin]
β ββ Independent DOM structure
β ββ Exclusive prop: pwdWrapBg
β
ββββ type="party" βββ party/index.vue (Party template)
ββ mixins: [templateMixin]
ββ Independent DOM structure
βββββββββββββββββββββββββββββββββββββββ
β template-mixin.js β
β (Common logic - shared by all) β
β β
β - props definition β
β - emits definition β
β - methods (event handlers) β
β - components (sub-components) β
βββββββββββββββββββββββββββββββββββββββ
# Template Layout Structure
Both templates share the same DOM layout:
βββββββββββββββββββββββ
β point-cost β β Point info + refresh button
β <slot /> β β Default slot (inside point-cost)
βββββββββββββββββββββββ€
β exchange-list β β Exchange item list
βββββββββββββββββββββββ
# π― Features
- β Support 2 preset templates (PWD/Party), each with independent DOM structure
- β Exchange list display
- β Point information display
- β Slot extension support
- β Event callback handling
- β Mixin shared logic, avoid code duplication
# π Usage
# Basic Usage - Using PWD Template
<template>
<PressConvertExchangeTemplate
type="pwd"
:exchange-list="exchangeList"
:point-icon="pointIcon"
:point-info="pointInfo"
@exchangeClick="handleExchangeClick"
@showRewardExplain="handleShowRewardExplain"
@refresh="handleRefresh"
/>
</template>
<script>
import PressConvertExchangeTemplate from 'press-plus/press-convert-exchange-template/press-convert-exchange-template';
export default {
components: {
PressConvertExchangeTemplate,
},
data() {
return {
pointIcon: 'https://example.com/point-icon.png',
exchangeList: [
{
pic: 'https://example.com/reward.png',
name: '$100 Coupon',
need_money: 1000,
num: 50,
showMoney: true,
btnTxt: 'Exchange Now',
disabled: false,
},
],
pointInfo: {
pointIcon: 'https://example.com/point-icon.png',
pointCount: 5000,
expireTime: '30 days',
},
};
},
methods: {
handleExchangeClick(item) {
console.log('Exchange item:', item);
},
handleShowRewardExplain(index) {
console.log('Show reward explanation:', index);
},
handleRefresh() {
console.log('Refresh points');
},
},
};
</script>
# Switch Between Templates
<!-- PWD Template - PWD exclusive layout -->
<PressConvertExchangeTemplate type="pwd" ... />
<!-- Party Template - Party carnival layout -->
<PressConvertExchangeTemplate type="party" ... />
# Using Slots
The default slot is located inside the point-cost component (within the point info area).
<PressConvertExchangeTemplate
type="pwd"
:exchange-list="exchangeList"
:point-icon="pointIcon"
:point-info="pointInfo"
>
<div class="custom-content">
<button @click="handleCustomAction">
View More Rewards
</button>
</div>
</PressConvertExchangeTemplate>
# π Props
# Template Configuration
| Prop | Type | Default | Description |
|---|---|---|---|
| type | String | 'pwd' | Template type: 'pwd' / 'party' |
# Exchange List Related
| Prop | Type | Default | Description |
|---|---|---|---|
| exchangeList | Array | [] | Exchange list data |
| pointIcon | String | '' | Point icon URL |
| exchangeListBg | String | '' | Exchange list background image |
| tagBg | String | '' | Exchange list tag background image |
| redeemRewardBg | String | '' | Reward box background image |
| rewardTextColor | String | '' | Reward text color |
| rewardBtnBg | String | '' | Reward button background image |
| rewardBtnTextColor | String | '' | Reward button text color |
# Point Cost Related
| Prop | Type | Default | Description |
|---|---|---|---|
| pointInfo | Object | {} | Point information object |
| pointTextColor | String | '' | Point text color |
# PWD Template Exclusive
| Prop | Type | Default | Description |
|---|---|---|---|
| pwdWrapBg | String | '' | Background image for PWD template outer container |
# exchangeList Data Structure
[
{
pic: 'https://example.com/reward.png', // Reward image
name: '$100 Coupon', // Reward name
need_money: 1000, // Required points
num: 50, // Remaining quantity
showMoney: true, // Show points or not
btnTxt: 'Exchange Now', // Button text
disabled: false, // Disabled or not
}
]
# pointInfo Data Structure
{
pointIcon: 'https://example.com/point-icon.png', // Point icon
pointCount: 5000, // Point count
expireTime: '30 days', // Expiration hint, displays as "Xεε€±ζ"; 0 = no expiry
}
# πͺ Events
| Event | Parameters | Description |
|---|---|---|
| exchangeClick | item: Object | Triggered when exchange button is clicked, returns exchange item data |
| showRewardExplain | index: Number | Triggered when reward image is clicked, returns index |
| refresh | - | Triggered when refresh button is clicked |
# π¨ Slots
| Slot | Description |
|---|---|
| default | Default slot, located inside the point-cost component |
# π‘ Template Differences
# PWD Template (pwd/index.vue)
Layout:
point-cost (point info + refresh)
ββ <slot />
exchange-list
Features:
- Supports
pwdWrapBgouter container background image - Suitable for PWD activity scenarios
# Party Template (party/index.vue)
Layout:
point-cost (point info + refresh)
ββ <slot />
exchange-list
Features:
- Suitable for party activity scenarios
# π§ Extend New Template
# Step 1: Create New Template Directory and File festival/index.vue
<template>
<div class="press-exchange-festival">
<point-cost
:point-info="pointInfo"
:text-color="pointTextColor"
@refresh="handleRefresh"
>
<slot />
</point-cost>
<exchange-list
:exchange-list="exchangeList"
:point-icon="pointIcon"
:exchange-list-bg="exchangeListBg"
:tag-bg="tagBg"
:redeem-reward-bg="redeemRewardBg"
:reward-text-color="rewardTextColor"
:reward-btn-bg="rewardBtnBg"
:reward-btn-text-color="rewardBtnTextColor"
@exchangeClick="handleExchangeClick"
@showRewardExplain="handleShowRewardExplain"
/>
</div>
</template>
<script>
import templateMixin from '../template-mixin';
export default {
name: 'PressExchangeTemplateFestival',
mixins: [templateMixin],
};
</script>
# Step 2: Register in Main Component
// press-convert-exchange-template.vue
import TemplateFestival from './festival/index.vue';
export default {
components: {
TemplatePwd,
TemplateParty,
TemplateFestival,
},
props: {
type: {
validator: value => ['pwd', 'party', 'festival'].includes(value),
},
},
};
# π Notes
- Modify Common Logic - Modifying
template-mixin.jsaffects all templates - Modify Template Structure - Modifying
pwd/index.vueorparty/index.vueonly affects corresponding template - Props Auto Pass-through - Main component props are automatically passed to sub-templates
- Event Auto Pass-through - Sub-template events automatically bubble to main component
- Image URLs need to be valid network addresses or local paths
- Recommend validating point balance and stock before exchange
# π¦ Dependencies
press-convert-exchange-list- Exchange list componentpress-convert-point-cost- Point cost component
β ConvertExchangeList ConvertPointCost β