Browse Source

拼团保存图片到本地开发

ZhangWenQiang 6 years ago
parent
commit
0ef36da1d2
3 changed files with 181 additions and 41 deletions
  1. 1 0
      components/wxa-plugin-canvas/index/index.js
  2. 176 40
      pages/pt-share/pt-share.js
  3. 4 1
      pages/pt-share/pt-share.wxml

+ 1 - 0
components/wxa-plugin-canvas/index/index.js

@@ -8,6 +8,7 @@ const main = {
         let blockWidth = 0; // 块的宽度
         let textX = 0;
         let textY = 0;
+        let wid = 750;
         if (typeof text !== 'undefined') {
             // 如果有文字并且块的宽度小于文字宽度,块的宽度为 文字的宽度 + 内边距
             const textWidth = this._getTextWidth(typeof text.text === 'string' ? text : text.text);

+ 176 - 40
pages/pt-share/pt-share.js

@@ -35,7 +35,7 @@ Page({
       this.setData({
         userInfo: app.globalData.userInfo
       })
-      this.fetchData()
+      this.start()
     } else if (this.data.canIUse) {
       // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
       // 所以此处加入 callback 以防止这种情况
@@ -44,7 +44,7 @@ Page({
         this.setData({
           userInfo: app.globalData.userInfo
         })
-        this.fetchData()
+        this.start()
       }
     } else {
       // 在没有 open-type=getUserInfo 版本的兼容处理
@@ -55,42 +55,188 @@ Page({
           this.setData({
             userInfo: app.globalData.userInfo
           })
-          this.fetchData()
+          this.start()
         }
       })
     }
+    this.setData({
+      hasAuth: true
+    })
   },
+
+  start() {
+    Promise.all([this.fetchData()]).then(data => {
+      let posterConfig = {
+        width: 700,
+        height: 950,
+        debug: false,
+        texts: [{
+            x: 54,
+            y: 260,
+            baseLine: 'middle',
+            text: this.data.userInfo.nickName,
+            fontSize: 38,
+            color: '#ffffff',
+            lineHeight: 30,
+            zIndex: 2,
+          },
+          {
+            x: 54,
+            y: 316,
+            baseLine: 'middle',
+            text: '“我在找好友一起上班!”',
+            fontSize: 26,
+            color: '#ffffff',
+            zIndex: 2,
+          },
+          {
+            x: 350,
+            y: 446,
+            baseLine: 'middle',
+            textAlign: "center",
+            width: 700,
+            text: this.data.postitionDetail.position.positionName,
+            fontSize: 38,
+            color: '#ffffff',
+            lineHeight: 38,
+            zIndex: 2
+          },
+          {
+            x: 350,
+            y: 494,
+            baseLine: 'middle',
+            textAlign: "center",
+            width: 700,
+            text: this.data.postitionDetail.position.hpCompany.companyName,
+            fontSize: 20,
+            color: '#ffffff',
+            zIndex: 2,
+          },
+          {
+            x: 350,
+            y: 542,
+            baseLine: 'middle',
+            textAlign: "center",
+            width: 700,
+            text: this.data.postitionDetail.position.totalSalary ? this.data.postitionDetail.position.totalSalary : this.data.postitionDetail.position.basicSalary,
+            fontSize: 50,
+            color: '#ffffff',
+            zIndex: 2,
+          },
+          {
+            x: 62,
+            y: 828,
+            baseLine: 'middle',
+            text: '专属客服,全程服务',
+            fontSize: 20,
+            color: '#ffffff',
+            zIndex: 2,
+          },
+          {
+            x: 434,
+            y: 786,
+            baseLine: 'middle',
+            text: '识别右侧二维码,',
+            fontSize: 20,
+            color: '#ffffff',
+            zIndex: 2,
+          },
+          {
+            x: 434,
+            y: 812,
+            baseLine: 'middle',
+            text: '即可参与我发起的拼工!',
+            fontSize: 20,
+            color: '#ffffff',
+            zIndex: 2,
+          }
+        ],
+        images: [{
+            width: 700,
+            height: 950,
+            x: 0,
+            y: 0,
+            url: `${imgServerUrl}/images/pt/bg.png`,
+            zIndex: 1,
+          },
+          {
+            width: 218,
+            height: 218,
+            x: 400,
+            y: 160,
+            url: app.globalData.userInfo.avatarUrl,
+            borderRadius: 222,
+            zIndex: 2,
+            borderWidth: 12,
+            borderColor: '#fff',
+          },
+          {
+            width: 196,
+            height: 40,
+            x: 50,
+            y: 772,
+            url: '/images/happyjob/logo.png',
+            zIndex: 2,
+          },
+          {
+            width: 120,
+            height: 120,
+            x: 280,
+            y: 744,
+            url: app.globalData.userInfo.avatarUrl, //二维码
+            zIndex: 2,
+          },
+        ],
+      }
+      console.log("sd", posterConfig)
+      this.setData({
+        posterConfig
+      })
+
+    })
+  },
+
   //获取历史记录
   fetchData() {
-    let paramsObj = {
-      positionCategory: this.data.positionCategory,
-      positionId: this.data.positionId,
-      groupId: this.data.hpPositionGroupId,
-      user_id: app.globalData.userId,
-      user_token: app.globalData.userToken
-    }
-    Object.assign(paramsObj);
-    getGroupDetail(paramsObj).then(data => {
-      console.log("groupDetail", data)
-      var leftTime = data.data.position.groupEndTime
-      this.setData({
-        postitionDetail: data.data
+    wx.showLoading({
+      title: 'loading',
+      mask: true
+    });
+    var that = this
+    return new Promise(function(resolve, reject) {
+      let paramsObj = {
+        positionCategory: that.data.positionCategory,
+        positionId: that.data.positionId,
+        groupId: that.data.hpPositionGroupId,
+        user_id: app.globalData.userId,
+        user_token: app.globalData.userToken
+      }
+      Object.assign(paramsObj);
+      getGroupDetail(paramsObj).then(data => {
+        console.log("groupDetail", data)
+        var leftTime = data.data.position.groupEndTime
+        that.setData({
+          postitionDetail: data.data
+        })
+        resolve(true)
+      }).catch(data => {
+        console.log(data)
+        reject(data)
       })
     })
   },
 
   onPosterSuccess(e) {
-    console.log(e)
-    const {
-      detail
-    } = e;
+    console.log("dddf", e)
+    var detail = e.detail;
+    console.log("df", detail)
     var that = this
     wx.saveImageToPhotosAlbum({
       filePath: detail,
       success(res) {
         console.log(res)
         wx.hideLoading();
-        showToast('已保存到相册,快去分享吧!', 'success', 3000)
+        showToast('已保存到相册,快去分享吧!')
       },
       fail(err) {
         wx.hideLoading();
@@ -111,29 +257,19 @@ Page({
   onCreatePoster() {
     Poster.create();
   },
-  getCode() {
-    wx.showLoading({
-      title: 'loading',
-      mask: true
-    });
-    var that = this
-    return new Promise(function(resolve, reject) {
-      let targetUrl = 'pages/pt-detail/index?hpPositionGroupId=' + that.data.hpPositionGroupId + '&shareToken=' + updataStorageData('shareToken')
-      shareQrCodeB(targetUrl).then(data => {
-        that.setData({
-          qrCode: data.data.imgUrl
-        })
-        resolve(true)
-      }).catch(data => {
-        console.log(data)
-        reject(data)
-      })
-    })
-  },
+
   qrcodeLoad(e) {
     wx.hideLoading()
   },
 
+  onShareAppMessage: function() {
+    return {
+      title: '开心工作参团有奖',
+      path: '/pages/pt-detail/index?gd=' + this.data.hpPositionGroupId + '&pc=' + this.data.positionCategory + '&pd=' + this.data.positionId,
+      imageUrl: ''
+    }
+  },
+
   onError(err) {
     app.aldstat.sendEvent('报错', {
       'err': err

+ 4 - 1
pages/pt-share/pt-share.wxml

@@ -67,4 +67,7 @@
     </view>
   </view>
 </view>
-<button class="create" bindtap='onCreatePoster' wx:if="{{hasAuth}}">保存图片</button>
+<button class="create" bindtap='onCreatePoster' wx:if="{{hasAuth}}">保存图片</button>
+<button class="create" open-type="openSetting" bindopensetting="onCreatePoster" wx:else>打开授权页</button>
+<poster id="poster" hide-loading="{{false}}" preload="{{false}}" config="{{posterConfig}}" bind:success="onPosterSuccess" bind:fail="onPosterFail">
+</poster>