Files
shoot-miniprograms/src/pages/image-share.vue

80 lines
1.8 KiB
Vue
Raw Normal View History

2025-06-21 03:34:10 +08:00
<script setup>
2025-06-21 12:59:59 +08:00
import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
2025-06-21 03:34:10 +08:00
import Container from "@/components/Container.vue";
2025-06-21 22:22:19 +08:00
import { generateCanvasImage } from "@/util";
2025-06-21 12:59:59 +08:00
import { getPractiseAPI } from "@/apis";
2025-06-21 22:22:19 +08:00
import { wxShare } from "@/util";
2025-06-21 12:59:59 +08:00
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
2025-06-21 03:34:10 +08:00
2025-06-21 12:59:59 +08:00
onLoad(async (options) => {
2025-06-22 16:15:37 +08:00
const id = options.id || 461;
2025-06-21 12:59:59 +08:00
const data = await getPractiseAPI(id);
if (!data.arrows.length) return;
2025-06-21 22:22:19 +08:00
generateCanvasImage("shareCanvas", options.type, user.value, data);
2025-06-21 03:34:10 +08:00
});
2025-06-21 12:59:59 +08:00
const saveImage = () => {
uni.canvasToTempFilePath({
canvasId: "shareCanvas",
success: (res) => {
const tempFilePath = res.tempFilePath;
// 保存图片到相册
uni.saveImageToPhotosAlbum({
filePath: tempFilePath,
success: () => {
uni.showToast({ title: "保存成功" });
},
fail: () => {
uni.showToast({ title: "保存失败", icon: "error" });
},
});
},
});
};
2025-06-21 03:34:10 +08:00
</script>
<template>
<Container>
<view class="content">
2025-06-21 12:59:59 +08:00
<view :style="{ overflow: 'hidden', borderRadius: '10px' }">
<canvas
2025-06-22 16:15:37 +08:00
:style="{ width: '300px', height: '534px' }"
2025-06-21 12:59:59 +08:00
canvas-id="shareCanvas"
></canvas>
</view>
2025-06-21 03:34:10 +08:00
</view>
</Container>
</template>
<style scoped>
.content {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
padding-top: 20px;
}
.footer {
width: 100%;
display: flex;
justify-content: space-around;
margin-top: 50px;
}
2025-06-21 22:22:19 +08:00
.footer > button {
2025-06-21 03:34:10 +08:00
display: flex;
flex-direction: column;
align-items: center;
color: #fff;
font-size: 12px;
}
2025-06-21 22:22:19 +08:00
.footer > button > image {
2025-06-21 03:34:10 +08:00
width: 45px;
margin-bottom: 10px;
}
</style>