sharePopup.js
4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// components/sharePopup/sharePopup.js
import { imgUrlMixin } from '~/mixins/index'
import index_const from '~/pages/tab/storeAssistant/pages/index/index_const'
import Draw from '~/utils/Draw'
import { getSystemInfoSync, getSystemInfo } from '~/utils/systemInfo'
Component({
/**
* 组件的属性列表
*/
behaviors: [imgUrlMixin],
properties: {
data: {
type: Object,
observer(val) {
let _this = this
// let thisPage = wx.$router.getPageInstance()
// _this.setData({
// navHeight: thisPage.data.navHeight
// })
if (val.showSharePopup) {
wx.$api.showLoading('处理中')
val.boxImageHeight = 66
// 计算弹窗图片区域最大高度
let windowHeight = getSystemInfoSync().windowHeight
let res = {
height: windowHeight - 150
}
// wx.$util.getViewInfo('#layout', res => {
console.log(res)
_this.setData({
postersBoxHeight: res.height * 0.7
})
wx.getImageInfo({
src: `${val.posterImg}?v=${Date.now()}`,
success(e) {
_this.setData({
postersImageHeight: (e.height / e.width) * 247
})
val.postersImageHeight = (e.height / e.width) * 247
_this.init(val)
},
fail() {
wx.$api.showToast('生成失败')
}
})
// })
}
}
}
},
/**
* 组件的初始数据
*/
data: {
USERINFO: wx.$storage.get('userInfo'),
activityTypList: index_const.data.activityTypList
},
/**
* 组件的方法列表
*/
methods: {
navbarReady(e) {
let { height } = e.detail
this.setData({
navHeight: height
})
},
async init(n) {
n.activityName = n.activityName.length > 12 ? `${n.activityName.substring(0, 12)}...` : n.activityName
const drawfun = new Draw(
{
width: 279,
height: n.postersImageHeight + 76,
borderRadius: 8
},
this
),
{ userInfo } = wx.$storage.get(),
res = await drawfun.begin({
imageList: [
{
x: 0,
y: 0,
width: 279,
height: n.boxImageHeight,
url: `${this.data.IMGURL}store-assistant/taskDetail_bg.png`
},
{
x: 12,
y: 12,
width: 20,
height: 20,
borderRadius: 40,
url: userInfo.sta_avatarUrl ? userInfo.sta_avatarUrl : userInfo.weChatAvatarUrl ? userInfo.weChatAvatarUrl : `${this.data.IMGURL}store-assistant/default_avatar.png`
},
{
x: 16,
y: n.boxImageHeight + 10,
width: 247,
height: n.postersImageHeight,
url: n.posterImg
}
],
textList: [
{
x: 44,
y: 14,
fontSize: 14,
color: '#2D2D33',
text: userInfo.name,
textBaseline: 'top'
},
{
x: 50 + drawfun.getTextWidth(userInfo.name, 14),
y: 15,
fontSize: 12,
color: '#6E6E7A',
text: '邀请你参加',
textBaseline: 'top'
},
{
x: 44,
y: 36,
fontSize: 14,
color: '#1B233D',
text: n.activityName,
textBaseline: 'top',
fontWeight: 500
},
{
x: 48 + drawfun.getTextWidth(n.activityName, 14) + 9,
y: 39,
fontSize: 10,
color: '#4466F0',
text: '众筹',
textBaseline: 'top',
border: {
width: 1,
color: '#8FA5FF',
radius: 2,
padding: [4, 5]
}
}
]
})
wx.hideLoading()
this.setData({
poster: res.path
})
},
close() {
let thisPage = wx.$router.getPageInstance()
this.setData({
poster: ''
})
thisPage.setData({
sharePopupData: {
showSharePopup: false
}
})
},
saveImage(e) {
const filePath = this.data.poster,
_this = this
wx.saveImageToPhotosAlbum({
filePath,
success() {
wx.$api.showToast('保存成功')
},
fail(err) {
if (err.errMsg == 'saveImageToPhotosAlbum:fail auth deny') {
_this.triggerEvent('showAuth', true)
}
// const auth = _this.selectComponent('#auth')
// auth.check()
}
})
},
emptyFunction() {},
authFail(e) {
this.setData({
showAuth: true
})
}
}
})