index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import user from './user';
  2. import goods from './goods';
  3. import groupon from './groupon';
  4. import sheep from '@/sheep';
  5. import {
  6. ref
  7. } from 'vue'
  8. import FileApi from '@/sheep/api/infra/file';
  9. let locaImage = ref("")
  10. async function getFileURL(file) {
  11. await FileApi.getFileIO(file).then((res) => {
  12. // #ifdef MP-WEIXIN
  13. locaImage.value = `data:image/png;base64,${res}`;
  14. console.log(locaImage.value)
  15. // #endif
  16. // #ifndef MP-WEIXIN
  17. locaImage.value = window.URL.createObjectURL(res);
  18. // #endif
  19. // locaImage.value = window.URL.createObjectURL(res);
  20. })
  21. }
  22. export async function getPosterData(options) {
  23. const userInfo = sheep.$store('user').userInfo;
  24. // console.log(JSON.parse(uni.getStorageSync("user-store")).userInfo)
  25. let avatar = userInfo.avatar
  26. switch (options.shareInfo.poster.type) {
  27. case 'user':
  28. await getFileURL(avatar)
  29. options.avatar = locaImage.value
  30. return user(options);
  31. case 'goods':
  32. await getFileURL(avatar)
  33. options.avatar = locaImage.value
  34. await getFileURL(options.shareInfo.poster.image)
  35. options.shareInfo.poster.image = locaImage.value
  36. return goods(options);
  37. case 'groupon':
  38. return groupon(options);
  39. }
  40. }
  41. export function formatImageUrlProtocol(url) {
  42. // #ifdef H5
  43. // H5平台 https协议下需要转换
  44. if (window.location.protocol === 'https:' && url.indexOf('http:') === 0) {
  45. url = url.replace('http:', 'https:');
  46. }
  47. // #endif
  48. // #ifdef MP-WEIXIN
  49. // 小程序平台 需要强制转换为https协议
  50. if (url.indexOf('http:') === 0) {
  51. url = url.replace('http:', 'https:');
  52. }
  53. // #endif
  54. return url;
  55. }