info.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. userInfo: app.globalData.userInfo,
  6. prompt: {
  7. title: "",
  8. cost: ""
  9. }
  10. },
  11. onReady() {
  12. this.prompt = this.selectComponent("#prompt");
  13. },
  14. onShow(){
  15. this.setData({ userInfo: app.globalData.userInfo});
  16. },
  17. chooseImg() {
  18. let that = this;
  19. wx.chooseImage({
  20. count: 1,
  21. sizeType: ['compressed'],
  22. sourceType: ['album', 'camera'],
  23. success: function (res) {
  24. that.uploadAli(res.tempFilePaths[0]);
  25. }
  26. })
  27. },
  28. uploadAli(img) {
  29. var _this = this, userInfo = app.globalData.userInfo;
  30. util.uploadFile("v2/user/avatar/ossPolicy", img, { "rid": (userInfo ? userInfo.rid : "")}, true).then((res) => {
  31. if (res.code == 0) {
  32. // res.uploadTask.onHeadersReceived((data) => {
  33. _this.setData({ percent: 100 });
  34. app.globalData.userInfo.avatar = res.url;
  35. _this.setData({ userInfo: app.globalData.userInfo });
  36. wx.setStorageSync("WXuserInfo", app.globalData.userInfo);
  37. // });
  38. res.uploadTask.onProgressUpdate((data) => {
  39. _this.setData({ percent: data.progress });
  40. });
  41. } else
  42. util.showTips(res.reason);
  43. });
  44. },
  45. promptNickname(){
  46. let that = this;
  47. this.prompt.showPrompt();
  48. this.data.prompt.title = '修改昵称';
  49. this.data.prompt.cost = this.data.userInfo.nickname;
  50. this.setData({prompt: this.data.prompt});
  51. },
  52. getInput(e) {
  53. this.data.prompt.cost = e.detail.value;
  54. this.setData({
  55. prompt: this.data.prompt
  56. });
  57. },
  58. confirm() {
  59. let that = this;
  60. let nickname = this.data.prompt.cost;
  61. if (util.isEmpty(nickname)) {
  62. util.showTips('请输入用户昵称。');
  63. return false;
  64. }
  65. util.ajax({
  66. func: "v2/user/nickname",
  67. data: { nickname },
  68. method: 'PUT',
  69. contentType: 'application/json'
  70. }, function (res) {
  71. if (res.code == 0) {
  72. let userInfo = app.globalData.userInfo;
  73. userInfo.nickname = nickname;
  74. that.setData({ userInfo });
  75. app.globalData.userInfo = userInfo;
  76. wx.setStorageSync("WXuserInfo", userInfo)
  77. that.cancel();
  78. } else {
  79. util.showTips(res.reason);
  80. }
  81. });
  82. },
  83. cancel() {
  84. this.prompt.hidePrompt();
  85. },
  86. navigatorURl(e) {
  87. util.navigator(e.currentTarget.dataset.url);
  88. },
  89. unty() {
  90. var that = this;
  91. wx.showModal({
  92. content: '确定解除本账号与微信绑定,解除后无法微信快捷登录?',
  93. success: function (res) {
  94. if (res.confirm) {
  95. util.ajax({ func: "user/unbound_weixin" }, function (res) {
  96. if (res.code == 0) {
  97. let userInfo = app.globalData.userInfo;
  98. userInfo.weixin = 0;
  99. that.setData({ userInfo });
  100. app.globalData.userInfo = userInfo;
  101. wx.setStorageSync("WXuserInfo", userInfo)
  102. }
  103. })
  104. }
  105. }
  106. })
  107. },
  108. })