hy-app 0.4.12 → 0.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/hy-card/index.scss +1 -1
- package/components/hy-coupon/README.md +133 -0
- package/components/hy-coupon/hy-coupon.vue +175 -0
- package/components/hy-coupon/index.scss +469 -0
- package/components/hy-coupon/props.ts +144 -0
- package/components/hy-coupon/typing.d.ts +136 -0
- package/components/hy-folding-panel/hy-folding-panel.vue +85 -333
- package/components/hy-folding-panel/typing.d.ts +57 -68
- package/components/hy-folding-panel-item/hy-folding-panel-item.vue +278 -228
- package/components/hy-folding-panel-item/index.scss +87 -0
- package/components/hy-folding-panel-item/typing.d.ts +23 -0
- package/components/hy-qrcode/hy-qrcode.vue +2 -2
- package/components/hy-submit-bar/hy-submit-bar.vue +5 -5
- package/components/hy-submit-bar/typing.d.ts +26 -25
- package/global.d.ts +2 -0
- package/libs/css/theme.scss +3 -3
- package/package.json +2 -2
- package/web-types.json +1 -1
- package/components/hy-folding-panel/index.scss +0 -9
- package/components/hy-folding-panel/props.ts +0 -17
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# HyCoupon 优惠券组件
|
|
2
|
+
|
|
3
|
+
市场上常用的优惠券组件,支持多种状态展示和丰富的功能配置。
|
|
4
|
+
|
|
5
|
+
## 引入方式
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
// 全局引入
|
|
9
|
+
import { createApp } from 'vue'
|
|
10
|
+
import HyDesignUni from '@/package'
|
|
11
|
+
import App from './App.vue'
|
|
12
|
+
|
|
13
|
+
const app = createApp(App)
|
|
14
|
+
app.use(HyDesignUni)
|
|
15
|
+
app.mount('#app')
|
|
16
|
+
|
|
17
|
+
// 局部引入
|
|
18
|
+
import { HyCoupon } from '@/package'
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
components: {
|
|
22
|
+
HyCoupon
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 基本用法
|
|
28
|
+
|
|
29
|
+
```html
|
|
30
|
+
<hy-coupon
|
|
31
|
+
amount="50"
|
|
32
|
+
title="新人专享优惠券"
|
|
33
|
+
subtitle="全场通用,无门槛使用"
|
|
34
|
+
validity="2023.10.01-2023.12.31"
|
|
35
|
+
@click="onCouponClick"
|
|
36
|
+
/>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 状态展示
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<!-- 已使用状态 -->
|
|
43
|
+
<hy-coupon
|
|
44
|
+
amount="30"
|
|
45
|
+
title="已使用优惠券"
|
|
46
|
+
status="used"
|
|
47
|
+
used-date="2023-10-15 14:30"
|
|
48
|
+
/>
|
|
49
|
+
|
|
50
|
+
<!-- 已过期状态 -->
|
|
51
|
+
<hy-coupon
|
|
52
|
+
amount="15"
|
|
53
|
+
title="已过期优惠券"
|
|
54
|
+
status="expired"
|
|
55
|
+
expire-date="2023-10-01"
|
|
56
|
+
/>
|
|
57
|
+
|
|
58
|
+
<!-- 已禁用状态 -->
|
|
59
|
+
<hy-coupon
|
|
60
|
+
amount="25"
|
|
61
|
+
title="已禁用优惠券"
|
|
62
|
+
status="disabled"
|
|
63
|
+
disabled-reason="账户等级不足"
|
|
64
|
+
/>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 增强功能
|
|
68
|
+
|
|
69
|
+
```html
|
|
70
|
+
<!-- 专属优惠券 -->
|
|
71
|
+
<hy-coupon
|
|
72
|
+
amount="40"
|
|
73
|
+
title="专属优惠券"
|
|
74
|
+
is-exclusive
|
|
75
|
+
limit-per-user="1"
|
|
76
|
+
/>
|
|
77
|
+
|
|
78
|
+
<!-- 显示操作按钮 -->
|
|
79
|
+
<hy-coupon
|
|
80
|
+
amount="60"
|
|
81
|
+
title="限时优惠券"
|
|
82
|
+
show-action-button
|
|
83
|
+
@receive="onCouponReceive"
|
|
84
|
+
/>
|
|
85
|
+
|
|
86
|
+
<!-- 自定义按钮文本 -->
|
|
87
|
+
<hy-coupon
|
|
88
|
+
amount="100"
|
|
89
|
+
title="大额优惠券"
|
|
90
|
+
show-action-button
|
|
91
|
+
custom-button-text="立即兑换"
|
|
92
|
+
/>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Props
|
|
96
|
+
|
|
97
|
+
| 属性名 | 类型 | 默认值 | 说明 |
|
|
98
|
+
|-------|------|-------|------|
|
|
99
|
+
| amount | string/number | - | 优惠券金额 |
|
|
100
|
+
| title | string | - | 优惠券标题 |
|
|
101
|
+
| subtitle | string | '' | 优惠券副标题 |
|
|
102
|
+
| status | string | 'normal' | 优惠券状态:normal/disabled/used/expired |
|
|
103
|
+
| minSpend | string/number | 0 | 最低消费金额 |
|
|
104
|
+
| validity | string | '' | 有效期文本 |
|
|
105
|
+
| customStyle | Object | {} | 自定义样式 |
|
|
106
|
+
| showRightBorder | boolean | true | 是否显示右侧边框装饰 |
|
|
107
|
+
| tooltip | string | '' | 提示文本 |
|
|
108
|
+
| showActionButton | boolean | false | 是否显示操作按钮 |
|
|
109
|
+
| customButtonText | string | '' | 自定义按钮文本 |
|
|
110
|
+
| isExclusive | boolean | false | 是否为专属优惠券 |
|
|
111
|
+
| limitPerUser | number | 0 | 每用户限领数量 |
|
|
112
|
+
| usedDate | string | '' | 使用日期(已使用状态时显示) |
|
|
113
|
+
| expireDate | string | '' | 过期日期(已过期状态时显示) |
|
|
114
|
+
| disabledReason | string | '' | 禁用原因(已禁用状态时显示) |
|
|
115
|
+
| triggerReceiveOnClick | boolean | true | 点击时是否触发receive事件 |
|
|
116
|
+
|
|
117
|
+
## Events
|
|
118
|
+
|
|
119
|
+
| 事件名 | 说明 | 回调参数 |
|
|
120
|
+
|-------|------|--------|
|
|
121
|
+
| click | 点击优惠券时触发(仅正常状态) | event: { status: CouponStatus } |
|
|
122
|
+
| receive | 领取优惠券时触发 | - |
|
|
123
|
+
| hover | 鼠标悬停状态改变时触发 | value: boolean |
|
|
124
|
+
|
|
125
|
+
## 示例页面
|
|
126
|
+
|
|
127
|
+
请查看 `pages/coupon-demo/index.vue` 了解更多使用示例。
|
|
128
|
+
|
|
129
|
+
## 注意事项
|
|
130
|
+
|
|
131
|
+
1. 在移动端环境下,`hover` 相关效果可能表现不同,请根据实际情况调整。
|
|
132
|
+
2. 当优惠券金额较大时,建议使用 `customStyle` 调整字体大小以保证显示效果。
|
|
133
|
+
3. 在小屏幕设备上,长文本可能会被截断,建议优化文本内容或调整组件宽度。
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
:class="['hy-coupon', `hy-coupon--${status}`, customClass]"
|
|
4
|
+
:style="customStyle"
|
|
5
|
+
@click="handleClick"
|
|
6
|
+
@mouseenter="handleMouseEnter"
|
|
7
|
+
@mouseleave="handleMouseLeave"
|
|
8
|
+
>
|
|
9
|
+
<!-- 顶部和底部波浪形装饰 -->
|
|
10
|
+
<view class="top-wave"></view>
|
|
11
|
+
<view class="bottom-wave"></view>
|
|
12
|
+
|
|
13
|
+
<!-- 左侧金额区域 -->
|
|
14
|
+
<view class="hy-coupon__left">
|
|
15
|
+
<!-- 背景纹理 -->
|
|
16
|
+
<view class="texture"></view>
|
|
17
|
+
<text class="amount">
|
|
18
|
+
<text class="amount-symbol">¥</text>
|
|
19
|
+
{{ amount }}
|
|
20
|
+
</text>
|
|
21
|
+
<text class="min-spend" v-if="minSpend > 0"> 满{{ minSpend }}可用 </text>
|
|
22
|
+
</view>
|
|
23
|
+
|
|
24
|
+
<!-- 优惠券左侧边框装饰 -->
|
|
25
|
+
<view v-if="showLeftBorder" class="coupon-border-left"></view>
|
|
26
|
+
|
|
27
|
+
<!-- 右侧内容区域 -->
|
|
28
|
+
<view class="hy-coupon__right">
|
|
29
|
+
<view class="content">
|
|
30
|
+
<text class="title">{{ title }}</text>
|
|
31
|
+
<text v-if="subTitle" class="subtitle">{{ subTitle }}</text>
|
|
32
|
+
</view>
|
|
33
|
+
<text class="validity">{{ validityText }}</text>
|
|
34
|
+
|
|
35
|
+
<!-- 限制标签 -->
|
|
36
|
+
<view class="limit-tags" v-if="limitTags.length > 0">
|
|
37
|
+
<text v-for="(tag, index) in limitTags" :key="index" class="limit-tag">
|
|
38
|
+
{{ tag }}
|
|
39
|
+
</text>
|
|
40
|
+
</view>
|
|
41
|
+
|
|
42
|
+
<!-- 立即领取按钮 -->
|
|
43
|
+
<view class="action-button" v-if="showActionButton">
|
|
44
|
+
<text class="action-button-text">{{ buttonText }}</text>
|
|
45
|
+
</view>
|
|
46
|
+
</view>
|
|
47
|
+
|
|
48
|
+
<!-- 优惠券右侧边框装饰 -->
|
|
49
|
+
<view v-if="showRightBorder" class="coupon-border-right"></view>
|
|
50
|
+
|
|
51
|
+
<!-- 悬浮提示 -->
|
|
52
|
+
<view v-if="tooltip" class="coupon-tooltip" :class="{ show: showTooltip }">
|
|
53
|
+
{{ tooltip }}
|
|
54
|
+
</view>
|
|
55
|
+
</view>
|
|
56
|
+
</template>
|
|
57
|
+
|
|
58
|
+
<script lang="ts">
|
|
59
|
+
import { defineComponent, ref, computed } from "vue";
|
|
60
|
+
import { props } from "./props";
|
|
61
|
+
import type { CouponStatus } from "./typing";
|
|
62
|
+
|
|
63
|
+
export default defineComponent({
|
|
64
|
+
name: "HyCoupon",
|
|
65
|
+
props,
|
|
66
|
+
emits: ["click", "receive", "hover"],
|
|
67
|
+
setup(props, { emit }) {
|
|
68
|
+
// 响应式数据
|
|
69
|
+
const showTooltip = ref(false);
|
|
70
|
+
|
|
71
|
+
// 计算有效性文本
|
|
72
|
+
const validityText = computed(() => {
|
|
73
|
+
if (!props.validity) return "";
|
|
74
|
+
|
|
75
|
+
// 根据状态显示不同的有效期文本
|
|
76
|
+
switch (props.status) {
|
|
77
|
+
case "used":
|
|
78
|
+
return props.usedDate ? `使用时间: ${props.usedDate}` : "已使用";
|
|
79
|
+
case "expired":
|
|
80
|
+
return props.expireDate ? `有效期至: ${props.expireDate}` : "已过期";
|
|
81
|
+
case "disabled":
|
|
82
|
+
return props.disabledReason || "已禁用";
|
|
83
|
+
default:
|
|
84
|
+
return props.validity;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// 计算限制标签
|
|
89
|
+
const limitTags = computed(() => {
|
|
90
|
+
const tags: string[] = [];
|
|
91
|
+
|
|
92
|
+
// 根据属性添加不同的标签
|
|
93
|
+
if (props.isExclusive) {
|
|
94
|
+
tags.push("专属");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (props.limitPerUser > 0) {
|
|
98
|
+
tags.push(`限领${props.limitPerUser}张`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (props.minSpend > 0 && props.minSpend <= 1000) {
|
|
102
|
+
// 小额满减可以显示在标签中
|
|
103
|
+
tags.push(`满${props.minSpend}可用`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return tags;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// 按钮文本
|
|
110
|
+
const buttonText = computed(() => {
|
|
111
|
+
return (
|
|
112
|
+
props.customButtonText || (props.status === "normal" ? "立即领取" : "")
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// 是否显示操作按钮
|
|
117
|
+
const showActionButton = computed(() => {
|
|
118
|
+
return props.showActionButton && props.status === "normal";
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// 是否显示左侧边框装饰
|
|
122
|
+
const showLeftBorder = computed(() => {
|
|
123
|
+
return true; // 默认显示左侧边框装饰
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// 是否显示右侧边框装饰
|
|
127
|
+
const showRightBorder = computed(() => {
|
|
128
|
+
return true; // 默认显示右侧边框装饰
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// 处理点击事件
|
|
132
|
+
const handleClick = () => {
|
|
133
|
+
if (props.status === "normal") {
|
|
134
|
+
emit("click", { status: props.status });
|
|
135
|
+
|
|
136
|
+
// 如果需要,可以同时触发receive事件
|
|
137
|
+
if (props.triggerReceiveOnClick) {
|
|
138
|
+
emit("receive");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// 鼠标悬停处理
|
|
144
|
+
const handleMouseEnter = () => {
|
|
145
|
+
if (props.tooltip) {
|
|
146
|
+
showTooltip.value = true;
|
|
147
|
+
}
|
|
148
|
+
emit("hover", true);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// 鼠标离开处理
|
|
152
|
+
const handleMouseLeave = () => {
|
|
153
|
+
showTooltip.value = false;
|
|
154
|
+
emit("hover", false);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
showTooltip,
|
|
159
|
+
validityText,
|
|
160
|
+
limitTags,
|
|
161
|
+
buttonText,
|
|
162
|
+
showActionButton,
|
|
163
|
+
showLeftBorder,
|
|
164
|
+
showRightBorder,
|
|
165
|
+
handleClick,
|
|
166
|
+
handleMouseEnter,
|
|
167
|
+
handleMouseLeave,
|
|
168
|
+
};
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
</script>
|
|
172
|
+
|
|
173
|
+
<style lang="scss" scoped>
|
|
174
|
+
@import "./index.scss";
|
|
175
|
+
</style>
|