doings.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // pages/doings/doings.js
  2. import {
  3. imgUrl,
  4. request,
  5. request2,
  6. baseUrl
  7. } from "../api/request"
  8. import {
  9. cacheGet
  10. } from "../../utils/cacheUtil"
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. imgUrl:imgUrl,
  17. codeImg: '',
  18. hidden: true
  19. },
  20. confirm(){
  21. this.setData({
  22. hidden: true
  23. })
  24. this.setData({
  25. codeImg: ''
  26. })
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad(options) {
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady() {
  37. },
  38. /**
  39. * 生命周期函数--监听页面显示
  40. */
  41. onShow() {
  42. },
  43. dy(){
  44. wx.getSetting({
  45. withSubscriptions: true,
  46. success (res) {
  47. console.log(res.subscriptionsSetting)
  48. if(res.subscriptionsSetting.itemSettings['0Rh0woW2g6Mu6SDwDSs4x2pm6b5Re0xo_7Ugc_3pJps'] == 'accept'){
  49. }
  50. }
  51. })
  52. let that = this
  53. wx.requestSubscribeMessage({
  54. tmplIds: ['0Rh0woW2g6Mu6SDwDSs4x2pm6b5Re0xo_7Ugc_3pJps'],
  55. success (res) {
  56. if(res['0Rh0woW2g6Mu6SDwDSs4x2pm6b5Re0xo_7Ugc_3pJps']=='accept'){
  57. wx.request({
  58. url: baseUrl + '/mini/qrCode/getQrCode?qrcodeSign=nazzd',
  59. method: 'GET',
  60. responseType: 'arraybuffer',
  61. header: {
  62. 'mini-token':cacheGet('token')
  63. },
  64. success: function(res){
  65. try{
  66. let str = String.fromCharCode.apply(null, new Uint8Array(res.data));
  67. str = decodeURIComponent(escape((str)));
  68. let result = JSON.parse(str)
  69. if (result.msg == '请重新登录' && !result.result) {
  70. wx.showModal({
  71. title: '掌新南岸欢迎您!',
  72. content: '使用完整服务需要登录!',
  73. confirmText: '登录',
  74. cancelText:"取消",
  75. success: function (res) {
  76. if (res.confirm) {
  77. wx.navigateTo({
  78. url: '/pages/login/login',
  79. });
  80. }if (res.cancel){
  81. wx.navigateTo({
  82. url: '/pages/index/index',
  83. })
  84. }
  85. },
  86. });
  87. return
  88. }
  89. }catch(e){
  90. console.log(e);
  91. }
  92. console.log(res);
  93. if(res.statusCode == 200){
  94. let url ="data:image/png;base64," + wx.arrayBufferToBase64(res.data)
  95. that.setData({
  96. codeImg : url, //设置data里面的图片url
  97. })
  98. that.setData({
  99. hidden: false
  100. })
  101. }else if(res.statusCode == 400){//二维码已经核销
  102. wx.showToast({
  103. title: '二维码已使用!',
  104. })
  105. }else if(res.statusCode == 401){//获取用户id失败
  106. wx.showToast({
  107. title: '异常问题!请退出移除小程序重新扫码二维码!',
  108. icon: 'error',
  109. duration: 800
  110. })
  111. }
  112. }
  113. })
  114. }
  115. }
  116. })
  117. },
  118. /**
  119. * 生命周期函数--监听页面隐藏
  120. */
  121. onHide() {
  122. },
  123. /**
  124. * 生命周期函数--监听页面卸载
  125. */
  126. onUnload() {
  127. },
  128. /**
  129. * 页面相关事件处理函数--监听用户下拉动作
  130. */
  131. onPullDownRefresh() {
  132. },
  133. /**
  134. * 页面上拉触底事件的处理函数
  135. */
  136. onReachBottom() {
  137. },
  138. /**
  139. * 用户点击右上角分享
  140. */
  141. onShareAppMessage() {
  142. }
  143. })