From 733048e2c9486c678ce3c1b51415b14ffd5c8ee3 Mon Sep 17 00:00:00 2001
From: lifizer <913626195@qq.com>
Date: Tue, 8 Sep 2026 15:23:29 +0800
Subject: [PATCH] =?UTF-8?q?Feat(=E9=80=81=E7=A4=BC):=E6=94=AF=E6=8C=81AI?=
=?UTF-8?q?=E7=9A=84=E6=96=87=E7=94=9F=E5=9B=BE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
api/gift.js | 24 +
.../views/gift/components/AiCoverPicker.vue | 155 +++++++
pkg_user/views/gift/gift.vue | 413 +++++++++++++++++-
3 files changed, 579 insertions(+), 13 deletions(-)
create mode 100644 pkg_user/views/gift/components/AiCoverPicker.vue
diff --git a/api/gift.js b/api/gift.js
index 3f33c62..17e7767 100644
--- a/api/gift.js
+++ b/api/gift.js
@@ -124,3 +124,27 @@ export function computedSojoumGroupBuyGiftOrderPrice(params) {
login: true
})
}
+
+/**
+ * 文生图发起生成
+ * @param {*} data
+ * @returns
+ */
+
+export function aiGiftImageGenerate(data) {
+ return request.post("/aiGiftImage/generate", data, {
+ login: true
+ })
+}
+
+/**
+ * 文生图状态查询
+ * @param {*} params
+ * @returns
+ */
+
+export function aiGiftImageStatus(params) {
+ return request.get("/aiGiftImage/" + params.productId, {
+ login: true
+ })
+}
diff --git a/pkg_user/views/gift/components/AiCoverPicker.vue b/pkg_user/views/gift/components/AiCoverPicker.vue
new file mode 100644
index 0000000..5bc70a7
--- /dev/null
+++ b/pkg_user/views/gift/components/AiCoverPicker.vue
@@ -0,0 +1,155 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 确定
+
+
+ 礼包封面在对方领取时展示
+
+
+
+
+
+
+
diff --git a/pkg_user/views/gift/gift.vue b/pkg_user/views/gift/gift.vue
index dd26b6a..53fa673 100644
--- a/pkg_user/views/gift/gift.vue
+++ b/pkg_user/views/gift/gift.vue
@@ -1,9 +1,81 @@
-
-
+
+
+
+ 选择礼包封面
+
+
+
+ AI生成礼包封面
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 生成礼包封面
+
+
+
+
+
+
+ 预览
+
+
+ 重新生成
+
+
+
+
+
@@ -130,7 +202,7 @@
- 付款并赠送
+ 付款并赠送
再送一份
@@ -148,6 +220,12 @@
:index="defaultIndex"
:message="message"
/>
+
{
this.popupCover = res.data[0]
})
+ getAiSystemInfoSetting().then(res => {
+ const { success, data } = res
+ if (success) {
+ this.settingInfo = data
+ this.aiCoverDesc = data.giftCardT2IPromptTemplate || ''
+ }
+ })
+ },
+ onUnload() {
+ this.clearIntervalPoll()
},
computed: {
...mapGetters(["userInfo"]),
@@ -333,6 +465,95 @@ export default {
}
},
methods: {
+ // 將面切换
+ toggleSelectCoverType(type) {
+ if (this.selectCoverType === type) return
+ this.selectCoverType = type
+ },
+ handleGenerateAiCover() {
+ if (!this.aiCoverDesc || !this.aiCoverDesc.trim()) {
+ uni.showToast({
+ title: '请先配置文生图提示词',
+ icon: 'none'
+ })
+ return
+ }
+ if (this.aiCoverGenerateLoading) return
+ if (this.pollInterval) return
+ // 点击生成后,禁用按钮,防止重复点击
+ this.aiCoverGenerateLoading = true
+ aiGiftImageGenerate({
+ prompt: this.aiCoverDesc,
+ productId: this.goodsInfo.productId
+ }).then(res => {
+ const { success, data } = res
+ if (success) {
+ this.aiDefaultIndex = 0
+ this.selectedAiCoverImage = {}
+ this.aiCoverImgsList = []
+ // 轮询查询状态
+ this.pollAiImageGenerateStatus()
+ }
+ }).catch(() => {
+ this.aiCoverGenerateLoading = false
+ })
+ },
+ pollAiImageGenerateStatus() {
+ const _this = this
+ this.pollInterval = setInterval(() => {
+ aiGiftImageStatus({
+ productId: _this.goodsInfo.productId
+ }).then(res => {
+ const { success, data } = res
+ if (success && data) {
+ // status: 0=生成中 / 1=成功 / 2=失败(无任何记录时为 null)
+ if (data.status === 1 || data.status === 2) {
+ _this.clearIntervalPoll()
+ }
+ if (data.status === 1 && data.groups && data.groups.length) {
+ _this.selectedAiCoverImage = data.groups[0]
+ _this.aiCoverImgsList = []
+ data.groups.map(item => {
+ _this.aiCoverImgsList.push({
+ id: item.id,
+ cover: item.coverUrl,
+ image: item.shareUrl,
+ name: item.name || ''
+ })
+ })
+ _this.selectedAiCoverImage = _this.aiCoverImgsList[0]
+ // 封面图片
+ _this.selectedCover = _this.selectedAiCoverImage.cover
+ // 分享对话图片
+ _this.giftImage = _this.selectedAiCoverImage.image
+ console.log(_this.selectedCover)
+ console.log(_this.giftImage)
+ _this.showGenerateBtn = false
+ _this.aiCoverGenerateLoading = false
+ }
+ } else {
+ _this.aiCoverGenerateLoading = false
+ _this.showGenerateBtn = true
+ }
+ }).catch(() => {
+ _this.aiCoverGenerateLoading = false
+ _this.showGenerateBtn = true
+ })
+ }, 2000)
+ },
+ clearIntervalPoll() {
+ if (this.pollInterval) {
+ clearInterval(this.pollInterval)
+ this.pollInterval = null
+ }
+ },
+ handleGenerateAgain() {
+ this.aiDefaultIndex = 0
+ this.selectedAiCoverImage = {}
+ this.aiCoverImgsList = []
+ this.showGenerateBtn = true
+ this.aiCoverGenerateLoading = false
+ },
resolvePageQuery() {
if (this.$yroute && this.$yroute.query) {
return this.$yroute.query
@@ -418,6 +639,9 @@ export default {
handleShowCover() {
this.showCoverPicker = true
},
+ handleShowAiCover() {
+ this.showAiCoverPicker = true
+ },
showCouponsPopup() {
if (this.isCountyLotteryGift) return
if (this.couponList.usable && this.couponList.usable.length === 0) return
@@ -472,6 +696,11 @@ export default {
console.log(this.defaultIndex, 'defaultIndex');
this.selectedCover = template.cover
this.giftImage = template.image
+ if (this.selectCoverType === 'ai') {
+ this.selectedCover = this.selectedAiCoverImage.cover
+ this.giftImage = this.selectedAiCoverImage.image
+ this.templateId = this.selectedAiCoverImage.id
+ }
this.couponId = ''
this.computedPrice(this.goodsInfo.cartNum)
})
@@ -520,6 +749,24 @@ export default {
this.$forceUpdate()
})
},
+ payNowToSendGift() {
+ if (this.selectCoverType === 'default') {
+ this.showPayPicker = true
+ return
+ }
+ if (this.selectCoverType === 'ai' && !this.selectedAiCoverImage.id) {
+ if (!this.selectedAiCoverImage.id) {
+ uni.showToast({
+ title: '请生成礼包封面再操作',
+ icon: 'none'
+ })
+ return
+ } else {
+ this.showPayPicker = true
+ }
+ return
+ }
+ },
pwdPopFinish(payPwd) {
this.payPassword = payPwd;
this.confirmGift(true);
@@ -531,9 +778,21 @@ export default {
onCoverConfirm(cover) {
this.cover = cover.name
this.templateId = cover.id
+ // 封面图片
this.selectedCover = cover.cover
+ // 分享对话图片
this.giftImage = cover.image
},
+ onAiCoverConfirm(cover) {
+ // 封面图片
+ this.selectedCover = cover.cover
+ // 分享对话图片
+ this.giftImage = cover.image
+ if (this.selectCoverType === 'ai') {
+ this.selectedAiCoverImage = cover
+ this.aiDefaultIndex = this.aiCoverImgsList.findIndex(item => item.id === cover.id)
+ }
+ },
showTips() {
this.$refs.giftTips.showTips = true
},
@@ -616,7 +875,9 @@ export default {
key: this.orderKey,
from: 'routine',
cartId: this.cartId,
- templateId: this.templateId,
+ templateId: this.selectCoverType === 'default' ? this.templateId : '',
+ aiGiftImageId: this.selectCoverType === 'default' ? '' : this.selectedAiCoverImage.id,
+ cover: this.selectedCover,
message : this.message || '礼笺轻启,礼藏心意',
canTransfer: this.canTransfer ? 1 : 0,
passwordPay: this.payPassword || '',
@@ -628,7 +889,8 @@ export default {
cartId: this.cartId,
couponId: this.getCouponId(),
recipientsNum: this.goodsInfo.cartNum,
- templateId: this.templateId,
+ templateId: this.selectCoverType === 'default' ? this.templateId : '',
+ aiGiftImageId: this.selectCoverType === 'default' ? '' : this.selectedAiCoverImage.id,
message : this.message || '礼笺轻启,礼藏心意',
cover: this.selectedCover,
canTransfer: this.canTransfer ? 1 : 0,
@@ -814,11 +1076,7 @@ export default {
border-radius: 16rpx;
}
.tip-wrap{
- position: absolute;
- bottom: 50rpx;
- left: 0;
- margin: auto;
- right: 0;
+ margin: 32rpx auto 68rpx auto;
align-items: center;
}
.tip-text{
@@ -844,7 +1102,6 @@ export default {
}
.top-card{
// height: 280rpx;
- background: #fff;
border-radius: 16rpx;
}
.line{
@@ -973,4 +1230,134 @@ export default {
.lottery-gift-btn.send::after{
border: none;
}
+.top-tab-nav-wrap {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ .item1 {
+ .txt {
+ left: -24rpx;
+ }
+ }
+ .item2 {
+ .txt {
+ padding-left: 32rpx;
+ }
+ }
+ .item {
+ position: relative;
+ flex: 1;
+ text-align: center;
+ font-size: 32rpx;
+ color: #333;
+ line-height: 80rpx;
+ &.active {
+ color: #fff;
+ .tab-img {
+ display: block;
+ }
+ }
+ .txt {
+ position: relative;
+ z-index: 5;
+ }
+ .tab-img {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 80rpx;
+ display: none;
+ }
+ }
+}
+.ai-cover-wrap {
+ padding: 20rpx;
+ margin-top: -1px;
+ box-sizing: border-box;
+ border-radius: 28rpx 0 28rpx 28rpx;
+ background-color: #C52932;
+ .ai-cover-body {
+ padding: 20rpx;
+ box-sizing: border-box;
+ border-radius: 40rpx;
+ background-color: #fff;
+ }
+ .ai-cover-container {
+ .prompt {
+ .prompt-textarea {
+ width: 100%;
+ height: 200rpx;
+ background: #fff;
+ border-radius: 16rpx;
+ padding: 0 20rpx 20rpx 20rpx;
+ box-sizing: border-box;
+ overflow-y: auto;
+ font-size: 28rpx;
+ color: #333333;
+ line-height: 40rpx;
+ }
+ }
+ .imgs-list-wrap {
+ display: flex;
+ justify-content: space-around;
+ align-items: baseline;
+ gap: 24rpx;
+ padding: 20rpx 0;
+ box-sizing: border-box;
+ }
+ .img-image {
+ display: block;
+ height: 176rpx;
+ &.active {
+ transform: scale(1.2);
+ }
+ }
+ }
+ .ai-cover-bottom {
+ margin-top: 12rpx;
+ .btn-wrap {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ .loading-img {
+ display: block;
+ width: 48rpx;
+ height: 48rpx;
+ margin-left: 20rpx;
+ }
+ }
+ .btn + .btn {
+ margin-left: 20rpx;
+ }
+ .btn {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ height: 54rpx;
+ line-height: 54rpx;
+ border-radius: 40rpx;
+ text-align: center;
+ font-size: 32rpx;
+ font-weight: 500;
+ box-sizing: border-box;
+ margin: 0;
+ padding: 0 32rpx;
+ border: 2rpx solid #c52733;
+ color: #fff;
+ background: #c52733;
+ .icon {
+ display: block;
+ width: 28rpx;
+ height: 28rpx;
+ margin-left: 16rpx;
+ }
+ }
+ .btn2 {
+ background: #fff;
+ color: #c52733;
+ border: 2rpx solid #c52733;
+ }
+ }
+}