Prechádzať zdrojové kódy

贷款-绘制海报

panyong 4 rokov pred
rodič
commit
f7865b9877

+ 6 - 0
htmldev/loan/package-lock.json

@@ -11296,6 +11296,12 @@
       "integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=",
       "dev": true
     },
+    "qrcodejs2": {
+      "version": "0.0.2",
+      "resolved": "https://registry.npm.taobao.org/qrcodejs2/download/qrcodejs2-0.0.2.tgz",
+      "integrity": "sha1-Rlr+Xjnxn6zsuTLBH3oYYQkUauE=",
+      "dev": true
+    },
     "qs": {
       "version": "6.5.2",
       "resolved": "https://registry.npm.taobao.org/qs/download/qs-6.5.2.tgz",

+ 1 - 0
htmldev/loan/package.json

@@ -32,6 +32,7 @@
     "node-sass": "^4.14.1",
     "path": "^0.12.7",
     "postcss-pxtorem": "^5.1.1",
+    "qrcodejs2": "0.0.2",
     "rimraf": "^3.0.2",
     "sass": "^1.26.11",
     "sass-loader": "^10.0.2",

+ 2 - 1
htmldev/loan/src/utils/wxShareConfig.js

@@ -32,7 +32,8 @@ export const WxConfig = async () => {
       'updateAppMessageShareData',
       'updateTimelineShareData',
       'onMenuShareAppMessage',
-      'onMenuShareTimeline']
+      'onMenuShareTimeline',
+      'previewImage']
   }
   wx.config(wxParam)
   return wx

+ 203 - 0
htmldev/loan/src/views/partner/poster/index.vue

@@ -0,0 +1,203 @@
+<template>
+  <div class="hmt-w">
+    <!--图片预览区域-->
+    <div class="preview-w" v-show="strPostSrc">
+      <div class="poster" @click="funPreviewImage">
+        <img :src="strPostSrc" alt="" ref="poster">
+      </div>
+      <p class="tips">长按可保存选手海报。分享海报邀请好友投票!</p>
+    </div>
+    <div class="hide" id="qr-code"></div>
+    <canvas class="canvas hide" ref="myCanvas"></canvas>
+  </div>
+</template>
+
+<script>
+  import QRCode from 'qrcodejs2'
+  export default {
+    name: 'poster',
+    components: {},
+    data () {
+      return {
+        no: '',
+        strPostSrc: '',
+        qrcode: null
+      }
+    },
+    methods: {
+      getQRCode (obj) {
+        let vm = this
+        vm.qrcode = new QRCode('qr-code', {
+          width: 130,
+          height: 130,
+          text: `${vm.$root.strPageUrl}#/detail/${vm.no}`,
+          colorDark: '#000',
+          colorLight: '#fff'
+        })
+        let timer = setTimeout(() => {
+          clearTimeout(timer)
+          vm.initPoster(obj)
+        }, 500)
+      },
+      initPoster (obj) {
+        let vm = this
+        const { bg, no, name, photo, mask, icon } = obj
+        let canvas = vm.$refs.myCanvas
+        let ctx = canvas.getContext('2d')
+        let canvas2 = document.getElementById('qr-code').getElementsByTagName('canvas')[0]
+        let code = {}
+        code.src = canvas2.toDataURL('image/png', 1)
+        canvas.width = 750
+        canvas.height = 1100
+
+        // 绘制背景
+        vm.setImg({
+          ctx,
+          src: bg['src'],
+          x: 0,
+          y: 0,
+          width: 750,
+          height: 1100,
+          cb () {
+            ctx.fillStyle = '#fff'
+            ctx.fillRect(469, 798, 158, 158)
+            // 绘制二维码
+            vm.setImg({
+              ctx,
+              src: code.src,
+              x: 479,
+              y: 808,
+              width: 138,
+              height: 138,
+              cb () {
+                // 绘制文本
+                ctx.font = '500 24px/44px STYuanti-Regular'
+                ctx.fillStyle = '#7B4D03'
+                ctx.fillText('编号:' + no.toString().padStart(4, '0'), 123, 820)
+
+                ctx.font = '700 32px/46px PingFangSC'
+                ctx.fillText(name, 123, 870)
+                ctx.save()
+                ctx.lineWidth = 0
+                ctx.strokeStyle = 'rgba(255,255,255,0)'
+                ctx.save()
+                vm.setImg({
+                  // 绘制用户图片
+                  ctx,
+                  src: photo['src'],
+                  x: photo['x'],
+                  y: photo['y'],
+                  width: photo['width'],
+                  height: photo['height'],
+                  cb () {
+                    ctx.restore()
+                    vm.setImg({
+                      ctx,
+                      src: mask['src'],
+                      x: mask['x'],
+                      y: mask['y'],
+                      width: mask['width'],
+                      height: mask['height'],
+                      cb () {
+                        ctx.restore()
+                        vm.setImg({
+                          ctx,
+                          src: icon['src'],
+                          x: icon['x'],
+                          y: icon['y'],
+                          width: icon['width'],
+                          height: icon['height'],
+                          cb () {
+                            vm.strPostSrc = canvas.toDataURL('image/png', 1)
+                          }
+                        })
+                      }
+                    })
+                  }
+                })
+              }
+            })
+          }
+        })
+      },
+      setImg (params) {
+        let width = params['width']
+        let height = params['height']
+        let img = new Image()
+        if (/^http/.test(params.src)) {
+          img.crossOrigin = ''
+        }
+        img.onload = function () {
+          if (/^http/.test(params.src)) {
+            width = this['width']
+            height = this['height']
+            if (width >= height) {
+              params.ctx.rotate(-2 * Math.PI / 180)
+              params.ctx.translate(-14, 17)
+            }
+          }
+          params.ctx.drawImage(img, params.x, params.y, width, height)
+          params.cb()
+        }
+        img.src = params.src
+      },
+      // 图片预览
+      funPreviewImage () {
+        const vm = this
+        if (!vm.strPostSrc) {
+          return
+        }
+        window.wx.previewImage({
+          current: vm.strPostSrc,
+          urls: [vm.strPostSrc]
+        })
+      }
+    }
+  }
+</script>
+
+<style lang="scss" scoped>
+  .hmt-w {
+    width: 100%;
+    min-height: 100vh;
+    background: #F1CA4F;
+    padding-top: 40px;
+  }
+
+  .hide {
+    display: none;
+  }
+
+  .preview-w {
+    width: 100%;
+  }
+
+  .poster {
+    position: relative;
+    left: 0;
+    top: 0;
+    width: 670px;
+    height: 1006px;
+    margin: 0 auto;
+    border-radius: 22px;
+    overflow: hidden;
+
+    img {
+      position: absolute;
+      left: 50%;
+      top: 50%;
+      transform: translate(-50%, -50%);
+      display: block;
+      width: 100%;
+      height: 100%;
+    }
+  }
+
+  .tips {
+    width: 100%;
+    padding: 27px 0 100px;
+    font: 400 24px/34px 'STYuanti-SC';
+    text-align: center;
+    color: #7B4D03;
+  }
+</style>

+ 4 - 0
htmldev/loan/todo.txt

@@ -0,0 +1,4 @@
+合伙人-申请时产品介绍
+合伙人-贷款产品的产品图
+合伙人-用户隐私协议、服务协议
+贷款-产品介绍、分享标题、描述