123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- // pages/Components/sharePianoImg/sharePianoImg.js
- const app = getApp()
- const util = require('../../../utils/util.js')
- const base64Util = require('../../../utils/base64')
- Component({
- lifetimes: {
- ready: function () {
- var obj = this.data.piano
- var str = ''
- for (var i = 0; i < obj.code.length; i++) {
- str += obj.code.substring(i, i + 1);
- if ((i + 1) % 4 == 0) {
- str += " "
- }
- }
- const imgUrl = "https://app.schoolwisdoms.com/schoolbaby/api/code/generate?content=" + obj.code
- const posterConfig = this.data.posterConfig
- posterConfig.images[0].url = imgUrl
- posterConfig.images[1].url = this.data.piano.imgUrl
- posterConfig.texts[1].text = str
- posterConfig.texts[2].text = this.data.piano.schemeType
- posterConfig.texts[3].text = "购买日期:" + this.data.piano.createdDate
- posterConfig.texts[4].text = app.globalData.orgTitle
- this.setData({
- posterConfig
- })
- },
- },
- /**
- * 组件的属性列表
- */
- properties: {
- code: {
- type: String,
- value: ''
- },
- piano: {
- type: Object,
- value: null
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- code: '',
- schoolName: app.globalData.orgTitle,
- posterConfig: {
- 'width': 590,
- 'height': 840,
- 'backgroundColor': '#fff',
- 'debug': false,
- 'preload': true,
- 'hide-loading': true,
- images: [{
- x: 45,
- y: 160,
- url: 'https://app.schoolwisdoms.com/schoolbaby/api/code/generate?content=',
- width: 500,
- height: 500
- },
- {
- x: 20,
- y: 20,
- url: '',
- width: 180,
- height: 120
- },
- ],
- texts: [{
- x: 247,
- y: 700,
- baseLine: 'middle',
- text: '序列号',
- fontSize: 32,
- color: '#333',
- },
- {
- x: 100,
- y: 770,
- baseLine: 'middle',
- text: '',
- fontSize: 32,
- color: '#333',
- },
- {
- x: 220,
- y: 40,
- baseLine: 'middle',
- title: '',
- fontSize: 32,
- color: '#333',
- },
- {
- x: 220,
- y: 80,
- baseLine: 'middle',
- title: '',
- fontSize: 24,
- color: '#999',
- },
- {
- x: 220,
- y: 120,
- baseLine: 'middle',
- title: '',
- fontSize: 24,
- color: '#999',
- }
- ]
- },
- },
- /**
- * 组件的方法列表
- */
- methods: {
- //生成图片并保存
- onPosterSuccess(e) {
- let that = this;
- let {
- detail
- } = e;
- wx.saveImageToPhotosAlbum({
- filePath: detail,
- success(res) {
- wx.showToast({
- title: '图片已保存到本地相册',
- icon: 'none'
- })
- that.setData({
- showSaveImage: false
- })
- that.triggerEvent("callMethod")
- },
- fail(res) {
- that.getSetting()
- },
- complete(res){
- that.triggerEvent('closeWindow')
- }
- })
- },
- closeWindow:function(){
- this.triggerEvent('closeWindow')
- },
- getSetting: function () {
- // 相册授权
- wx.getSetting({
- success(res) {
- // 进行授权检测,未授权则进行弹层授权
- if (!res.authSetting["scope.writePhotosAlbum"]) {
- wx.showModal({
- title: '提示',
- content: '您未授权相册使用权限,是否重新授权?',
- success: function (res) {
- if (res.confirm) {
- wx.openSetting({
- success(settingdata) {
- if (settingdata.authSetting["scope.writePhotosAlbum"]) {
- console.log("获取权限成功,再次点击图片保存到相册")
- } else {
- console.log("获取权限失败")
- }
- },
- fail(res) {
- console.log(res)
- }
- })
- }
- }
- })
- }
- },
- fail(res) {
- console.log(res);
- }
- });
- },
- }
- })
|