index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. const _Http = getApp().globalData.http;
  2. let downCount = null;
  3. Component({
  4. properties: {
  5. },
  6. options: {
  7. addGlobalClass: true,
  8. },
  9. data: {},
  10. methods: {
  11. init() {
  12. this.queryUserMsg();
  13. let authlist = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['个人中心']);
  14. let pathList = [{
  15. name: "修改登录密码",
  16. icon: "icon-a-wodeguanyuyingyong",
  17. color: "var(--warning)",
  18. path: `/pages/index/userCenter/changePassword/index`
  19. }]
  20. if (authlist[0].apps.some(v => v.name == "teamManagement")) pathList.unshift({
  21. name: "团队管理",
  22. icon: "icon-a-wodetuanduiguanli",
  23. color: "var(--assist)",
  24. path: `/pages/teams/index`
  25. });
  26. this.setData({
  27. pathList
  28. })
  29. return true;
  30. },
  31. /* 查询用户信息 */
  32. queryUserMsg() {
  33. _Http.basic({
  34. "classname": "common.usercenter.usercenter",
  35. "method": "queryUserMsg",
  36. "content": {
  37. "nocache": true
  38. }
  39. }).then(res => {
  40. console.log("查询用户信息", res)
  41. if (res.msg != '成功') {
  42. wx.showToast({
  43. title: res.msg,
  44. icon: "none"
  45. })
  46. } else {
  47. this.setData({
  48. userMsg: res.data
  49. })
  50. }
  51. })
  52. },
  53. /* 退出登录 */
  54. outLogin() {
  55. clearTimeout(downCount);
  56. wx.showLoading({
  57. title: '正在退出...',
  58. })
  59. downCount = setTimeout(() => {
  60. _Http.logout().then(res => {
  61. getApp().globalData.SocketTask.close()
  62. wx.showToast({
  63. title: '退出成功',
  64. mask: true
  65. });
  66. let loginMsg = wx.getStorageSync("loginMsg");
  67. wx.clearStorageSync();
  68. wx.setStorageSync('loginMsg', loginMsg)
  69. wx.setStorageSync('isAgree', true)
  70. setTimeout(() => {
  71. wx.reLaunch({
  72. url: '/pages/login/phone',
  73. })
  74. }, 300)
  75. })
  76. }, 300);
  77. },
  78. /* 去修改用户信息 */
  79. changeUserMsg() {
  80. let {
  81. name,
  82. phonenumber,
  83. attinfos,
  84. hr
  85. } = this.data.userMsg;
  86. wx.navigateTo({
  87. url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}&email=${hr.email}`
  88. })
  89. },
  90. /* 绑定或解绑微信 */
  91. bindingWechat(e) {
  92. if (this.data.userMsg.iswechatbinding) {
  93. let that = this;
  94. wx.showModal({
  95. title: "提示",
  96. content: "是否解除绑定",
  97. success: (res) => {
  98. if (res.confirm) that.handleBDWechat(0);
  99. }
  100. })
  101. } else {
  102. this.handleBDWechat(1);
  103. }
  104. },
  105. handleBDWechat(isbinging) {
  106. let that = this;
  107. wx.getUserProfile({
  108. desc: '用于完善用户资料',
  109. success: ({
  110. userInfo
  111. }) => {
  112. wx.login({
  113. success(res) {
  114. if (res.code) _Http.basic({
  115. "classname": "common.usercenter.usercenter",
  116. "method": "WechatBinding",
  117. content: {
  118. "wechat_code": res.code,
  119. isbinging, // 0解绑 1绑定
  120. wechatuserinfo: userInfo
  121. }
  122. }).then(s => {
  123. if (s.msg != '成功') return wx.showToast({
  124. title: s.data,
  125. icon: "none"
  126. });
  127. setTimeout(() => {
  128. wx.showToast({
  129. title: isbinging == 0 ? '解除成功' : '绑定成功',
  130. icon: "none"
  131. })
  132. }, 100);
  133. that.queryUserMsg();
  134. })
  135. }
  136. })
  137. },
  138. fail: () => {
  139. wx.showToast({
  140. title: '操作失败,未获得授权',
  141. icon: "none"
  142. })
  143. }
  144. })
  145. },
  146. }
  147. })