userinfo.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="content">
  3. <view class="row1">
  4. <text class="tit">头像</text>
  5. <view class="background-img" @click.stop="imgsub()">
  6. <image class="background-img" v-model="userInfo.avatar" :src="userInfo.avatar" mode="aspectFill">
  7. </image>
  8. </view>
  9. </view>
  10. <view class="row">
  11. <text class="tit">昵称</text>
  12. <input class="input" type="text" v-model="userInfo.nickname" placeholder-class="placeholder" />
  13. </view>
  14. <view class="row">
  15. <text class="tit">ID</text>
  16. <input class="input" type="text" disabled="true" v-model="userInfo.uid" placeholder-class="placeholder" />
  17. </view>
  18. <view class="row">
  19. <text class="tit">账户</text>
  20. <input class="input" type="text" disabled="true" v-model="userInfo.phone" placeholder-class="placeholder" />
  21. </view>
  22. <view class="add-btn" @click="confirm">提交</view>
  23. <canvas canvas-id="canvas" v-if="canvasStatus"
  24. :style="{width: canvasWidth + 'px', height: canvasHeight + 'px',position: 'absolute',left:'-100000px',top:'-100000px'}"></canvas>
  25. <uni-popup ref="popup" type="center">
  26. <view class="alertprogress">
  27. {{progress}}%
  28. </view>
  29. </uni-popup>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. mapState,
  35. mapMutations
  36. } from 'vuex';
  37. import {
  38. upload
  39. } from '@/api/order.js';
  40. import {
  41. userEdit,
  42. logout,
  43. test
  44. } from '@/api/set.js';
  45. export default {
  46. data() {
  47. return {
  48. show: false,
  49. password: '',
  50. upFileLoding: false,
  51. canvasStatus: false,
  52. canvasWidth:0,
  53. canvasHeight:0,
  54. progress:0,
  55. }
  56. },
  57. onLoad() {
  58. console.log(this.userInfo)
  59. test();
  60. },
  61. computed: {
  62. ...mapState('user', ['userInfo'])
  63. },
  64. methods: {
  65. ...mapMutations('user', ['logout']),
  66. imgsub() {
  67. const that = this;
  68. if (that.upFileLoding) {
  69. return
  70. }
  71. that.upFileLoding = true;
  72. that.canvasStatus = true;
  73. setTimeout(() => {
  74. that.upFileLoding = false;
  75. }, 1000);
  76. upload({
  77. filename: ''
  78. }, (res) => {
  79. that.userInfo.avatar = res[0].url;
  80. that.canvasStatus = false
  81. }, (res) => {
  82. that.canvasStatus = false
  83. }, (res) => {
  84. that.canvasWidth = res.w
  85. that.canvasHeight = res.h
  86. },(res)=>{
  87. // console.log(res,'res');
  88. if(res.progress==100){
  89. this.$refs.popup.close()
  90. uni.showToast({
  91. title: '上传成功'
  92. });
  93. }else if(res.progress==0){
  94. this.$refs.popup.open()
  95. }
  96. that.progress = res.progress;
  97. // console.log(res,'进度条');
  98. })
  99. },
  100. confirm() {
  101. userEdit({
  102. avatar: this.userInfo.avatar,
  103. nickname: this.userInfo.nickname
  104. })
  105. .then(e => {
  106. this.$api.msg('修改成功');
  107. setTimeout(() => {
  108. uni.switchTab({
  109. url: '/pages/user/user'
  110. });
  111. }, 1000);
  112. console.log(e);
  113. })
  114. .catch(e => {
  115. console.log(e);
  116. });
  117. },
  118. toLogout() {
  119. let obj = this;
  120. uni.showModal({
  121. content: '确定要退出登录么',
  122. success: (e) => {
  123. if (e.confirm) {
  124. logout({}).then((e) => {
  125. uni.navigateBack();
  126. }).catch((e) => {
  127. console.log(e);
  128. })
  129. obj.logout();
  130. }
  131. }
  132. });
  133. },
  134. }
  135. }
  136. </script>
  137. <style lang="scss">
  138. .row1 {
  139. display: flex;
  140. align-items: center;
  141. justify-content: space-between;
  142. position: relative;
  143. padding: 0 30upx;
  144. height: 110upx;
  145. background: #fff;
  146. margin-bottom: 20upx;
  147. .tit {
  148. flex-shrink: 0;
  149. width: 120upx;
  150. font-size: $font-lg;
  151. color: $font-color-dark;
  152. }
  153. .background-img {
  154. width: 80rpx;
  155. height: 80rpx;
  156. border-radius: 50%;
  157. background: #f2f2f2;
  158. }
  159. }
  160. .row {
  161. display: flex;
  162. align-items: center;
  163. padding: 0 30upx;
  164. height: 110upx;
  165. background: #fff;
  166. .tit {
  167. flex-shrink: 0;
  168. width: 120upx;
  169. font-size: $font-lg;
  170. color: $font-color-dark;
  171. }
  172. .input {
  173. flex: 1;
  174. text-align: right;
  175. font-size: $font-base;
  176. color: $color-gray;
  177. }
  178. }
  179. .add-btn {
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. margin: 158rpx auto 30rpx;
  184. width: 560rpx;
  185. height: 80rpx;
  186. background: #DC262B;
  187. border-radius: 40px;
  188. color: #FFFFFF;
  189. }
  190. .out {
  191. display: flex;
  192. align-items: center;
  193. justify-content: center;
  194. margin: 0 auto 30rpx;
  195. width: 560rpx;
  196. height: 80rpx;
  197. border: 1px solid #32C6FF;
  198. background: #FFFFFF;
  199. border-radius: 40px;
  200. color: #32C6FF;
  201. }
  202. .psw-wrapper {
  203. width: 548rpx;
  204. height: 344rpx;
  205. background-color: #ffffff;
  206. .psw-title {
  207. width: 100%;
  208. font-size: 35rpx;
  209. padding: 43rpx 0 49rpx;
  210. text-align: center;
  211. font-weight: 800;
  212. }
  213. .psw-ipt {
  214. display: block;
  215. background-color: #dce3ed;
  216. height: 90rpx;
  217. width: 464rpx;
  218. padding-left: 30rpx;
  219. margin: 0 auto;
  220. font-size: 80rpx;
  221. }
  222. .psw-btn text {
  223. display: inline-block;
  224. text-align: center;
  225. width: 50%;
  226. padding-top: 29rpx;
  227. font-size: 35rpx;
  228. }
  229. .psw-qd {
  230. color: #32C6FF;
  231. }
  232. }
  233. </style>