index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // pages/setting/index.js
  2. /**
  3. * 设置
  4. */
  5. import * as API_Shop from '../../api/shop.js'
  6. import * as Common from '../../utils/common.js'
  7. import * as API_Passport from '../../api/passport.js'
  8. const app=getApp()
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. bool_bind:false
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. const that = this
  21. that.getTabBar().init()
  22. },
  23. /**
  24. * 生命周期函数--监听页面初次渲染完成
  25. */
  26. onReady: function () {
  27. },
  28. /**
  29. * 生命周期函数--监听页面显示
  30. */
  31. onShow: function () {
  32. const that = this
  33. that.getTabBar().init()
  34. that.setData({
  35. bool_bind:app.globalData.authorInfo.bool_bind
  36. })
  37. },
  38. /**
  39. * 生命周期函数--监听页面隐藏
  40. */
  41. onHide: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面卸载
  45. */
  46. onUnload: function () {
  47. },
  48. /**
  49. * 页面相关事件处理函数--监听用户下拉动作
  50. */
  51. onPullDownRefresh: function () {
  52. },
  53. /**
  54. * 页面上拉触底事件的处理函数
  55. */
  56. onReachBottom: function () {
  57. },
  58. /**
  59. * 用户点击右上角分享
  60. */
  61. onShareAppMessage: function () {
  62. },
  63. logout(e){
  64. API_Passport.logout({'uid':app.globalData.authorInfo.uid}).then(res=>{
  65. wx.removeStorageSync('authorInfo')
  66. wx.removeStorageSync('sellerUser')
  67. wx.removeStorageSync('sellerShop')
  68. wx.removeStorageSync('login_result')
  69. app.globalData.authorInfo = {}
  70. app.globalData.sellerUser = {}
  71. app.globalData.sellerShop = {}
  72. //退出登录 会清除redis授权缓存,自动登录一下,把redis授权重新写入,以防用户又直接登录
  73. // Common.toAutoLogin()
  74. wx.redirectTo({
  75. url: '/pages/login/login',
  76. })
  77. })
  78. },
  79. onStateChange: function(e) {
  80. const that=this
  81. wx.login({
  82. success(res){
  83. const param={
  84. mini_program_type:app.globalData.miniProgramType,
  85. uuid:app.globalData.uuid,
  86. uid:app.globalData.authorInfo.uid,
  87. code:res.code
  88. }
  89. if(e.detail.value){//绑定
  90. API_Passport.bindUser(param).then(res=>{
  91. app.globalData.authorInfo.bool_bind=1
  92. wx.setStorageSync('authorInfo',app.globalData.authorInfo)
  93. that.setData({
  94. bool_bind: e.detail.value
  95. })
  96. }).catch(err=>{
  97. console.log(err)
  98. })
  99. }else{ //解绑
  100. API_Passport.unbindUser(param).then(res=>{
  101. app.globalData.authorInfo.bool_bind=0
  102. wx.setStorageSync('authorInfo',app.globalData.authorInfo)
  103. that.setData({
  104. bool_bind: e.detail.value
  105. })
  106. }).catch(err=>{
  107. console.log(err)
  108. })
  109. }
  110. }
  111. })
  112. },
  113. subscribeMessage(e){
  114. console.log(e)
  115. wx.requestSubscribeMessage({
  116. tmplIds: ['Y2LCDRXld1ccrdmPavW4gBi1RhI8rjVyeOUencmPMpw'],
  117. success (res) {
  118. console.log(res)
  119. },
  120. complete(res){
  121. console.log(res)
  122. }
  123. })
  124. }
  125. })