index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. setTimeout(() => {
  74. wx.reLaunch({
  75. url: '/pages/login/phone',
  76. })
  77. }, 300)
  78. })
  79. },
  80. /* 去修改用户信息 */
  81. changeUserMsg() {
  82. let {
  83. name,
  84. phonenumber,
  85. attinfos
  86. } = this.data.userMsg;
  87. wx.navigateTo({
  88. url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}`
  89. })
  90. },
  91. /* 绑定或解绑微信 */
  92. bindingWechat(e) {
  93. if (this.data.userMsg.iswechatbinding) {
  94. let that = this;
  95. wx.showModal({
  96. title: "提示",
  97. content: "是否解除绑定",
  98. success: (res) => {
  99. console.log(res)
  100. if (res.confirm) that.handleBDWechat(0);
  101. }
  102. })
  103. } else {
  104. this.handleBDWechat(1);
  105. }
  106. },
  107. handleBDWechat(isbinging) {
  108. let that = this;
  109. wx.getUserProfile({
  110. desc: '用于完善用户资料',
  111. success: ({
  112. userInfo
  113. }) => {
  114. wx.login({
  115. success(res) {
  116. if (res.code) _Http.basic({
  117. "classname": "common.usercenter.usercenter",
  118. "method": "WechatBinding",
  119. content: {
  120. "wechat_code": res.code,
  121. isbinging, // 0解绑 1绑定
  122. wechatuserinfo: userInfo
  123. }
  124. }).then(s => {
  125. if (s.msg != '成功') return wx.showToast({
  126. title: s.data,
  127. icon: "none"
  128. });
  129. setTimeout(() => {
  130. wx.showToast({
  131. title: isbinging == 0 ? '解除成功' : '绑定成功',
  132. icon: "none"
  133. })
  134. }, 100);
  135. that.queryUserMsg();
  136. })
  137. }
  138. })
  139. },
  140. fail: () => {
  141. wx.showToast({
  142. title: '操作失败,未获得授权',
  143. icon: "none"
  144. })
  145. }
  146. })
  147. },
  148. })