123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <script setup>
- import Container from "../../components/Container/Container.vue";
- import lPainter from "@/uni_modules/lime-painter/components/l-painter/l-painter.vue";
- import lPainterView from "@/uni_modules/lime-painter/components/l-painter-view/l-painter-view.vue";
- import lPainterImage from "@/uni_modules/lime-painter/components/l-painter-image/l-painter-image.vue";
- import { ref } from "vue";
- import { request } from "../../utils/request";
- import { onShow } from "@dcloudio/uni-app";
- const qrCode = ref("");
- const painter = ref(null);
- const showShare = ref(false);
- const onSaveImage = () => {
- painter.value?.canvasToTempFilePathSync({
- fileType: "jpg",
- pathType: "url",
- quality: 1,
- success: (res) => {
- // 非H5 保存到相册
- uni.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: function () {
- uni.showToast({
- title: "保存成功",
- icon: "success",
- });
- showShare.value = false;
- },
- });
- },
- });
- };
- onShow(() => {
- const userInfo = uni.getStorageSync("userInfo");
- // 生成二维码
- request("api/question_bank/question_reception/user_share/get_invite_qrcode", {
- page_url: "pages/index/index",
- scene: `share_uid=${userInfo.uid}`
- }).then((res) => {
- let url = res.data?.image;
- if (url.startsWith("data:")) {
- var imgPath =
- uni.env.USER_DATA_PATH + "/e-invoice" + Date.parse(new Date()) + ".png";
- var imageData = url.replace(/^data:image\/\w+;base64,/, "");
- var fs = uni.getFileSystemManager();
- fs.writeFileSync(imgPath, imageData, "base64");
- fs.close();
- url = imgPath;
- }
- qrCode.value = url;
- });
- });
- </script>
- <template>
- <Container
- :scrollStyle="{
- padding: 0,
- }"
- title="分享有礼"
- v-if="!showShare"
- >
- <view>
- <view class="bg">
-
- <image class="qr-code" :src="qrCode" mode="scaleToFill" />
- </view>
- </view>
- <template #footer>
- <button @click="showShare = true">立即分享</button>
- </template>
- </Container>
- <view class="share-template" v-else>
- <view class="share-img">
- <l-painter ref="painter">
- <l-painter-view
- css="width: 686rpx; height: 888rpx; position: relative;"
- >
- <l-painter-image
- src="https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/12nSpSIh19rrhQBm0q3jvmT6dgXeN77q4el6cdXX.png"
- css="width: 686rpx; height: 888rpx; position: absolute;top: 0;"
- />
- <l-painter-image
- :src="qrCode"
- css="width: 448rpx; height: 448rpx; position: absolute;top: 268rpx;left: 119rpx;"
- />
- </l-painter-view>
- </l-painter>
- </view>
- <view class="footer">
- <div class="title">
- <view>分享更多好友</view>
- <uni-icons
- type="closeempty"
- class="closeempty"
- @click="showShare = false"
- />
- </div>
- <view class="items">
- <view class="save-img" @click="onSaveImage">
- <image
- src="https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/zGBXaE27pgRjEA6NoMLC75CSdMs3BKjh1vnpGKAc.png"
- mode="scaleToFill"
- class="save"
- />
- <text>保存图片</text>
- </view>
- </view>
- </view>
- </view>
- </template>
- <style scoped lang="scss">
- @import "@/uni.scss";
- .bg {
- height: 1285rpx;
- width: 100%;
- background: url("https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/Ahdg7M3KIES9pNSnFB55Mlm9NNf6wrGq8oltvNUB.png");
- background-size: cover;
- position: relative;
- .qr-code {
- position: absolute;
- width: 322.14rpx;
- height: 322.14rpx;
- border-radius: 24rpx;
- border: 8rpx solid $primary;
- left: 50%;
- top: 36.5%;
- transform: translateX(-50%);
- }
- }
- .share-template {
- height: 100vh;
- width: 100%;
- background: #999999;
- position: relative;
- .share-img {
- position: absolute;
- top: 368rpx;
- left: 32rpx;
- }
- .footer {
- position: absolute;
- bottom: 0;
- left: 0;
- width: 100%;
- height: calc(68rpx + 80rpx + 140rpx);
- background-color: #fff;
- border-radius: 40rpx 40rpx 0rpx 0rpx;
- .title {
- display: flex;
- height: 80rpx;
- align-items: center;
- justify-content: center;
- position: relative;
- .closeempty {
- position: absolute;
- right: 32rpx;
- }
- }
- .items {
- display: flex;
- align-items: center;
- justify-content: center;
- height: 140rpx;
- .save-img {
- display: flex;
- align-items: center;
- gap: 12rpx;
- font-weight: 400;
- font-size: 28rpx;
- color: #000000;
- .save {
- width: 60rpx;
- height: 60rpx;
- }
- }
- }
- }
- }
- </style>
|