index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. userMsg: {},
  8. pathList: [], //功能权限
  9. teamAuth: '', //团队管理权限列表 JSON字符串 用于传递
  10. },
  11. onLoad(options) {
  12. this.queryUserMsg();
  13. let auth = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['个人中心'])[0].apps;
  14. let pathList = [];
  15. console.log(auth)
  16. auth.forEach(v => {
  17. switch (v.name) {
  18. case "teamManagement":
  19. pathList.push({
  20. name: "团队管理",
  21. icon: "icon-a-wodetuanduiguanli",
  22. color: "var(--assist)",
  23. path: `/${v.path}`
  24. })
  25. this.setData({
  26. teamAuth: JSON.stringify(v.meta.auth)
  27. })
  28. break;
  29. }
  30. });
  31. pathList.push({
  32. name: "修改登录密码",
  33. icon: "icon-a-wodeguanyuyingyong",
  34. color: "var(--warning)",
  35. path: `/pages/tabbar/mine/changePassword/index`
  36. })
  37. this.setData({
  38. pathList
  39. })
  40. },
  41. /* 查询用户信息 */
  42. queryUserMsg() {
  43. _Http.basic({
  44. "classname": "common.usercenter.usercenter",
  45. "method": "queryUserMsg",
  46. "content": {}
  47. }).then(res => {
  48. console.log("个人信息", 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. _Http.logout().then(res => {
  64. wx.showToast({
  65. title: '退出成功'
  66. });
  67. let loginMsg = wx.getStorageSync("loginMsg");
  68. wx.clearStorage();
  69. wx.setStorageSync('loginMsg', loginMsg)
  70. setTimeout(() => {
  71. wx.reLaunch({
  72. url: '/pages/login/phone',
  73. })
  74. }, 300)
  75. })
  76. },
  77. /* 去修改用户信息 */
  78. changeUserMsg() {
  79. let {
  80. name,
  81. phonenumber,
  82. attinfos,
  83. hr
  84. } = this.data.userMsg;
  85. wx.navigateTo({
  86. url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}&email=${hr.email}`
  87. })
  88. },
  89. /* 绑定或解绑微信 */
  90. bindingWechat(e) {
  91. if (this.data.userMsg.iswechatbinding) {
  92. let that = this;
  93. wx.showModal({
  94. title: "提示",
  95. content: "是否解除绑定",
  96. success: (res) => {
  97. console.log(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. })