@didaoktv/didaoui-uniapp 2.3.0 → 2.5.0
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/dd-goods-card/dd-goods-card.vue +25 -3
- package/components/dd-goods-sku/dd-goods-sku.vue +20 -2
- package/components/dd-package-sku/dd-package-sku.vue +112 -9
- package/components/dd-package-sku/package-sku.ts +25 -0
- package/libs/utils.ts +17 -0
- package/package.json +1 -1
- package/scss/_mixins.scss +11 -0
|
@@ -10,14 +10,16 @@
|
|
|
10
10
|
:hover-stay-time="120"
|
|
11
11
|
@click="onClick"
|
|
12
12
|
>
|
|
13
|
-
<!-- 缩略图 +
|
|
14
|
-
<view class="dd-goods-card__thumb">
|
|
13
|
+
<!-- 缩略图 + 金色角标(缺图时文字占位:随机主题底色 + 名称前 2 字) -->
|
|
14
|
+
<view class="dd-goods-card__thumb" :class="'dd-goods-card__thumb--' + avatarHue">
|
|
15
15
|
<slot name="thumb">
|
|
16
16
|
<image
|
|
17
|
+
v-if="thumb"
|
|
17
18
|
class="dd-goods-card__thumb-img"
|
|
18
19
|
:src="thumb"
|
|
19
20
|
:mode="thumbMode"
|
|
20
21
|
></image>
|
|
22
|
+
<text v-else class="dd-goods-card__thumb-text">{{ avatarText }}</text>
|
|
21
23
|
</slot>
|
|
22
24
|
<text v-if="tag" class="dd-goods-card__tag" :style="{ zIndex: zIndexConfig.base }">{{ tag }}</text>
|
|
23
25
|
</view>
|
|
@@ -40,7 +42,10 @@
|
|
|
40
42
|
{{ currency }}{{ originPrice }}
|
|
41
43
|
</text>
|
|
42
44
|
</view>
|
|
43
|
-
|
|
45
|
+
<!-- 价格行右侧扩展位(步进器/加购等与价格同排贴底);未用时回退已选数量 -->
|
|
46
|
+
<slot name="price-right">
|
|
47
|
+
<text v-if="num" class="dd-goods-card__num">×{{ num }}</text>
|
|
48
|
+
</slot>
|
|
44
49
|
</view>
|
|
45
50
|
|
|
46
51
|
<view v-if="$slots.bottom" class="dd-goods-card__bottom">
|
|
@@ -52,9 +57,11 @@
|
|
|
52
57
|
</template>
|
|
53
58
|
|
|
54
59
|
<script setup lang="ts">
|
|
60
|
+
import { computed, ref } from 'vue'
|
|
55
61
|
import DdPrice from '../dd-price/dd-price.vue'
|
|
56
62
|
// z-index 统一取 libs/config/zIndex.js(角标抬到缩略图之上取 base 档)
|
|
57
63
|
import zIndexConfig from '../../libs/config/zIndex.js'
|
|
64
|
+
import { pickAvatarHue, avatarText as calcAvatarText } from '../../libs/utils'
|
|
58
65
|
|
|
59
66
|
interface Props {
|
|
60
67
|
/** 商品图片地址 */
|
|
@@ -106,6 +113,10 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
106
113
|
|
|
107
114
|
const emit = defineEmits<{ (e: 'click', val: Event): void }>()
|
|
108
115
|
|
|
116
|
+
// 缺图文字占位(与 dd-goods-sku / dd-package-sku 同规则):随机主题底色 + 名称前 2 字(实例化时随机一次)
|
|
117
|
+
const avatarHue = ref<string>(pickAvatarHue())
|
|
118
|
+
const avatarText = computed(() => calcAvatarText(props.title))
|
|
119
|
+
|
|
109
120
|
function onClick(e: Event) {
|
|
110
121
|
if (props.disabled) return
|
|
111
122
|
emit('click', e)
|
|
@@ -140,12 +151,23 @@ function onClick(e: Event) {
|
|
|
140
151
|
position: relative;
|
|
141
152
|
flex-shrink: 0;
|
|
142
153
|
overflow: hidden;
|
|
154
|
+
display: flex;
|
|
155
|
+
align-items: center;
|
|
156
|
+
justify-content: center;
|
|
143
157
|
|
|
144
158
|
&-img {
|
|
145
159
|
display: block;
|
|
146
160
|
width: 100%;
|
|
147
161
|
height: 100%;
|
|
148
162
|
}
|
|
163
|
+
|
|
164
|
+
&-text {
|
|
165
|
+
font-size: 40rpx;
|
|
166
|
+
font-weight: bold;
|
|
167
|
+
line-height: 1;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@include dd-avatar-colors;
|
|
149
171
|
}
|
|
150
172
|
|
|
151
173
|
&__tag {
|
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
<view class="dd-goods-sku__container" :style="{ padding: pageInline ? '0px' : '' }">
|
|
15
15
|
<view class="dd-goods-sku__header">
|
|
16
16
|
<slot name="header">
|
|
17
|
-
<view class="dd-goods-sku__header__image">
|
|
18
|
-
<image :src="
|
|
17
|
+
<view class="dd-goods-sku__header__image" :class="'dd-goods-sku__header__image--' + avatarHue">
|
|
18
|
+
<image v-if="headerImage" :src="headerImage" mode="aspectFill"></image>
|
|
19
|
+
<text v-else class="dd-goods-sku__header__image__text">{{ avatarText }}</text>
|
|
19
20
|
</view>
|
|
20
21
|
<view class="dd-goods-sku__header__info">
|
|
21
22
|
<view class="dd-goods-sku__header__info__price">
|
|
@@ -75,6 +76,7 @@ import { computed, reactive, ref } from 'vue'
|
|
|
75
76
|
import DdPopup from '../dd-popup/dd-popup.vue'
|
|
76
77
|
import DdStepper from '../dd-stepper/dd-stepper.vue'
|
|
77
78
|
import DdButton from '../dd-button/dd-button.vue'
|
|
79
|
+
import { pickAvatarHue, avatarText as calcAvatarText } from '../../libs/utils'
|
|
78
80
|
|
|
79
81
|
interface SkuLeaf {
|
|
80
82
|
id: string | number
|
|
@@ -137,6 +139,11 @@ const price = computed(() => {
|
|
|
137
139
|
return props.goodsInfo.price || props.goodsInfo.price_fee || 0
|
|
138
140
|
})
|
|
139
141
|
|
|
142
|
+
// 头图:缺图时文字占位(与 dd-package-sku / dd-goods-card 同规则)——随机主题底色 + 名称前 2 字
|
|
143
|
+
const headerImage = computed(() => props.goodsInfo.image || props.goodsInfo.picture || '')
|
|
144
|
+
const avatarHue = ref<string>(pickAvatarHue())
|
|
145
|
+
const avatarText = computed(() => calcAvatarText(props.goodsInfo.name))
|
|
146
|
+
|
|
140
147
|
// 当前库存
|
|
141
148
|
const stock = computed(() => {
|
|
142
149
|
const comb = getSelectedSkuComb()
|
|
@@ -329,11 +336,22 @@ defineExpose({ open, close, reset })
|
|
|
329
336
|
border-radius: 10rpx;
|
|
330
337
|
overflow: hidden;
|
|
331
338
|
margin-right: 20rpx;
|
|
339
|
+
display: flex;
|
|
340
|
+
align-items: center;
|
|
341
|
+
justify-content: center;
|
|
332
342
|
|
|
333
343
|
image {
|
|
334
344
|
width: 100%;
|
|
335
345
|
height: 100%;
|
|
336
346
|
}
|
|
347
|
+
|
|
348
|
+
&__text {
|
|
349
|
+
font-size: 56rpx;
|
|
350
|
+
font-weight: bold;
|
|
351
|
+
line-height: 1;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
@include dd-avatar-colors;
|
|
337
355
|
}
|
|
338
356
|
|
|
339
357
|
&__info {
|
|
@@ -13,6 +13,23 @@
|
|
|
13
13
|
<view class="dd-package-sku__container">
|
|
14
14
|
<view class="dd-package-sku__title">{{ title }}</view>
|
|
15
15
|
|
|
16
|
+
<view v-if="hasHeader" class="dd-package-sku__header">
|
|
17
|
+
<view class="dd-package-sku__header__image" :class="'dd-package-sku__header__image--' + avatarHue">
|
|
18
|
+
<image v-if="headerImage" :src="headerImage" mode="aspectFill" />
|
|
19
|
+
<text v-else class="dd-package-sku__header__image__text">{{ avatarText }}</text>
|
|
20
|
+
</view>
|
|
21
|
+
<view class="dd-package-sku__header__info">
|
|
22
|
+
<view class="dd-package-sku__header__info__price">
|
|
23
|
+
<text class="dd-package-sku__header__info__price__symbol">¥</text>
|
|
24
|
+
<text class="dd-package-sku__header__info__price__value">{{ price }}</text>
|
|
25
|
+
</view>
|
|
26
|
+
<view v-if="stock !== undefined && stock !== null" class="dd-package-sku__header__info__stock">
|
|
27
|
+
库存 {{ stock }} 件
|
|
28
|
+
</view>
|
|
29
|
+
<view class="dd-package-sku__header__info__selected">已选: {{ selectedText || '未选择' }}</view>
|
|
30
|
+
</view>
|
|
31
|
+
</view>
|
|
32
|
+
|
|
16
33
|
<scroll-view class="dd-package-sku__content" scroll-y>
|
|
17
34
|
<view v-for="group in groups" :key="group.id" class="dd-package-sku__group">
|
|
18
35
|
<view class="dd-package-sku__group__header">
|
|
@@ -52,13 +69,15 @@
|
|
|
52
69
|
|
|
53
70
|
<script setup lang="ts">
|
|
54
71
|
/**
|
|
55
|
-
* 套餐可选组选择弹层(N选M 多选 + 加价 + 售罄置灰)
|
|
72
|
+
* 套餐可选组选择弹层(N选M 多选 + N选1 单选直接替换 + 加价 + 售罄置灰)
|
|
56
73
|
* - groups 通用形状,不绑业务 DTO;FIXED 组只读展示,OPTIONAL 组按 minSel/maxSel 校验
|
|
74
|
+
* - goodsInfo 传入时头部展示图片/价格(底价+已选加价)/库存/已选项,对齐 dd-goods-sku;图块必有,缺图时以主题随机色块 + 套餐名前 2 字占位
|
|
57
75
|
* - confirm emit { options:[{groupId,skuId}], surchargeFen, selectedText };确认后不自动关闭,由调用方 ref.close()
|
|
58
76
|
*/
|
|
59
77
|
import { computed, reactive, ref } from 'vue'
|
|
60
78
|
import DdPopup from '../dd-popup/dd-popup.vue'
|
|
61
79
|
import DdButton from '../dd-button/dd-button.vue'
|
|
80
|
+
import { pickAvatarHue, avatarText as calcAvatarText } from '../../libs/utils'
|
|
62
81
|
import {
|
|
63
82
|
type PackageSkuGroup,
|
|
64
83
|
type PackageSkuItem,
|
|
@@ -68,6 +87,7 @@ import {
|
|
|
68
87
|
isItemDisabled,
|
|
69
88
|
groupHint,
|
|
70
89
|
groupMax,
|
|
90
|
+
nextSelection,
|
|
71
91
|
isGroupSatisfied,
|
|
72
92
|
canConfirm as calcCanConfirm,
|
|
73
93
|
unmetText,
|
|
@@ -80,6 +100,8 @@ import {
|
|
|
80
100
|
interface Props {
|
|
81
101
|
/** 选择组列表 */
|
|
82
102
|
groups?: PackageSkuGroup[]
|
|
103
|
+
/** 套餐主图/底价/库存(与 dd-goods-sku 对齐:image|picture / price|price_fee / stock|quantity) */
|
|
104
|
+
goodsInfo?: Record<string, any>
|
|
83
105
|
/** 弹层标题 */
|
|
84
106
|
title?: string
|
|
85
107
|
/** 确认按钮文字 */
|
|
@@ -90,6 +112,7 @@ interface Props {
|
|
|
90
112
|
|
|
91
113
|
const props = withDefaults(defineProps<Props>(), {
|
|
92
114
|
groups: () => [],
|
|
115
|
+
goodsInfo: () => ({}),
|
|
93
116
|
title: '选择套餐内容',
|
|
94
117
|
confirmText: '确定',
|
|
95
118
|
closeable: true,
|
|
@@ -108,6 +131,26 @@ const selections = reactive<PackageSkuSelections>({})
|
|
|
108
131
|
const canConfirmNow = computed(() => calcCanConfirm(props.groups, selections))
|
|
109
132
|
const unmetTip = computed(() => unmetText(props.groups, selections))
|
|
110
133
|
|
|
134
|
+
/** 头部(对齐 dd-goods-sku):传了 goodsInfo 才渲染,存量调用方零改动不显示 */
|
|
135
|
+
const hasHeader = computed(() => Object.keys(props.goodsInfo).length > 0)
|
|
136
|
+
const headerImage = computed(() => props.goodsInfo.image || props.goodsInfo.picture || '')
|
|
137
|
+
/** 缺图时文字占位块:每次 open 从主题 6 档基色随机取底色(libs/utils + dd-avatar-colors mixin) */
|
|
138
|
+
const avatarHue = ref<string>(pickAvatarHue())
|
|
139
|
+
/** 占位文字:取套餐名前 2 字 */
|
|
140
|
+
const avatarText = computed(() => calcAvatarText(props.goodsInfo.name))
|
|
141
|
+
/** 展示价(元)= 套餐底价 + 已选 OPTIONAL 项加价合计;按分相加再除 100,避免浮点误差 */
|
|
142
|
+
const surchargeFen = computed(() => computeSurchargeFen(props.groups, selections))
|
|
143
|
+
const price = computed(
|
|
144
|
+
() =>
|
|
145
|
+
(Math.round((props.goodsInfo.price ?? props.goodsInfo.price_fee ?? 0) * 100) +
|
|
146
|
+
surchargeFen.value) /
|
|
147
|
+
100,
|
|
148
|
+
)
|
|
149
|
+
/** 库存:缺省不显示库存行(套餐可能无台账库存,如房时套餐) */
|
|
150
|
+
const stock = computed(() => props.goodsInfo.stock ?? props.goodsInfo.quantity)
|
|
151
|
+
/** 已选项实时摘要(确认前即联动展示) */
|
|
152
|
+
const selectedText = computed(() => buildSelectedText(props.groups, selections))
|
|
153
|
+
|
|
111
154
|
// 模板内避免复杂表达式(小程序约束),逐一下沉为方法
|
|
112
155
|
function isFixedGroup(group: PackageSkuGroup): boolean {
|
|
113
156
|
return isFixed(group)
|
|
@@ -132,17 +175,12 @@ function isSelected(group: PackageSkuGroup, item: PackageSkuItem): boolean {
|
|
|
132
175
|
function onItemClick(group: PackageSkuGroup, item: PackageSkuItem): void {
|
|
133
176
|
if (isFixed(group) || isItemDisabled(item)) return
|
|
134
177
|
const key = String(group.id)
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
if (at >= 0) {
|
|
138
|
-
selected.splice(at, 1)
|
|
139
|
-
} else if (selected.length >= groupMax(group)) {
|
|
178
|
+
const next = nextSelection(group, selections[key] ?? [], item.id)
|
|
179
|
+
if (next === null) {
|
|
140
180
|
uni.showToast({ title: `最多选择${groupMax(group)}项`, icon: 'none' })
|
|
141
181
|
return
|
|
142
|
-
} else {
|
|
143
|
-
selected.push(item.id)
|
|
144
182
|
}
|
|
145
|
-
selections[key] =
|
|
183
|
+
selections[key] = next
|
|
146
184
|
}
|
|
147
185
|
|
|
148
186
|
function reset(): void {
|
|
@@ -150,6 +188,7 @@ function reset(): void {
|
|
|
150
188
|
}
|
|
151
189
|
|
|
152
190
|
function open(): void {
|
|
191
|
+
avatarHue.value = pickAvatarHue()
|
|
153
192
|
show.value = true
|
|
154
193
|
emit('open')
|
|
155
194
|
}
|
|
@@ -190,6 +229,70 @@ defineExpose({ open, close, reset })
|
|
|
190
229
|
color: var(--dd-text-primary, #{$dd-text-primary});
|
|
191
230
|
}
|
|
192
231
|
|
|
232
|
+
&__header {
|
|
233
|
+
display: flex;
|
|
234
|
+
flex-direction: row;
|
|
235
|
+
padding: 20rpx 0;
|
|
236
|
+
|
|
237
|
+
&__image {
|
|
238
|
+
width: 180rpx;
|
|
239
|
+
height: 180rpx;
|
|
240
|
+
border-radius: 10rpx;
|
|
241
|
+
overflow: hidden;
|
|
242
|
+
margin-right: 20rpx;
|
|
243
|
+
display: flex;
|
|
244
|
+
align-items: center;
|
|
245
|
+
justify-content: center;
|
|
246
|
+
|
|
247
|
+
image {
|
|
248
|
+
width: 100%;
|
|
249
|
+
height: 100%;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
&__text {
|
|
253
|
+
font-size: 56rpx;
|
|
254
|
+
font-weight: bold;
|
|
255
|
+
line-height: 1;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
@include dd-avatar-colors;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
&__info {
|
|
262
|
+
flex: 1;
|
|
263
|
+
|
|
264
|
+
&__price {
|
|
265
|
+
display: flex;
|
|
266
|
+
flex-direction: row;
|
|
267
|
+
align-items: baseline;
|
|
268
|
+
margin-bottom: 20rpx;
|
|
269
|
+
|
|
270
|
+
&__symbol {
|
|
271
|
+
font-size: 24rpx;
|
|
272
|
+
color: var(--dd-error-400, #{$dd-error-400});
|
|
273
|
+
margin-right: 4rpx;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
&__value {
|
|
277
|
+
font-size: 36rpx;
|
|
278
|
+
color: var(--dd-error-400, #{$dd-error-400});
|
|
279
|
+
font-weight: bold;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
&__stock {
|
|
284
|
+
font-size: 26rpx;
|
|
285
|
+
color: var(--dd-text-tertiary, #{$dd-text-tertiary});
|
|
286
|
+
margin-bottom: 20rpx;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
&__selected {
|
|
290
|
+
font-size: 26rpx;
|
|
291
|
+
color: var(--dd-text-primary, #{$dd-text-primary});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
193
296
|
&__content {
|
|
194
297
|
max-height: 640rpx;
|
|
195
298
|
padding-bottom: 10rpx;
|
|
@@ -58,6 +58,31 @@ export function groupHint(group: PackageSkuGroup): string {
|
|
|
58
58
|
return `最多选${max}项`
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/** 单选组:上限为 1 的 OPTIONAL 组(N选1),点非选中项直接替换选中,无需先取消 */
|
|
62
|
+
export function isSingleSelect(group: PackageSkuGroup): boolean {
|
|
63
|
+
return !isFixed(group) && groupMax(group) === 1
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 点击可选项后的新选中集(纯逻辑,供组件与自检共用)
|
|
68
|
+
* 返回 null 表示多选上限拦截;FIXED/售罄由调用方先行拦截,不在此处理
|
|
69
|
+
*/
|
|
70
|
+
export function nextSelection(
|
|
71
|
+
group: PackageSkuGroup,
|
|
72
|
+
selected: (string | number)[],
|
|
73
|
+
itemId: string | number,
|
|
74
|
+
): (string | number)[] | null {
|
|
75
|
+
const at = selected.indexOf(itemId)
|
|
76
|
+
if (at >= 0) {
|
|
77
|
+
const copy = selected.slice()
|
|
78
|
+
copy.splice(at, 1)
|
|
79
|
+
return copy
|
|
80
|
+
}
|
|
81
|
+
if (isSingleSelect(group)) return [itemId]
|
|
82
|
+
if (selected.length >= groupMax(group)) return null
|
|
83
|
+
return [...selected, itemId]
|
|
84
|
+
}
|
|
85
|
+
|
|
61
86
|
/** 组是否已选满最低要求(上限在点击时拦截,不会超) */
|
|
62
87
|
export function isGroupSatisfied(group: PackageSkuGroup, selections: PackageSkuSelections): boolean {
|
|
63
88
|
if (isFixed(group)) return true
|
package/libs/utils.ts
CHANGED
|
@@ -136,6 +136,23 @@ export function daysInMonth(year: number, month: number): number {
|
|
|
136
136
|
return new Date(year, month + 1, 0).getDate()
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
// ============================================================
|
|
140
|
+
// 缺图文字占位(供 dd-goods-sku / dd-goods-card / dd-package-sku 图块使用)
|
|
141
|
+
// 底色档位与 scss 的 dd-avatar-colors mixin 一一对应:bg=主题基色、文字=各自 contrast
|
|
142
|
+
// ============================================================
|
|
143
|
+
export const AVATAR_HUES = ['primary', 'accent', 'success', 'warning', 'error', 'info'] as const
|
|
144
|
+
export type AvatarHue = (typeof AVATAR_HUES)[number]
|
|
145
|
+
|
|
146
|
+
/** 随机取一种占位底色档位 */
|
|
147
|
+
export function pickAvatarHue(): AvatarHue {
|
|
148
|
+
return AVATAR_HUES[Math.floor(Math.random() * AVATAR_HUES.length)]
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** 占位文字:取名称前 2 字 */
|
|
152
|
+
export function avatarText(name?: string): string {
|
|
153
|
+
return String(name ?? '').slice(0, 2)
|
|
154
|
+
}
|
|
155
|
+
|
|
139
156
|
// ============================================================
|
|
140
157
|
// 二维码(QR Code)生成 — 纯 JS,无三方依赖
|
|
141
158
|
// port: 移植自 Project Nayuki QR Code generator(public domain,qrcodegen)。
|
package/package.json
CHANGED
package/scss/_mixins.scss
CHANGED
|
@@ -152,3 +152,14 @@
|
|
|
152
152
|
pointer-events: none;
|
|
153
153
|
user-select: none;
|
|
154
154
|
}
|
|
155
|
+
|
|
156
|
+
// 缺图文字占位底色:6 档主题基色 + 各自 contrast 文字色(配套 libs/utils.ts 的 AVATAR_HUES,
|
|
157
|
+
// 随机命中其一;运行时可换肤,明暗主题自动跟随)
|
|
158
|
+
@mixin dd-avatar-colors {
|
|
159
|
+
&--primary { background-color: var(--dd-primary, #{$dd-primary}); color: var(--dd-primary-contrast, #{$dd-primary-contrast}); }
|
|
160
|
+
&--accent { background-color: var(--dd-accent, #{$dd-accent}); color: var(--dd-accent-contrast, #{$dd-accent-contrast}); }
|
|
161
|
+
&--success { background-color: var(--dd-success, #{$dd-success}); color: var(--dd-success-contrast, #{$dd-success-contrast}); }
|
|
162
|
+
&--warning { background-color: var(--dd-warning, #{$dd-warning}); color: var(--dd-warning-contrast, #{$dd-warning-contrast}); }
|
|
163
|
+
&--error { background-color: var(--dd-error, #{$dd-error}); color: var(--dd-error-contrast, #{$dd-error-contrast}); }
|
|
164
|
+
&--info { background-color: var(--dd-info, #{$dd-info}); color: var(--dd-info-contrast, #{$dd-info-contrast}); }
|
|
165
|
+
}
|