index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. // pages/user/user.js
  2. import util from '../../utils/util'
  3. import api from '../../utils/api'
  4. const app = getApp()
  5. Page({
  6. // 页面的初始数据
  7. data: {
  8. auth: {},
  9. userInfo: {},
  10. howToWithdraw: false,
  11. qrCode: '',
  12. GamePlayList: [],
  13. CenterData: {},
  14. showText: false,
  15. system: {},
  16. sharePath: 'pages/share/share',
  17. shareInfo: {},
  18. ShowShareMask: false,
  19. ShowshareCirclesMask: false,
  20. mpType: app.globalData.mpType
  21. },
  22. onPageScroll: function (res) {
  23. if (this.data.howToWithdraw) {
  24. this.setData({
  25. howToWithdraw: false
  26. })
  27. }
  28. },
  29. // 生命周期函数--监听页面加载
  30. onLoad: function (options) {
  31. this.getShareInfo()
  32. this.getSystem()
  33. },
  34. onShow: function (e) {
  35. if (app.globalData.openGZH) {
  36. this.OpenWithdraw()
  37. app.globalData.openGZH = false
  38. } else {
  39. this.setData({
  40. howToWithdraw: false
  41. })
  42. }
  43. let timer = setInterval(() => {
  44. console.log(app.globalData.PageCallback)
  45. if (app.globalData.PageCallback) {
  46. this.getGamePlayList()
  47. api.getUserInfo().then(res => {
  48. this.setData({
  49. userInfo: res.data,
  50. auth: res.data.auth
  51. })
  52. })
  53. if (this.data.auth.memcenter === 1) {
  54. this.getCenterInfo()
  55. }
  56. clearInterval(timer)
  57. }
  58. }, 200)
  59. },
  60. getShareInfo: function () {
  61. api.getShareInfo({
  62. data: {
  63. path: this.data.sharePath
  64. }
  65. }).then(res => {
  66. this.setData({
  67. shareInfo: res.data
  68. })
  69. }).catch(err => {
  70. console.log('getShare', err)
  71. })
  72. },
  73. contact: function (e) {
  74. console.log('客服消息回调', e)
  75. },
  76. routeTo: function (e) {
  77. util.routeTo(e.currentTarget.dataset.url)
  78. },
  79. OpenWithdraw: function (e) {
  80. console.log(this.data.qrCode)
  81. if (!this.data.qrCode) {
  82. api.getWithdrawTips().then(res => {
  83. if (res.code === 200) {
  84. this.setData({
  85. howToWithdraw: true,
  86. qrCode: res.data.image
  87. })
  88. }
  89. })
  90. } else {
  91. this.setData({
  92. howToWithdraw: true
  93. })
  94. }
  95. },
  96. CloseWithdraw: function (e) {
  97. app.globalData.oepnGZH = false
  98. this.setData({
  99. howToWithdraw: false
  100. })
  101. },
  102. // 评论/客服
  103. getCenterInfo: function () {
  104. api.getCommentIndex().then(res => {
  105. if (res.code === 200) {
  106. this.setData({
  107. CenterData: res.data
  108. })
  109. }
  110. })
  111. },
  112. // 我玩过的游戏
  113. getGamePlayList: function () {
  114. api.getGamePlayList({
  115. page: 1,
  116. offset: 4,
  117. HideLoading: true
  118. }).then(res => {
  119. console.log(res, '----------------')
  120. if (!res.data.list.length) {
  121. api.getGameList({
  122. rank_type: 3,
  123. page: 1,
  124. offset: 4,
  125. HideLoading: true
  126. }).then(res => {
  127. this.setData({
  128. GamePlayList: res.data.list,
  129. showText: true
  130. })
  131. })
  132. } else {
  133. this.setData({
  134. GamePlayList: res.data.list,
  135. showText: false
  136. })
  137. }
  138. })
  139. },
  140. // 领取任务奖励
  141. getTaskReward: function (e) {
  142. new Promise((resolve, reject) => {
  143. switch (e.currentTarget.dataset.tasktype) {
  144. case 'sign':
  145. api.getSignIncome().then(res => {
  146. if (res.code === 200) {
  147. resolve({ title: '签到奖励', content: this.data.mpType === 'gd' ? `恭喜获得${res.data.gain_integral}金币!` : `恭喜获得${res.data.gain_amount}元!` })
  148. }
  149. })
  150. break;
  151. case 'share':
  152. api.getShareIncome().then(res => {
  153. if (res.code === 200) {
  154. resolve({ title: '邀请奖励', content: this.data.mpType === 'gd' ? `恭喜获得${res.data.gain_integral}金币!` : `恭喜获得${res.data.gain_amount}元!` })
  155. }
  156. })
  157. break;
  158. case 'play':
  159. api.getPlayIncome().then(res => {
  160. if (res.code === 200) {
  161. resolve({ title: '试玩奖励', content: this.data.mpType === 'gd' ? `恭喜获得${res.data.gain_integral}金币!` : `恭喜获得${res.data.gain_amount}元!` })
  162. }
  163. })
  164. break;
  165. }
  166. }).then(info => {
  167. const _self = this
  168. wx.showModal({
  169. title: info.title,
  170. content: info.content,
  171. showCancel: false,
  172. success: (e) => {
  173. api.getUserInfo().then(res => {
  174. _self.updateUserInfo(res.data)
  175. })
  176. }
  177. })
  178. })
  179. },
  180. // 更新用户信息
  181. updateUserInfo: function (data) {
  182. this.setData({
  183. userInfo: data,
  184. auth: data.auth
  185. })
  186. },
  187. openGame: function (e) {
  188. let id = e.currentTarget.dataset.id
  189. api.openGame({
  190. game_id: id
  191. }).then(res => {
  192. console.log(res)
  193. }, err => {
  194. console.log(err)
  195. })
  196. },
  197. hideWithdraw: function (e) {
  198. this.setData({
  199. howToWithdraw: false
  200. })
  201. },
  202. showPop: function (e) {
  203. wx.previewImage({
  204. urls: [e.currentTarget.dataset.entrance]
  205. })
  206. },
  207. // 跳转赚钱技巧页
  208. routeTips: function (e) {
  209. if (this.data.mpType === 'gd') {
  210. util.routeTo('/pages/lottery/lottery')
  211. } else {
  212. util.routeTo('/pages/user/purse')
  213. }
  214. },
  215. // 显示隐藏分享menu
  216. ChangeShare: function (e) {
  217. wx.hideTabBar({
  218. animation: true
  219. })
  220. if (!this.data.shareInfo.title) {
  221. api.getShareInfo({
  222. data: {
  223. path: this.data.sharePath
  224. }
  225. }).then(res => {
  226. console.log('getShare', res)
  227. this.setData({
  228. shareInfo: res.data,
  229. ShowShareMask: e.currentTarget.dataset.show ? true : false
  230. })
  231. }).catch(err => {
  232. console.log('getShare', err)
  233. })
  234. } else {
  235. this.setData({
  236. ShowShareMask: e.currentTarget.dataset.show ? true : false
  237. })
  238. }
  239. this.getShareInfo()
  240. },
  241. // 显示隐藏分享弹框
  242. showShare: function (e) {
  243. let { show } = e.currentTarget.dataset
  244. if (!show) {
  245. wx.showTabBar({
  246. animation: true
  247. })
  248. }
  249. this.setData({
  250. ShowShareMask: show ? true : false
  251. })
  252. },
  253. // 关闭分享朋友圈弹框
  254. CloseshareCircles: function () {
  255. wx.showTabBar({
  256. aniamtion: true
  257. })
  258. this.setData({
  259. ShowshareCirclesMask: false
  260. })
  261. },
  262. // 分享朋友圈
  263. shareCircles: function () {
  264. console.log(this.data.shareImgSrc)
  265. if (this.data.shareImgSrc) {
  266. this.setData({
  267. ShowShareMask: false,
  268. ShowshareCirclesMask: true
  269. })
  270. return false
  271. }
  272. wx.showLoading({
  273. title: '正在生成',
  274. mask: true
  275. })
  276. this.setData({
  277. ShowShareMask: false,
  278. ShowshareCirclesMask: true
  279. })
  280. const _self = this
  281. const rpx = this.data.system.windowWidth / 750
  282. const ctx = wx.createCanvasContext('shareCanvas')
  283. const canvasW = 466 * rpx
  284. const canvasH = 828 * rpx
  285. const avatarW = 70 * rpx
  286. const avatarH = 70 * rpx
  287. const avatarX = 200 * rpx
  288. const avatarY = 19 * rpx
  289. const avatarBW = 66 * rpx
  290. const avatarBH = 66 * rpx
  291. const avatarBX = 200 * rpx
  292. const avatarBY = 20 * rpx
  293. const QRcodeW = 454 * rpx
  294. const QRcodeH = 454 * rpx
  295. const QRcodeX = 6 * rpx
  296. const QRcodeY = 374 * rpx
  297. const QRcodeBW = 147 * rpx
  298. const QRcodeBH = 147 * rpx
  299. const QRcodeBX = 160 * rpx
  300. const QRcodeBY = 580 * rpx
  301. util.getImageInfo(this.data.shareInfo.pyq_bg).then(res => {
  302. ctx.drawImage(res.path, 0, 0, canvasW, canvasH)
  303. ctx.save()
  304. ctx.beginPath()
  305. ctx.arc(avatarBW / 2 + avatarBX, avatarBH / 2 + avatarBY, avatarBW / 2, 0, Math.PI * 2, false)
  306. ctx.clip()
  307. ctx.setFillStyle('white')
  308. ctx.fillRect(avatarBX, avatarBY, avatarBW, avatarBH)
  309. ctx.restore()
  310. ctx.draw(true)
  311. ctx.save()
  312. ctx.beginPath()
  313. ctx.arc(QRcodeBW / 2 + QRcodeBX, QRcodeBH / 2 + QRcodeBY, QRcodeBW / 2, 0, Math.PI * 2, false)
  314. ctx.clip()
  315. ctx.setFillStyle('white')
  316. ctx.fillRect(QRcodeBX, QRcodeBY, QRcodeBW, QRcodeBH)
  317. ctx.restore()
  318. ctx.draw(true)
  319. }).then(res => {
  320. return util.getImageInfo(this.data.shareInfo.mp_qr).then(res => {
  321. ctx.save()
  322. ctx.beginPath()
  323. ctx.arc(QRcodeW / 2 + QRcodeX, QRcodeH / 2 + QRcodeY, QRcodeW / 2, 0, Math.PI * 2, false)
  324. ctx.clip()
  325. ctx.drawImage(res.path, canvasW / 2 - QRcodeW / 2, QRcodeY, QRcodeW, QRcodeH)
  326. ctx.restore()
  327. ctx.draw(true)
  328. })
  329. }).then(res => {
  330. return util.getImageInfo(this.data.userInfo.avatar).then(res => {
  331. ctx.beginPath()
  332. ctx.arc(avatarW / 2 + avatarX, avatarH / 2 + avatarY, avatarW / 2, 0, Math.PI * 2, false)
  333. ctx.clip()
  334. ctx.drawImage(res.path, canvasW / 2 - avatarW / 2, avatarY, avatarW, avatarH)
  335. ctx.restore()
  336. ctx.draw(true)
  337. })
  338. }).then(res => {
  339. setTimeout(() => {
  340. wx.canvasToTempFilePath({
  341. x: 0,
  342. y: 0,
  343. width: canvasW,
  344. height: canvasH,
  345. destWidth: canvasW * 4,
  346. destHeight: canvasH * 4,
  347. canvasId: 'shareCanvas',
  348. success: function (res) {
  349. wx.hideLoading()
  350. _self.setData({
  351. shareImgSrc: res.tempFilePath
  352. })
  353. },
  354. fail: function (res) {
  355. console.log(res)
  356. }
  357. })
  358. }, 500)
  359. }).catch(err => {
  360. wx.hideLoading()
  361. console.log(err)
  362. })
  363. },
  364. // 保存分享朋友圈图片
  365. saveMemQRcode: function (e) {
  366. const _self = this
  367. wx.showLoading({
  368. title: '正在保存...'
  369. })
  370. wx.saveImageToPhotosAlbum({
  371. filePath: _self.data.shareImgSrc,
  372. success: function (res) {
  373. console.log('保存图片', res)
  374. wx.showToast({
  375. title: '保存成功',
  376. icon: 'success',
  377. duration: 1000
  378. })
  379. },
  380. fail: function (err) {
  381. console.log('保存图片', err)
  382. if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied") {
  383. console.log("用户一开始拒绝了,我们想再次发起授权")
  384. console.log('打开设置窗口')
  385. wx.openSetting({
  386. success(settingdata) {
  387. console.log(settingdata)
  388. if (settingdata.authSetting['scope.writePhotosAlbum']) {
  389. console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
  390. } else {
  391. console.log('获取权限失败,给出不给权限就无法正常使用的提示')
  392. }
  393. }
  394. })
  395. }
  396. },
  397. complete: function () {
  398. wx.hideLoading()
  399. _self.setData({
  400. ShowshareCirclesMask: false
  401. })
  402. wx.showTabBar({
  403. aniamtion: true
  404. })
  405. }
  406. })
  407. },
  408. // 获取设备信息
  409. getSystem: function (e) {
  410. const _self = this
  411. wx.getSystemInfo({
  412. success: function (res) {
  413. _self.setData({
  414. system: res
  415. })
  416. }
  417. })
  418. }
  419. })