community_user_profile.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="user-profile">
  3. <view class="form bg-white m-t-20">
  4. <view class="form--item bb">
  5. <view class="label normal nr">签名</view>
  6. <view class="flex-1">
  7. <input type="text" v-model="formData.signature" placeholder="请输入个性签名">
  8. </view>
  9. </view>
  10. <view class="form--item ">
  11. <view class="label normal nr">背景</view>
  12. <view class="flex-1">
  13. <u-upload @on-change="change" :action="action" :header="{'token': token,'version': version}"
  14. deletable :max-count="1" @on-remove="remove" custom-btn :width="264"
  15. :height="200" ref="upload" :file-list="fileList" :show-progress="false">
  16. <view slot="addBtn" class="uplader-upload" hover-class="slot-btn__hover" hover-stay-time="150">
  17. <u-icon size="48" color="#dcdee0" name="camera" />
  18. <view class="xs m-t-10">
  19. 上传背景图
  20. </view>
  21. </view>
  22. </u-upload>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="footer">
  27. <button class="bg-primary br60 white lg" @click="onSubmit">确定</button>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import store from '@/store'
  33. import {
  34. baseURL,
  35. version
  36. } from '@/config/app.js'
  37. import {
  38. uploadFile
  39. } from "@/utils/tools.js"
  40. import {
  41. getCommunitySetting,
  42. apiCommunitySetSetting
  43. } from "@/api/community.js"
  44. export default {
  45. data() {
  46. return {
  47. action: '',
  48. token: '',
  49. version: version,
  50. formData: {
  51. signature: '',
  52. image: ''
  53. },
  54. }
  55. },
  56. computed: {
  57. fileList() {
  58. const { image } = this.formData;
  59. return image ? [{url: image}] : []
  60. }
  61. },
  62. onLoad() {
  63. this.action = baseURL + '/api/file/formimage';
  64. this.token = store.getters.token
  65. this.initCommunitySetting()
  66. },
  67. methods: {
  68. // 初始化设置
  69. initCommunitySetting() {
  70. getCommunitySetting().then(res => {
  71. Object.keys(this.formData).map(item => {
  72. this.$set(this.formData, item, res.data[item])
  73. })
  74. })
  75. },
  76. // 上传,不管成不成功都返回数据|提示
  77. change(event) {
  78. this.$toast({
  79. title: JSON.parse(event.data).msg
  80. })
  81. if (JSON.parse(event.data).code == 1) {
  82. this.formData.image = JSON.parse(event.data).data.uri
  83. }
  84. },
  85. // 删除
  86. remove(event) {
  87. this.formData.image = '';
  88. },
  89. // 提交
  90. onSubmit() {
  91. apiCommunitySetSetting({
  92. ...this.formData
  93. }).then(res => {
  94. this.$toast({
  95. title: res.msg
  96. })
  97. setTimeout(() => this.$Router.back(), 500)
  98. })
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss">
  104. .user-profile {
  105. .bb {
  106. border-bottom: 1px solid #f2f2f2;
  107. }
  108. .form {
  109. padding-left: 24rpx;
  110. &--item {
  111. display: flex;
  112. padding: 30rpx 0;
  113. .label {
  114. width: 100rpx;
  115. }
  116. }
  117. }
  118. // 上传图片
  119. .uplader-upload {
  120. position: relative;
  121. width: 264rpx;
  122. height: 200rpx;
  123. padding-top: 40rpx;
  124. text-align: center;
  125. margin: 11rpx;
  126. border: 2px dashed #e5e5e5;
  127. background-color: #FFFFFF;
  128. >view {
  129. color: #BBB;
  130. }
  131. }
  132. .footer {
  133. padding: 50rpx 26rpx;
  134. }
  135. }
  136. </style>