index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // pages/mine/setting/editName/index.js
  2. import HTTP from "../../../../../requestFn/Api"
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. nick_name: "",
  9. userInfo: {}
  10. },
  11. onLoad(options) {
  12. const {
  13. nick_name
  14. } = options;
  15. this.setData({
  16. nick_name
  17. })
  18. const that = this;
  19. wx.getStorage({
  20. key: "userInfo",
  21. success(e) {
  22. that.setData({
  23. userInfo: e.data
  24. })
  25. },
  26. fail() {
  27. wx.showToast({
  28. title: '请先登录',
  29. icon:"none",
  30. success: () => {
  31. setTimeout(() => {
  32. wx.switchTab({
  33. url: '/page/tabBar/mine/index',
  34. })
  35. }, 1000)
  36. }
  37. })
  38. }
  39. })
  40. },
  41. getValue(e) {
  42. const that = this;
  43. that.setData({
  44. nick_name: e.detail.value
  45. })
  46. },
  47. editName() {
  48. const that = this;
  49. const {
  50. nick_name,
  51. userInfo
  52. } = that.data;
  53. HTTP.UsernickName({
  54. nick_name
  55. }).then(res => {
  56. if (res.code == 0) {
  57. wx.showToast({
  58. title: '修改成功',
  59. icon: 'success',
  60. duration: 1500,
  61. success() {
  62. wx.setStorage({
  63. data: {
  64. ...userInfo,
  65. nick_name
  66. },
  67. key: "userInfo"
  68. })
  69. setTimeout(() => {
  70. wx.navigateBack({
  71. delta: 1,
  72. })
  73. }, 1000)
  74. }
  75. })
  76. }
  77. })
  78. }
  79. })