import user from './user'; import goods from './goods'; import groupon from './groupon'; import sheep from '@/sheep'; import { ref } from 'vue' import FileApi from '@/sheep/api/infra/file'; let locaImage = ref("") async function getFileURL(file) { await FileApi.getFileIO(file).then((res) => { // #ifdef MP-WEIXIN locaImage.value = `data:image/png;base64,${res}`; console.log(locaImage.value) // #endif // #ifndef MP-WEIXIN locaImage.value = window.URL.createObjectURL(res); // #endif // locaImage.value = window.URL.createObjectURL(res); }) } export async function getPosterData(options) { const userInfo = sheep.$store('user').userInfo; // console.log(JSON.parse(uni.getStorageSync("user-store")).userInfo) let avatar = userInfo.avatar switch (options.shareInfo.poster.type) { case 'user': await getFileURL(avatar) options.avatar = locaImage.value return user(options); case 'goods': await getFileURL(avatar) options.avatar = locaImage.value await getFileURL(options.shareInfo.poster.image) options.shareInfo.poster.image = locaImage.value return goods(options); case 'groupon': return groupon(options); } } export function formatImageUrlProtocol(url) { // #ifdef H5 // H5平台 https协议下需要转换 if (window.location.protocol === 'https:' && url.indexOf('http:') === 0) { url = url.replace('http:', 'https:'); } // #endif // #ifdef MP-WEIXIN // 小程序平台 需要强制转换为https协议 if (url.indexOf('http:') === 0) { url = url.replace('http:', 'https:'); } // #endif return url; }