Forráskód Böngészése

fix:海报图片协议转换,自动识别https协议

ldh 2 éve
szülő
commit
e7c6c55786

+ 5 - 4
sheep/components/s-share-modal/canvas-poster/poster/goods.js

@@ -1,11 +1,12 @@
 import sheep from '@/sheep';
+import { formatImageUrlProtocol } from './index';
 
 const goods = (poster) => {
   const width = poster.width;
   const userInfo = sheep.$store('user').userInfo;
 
   return {
-    background: sheep.$url.cdn(sheep.$store('app').platform.share.posterInfo.goods_bg),
+    background: formatImageUrlProtocol(sheep.$url.cdn(sheep.$store('app').platform.share.posterInfo.goods_bg)),
     list: [
       {
         name: 'nickname',
@@ -24,7 +25,7 @@ const goods = (poster) => {
       {
         name: 'avatar',
         type: 'image',
-        val: sheep.$url.cdn(userInfo.avatar),
+        val: formatImageUrlProtocol(sheep.$url.cdn(userInfo.avatar)),
         x: width * 0.04,
         y: width * 0.04,
         width: width * 0.14,
@@ -34,7 +35,7 @@ const goods = (poster) => {
       {
         name: 'goodsImage',
         type: 'image',
-        val: poster.shareInfo.poster.image,
+        val: formatImageUrlProtocol(poster.shareInfo.poster.image),
         x: width * 0.03,
         y: width * 0.21,
         width: width * 0.94,
@@ -47,8 +48,8 @@ const goods = (poster) => {
         val: poster.shareInfo.poster.title,
         x: width * 0.04,
         y: width * 1.18,
-        line: 2,
         maxWidth: width * 0.91,
+        line: 2,
         lineHeight: 5,
         paintbrushProps: {
           fillStyle: '#333',

+ 4 - 3
sheep/components/s-share-modal/canvas-poster/poster/groupon.js

@@ -1,11 +1,12 @@
 import sheep from '@/sheep';
+import { formatImageUrlProtocol } from './index';
 
 const groupon = (poster) => {
   const width = poster.width;
   const userInfo = sheep.$store('user').userInfo;
 
   return {
-    background: sheep.$url.cdn(sheep.$store('app').platform.share.posterInfo.groupon_bg),
+    background: formatImageUrlProtocol(sheep.$url.cdn(sheep.$store('app').platform.share.posterInfo.groupon_bg)),
     list: [
       {
         name: 'nickname',
@@ -24,7 +25,7 @@ const groupon = (poster) => {
       {
         name: 'avatar',
         type: 'image',
-        val: sheep.$url.cdn(userInfo.avatar),
+        val: formatImageUrlProtocol(sheep.$url.cdn(userInfo.avatar)),
         x: width * 0.04,
         y: width * 0.04,
         width: width * 0.14,
@@ -34,7 +35,7 @@ const groupon = (poster) => {
       {
         name: 'goodsImage',
         type: 'image',
-        val: poster.shareInfo.poster.image,
+        val: formatImageUrlProtocol(poster.shareInfo.poster.image),
         x: width * 0.03,
         y: width * 0.21,
         width: width * 0.94,

+ 18 - 0
sheep/components/s-share-modal/canvas-poster/poster/index.js

@@ -12,3 +12,21 @@ export function getPosterData(options) {
       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;
+}

+ 3 - 2
sheep/components/s-share-modal/canvas-poster/poster/user.js

@@ -1,11 +1,12 @@
 import sheep from '@/sheep';
+import { formatImageUrlProtocol } from './index';
 
 const user = (poster) => {
   const width = poster.width;
   const userInfo = sheep.$store('user').userInfo;
 
   return {
-    background: sheep.$url.cdn(sheep.$store('app').platform.share.posterInfo.user_bg),
+    background: formatImageUrlProtocol(sheep.$url.cdn(sheep.$store('app').platform.share.posterInfo.user_bg)),
     list: [
       {
         name: 'nickname',
@@ -25,7 +26,7 @@ const user = (poster) => {
       {
         name: 'avatar',
         type: 'image',
-        val: sheep.$url.cdn(userInfo.avatar),
+        val: formatImageUrlProtocol(sheep.$url.cdn(userInfo.avatar)),
         x: width * 0.4,
         y: width * 0.16,
         width: width * 0.2,