editMyself.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // pages/editMyself/editMyself.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. index: 0,
  11. array:['未知','男','女'],
  12. name: '',
  13. src: ''
  14. },
  15. changeHead: function () {
  16. const that = this
  17. const urls = urlDef.urls;
  18. wx.chooseImage({
  19. count: 6,
  20. sourceType: ['album', 'camera'],
  21. success(res) {
  22. wx.showLoading({
  23. title: '上传中...',
  24. })
  25. for (var i in res.tempFilePaths) {
  26. wx.uploadFile({
  27. filePath: res.tempFilePaths[i],
  28. name: 'name',
  29. url: urls.file_upload,
  30. header: util.getHeaders(),
  31. success(res) {
  32. wx.showToast({
  33. title: '上传成功',
  34. })
  35. const rs = JSON.parse(JSON.parse(JSON.stringify(res.data)))
  36. that.setData({
  37. src: rs.data[0].url
  38. })
  39. },
  40. fail(res) {
  41. wx.showToast({
  42. title: '上传失败',
  43. icon: none
  44. })
  45. },
  46. complete(res) {
  47. wx.hideLoading({
  48. success: (res) => { },
  49. })
  50. }
  51. })
  52. }
  53. }
  54. })
  55. },
  56. /**
  57. * 生命周期函数--监听页面加载
  58. */
  59. onLoad: function (options) {
  60. const sex = wx.getStorageSync('student').sex.substring(29,wx.getStorageSync('student').sex.length)
  61. let index = 0
  62. if( sex == 'bf7'){
  63. index = 0
  64. } else if( sex == 'fbc' ){
  65. index = 1
  66. } else if( sex == '098' ){
  67. index =2
  68. }
  69. this.setData({
  70. index,
  71. name: wx.getStorageSync('student').name,
  72. src: wx.getStorageSync('student').headImg
  73. })
  74. },
  75. /**
  76. * 生命周期函数--监听页面初次渲染完成
  77. */
  78. onReady: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面显示
  82. */
  83. onShow: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面隐藏
  87. */
  88. onHide: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面卸载
  92. */
  93. onUnload: function () {
  94. },
  95. /**
  96. * 页面相关事件处理函数--监听用户下拉动作
  97. */
  98. onPullDownRefresh: function () {
  99. },
  100. /**
  101. * 页面上拉触底事件的处理函数
  102. */
  103. onReachBottom: function () {
  104. },
  105. /**
  106. * 用户点击右上角分享
  107. */
  108. onShareAppMessage: function () {
  109. }
  110. })