index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. const _Http = getApp().globalData.http;
  2. let downCount = null;
  3. Component({
  4. properties: {
  5. },
  6. options: {
  7. addGlobalClass: true,
  8. },
  9. data: {},
  10. methods: {
  11. init() {
  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. return true;
  40. },
  41. /* 查询用户信息 */
  42. queryUserMsg() {
  43. _Http.basic({
  44. "classname": "common.usercenter.usercenter",
  45. "method": "queryUserMsg",
  46. "content": {
  47. "nocache": true
  48. }
  49. }).then(res => {
  50. console.log("查询用户信息", res)
  51. if (res.msg != '成功') {
  52. wx.showToast({
  53. title: res.msg,
  54. icon: "none"
  55. })
  56. } else {
  57. this.setData({
  58. userMsg: res.data
  59. })
  60. }
  61. })
  62. },
  63. /* 退出登录 */
  64. outLogin() {
  65. clearTimeout(downCount);
  66. wx.showLoading({
  67. title: '正在退出...',
  68. })
  69. downCount = setTimeout(() => {
  70. _Http.logout().then(res => {
  71. wx.showToast({
  72. title: '退出成功'
  73. });
  74. let loginMsg = wx.getStorageSync("loginMsg");
  75. wx.clearStorageSync();
  76. wx.setStorageSync('loginMsg', loginMsg)
  77. setTimeout(() => {
  78. wx.reLaunch({
  79. url: '/pages/login/phone',
  80. })
  81. }, 300)
  82. })
  83. }, 300);
  84. },
  85. /* 去修改用户信息 */
  86. changeUserMsg() {
  87. let {
  88. name,
  89. phonenumber,
  90. attinfos,
  91. hr
  92. } = this.data.userMsg;
  93. wx.navigateTo({
  94. url: `./userMsg/index?attinfos=${JSON.stringify(attinfos)}&name=${name}&phonenumber=${phonenumber}&email=${hr.email}`
  95. })
  96. },
  97. /* 绑定或解绑微信 */
  98. bindingWechat(e) {
  99. if (this.data.userMsg.iswechatbinding) {
  100. let that = this;
  101. wx.showModal({
  102. title: "提示",
  103. content: "是否解除绑定",
  104. success: (res) => {
  105. if (res.confirm) that.handleBDWechat(0);
  106. }
  107. })
  108. } else {
  109. this.handleBDWechat(1);
  110. }
  111. },
  112. handleBDWechat(isbinging) {
  113. let that = this;
  114. wx.getUserProfile({
  115. desc: '用于完善用户资料',
  116. success: ({
  117. userInfo
  118. }) => {
  119. wx.login({
  120. success(res) {
  121. if (res.code) _Http.basic({
  122. "classname": "common.usercenter.usercenter",
  123. "method": "WechatBinding",
  124. content: {
  125. "wechat_code": res.code,
  126. isbinging, // 0解绑 1绑定
  127. wechatuserinfo: userInfo
  128. }
  129. }).then(s => {
  130. if (s.msg != '成功') return wx.showToast({
  131. title: s.data,
  132. icon: "none"
  133. });
  134. setTimeout(() => {
  135. wx.showToast({
  136. title: isbinging == 0 ? '解除成功' : '绑定成功',
  137. icon: "none"
  138. })
  139. }, 100);
  140. that.queryUserMsg();
  141. })
  142. }
  143. })
  144. },
  145. fail: () => {
  146. wx.showToast({
  147. title: '操作失败,未获得授权',
  148. icon: "none"
  149. })
  150. }
  151. })
  152. },
  153. }
  154. })