index.js 5.0 KB

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