more.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div class="app-container">
  3. <div class="card-inset">
  4. <van-skeleton
  5. avatar
  6. avatar-size="50"
  7. :row="2"
  8. :loading="loading" >
  9. <van-row>
  10. <van-col span="6" style="display: flex;flex-direction: column;align-items: center;">
  11. <!-- <van-image
  12. width="80px"
  13. height="80px"
  14. fit="fill"
  15. round
  16. :src="userinfo.avatar || default_avatar"
  17. /> -->
  18. <van-uploader :after-read="afterRead" :max-size="500 * 1024" @oversize="onOversize">
  19. <van-image
  20. width="80px"
  21. height="80px"
  22. fit="fill"
  23. round
  24. :src="userAvatar || default_avatar"
  25. />
  26. </van-uploader>
  27. <span style="color:#2196f3;">更换头像</span>
  28. </van-col>
  29. <van-col span="14">
  30. <div class="user-info">
  31. <p>昵称:{{userinfo.realname || '用户'+ userinfo.phone}}</p>
  32. <p>手机:{{userinfo.phone}}</p>
  33. </div>
  34. </van-col>
  35. <van-col span="4">
  36. <span @click="editProfile" style="color: #2196f3;">编辑资料</span>
  37. </van-col>
  38. </van-row>
  39. <div class="padding-top-20"></div>
  40. <van-cell-group >
  41. <van-cell is-link icon="bell" to="devices">
  42. <template #title>
  43. <span class="custom-title">我的车辆</span>
  44. <!-- <van-tag type="danger">标签</van-tag> -->
  45. </template>
  46. </van-cell>
  47. <van-cell is-link icon="friends" to="insure">
  48. <template #title>
  49. <span class="custom-title">我的保险</span>
  50. <!-- <van-tag type="danger">标签</van-tag> -->
  51. </template>
  52. </van-cell>
  53. <!-- <van-cell is-link icon="new" to="/news">
  54. <template #title>
  55. <span class="custom-title">新闻动态</span>
  56. </template>
  57. </van-cell>
  58. <van-cell is-link icon="friends" to="activities" v-if="userType != 'personal'">
  59. <template #title>
  60. <span class="custom-title">研学活动</span>
  61. </template>
  62. </van-cell> -->
  63. <van-cell is-link icon="info">
  64. <template #title>
  65. <span class="custom-title">关于</span>
  66. </template>
  67. </van-cell>
  68. </van-cell-group>
  69. <div style="margin: 26px;">
  70. <van-button block round type="danger" size="small" @click="logout">退出登录</van-button>
  71. </div>
  72. </van-skeleton>
  73. </div>
  74. </div>
  75. </template>
  76. <script>
  77. import Vue from 'vue';
  78. import { Skeleton,Image as VanImage, Row, Col, Cell, CellGroup, Tag, Dialog, Button, Uploader } from 'vant';
  79. Vue.use(Skeleton);
  80. Vue.use(Button);
  81. Vue.use(VanImage);
  82. Vue.use(Row);
  83. Vue.use(Col);
  84. Vue.use(Cell);
  85. Vue.use(CellGroup);
  86. Vue.use(Tag);
  87. Vue.use(Dialog);
  88. Vue.use(Uploader);
  89. export default {
  90. data() {
  91. return {
  92. loading: true,
  93. userinfo: {},
  94. userType: 'personal',
  95. default_avatar: '/static/avatar_default.png',
  96. userAvatar: ''
  97. }
  98. },
  99. created() {
  100. this.userType = localStorage.getItem('userType');
  101. },
  102. mounted() {
  103. this.loading = false;
  104. this.userinfo = JSON.parse(localStorage.getItem('userinfo'));
  105. this.getUserAvatar();
  106. },
  107. methods: {
  108. /**
  109. * 退出登录
  110. */
  111. logout() {
  112. Dialog.confirm({
  113. title: '提醒',
  114. message: '确定要退出登录吗?'
  115. })
  116. .then(resp => {
  117. if (resp === 'confirm') {
  118. this.clearLocalStorage();
  119. this.$router.replace({ name: 'first' });
  120. }
  121. })
  122. .catch((resp) => {
  123. console.log('logout', resp);
  124. });
  125. },
  126. /**
  127. * 清除缓存
  128. */
  129. clearLocalStorage() {
  130. localStorage.removeItem('userType');
  131. localStorage.removeItem('deviceType');
  132. localStorage.removeItem('userid');
  133. localStorage.removeItem('userinfo');
  134. },
  135. getUserAvatar(){
  136. let that = this;
  137. that.$http.get("/getUserAvatar&uid=" + localStorage.getItem("userid") )
  138. .then(res => {
  139. let resp = res.data;
  140. if(!resp.success){
  141. return;
  142. }
  143. that.userAvatar = resp.data
  144. })
  145. .catch(res => {
  146. console.log(res);
  147. });
  148. },
  149. /**
  150. * 修改信息
  151. */
  152. editProfile() {
  153. this.$router.push('edit_profile');
  154. },
  155. afterRead(file){
  156. let that= this;
  157. console.log(file)
  158. // return;
  159. // var form=new FormData();
  160. // let blob = that.blob, imei = that.$route.params.imei;
  161. // let fileName = 'avatar-user-' + that.userinfo.id + '-' + new Date().getTime() + Math.floor(Math.random()*1000);
  162. // console.log(fileName)
  163. // form.append("upfile",file,fileName);
  164. // form.append('imei', imei);
  165. // form.append('userid', localStorage.getItem("userid"));
  166. // console.log(form);
  167. // //上传
  168. let postData = {
  169. uid: localStorage.getItem("userid"),
  170. avatar64content: file.content
  171. }
  172. that.$http({
  173. method: "post",
  174. url: "/saveUserAvatar",
  175. data: JSON.stringify(postData) ,
  176. })
  177. .then(({ data }) => {
  178. that.getUserAvatar()
  179. console.log(data, 'save res');
  180. });
  181. },
  182. onOversize(file){
  183. Dialog({ message: "头像勿超过500KB"});
  184. }
  185. }
  186. }
  187. </script>
  188. <style lang="scss" scoped>
  189. .user-info {
  190. height: 2rem;
  191. display: flex;
  192. flex-flow: column;
  193. justify-content: center;
  194. font-size: 14px;
  195. line-height: 24px;
  196. color: #6f6f6f;
  197. padding-left: 10px;
  198. }
  199. .card-inset {
  200. padding: 10px;
  201. border-radius: 5px;
  202. }
  203. .padding-top-20 {
  204. padding-top: 20px;
  205. }
  206. </style>