commission--yt-commit
This commit is contained in:
160
pages/course/applyPromotion/applyPromotion.js
Normal file
160
pages/course/applyPromotion/applyPromotion.js
Normal file
@ -0,0 +1,160 @@
|
||||
// pages/course/applyPromotion/applyPromotion.js
|
||||
Page({
|
||||
|
||||
data: {
|
||||
showCode: false,
|
||||
buttonText: '生成推广码',
|
||||
codeImageUrl: 'https://img.picui.cn/free/2025/06/24/685a8953cae83.png'
|
||||
},
|
||||
|
||||
// 点击“生成推广码”或“查看推荐的用户”
|
||||
handleGenerate() {
|
||||
if (!this.data.showCode) {
|
||||
// 1. 显示带遮罩的 loading,防止用户点击其他地方
|
||||
wx.showLoading({
|
||||
title: '生成中...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
// 2. 调用后端接口生成推广码图片
|
||||
wx.request({
|
||||
url: 'https://your-backend.com/api/generatePromotionCode', // TODO: 替换成你真实的接口地址
|
||||
method: 'POST',
|
||||
data: {
|
||||
// 如果需要传用户信息或参数,在这里补充
|
||||
},
|
||||
success: res => {
|
||||
if (1) {
|
||||
// 3. 接口返回正确,更新图片地址并显示
|
||||
this.setData({
|
||||
codeImageUrl: res.data.imageUrl,
|
||||
showCode: true,
|
||||
buttonText: '查看推荐的用户'
|
||||
});
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '生成失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.showToast({
|
||||
title: '网络错误,请检查连接',
|
||||
icon: 'none'
|
||||
});
|
||||
},
|
||||
complete: () => {
|
||||
// 4. 隐藏 loading
|
||||
wx.hideLoading();
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
// 已生成时,跳转到查看推荐用户页(如有)
|
||||
wx.navigateTo({
|
||||
url: '/pages/course/recommendUser/recommendUser',
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 保存图片到相册(与之前一致)
|
||||
saveImage() {
|
||||
const {
|
||||
codeImageUrl
|
||||
} = this.data;
|
||||
wx.showLoading({
|
||||
title: '保存中...',
|
||||
mask: true
|
||||
});
|
||||
wx.downloadFile({
|
||||
url: codeImageUrl,
|
||||
success: res => {
|
||||
if (res.statusCode === 200) {
|
||||
wx.saveImageToPhotosAlbum({
|
||||
filePath: res.tempFilePath,
|
||||
success: () => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '保存成功',
|
||||
icon: 'success'
|
||||
});
|
||||
},
|
||||
fail: err => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '保存失败',
|
||||
icon: 'none'
|
||||
});
|
||||
console.error('saveImageToPhotosAlbum 失败', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: err => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '下载失败',
|
||||
icon: 'none'
|
||||
});
|
||||
console.error('downloadFile 失败', err);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(options) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
|
||||
}
|
||||
})
|
3
pages/course/applyPromotion/applyPromotion.json
Normal file
3
pages/course/applyPromotion/applyPromotion.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
36
pages/course/applyPromotion/applyPromotion.wxml
Normal file
36
pages/course/applyPromotion/applyPromotion.wxml
Normal file
@ -0,0 +1,36 @@
|
||||
<!-- pages/course/applyPromotion/applyPromotion.wxml -->
|
||||
<view class="flex-col page">
|
||||
<view class="flex-col items-center group">
|
||||
<!-- 生成推广码按钮,文字垂直居中,点击触发 handleGenerate -->
|
||||
<view class="flex-col justify-center items-center text-wrapper" bindtap="handleGenerate">
|
||||
<text class="font text">{{buttonText}}</text>
|
||||
</view>
|
||||
|
||||
<!-- 只有当 showCode 为 true 时才显示推广码图片 -->
|
||||
<image
|
||||
wx:if="{{showCode}}"
|
||||
class="mt-12 image"
|
||||
src="{{codeImageUrl}}"
|
||||
/>
|
||||
|
||||
<!-- 只有当 showCode 为 true 时才显示保存图片按钮,且垂直居中 -->
|
||||
<view
|
||||
wx:if="{{showCode}}"
|
||||
class="mt-12 flex-col justify-center items-center text-wrapper_2"
|
||||
bindtap="saveImage"
|
||||
>
|
||||
<text class="font">保存图片</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="flex-col section">
|
||||
<view class="flex-row items-center group_2">
|
||||
<image
|
||||
class="image_2"
|
||||
src="./image/wenhao.png"
|
||||
/>
|
||||
<text class="ml-6 font text_2">推广码说明</text>
|
||||
</view>
|
||||
<view class="section_2"></view>
|
||||
</view>
|
||||
</view>
|
61
pages/course/applyPromotion/applyPromotion.wxss
Normal file
61
pages/course/applyPromotion/applyPromotion.wxss
Normal file
@ -0,0 +1,61 @@
|
||||
/* pages/course/applyPromotion/applyPromotion.wxss */
|
||||
.page {
|
||||
background-color: #f6f7f9;
|
||||
width: 100%;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
height: 100%;
|
||||
}
|
||||
.group {
|
||||
padding: 69.38rpx 0 52.5rpx;
|
||||
}
|
||||
/* 上下居中改由 justify-center 控制,无需修改原有 padding */
|
||||
.text-wrapper {
|
||||
padding: 30rpx 0 30rpx;
|
||||
background-color: #a5d63f;
|
||||
border-radius: 46.07rpx;
|
||||
width: 395.63rpx;
|
||||
}
|
||||
.image {
|
||||
width: 667.5rpx;
|
||||
height: 763.13rpx;
|
||||
}
|
||||
.text-wrapper_2 {
|
||||
padding: 30rpx 0 30rpx;
|
||||
background-color: #ff8d1a;
|
||||
border-radius: 46.07rpx;
|
||||
width: 395.63rpx;
|
||||
}
|
||||
.section {
|
||||
padding: 0 30rpx 60rpx;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.group_2 {
|
||||
padding: 35.63rpx 0 30rpx;
|
||||
}
|
||||
.image_2 {
|
||||
width: 45rpx;
|
||||
height: 45rpx;
|
||||
}
|
||||
.font {
|
||||
font-size: 30rpx;
|
||||
font-family: SourceHanSansCN;
|
||||
line-height: 27.99rpx;
|
||||
color: #ffffff;
|
||||
}
|
||||
.text {
|
||||
line-height: 28.29rpx;
|
||||
}
|
||||
.text_2 {
|
||||
color: #000000;
|
||||
font-size: 28.13rpx;
|
||||
line-height: 26.19rpx;
|
||||
}
|
||||
.section_2 {
|
||||
background-color: #ffffff00;
|
||||
height: 813.75rpx;
|
||||
border-left: solid 1.88rpx #000000;
|
||||
border-right: solid 1.88rpx #000000;
|
||||
border-top: solid 1.88rpx #000000;
|
||||
border-bottom: solid 1.88rpx #000000;
|
||||
}
|
BIN
pages/course/applyPromotion/image/wenhao.png
Normal file
BIN
pages/course/applyPromotion/image/wenhao.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
Reference in New Issue
Block a user