index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. url: '../student/user/user',
  21. },
  22. {
  23. title: '我的设置',
  24. icon: 'shezhi',
  25. url: 'setting/index',
  26. }
  27. ]
  28. })
  29. },
  30. onShow() {
  31. let userInfo = wx.getStorageSync('user')
  32. this.setData({
  33. photo: userInfo.headImage ? api.total.split('.if')[0] + userInfo.headImage :'/images/head.png',
  34. viewName: userInfo.userName
  35. })
  36. // if (!userInfo){
  37. // let { viewName = '', photo = '' } = await getUserInfo()
  38. // this.setData({
  39. // photo,
  40. // viewName
  41. // })
  42. // }else{
  43. // this.setData({
  44. // photo: userInfo.avatarUrl,
  45. // viewName: userInfo.nickName
  46. // })
  47. // }
  48. },
  49. navigate_auth:function(e){
  50. wx.navigateTo({
  51. url: e.currentTarget.dataset.url,
  52. })
  53. },
  54. updateimage:function(){
  55. let that=this
  56. wx.chooseImage({
  57. count:1,
  58. success: function(res) {
  59. wx.showLoading({
  60. title: '正在上传',
  61. })
  62. wx.uploadFile({
  63. url: api.updateimage,
  64. filePath: res.tempFilePaths[0],
  65. header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', },
  66. name: 'file',
  67. formData: {
  68. 'fileType': 'image',
  69. 'loginId': wx.getStorageSync('loginId')
  70. },
  71. success(res) {
  72. wx.hideLoading()
  73. console.log(res)
  74. if (JSON.parse(res.data).status == true) {
  75. let user = wx.getStorageSync('userInfo')
  76. user.avatarUrl = api.total.split('.if')[0] + JSON.parse(res.data).headImage
  77. wx.setStorageSync('userInfo', user)
  78. that.setData({
  79. photo: user.avatarUrl
  80. })
  81. wx.showToast({
  82. title: '修改成功',
  83. icon:'none'
  84. })
  85. }
  86. }
  87. })
  88. },
  89. })
  90. },
  91. // goLogin,
  92. // navigate_auth_native
  93. })