index.js 4.7 KB

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