index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view>
  3. <view class="list">
  4. <view class="li">
  5. <text>头像</text>
  6. <button open-type="chooseAvatar" hover-class="none" class="item" @chooseavatar="uploadAvatar">
  7. <image :src="avatar" mode="aspectFit" class="logo"></image>
  8. </button>
  9. <image src="/static/pages/images/more.png" class="rico"></image>
  10. </view>
  11. <view class="li">
  12. <text>昵称</text>
  13. <view class="item">
  14. <input type="nickname" name="nickName" placeholder="请输入昵称" :value="nickName" @input="intNickName"></input>
  15. </view>
  16. </view>
  17. </view>
  18. <button class="submit" @tap="confirm">确定</button>
  19. </view>
  20. </template>
  21. <script>
  22. // pages/userinfo/userinfo.js
  23. const app = getApp();
  24. const req = require("../../utils/request.js");
  25. var QQMapWX = require("../../utils/qqmap.js");
  26. export default {
  27. data() {
  28. return {
  29. avatar: "",
  30. nickName: "",
  31. };
  32. },
  33. components: {},
  34. props: {},
  35. onLoad: function() {
  36. this.getInfo();
  37. },
  38. methods: {
  39. getInfo() {
  40. let that = this;
  41. let isShowLoading = false;
  42. if (!isShowLoading) {
  43. req.loadIng('加载中');
  44. isShowLoading = true;
  45. }
  46. req.getRequest('/api/user/info', {}, data => {
  47. this.setData(data);
  48. req.setStorage('userInfo', data);
  49. uni.hideLoading();
  50. isShowLoading = false;
  51. });
  52. },
  53. uploadAvatar(e) {
  54. req.uploadFile('/api/upload', e.detail.avatarUrl, res => {
  55. this.avatar = res.src
  56. });
  57. },
  58. intNickName(e) {
  59. this.nickName = e.detail.value
  60. },
  61. confirm() {
  62. let that = this;
  63. let d = {
  64. avatar: that.avatar,
  65. nickName: that.nickName,
  66. };
  67. let isShowLoading = false;
  68. if (!isShowLoading) {
  69. req.loadIng('保存中');
  70. isShowLoading = true;
  71. }
  72. req.postRequest('/api/user/save', d, res => {
  73. if (isShowLoading) {
  74. uni.hideLoading();
  75. that.getInfo();
  76. uni.navigateBack();
  77. isShowLoading = false;
  78. }
  79. });
  80. },
  81. }
  82. };
  83. </script>
  84. <style>
  85. @import "./index.css";
  86. </style>