index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const api = require('../../utils/api.js');
  2. // const app = getApp(),
  3. // {
  4. // globalData: {
  5. // util: {
  6. // regeneratorRuntime,
  7. // goLogin,
  8. // navigate_auth_native,
  9. // getUserInfo
  10. // }
  11. // }
  12. // } = app;
  13. Page({
  14. onLoad() {
  15. this.setData({
  16. list: [
  17. {
  18. title: '个人信息',
  19. icon: 'user-icon',
  20. studenturl: '/pages/student/user/user',
  21. teacherurl:'/pages/student/user/user'
  22. },
  23. {
  24. title: '我的投诉建议',
  25. icon: 'tousu',
  26. studenturl: '/pages/student/proposalList/proposalList',
  27. teacherurl:''
  28. },
  29. {
  30. title: '我的设置',
  31. icon: 'shezhi',
  32. studenturl: 'setting/index',
  33. teacherurl:'setting/index'
  34. }
  35. ]
  36. })
  37. },
  38. onShow() {
  39. let userInfo = wx.getStorageSync('user')
  40. for(let index in this.data.list){
  41. if (userInfo.roleType == 10001){
  42. if (!this.data.list[index].teacherurl) {
  43. this.data.list.splice(index,1)
  44. }
  45. }else{
  46. if (!this.data.list[index].studenturl) {
  47. this.data.list.splice(index, 1)
  48. }
  49. }
  50. }
  51. this.setData({
  52. photo: userInfo.headImage ? api.total.split('.if')[0]+userInfo.headImage :'/images/default-urser.png',
  53. viewName: userInfo.userName,
  54. roleType:wx.getStorageSync('user').roleType,
  55. list: this.data.list
  56. })
  57. // if (!userInfo){
  58. // let { viewName = '', photo = '' } = await getUserInfo()
  59. // this.setData({
  60. // photo,
  61. // viewName
  62. // })
  63. // }else{
  64. // this.setData({
  65. // photo: userInfo.avatarUrl,
  66. // viewName: userInfo.nickName
  67. // })
  68. // }
  69. },
  70. navigate_auth:function(e){
  71. if (e.currentTarget.dataset.url){
  72. wx.navigateTo({
  73. url: e.currentTarget.dataset.url,
  74. })
  75. }else{
  76. wx.showToast({
  77. title: '功能开发中',
  78. icon:'none'
  79. })
  80. }
  81. },
  82. updateimage:function(){
  83. let that=this
  84. wx.chooseImage({
  85. count:1,
  86. success: function(res) {
  87. wx.showLoading({
  88. title: '正在上传',
  89. })
  90. wx.uploadFile({
  91. url: api.updateimage,
  92. filePath: res.tempFilePaths[0],
  93. header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', },
  94. name: 'file',
  95. formData: {
  96. 'fileType': 'image',
  97. 'loginId': wx.getStorageSync('loginId')
  98. },
  99. success(res) {
  100. wx.hideLoading()
  101. if (JSON.parse(res.data).status == true) {
  102. let user = wx.getStorageSync('user')
  103. user.headImage = JSON.parse(res.data).headImage
  104. wx.setStorageSync('user', user)
  105. that.setData({
  106. photo: api.total.split('.if')[0]+user.headImage
  107. })
  108. wx.showToast({
  109. title: '修改成功',
  110. icon:'none'
  111. })
  112. }
  113. }
  114. })
  115. },
  116. })
  117. },
  118. // goLogin,
  119. // navigate_auth_native
  120. })