问星数据小程序

index.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. const app = getApp();
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. user_id:{
  8. type: String|Number,
  9. value: false,
  10. },
  11. height:{
  12. type:String,
  13. value:'900rpx'
  14. }
  15. },
  16. /**
  17. * 组件的初始数据
  18. */
  19. data: {
  20. imgCode:'',
  21. minute:300,
  22. timer:1,
  23. timeMsg:'',
  24. isIOS:app.data.isIOS,
  25. writePhotosFlag:-1,
  26. token:''
  27. },
  28. pageLifetimes: {
  29. show: function(options) {
  30. this.getSet()
  31. },
  32. hide: function() {
  33. // 页面被隐藏
  34. clearInterval(this.data.timer)
  35. },
  36. },
  37. lifetimes: {
  38. attached: function() {
  39. // 在组件实例进入页面节点树时执行
  40. this.getToken()
  41. this.getSet()
  42. }
  43. },
  44. /**
  45. * 组件的方法列表
  46. */
  47. methods: {
  48. getSet(){
  49. var _this = this;
  50. wx.getSetting({
  51. success(res) {
  52. if(res.authSetting['scope.writePhotosAlbum'] == false){
  53. _this.setData({writePhotosFlag:false})
  54. }
  55. if(res.authSetting['scope.writePhotosAlbum'] == true){
  56. _this.setData({writePhotosFlag:true})
  57. }
  58. }
  59. })
  60. },
  61. CountDown() {//倒计时
  62. var maxtime = this.data.minute
  63. var minutes = '', seconds = ''
  64. this.setData({timeMsg:''})
  65. var timer = setInterval(()=>{
  66. if (maxtime >= 0) {
  67. minutes = Math.floor(maxtime / 60)<10?('0'+Math.floor(maxtime / 60)):Math.floor(maxtime / 60);
  68. seconds = Math.floor(maxtime % 60)<10?('0'+Math.floor(maxtime % 60)):Math.floor(maxtime % 60);
  69. this.setData({timeMsg: minutes + ":" + seconds + "后失效"});
  70. --maxtime;
  71. } else{
  72. this.setData({timeMsg:'已失效,请重新刷新'})
  73. clearInterval(this.data.timer);
  74. }
  75. },1000)
  76. this.setData({timer:timer})
  77. },
  78. getToken(){
  79. wx.showLoading({
  80. title: '加载中',
  81. })
  82. app.func.req('/api/sphClaim/getToken', 'get', {}, (res) => {
  83. wx.hideLoading()
  84. if(res && res.errno == 0){
  85. this.setData({
  86. token:res.rst.token
  87. })
  88. wx.setStorageSync('claim_token', res.rst.token)
  89. this.getEvm()
  90. }else{
  91. wx.showToast({
  92. title: res.err,
  93. icon: 'none',
  94. duration: 2000
  95. })
  96. }
  97. },()=>{
  98. wx.hideLoading()
  99. })
  100. },
  101. getEvm(){
  102. this.setData({
  103. imgCode:app.data.rootDocment+'/api/sphClaim/getQRcode?token='+this.data.token,
  104. })
  105. this.CountDown()
  106. },
  107. downLoadImgEvent(){
  108. if(!this.data.writePhotosFlag){
  109. wx.openSetting()
  110. return
  111. }
  112. var _this = this;
  113. wx.getSetting({
  114. success(res) {
  115. if (!res.authSetting['scope.writePhotosAlbum']) {
  116. _this.setData({writePhotosFlag:false})
  117. wx.authorize({
  118. scope:'scope.writePhotosAlbum',
  119. success() {//授权成功
  120. _this.setData({writePhotosFlag:true})
  121. _this.downloadImg()
  122. },
  123. fail:function(err){
  124. _this.setData({writePhotosFlag:false})
  125. }
  126. })
  127. }else{//已经授权
  128. _this.setData({writePhotosFlag:true})
  129. _this.downloadImg()
  130. }
  131. }
  132. })
  133. },
  134. downloadImg(){
  135. var imgSrc = this.data.imgCode
  136. wx.downloadFile({
  137. url: imgSrc,
  138. success: function (res) {
  139. wx.saveImageToPhotosAlbum({
  140. filePath: res.tempFilePath,
  141. success: function (data) {
  142. wx.showToast({
  143. title: '保存成功',
  144. icon: 'success',
  145. duration: 2000
  146. })
  147. },
  148. fail: function (err) {
  149. },
  150. complete(res){
  151. }
  152. })
  153. }
  154. })
  155. },
  156. claimResetList(){
  157. this.triggerEvent('claimResetList')
  158. },
  159. cancelTask(){
  160. this.triggerEvent('closeClaimMask')
  161. },
  162. }
  163. })