index.js 4.8 KB

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