index.js 3.3 KB

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