index.js 4.8 KB

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