user.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. const app = getApp()
  2. let userInfo = app.globalData.userInfo;
  3. Page({
  4. data: {
  5. timeout: [
  6. { text: "不开启" },
  7. { text: "播放当前声音关闭" },
  8. { text: "播放2首声音关闭" },
  9. { text: "播放3首声音关闭" },
  10. { text: "播放4首声音关闭" },
  11. { text: "10分钟后" },
  12. { text: "20分钟后" },
  13. { text: "30分钟后" },
  14. ],
  15. activeIndex: 0,
  16. login: false,
  17. avatarUrl: "",
  18. nickName: ""
  19. },
  20. onLoad() {
  21. const that = this;
  22. //获得设备信息
  23. wx.getSystemInfo({
  24. success(res) {
  25. that.setData({
  26. phoneHeight: res.windowHeight,
  27. })
  28. }
  29. })
  30. },
  31. onShow() {
  32. const that = this
  33. if (!that.login) {
  34. wx.getStorage({
  35. key: 'userinfo',
  36. success(res) {
  37. if (res.data) {
  38. const userinfo = JSON.parse(res.data)
  39. that.setData({
  40. login: true,
  41. avatarUrl: userinfo.avatarUrl,
  42. nickName: userinfo.nickName
  43. })
  44. }
  45. }
  46. })
  47. }
  48. },
  49. // 获取用户的头像和昵称信息
  50. bindGetUserInfo(e) {
  51. const that = this;
  52. wx.getUserInfo({
  53. success: function (res) {
  54. wx.setStorage({
  55. key: "userinfo",
  56. data: JSON.stringify(res.userInfo)
  57. })
  58. that.setData({
  59. login: true,
  60. avatarUrl: res.userInfo.avatarUrl,
  61. nickName: res.userInfo.nickName
  62. })
  63. }
  64. })
  65. },
  66. phoneLogin() {
  67. wx.navigateTo({
  68. url: './phoneLogin/phoneLogin',
  69. });
  70. },
  71. gotoLogin() {
  72. wx.navigateTo({
  73. url: './phoneLogin/phoneLogin',
  74. });
  75. },
  76. openSwitch() {
  77. const that = this;
  78. that.setData({
  79. show: true
  80. })
  81. },
  82. close() {
  83. const that = this;
  84. that.setData({
  85. show: false
  86. })
  87. },
  88. chooseTimeOut(e) {
  89. const that = this;
  90. that.setData({
  91. activeIndex: e.currentTarget.dataset.activeindex
  92. })
  93. }
  94. })