index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. uni.showLoading({
  55. title:'上传中'
  56. })
  57. req.uploadFile('/api/nocheck/upload', e.detail.avatarUrl, res => {
  58. uni.hideLoading()
  59. this.avatar = res.src
  60. });
  61. },
  62. intNickName(e) {
  63. this.nickName = e.detail.value
  64. },
  65. confirm() {
  66. let that = this;
  67. let d = {
  68. avatar: that.avatar,
  69. nickName: that.nickName,
  70. };
  71. let isShowLoading = false;
  72. if (!isShowLoading) {
  73. req.loadIng('保存中');
  74. isShowLoading = true;
  75. }
  76. req.postRequest('/api/user/save', d, res => {
  77. if (isShowLoading) {
  78. uni.hideLoading();
  79. that.getInfo();
  80. uni.navigateBack();
  81. isShowLoading = false;
  82. }
  83. });
  84. },
  85. }
  86. };
  87. </script>
  88. <style>
  89. @import "./index.css";
  90. </style>