Files
frontend-app/pages/other_package/invite_friends/invite_friends.vue
T

125 lines
2.7 KiB
Vue
Raw Normal View History

2025-08-05 15:25:23 +08:00
<template>
<view class="invite_friends_warp">
<view class="invite_img">
2025-08-23 14:25:27 +08:00
<up-image :loading="imageLoading" :src="inviteImage" width="100%" height="460" bgColor="#f1f6ff00" shape="square"
radius=10></up-image>
2025-08-05 15:25:23 +08:00
</view>
<view class="invite_but">
<view class="save_but">
<text style="margin-left: 10rpx;" @click="saveBaseImgFile">保存图片</text>
</view>
</view>
<up-toast ref="uToastRef"></up-toast>
</view>
</template>
<script>
2025-08-23 14:25:27 +08:00
import { getSharePoster, generateSharePoster } from '@/api/common.js';
export default {
data() {
return {
inviteImage: null,
imageLoading: false,
}
},
mounted() {
this.getSharePoster();
},
methods: {
// 查询分享模版
async getSharePoster() {
this.imageLoading = true;
const resp = await getSharePoster();
if (resp && resp.bizcode === 100) {
const data = resp.data[0];
// 生成分享图
const generateResp = await generateSharePoster({ id: data.id });
if (generateResp && generateResp.bizcode === 100) {
this.inviteImage = generateResp.data;
2025-08-05 15:25:23 +08:00
}
2025-08-23 14:25:27 +08:00
}
this.imageLoading = false;
},
saveBaseImgFile() {
uni.showLoading({
title: '保存中...',
})
const currentBase64 = this.inviteImage;
const bitmap = new plus.nativeObj.Bitmap('base64')
bitmap.loadBase64Data(currentBase64, () => {
const url = '_doc/' + new Date().getTime() + '.png'
bitmap.save(
url,
{
overwrite: false, // 是否覆盖
},
(i) => {
uni.saveImageToPhotosAlbum({
filePath: url,
success: () => {
2025-08-05 15:25:23 +08:00
uni.hideLoading();
this.$refs.uToastRef.show({
2025-08-23 14:25:27 +08:00
type: 'success',
message: "图片保存到相册成功",
2025-08-05 15:25:23 +08:00
});
2025-08-23 14:25:27 +08:00
bitmap.clear()
}
})
},
(e) => {
2025-08-05 15:25:23 +08:00
uni.hideLoading();
2025-08-23 14:25:27 +08:00
console.log('图片保存失败', e)
2025-08-05 15:25:23 +08:00
this.$refs.uToastRef.show({
type: 'error',
message: "图片保存失败",
});
2025-08-23 14:25:27 +08:00
bitmap.clear()
}
)
},
(e) => {
uni.hideLoading();
console.log('图片保存失败', e)
this.$refs.uToastRef.show({
type: 'error',
message: "图片保存失败",
});
bitmap.clear()
}
)
2025-08-05 15:25:23 +08:00
}
}
2025-08-23 14:25:27 +08:00
}
2025-08-05 15:25:23 +08:00
</script>
<style lang="scss" scoped>
2025-08-23 14:25:27 +08:00
.invite_friends_warp {
height: calc(100vh - 80rpx);
padding: 40rpx;
}
.invite_img {
margin-top: 52rpx;
height: 930rpx;
}
.invite_but {
padding: 20rpx 50rpx;
margin-top: 52rpx;
.save_but {
text-align: center;
background: $app-bt-bj;
border-radius: 45rpx;
width: 100%;
color: #FFF;
padding: 30rpx 0;
font-weight: 500;
font-size: 32rpx;
color: #FFFFFF;
2025-08-05 15:25:23 +08:00
}
2025-08-23 14:25:27 +08:00
}
2025-08-05 15:25:23 +08:00
</style>