大数据平台的小程序版本

index.js 3.9KB

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