index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <style>
  2. page {
  3. background: #f5f5f5
  4. }
  5. .user-line {
  6. padding: 0 15px;
  7. height: 70px;
  8. background: #fff;
  9. border-top: 1px #f5f5f5 solid;
  10. display: flex;
  11. align-items: center
  12. }
  13. .ul-left {
  14. color: #585858;
  15. font-size: 14px
  16. }
  17. .ul-right {
  18. width: 60%;
  19. margin-left: auto;
  20. display: flex;
  21. align-items: center;
  22. justify-content: flex-end
  23. }
  24. .ulr-name {
  25. color: #9b9b9b;
  26. font-size: 13px
  27. }
  28. .ulr-img {
  29. width: 50px;
  30. height: 50px
  31. }
  32. .ulr-img image {
  33. width: 100%;
  34. height: 100%;
  35. border-radius: 100%
  36. }
  37. .ulr-jiantou {
  38. width: 16px;
  39. height: 16px;
  40. margin-left: 10px
  41. }
  42. .ulr-jiantou image {
  43. width: 100%;
  44. height: 100%
  45. }
  46. </style>
  47. <template>
  48. <view id="box">
  49. <view class="user-line">
  50. <view class="ul-left"><text>头像</text></view>
  51. <view class="ul-right" @tap="upImgs">
  52. <view class="ulr-img">
  53. <image :src="userInfo.avatar ? userInfo.avatar : '/static/img/user-avatar2.png'" mode="aspectFill">
  54. </image>
  55. </view>
  56. <view class="ulr-jiantou">
  57. <image src="/static/img/ic_next.png"></image>
  58. </view>
  59. </view>
  60. </view>
  61. <view class="user-line" @tap="tapOpen" :data-url="'/pages/user/userinfo/mobile'">
  62. <view class="ul-left"><text>手机号码</text></view>
  63. <view class="ul-right">
  64. <view class="ulr-name">
  65. <text>{{userInfo.mobile}}</text>
  66. </view>
  67. </view>
  68. </view>
  69. <view class="user-line" @tap="tapOpen" :data-url="'/pages/user/userinfo/area?val='+ userInfo.region">
  70. <view class="ul-left"><text>地区</text></view>
  71. <view class="ul-right">
  72. <view class="ulr-name">
  73. <text>{{userInfo.region || "请输入省市区"}}</text>
  74. </view>
  75. <view class="ulr-jiantou">
  76. <image src="/static/img/ic_next.png"></image>
  77. </view>
  78. </view>
  79. </view>
  80. <view class="user-line" @tap="tapOpen" :data-url="'/pages/user/userinfo/nickname?val='+ userInfo.nickname">
  81. <view class="ul-left"><text>昵称</text></view>
  82. <view class="ul-right">
  83. <view class="ulr-name">
  84. <text>{{userInfo.nickname}}</text>
  85. </view>
  86. <view class="ulr-jiantou">
  87. <image src="/static/img/ic_next.png"></image>
  88. </view>
  89. </view>
  90. </view>
  91. <view class="user-line" @tap="tapOpen" data-url="/pages/user/address/address">
  92. <view class="ul-left"><text>地址管理</text></view>
  93. <view class="ul-right">
  94. <view class="ulr-name">
  95. <text></text>
  96. </view>
  97. <view class="ulr-jiantou">
  98. <image src="/static/img/ic_next.png"></image>
  99. </view>
  100. </view>
  101. </view>
  102. <view class="user-line" @tap="tapOpen" data-url="/pages/user/userinfo/password">
  103. <view class="ul-left"><text>修改密码</text></view>
  104. <view class="ul-right">
  105. <view class="ulr-name">
  106. <text></text>
  107. </view>
  108. <view class="ulr-jiantou">
  109. <image src="/static/img/ic_next.png"></image>
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. </template>
  115. <script>
  116. import {
  117. mapState,
  118. mapMutations
  119. } from 'vuex'
  120. export default {
  121. computed: mapState(['user']),
  122. data() {
  123. return {
  124. userInfo: {}
  125. }
  126. },
  127. onShow() {
  128. this.getData();
  129. },
  130. methods: {
  131. ...mapMutations(['loginOut']),
  132. getData() {
  133. this
  134. .request
  135. .post("userInfo")
  136. .then(res => {
  137. if (res.code == 200) {
  138. this.userInfo = res.data;
  139. } else {
  140. this.utils.Tip(res.msg);
  141. }
  142. })
  143. .catch(err => {
  144. this.utils.Tip("网络错误,请稍后尝试");
  145. });
  146. },
  147. /**
  148. * 打开文件
  149. * @param {Object} ev
  150. */
  151. tapOpen: function(ev) {
  152. console.log(ev)
  153. let url = ev.currentTarget.dataset.url
  154. uni.navigateTo({
  155. url: url
  156. });
  157. },
  158. upImgs: function() {
  159. // #ifdef APP-PLUS
  160. this.$store.dispatch('permission/requestPermissions', 'WRITE_EXTERNAL_STORAGE').then(res => {
  161. // if (res !== 1) return;
  162. console.log(res,'11');
  163. this.upImg();
  164. });
  165. return;
  166. // #endif
  167. // #ifndef APP
  168. this.upImg();
  169. // #endif
  170. },
  171. upImg: function() {
  172. uni.chooseImage({
  173. count: 1,
  174. sizeType: ['compressed'],
  175. success: (res) => {
  176. let img = res.tempFilePaths[0];
  177. this.utils.loadIng();
  178. this
  179. .request
  180. .post("qiniu")
  181. .then(res => {
  182. uni.uploadFile({
  183. url: 'https://up-z0.qiniup.com',
  184. filePath: img,
  185. name: 'file',
  186. formData: {
  187. 'key': res.data.mk_str,
  188. 'token': res.data.token
  189. },
  190. success: (uploadFileRes) => {
  191. this.request.post("saveAvatar", {
  192. img: res.data.url
  193. }).then(
  194. (res2) => {
  195. uni.hideLoading();
  196. if (res2.code == 200) {
  197. this.userInfo.avatar = res.data
  198. .url;
  199. } else {
  200. this.utils.Tip(res2.msg);
  201. }
  202. }).catch(err => {
  203. this.utils.Tip("网络错误,请稍后尝试");
  204. });
  205. },
  206. fail: () => {
  207. uni.hideLoading();
  208. this.utils.Tip("上传失败,请重新尝试");
  209. }
  210. });
  211. })
  212. .catch(err => {
  213. uni.hideLoading();
  214. this.utils.Tip("请重新上传图片");
  215. });
  216. }
  217. });
  218. },
  219. },
  220. }
  221. </script>