Showing
2 changed files
with
98 additions
and
32 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2024-04-07 10:15:55 | 2 | * @Date: 2024-04-07 10:15:55 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-04-12 12:16:24 | 4 | + * @LastEditTime: 2024-04-12 15:42:26 |
| 5 | * @FilePath: /fxPark/src/views/fxPark/index.vue | 5 | * @FilePath: /fxPark/src/views/fxPark/index.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -12,14 +12,17 @@ | ... | @@ -12,14 +12,17 @@ |
| 12 | <div class="quick-entrance-item" @click="goToAudio"> | 12 | <div class="quick-entrance-item" @click="goToAudio"> |
| 13 | <van-icon name="chat-o" /> <span>植物之声</span> | 13 | <van-icon name="chat-o" /> <span>植物之声</span> |
| 14 | </div> | 14 | </div> |
| 15 | + <div class="quick-entrance-item" @click="onShare"> | ||
| 16 | + <van-icon name="chat-o" /> <span>分享海报</span> | ||
| 17 | + </div> | ||
| 15 | </div> | 18 | </div> |
| 16 | <div class="container" v-for="(item, index) in data_list" :key="index" @click="onChipClick()"> | 19 | <div class="container" v-for="(item, index) in data_list" :key="index" @click="onChipClick()"> |
| 17 | <img :src="item.chip_src" class="img"> | 20 | <img :src="item.chip_src" class="img"> |
| 18 | </div> | 21 | </div> |
| 19 | - <div style="position: fixed; bottom: 1rem; left: 0; right: 0; display: flex; z-index: 25;justify-content: space-evenly;"> | 22 | + <!-- <div style="position: fixed; bottom: 1rem; left: 0; right: 0; display: flex; z-index: 25;justify-content: space-evenly;"> --> |
| 20 | - <div v-if="all_actived" @click="onShare" style="display: inline-flex; padding: 0.6rem 2rem; color: #F68015; background-color: #fff; align-items: center; border-radius: 1.5rem;">分享海报</div> | 23 | + <!-- <div v-if="all_actived" @click="onShare" style="display: inline-flex; padding: 0.6rem 2rem; color: #F68015; background-color: #fff; align-items: center; border-radius: 1.5rem;">分享海报</div> --> |
| 21 | <!-- <div @click="commentsBtn" style="display: inline-flex; padding: 0.6rem 2rem; color: #fff; background-color: #F68015;align-items: center; border-radius: 1.5rem;">弹幕留言</div> --> | 24 | <!-- <div @click="commentsBtn" style="display: inline-flex; padding: 0.6rem 2rem; color: #fff; background-color: #F68015;align-items: center; border-radius: 1.5rem;">弹幕留言</div> --> |
| 22 | - </div> | 25 | + <!-- </div> --> |
| 23 | 26 | ||
| 24 | <van-action-sheet v-model:show="show_danmu_message" title="留言" :round="false" :close-on-click-overlay="false" @cancel="onCancel"> | 27 | <van-action-sheet v-model:show="show_danmu_message" title="留言" :round="false" :close-on-click-overlay="false" @cancel="onCancel"> |
| 25 | <div style="padding: 1rem 0; height: 10vh; display: flex; padding: 0.5rem;"> | 28 | <div style="padding: 1rem 0; height: 10vh; display: flex; padding: 0.5rem;"> |
| ... | @@ -138,9 +141,9 @@ const onChipClick = () => { // 点击碎片回调 | ... | @@ -138,9 +141,9 @@ const onChipClick = () => { // 点击碎片回调 |
| 138 | needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果, | 141 | needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果, |
| 139 | scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有 | 142 | scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有 |
| 140 | success: function (res) { | 143 | success: function (res) { |
| 141 | - // let result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果 | 144 | + let result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果 |
| 142 | // 跳转到相应植被介绍页 | 145 | // 跳转到相应植被介绍页 |
| 143 | - let result = 'http://oa.allforlove.org.cn/f/carbon/#/intro?revision=1'; | 146 | + // let result = 'http://oa.allforlove.org.cn/f/carbon/#/intro?revision=1'; |
| 144 | let revision = parseQueryString(result).revision; | 147 | let revision = parseQueryString(result).revision; |
| 145 | go('/intro', { revision }); | 148 | go('/intro', { revision }); |
| 146 | }, | 149 | }, |
| ... | @@ -176,11 +179,13 @@ const sendMessage = async () => { | ... | @@ -176,11 +179,13 @@ const sendMessage = async () => { |
| 176 | const onDanmuBlur = (evt) => { | 179 | const onDanmuBlur = (evt) => { |
| 177 | show_danmu_message.value = false; | 180 | show_danmu_message.value = false; |
| 178 | spaceDiv.value = false; | 181 | spaceDiv.value = false; |
| 182 | + document.body.scrollIntoView({behavior: 'smooth'}); | ||
| 179 | } | 183 | } |
| 180 | 184 | ||
| 181 | const handleEnterPress = (evt) => { | 185 | const handleEnterPress = (evt) => { |
| 182 | if (evt.keyCode === 13) { | 186 | if (evt.keyCode === 13) { |
| 183 | sendMessage(); | 187 | sendMessage(); |
| 188 | + document.body.scrollIntoView({behavior: 'smooth'}); | ||
| 184 | } | 189 | } |
| 185 | } | 190 | } |
| 186 | 191 | ||
| ... | @@ -193,7 +198,15 @@ const onCancel = () => { | ... | @@ -193,7 +198,15 @@ const onCancel = () => { |
| 193 | } | 198 | } |
| 194 | 199 | ||
| 195 | const onShare = () => { // 分享海报按钮 | 200 | const onShare = () => { // 分享海报按钮 |
| 196 | - go('/finish') | 201 | + // go('/finish') |
| 202 | + let raw_data = data_list.value.filter(item => item.is_light === '1'); // 获取所有已点亮的植被 | ||
| 203 | + // | ||
| 204 | + $router.push({ | ||
| 205 | + path: '/poster', | ||
| 206 | + query: { | ||
| 207 | + revision: raw_data.length ? raw_data[0].revision : -1 | ||
| 208 | + } | ||
| 209 | + }); | ||
| 197 | } | 210 | } |
| 198 | 211 | ||
| 199 | const goToAudio = () => { | 212 | const goToAudio = () => { |
| ... | @@ -209,17 +222,18 @@ const onCloseDanmu = () => { | ... | @@ -209,17 +222,18 @@ const onCloseDanmu = () => { |
| 209 | .fxPark-page { | 222 | .fxPark-page { |
| 210 | position: relative; | 223 | position: relative; |
| 211 | .quick-entrance-wrapper { | 224 | .quick-entrance-wrapper { |
| 225 | + position: absolute; | ||
| 226 | + right: 0; | ||
| 227 | + top: 1.5rem; | ||
| 228 | + z-index: 20; | ||
| 212 | .quick-entrance-item { | 229 | .quick-entrance-item { |
| 213 | - position: absolute; | ||
| 214 | - right: 0; | ||
| 215 | - top: 1.5rem; | ||
| 216 | color: white; | 230 | color: white; |
| 217 | background-color: green; | 231 | background-color: green; |
| 218 | border-top-left-radius: 1rem; | 232 | border-top-left-radius: 1rem; |
| 219 | border-bottom-left-radius: 1rem; | 233 | border-bottom-left-radius: 1rem; |
| 220 | - z-index: 20; | ||
| 221 | font-size: 0.9rem; | 234 | font-size: 0.9rem; |
| 222 | padding: 0.5rem; | 235 | padding: 0.5rem; |
| 236 | + margin-bottom: 1rem; | ||
| 223 | } | 237 | } |
| 224 | } | 238 | } |
| 225 | .container { | 239 | .container { | ... | ... |
| ... | @@ -4,14 +4,13 @@ | ... | @@ -4,14 +4,13 @@ |
| 4 | <div v-if="flag" ref="canvasRef" style="position: relative; padding: 1rem; background-color: #fff;"> | 4 | <div v-if="flag" ref="canvasRef" style="position: relative; padding: 1rem; background-color: #fff;"> |
| 5 | <div style="position: absolute; top: 3rem; left: 2rem; color: #FFF; writing-mode: vertical-lr; text-orientation: upright;"> | 5 | <div style="position: absolute; top: 3rem; left: 2rem; color: #FFF; writing-mode: vertical-lr; text-orientation: upright;"> |
| 6 | <div style="position: relative;"> | 6 | <div style="position: relative;"> |
| 7 | - <span style="font-size: 2.5rem; font-weight: bolder; letter-spacing: 5px;">悬铃木</span> | 7 | + <span style="font-size: 2.5rem; font-weight: bolder; letter-spacing: 5px;">{{ tree_data?.name }}</span> |
| 8 | - <div style="position: absolute; bottom: -1rem; letter-spacing: 5px;">智者长老</div> | 8 | + <div style="position: absolute; bottom: -1rem; letter-spacing: 5px;">{{ tree_data?.nickname }}</div> |
| 9 | </div> | 9 | </div> |
| 10 | </div> | 10 | </div> |
| 11 | <img :src="imgSrc" style="width: 100%; height: 67vh;"> | 11 | <img :src="imgSrc" style="width: 100%; height: 67vh;"> |
| 12 | <div style="color: #CCCCCC; margin-top: 1rem;"> | 12 | <div style="color: #CCCCCC; margin-top: 1rem;"> |
| 13 | - <div style="font-weight: bold; text-decoration: underline; margin-bottom: 0.5rem;">自带咖啡杯</div> | 13 | + <div style="font-weight: bold; text-decoration: underline; margin-bottom: 0.5rem;">{{ tree_data?.mission_title }}</div> |
| 14 | - <div style="font-size: 0.9rem;">去咖啡店时自带咖啡杯,代替一次性纸杯。</div> | ||
| 15 | </div> | 14 | </div> |
| 16 | </div> | 15 | </div> |
| 17 | <div v-if="imgUrl"> | 16 | <div v-if="imgUrl"> |
| ... | @@ -21,12 +20,12 @@ | ... | @@ -21,12 +20,12 @@ |
| 21 | <div class="poster-control-wrapper"> | 20 | <div class="poster-control-wrapper"> |
| 22 | <p class="save-text">长按保存到相册</p> | 21 | <p class="save-text">长按保存到相册</p> |
| 23 | <div class="poster-control"> | 22 | <div class="poster-control"> |
| 24 | - <div class="poster-prev">上一个</div> | 23 | + <div @click="posterPrev" class="poster-prev">上一个</div> |
| 25 | - <van-uploader :before-read="beforeRead" :after-read="afterRead" :max-size="1000 * 1024" accept="file"> | 24 | + <van-uploader v-if="tree_data?.is_tree === 1" :before-read="beforeRead" :after-read="afterRead" accept="file"> |
| 26 | <div v-if="!upload_loading" class="poster-upload-btn" style="">上传图片</div> | 25 | <div v-if="!upload_loading" class="poster-upload-btn" style="">上传图片</div> |
| 27 | - <van-loading v-else size="24px" color="#E82D2D" text-color="#E82D2D" vertical>上传中...</van-loading> | 26 | + <van-loading v-else size="24px" color="#fff" text-color="#fff" vertical>上传中...</van-loading> |
| 28 | </van-uploader> | 27 | </van-uploader> |
| 29 | - <div class="poster-next">下一个</div> | 28 | + <div @click="posterNext" class="poster-next">下一个</div> |
| 30 | </div> | 29 | </div> |
| 31 | </div> | 30 | </div> |
| 32 | </div> | 31 | </div> |
| ... | @@ -37,7 +36,9 @@ import { ref } from 'vue' | ... | @@ -37,7 +36,9 @@ import { ref } from 'vue' |
| 37 | import { useRoute, useRouter } from 'vue-router' | 36 | import { useRoute, useRouter } from 'vue-router' |
| 38 | import { v4 as uuidv4 } from 'uuid'; | 37 | import { v4 as uuidv4 } from 'uuid'; |
| 39 | import { qiniuTokenAPI, qiniuUploadAPI, saveFileAPI } from '@/api/common'; | 38 | import { qiniuTokenAPI, qiniuUploadAPI, saveFileAPI } from '@/api/common'; |
| 39 | +import { getTreeAPI, savePosterAPI } from '@/api/carbon.js'; | ||
| 40 | import html2canvas from "html2canvas"; | 40 | import html2canvas from "html2canvas"; |
| 41 | +import { showToast } from 'vant'; | ||
| 41 | import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js' | 42 | import { Cookies, $, _, axios, storeToRefs, mainStore, Toast, useTitle } from '@/utils/generatePackage.js' |
| 42 | //import { } from '@/utils/generateModules.js' | 43 | //import { } from '@/utils/generateModules.js' |
| 43 | //import { } from '@/utils/generateIcons.js' | 44 | //import { } from '@/utils/generateIcons.js' |
| ... | @@ -48,22 +49,64 @@ useTitle($route.meta.title); | ... | @@ -48,22 +49,64 @@ useTitle($route.meta.title); |
| 48 | 49 | ||
| 49 | const canvasRef = ref(null); | 50 | const canvasRef = ref(null); |
| 50 | const imgUrl = ref(''); | 51 | const imgUrl = ref(''); |
| 51 | -const imgSrc = ref('https://picsum.photos/800'); | 52 | +const imgSrc = ref(''); |
| 52 | const flag = ref(true); | 53 | const flag = ref(true); |
| 53 | const ref_width = ref(''); | 54 | const ref_width = ref(''); |
| 54 | const ref_height = ref(''); | 55 | const ref_height = ref(''); |
| 55 | 56 | ||
| 57 | +const revision = $route.query.revision; // revision 植被编号 | ||
| 58 | +const raw_data = ref([]); | ||
| 59 | +const tree_data = ref({}); | ||
| 60 | + | ||
| 61 | +const posterIndex = ref(0); | ||
| 62 | + | ||
| 56 | onMounted(async () => { | 63 | onMounted(async () => { |
| 64 | + const { code, data } = await getTreeAPI(); | ||
| 65 | + if (code) { | ||
| 66 | + raw_data.value = data.filter(item => item.is_light === '1'); // 获取所有已点亮的植被 | ||
| 67 | + let index = raw_data.value.findIndex(item => item.revision == revision); // 植被信息index | ||
| 68 | + tree_data.value = raw_data.value[index]; | ||
| 69 | + imgSrc.value = tree_data.value.user_poster !== null ? tree_data.value.user_poster : tree_data.value.poster_pic; | ||
| 70 | + } | ||
| 57 | nextTick(() => { | 71 | nextTick(() => { |
| 58 | let canvasDom = canvasRef.value; | 72 | let canvasDom = canvasRef.value; |
| 59 | ref_width.value = canvasDom.offsetWidth + 'px'; | 73 | ref_width.value = canvasDom.offsetWidth + 'px'; |
| 60 | ref_height.value = canvasDom.offsetHeight + 'px'; | 74 | ref_height.value = canvasDom.offsetHeight + 'px'; |
| 61 | - // const screenWidth = window.innerWidth; | ||
| 62 | - // alert(screenWidth); // 输出移动设备屏幕的宽度 | ||
| 63 | }); | 75 | }); |
| 64 | createImage(); | 76 | createImage(); |
| 65 | }); | 77 | }); |
| 66 | 78 | ||
| 79 | +const resizePoster = () => { | ||
| 80 | + tree_data.value = raw_data.value[posterIndex.value]; | ||
| 81 | + flag.value = true; | ||
| 82 | + imgUrl.value = ''; | ||
| 83 | + imgSrc.value = tree_data.value.user_poster !== null ? tree_data.value.user_poster : tree_data.value.poster_pic; | ||
| 84 | + nextTick(() => { | ||
| 85 | + let canvasDom = canvasRef.value; | ||
| 86 | + ref_width.value = canvasDom.offsetWidth + 'px'; | ||
| 87 | + ref_height.value = canvasDom.offsetHeight + 'px'; | ||
| 88 | + }); | ||
| 89 | + createImage(); | ||
| 90 | +}; | ||
| 91 | + | ||
| 92 | +const posterPrev = () => { | ||
| 93 | + if (posterIndex.value > 0) { | ||
| 94 | + posterIndex.value--; | ||
| 95 | + } else { | ||
| 96 | + posterIndex.value = raw_data.value.length - 1; | ||
| 97 | + } | ||
| 98 | + resizePoster(); | ||
| 99 | +}; | ||
| 100 | + | ||
| 101 | +const posterNext = () => { | ||
| 102 | + if (posterIndex.value < raw_data.value.length - 1) { | ||
| 103 | + posterIndex.value++; | ||
| 104 | + } else { | ||
| 105 | + posterIndex.value = 0; | ||
| 106 | + } | ||
| 107 | + resizePoster(); | ||
| 108 | +}; | ||
| 109 | + | ||
| 67 | // 获取像素比 | 110 | // 获取像素比 |
| 68 | const DPR = () => { | 111 | const DPR = () => { |
| 69 | // 获取设备dpi | 112 | // 获取设备dpi |
| ... | @@ -112,10 +155,14 @@ const createImage = () => { | ... | @@ -112,10 +155,14 @@ const createImage = () => { |
| 112 | 155 | ||
| 113 | const upload_loading = ref(false); | 156 | const upload_loading = ref(false); |
| 114 | const beforeRead = (file) => { | 157 | const beforeRead = (file) => { |
| 115 | - // if (file.type.indexOf('audio') < 0) { | 158 | + if (file.type.indexOf('image') < 0) { |
| 116 | - // showToast('请上传音频格式'); | 159 | + showToast('请上传图片格式'); |
| 117 | - // return false; | 160 | + return false; |
| 118 | - // } | 161 | + } |
| 162 | + if (file.size > 1000 * 1024) { | ||
| 163 | + showToast('图片大小超过1M'); | ||
| 164 | + return false; | ||
| 165 | + } | ||
| 119 | return true; | 166 | return true; |
| 120 | }; | 167 | }; |
| 121 | 168 | ||
| ... | @@ -138,12 +185,17 @@ const afterRead = async (res) => { | ... | @@ -138,12 +185,17 @@ const afterRead = async (res) => { |
| 138 | const { filekey, hash, image_info } = await qiniuUploadAPI('http://upload.qiniup.com/putb64/-1/key/' + key, base64url, config) | 185 | const { filekey, hash, image_info } = await qiniuUploadAPI('http://upload.qiniup.com/putb64/-1/key/' + key, base64url, config) |
| 139 | if (filekey) { | 186 | if (filekey) { |
| 140 | // 保存图片 | 187 | // 保存图片 |
| 141 | - const { data } = await saveFileAPI({ filekey, hash, format: '0', height: '0', width: '0' }); | 188 | + const { code, data } = await saveFileAPI({ filekey, hash, format: '0', height: '0', width: '0' }); |
| 142 | - flag.value = true; | 189 | + if (code) { |
| 143 | - imgUrl.value = ''; | 190 | + const { code: tree_code, data: tree_data } = await savePosterAPI({ tree_revision: revision, poster_pic: data.src }) |
| 144 | - imgSrc.value = data.src; | 191 | + if (tree_code) { |
| 145 | - upload_loading.value = false; | 192 | + flag.value = true; |
| 146 | - createImage(); | 193 | + imgUrl.value = ''; |
| 194 | + imgSrc.value = data.src; | ||
| 195 | + upload_loading.value = false; | ||
| 196 | + createImage(); | ||
| 197 | + } | ||
| 198 | + } | ||
| 147 | } | 199 | } |
| 148 | } | 200 | } |
| 149 | }; | 201 | }; | ... | ... |
-
Please register or login to post a comment