me.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <!-- pages/me.wxml -->
  3. <view class="uni-container" style="padding: 0;">
  4. <view class="uni-header-logo header-custom">
  5. <img
  6. @headImg="uploadHeadImg"
  7. @click="updateImg"
  8. class="uni-header-image"
  9. :src="!initInfo.headImg || initInfo.headImg == '' ? loadImgSrcLocalhost(testPic) : loadImgSrcLocalhost(initInfo.headImg)"
  10. style="margin-left: 5%;border-radius: 45px;border: 1px solid #89DDFF;"
  11. />
  12. <view class="userInfo">
  13. <span>{{ initInfo.name == null || initInfo.name == '' ? initInfo.wechatName : initInfo.name }}</span>
  14. <text>积分:{{ initInfo.scoreNum }}</text>
  15. </view>
  16. </view>
  17. <view class="panel-contain">
  18. <view class="uni-panel" v-for="(item, index) in list" :key="item.id">
  19. <view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="goDetailPage(item.id)">
  20. <text class="uni-panel-text">{{ item.name }}</text>
  21. <text class="uni-panel-icon uni-icon" :class="item.open ? 'uni-panel-icon-on' : ''">{{ item.pages ? '&#xe581;' : '&#xe470;' }}</text>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import { getScore, getUserInfo, uploadHeadImg } from '@/api/me/me.js';
  29. import { getToken } from '@/utils/auth';
  30. export default {
  31. data() {
  32. return {
  33. testPic:'/profile/upload/2024/03/14/9dvR5kqPY4D64a27be3ba1f2bd3095eaa1ad61221bed_20240314150249A005.jpg',
  34. headers: {
  35. Authorization: 'Bearer ' + getToken()
  36. },
  37. initImgPath: 'https://sookajs.top:8888/profile/upload/moren.png',
  38. initInfo: {
  39. id: getApp().globalData.userId,
  40. scoreNum: 0,
  41. wechatName: '微信用户',
  42. name: null,
  43. headImg: null
  44. },
  45. list: [
  46. {
  47. id: 'me/meOperate/meOperate', //id是文件路径
  48. name: '积分流水',
  49. open: false
  50. },
  51. {
  52. id: 'demo/wenba/wenba',
  53. name: '我的问答',
  54. open: false
  55. },
  56. {
  57. id: 'me/nameAuthentication/nameAuthentication',
  58. name: '实名认证',
  59. open: false
  60. },
  61. {
  62. id: 'me/officialAuthentication/officialAuthentication',
  63. name: '官方认证',
  64. open: false
  65. },
  66. {
  67. id: 'matters/matters',
  68. name: '我的事项',
  69. open: false
  70. },
  71. {
  72. id: 'me/myPayKnow/myPayKnow',
  73. name: '付费知识',
  74. open: false
  75. }
  76. ],
  77. };
  78. },
  79. /**
  80. * 生命周期函数--监听页面初次渲染完成
  81. */
  82. onReady() {
  83. this.getUserInfoByUserId(this.initInfo.id);
  84. this.getScoreForMe(this.initInfo.id);
  85. },
  86. methods: {
  87. goDetailPage(e) {
  88. const url = '/pages/' + e;
  89. uni.navigateTo({
  90. url: url
  91. });
  92. },
  93. //获取用户信息:用户名称:头像
  94. getUserInfoByUserId(userId) {
  95. console.log(userId)
  96. getUserInfo(userId).then((res) => {
  97. this.initInfo.wechatName = res.data.wechatName;
  98. this.initInfo.name = res.data.name;
  99. this.initInfo.headImg = res.data.headImg;
  100. });
  101. },
  102. //获取当前积分
  103. getScoreForMe(userId) {
  104. console.log(userId)
  105. getScore(userId).then((res) => {
  106. this.initInfo.scoreNum = res.data.scoreNum;
  107. });
  108. },
  109. updateImg() {
  110. let _this = this;
  111. uni.chooseImage({
  112. success(resp) {
  113. uni.uploadFile({
  114. url: _this.$HTTP + `/common/upload`,
  115. filePath: resp.tempFilePaths[0],
  116. name: 'file',
  117. formData: {},
  118. header: _this.headers,
  119. success: (res) => {
  120. // 判断是否json字符串,将其转为json格式
  121. let data = JSON.parse(res.data);
  122. if (![200].includes(data.code)) {
  123. _this.$modal.msg(data.msg);
  124. } else {
  125. _this.initInfo.headImg = data.fileName;
  126. _this.uploadImg();
  127. _this.$modal.msg('更新成功');
  128. }
  129. },
  130. fail: (e) => {
  131. debugger;
  132. console.log(e);
  133. _this.$modal.msg('上传失败!');
  134. }
  135. });
  136. }
  137. });
  138. },
  139. uploadImg(){
  140. //更新数据库
  141. uploadHeadImg(this.initInfo).then((res) => {
  142. console.log(res);
  143. if (res.code === 200) {
  144. console.log(this.initInfo)
  145. }
  146. });
  147. }
  148. }
  149. };
  150. </script>
  151. <style>
  152. @import './me.css';
  153. .header-custom{
  154. margin: 0;
  155. padding: 0;
  156. background-color: #07C160;
  157. height: 30vh;
  158. padding-top: 8%;
  159. }
  160. .panel-contain{
  161. position: absolute;
  162. top: 25%;
  163. z-index: 100;
  164. width: 100%;
  165. height: 75vh;
  166. padding-top: 30%;
  167. border-top-right-radius: 25px;
  168. border-top-left-radius: 25px;
  169. background-color: #fff;
  170. }
  171. .uni-panel {
  172. position: relative;
  173. width: 90%;
  174. margin: auto;
  175. margin-bottom: 12px;
  176. border-bottom: 3px solid #FCFCFC;
  177. }
  178. .uni-panel::after{
  179. position: absolute;
  180. content: '';
  181. width: 20px;
  182. height: 20px;
  183. top: 28%;
  184. right: 0%;
  185. background: url('@/static/images/more/enter.png');
  186. background-size: 100% 100%;
  187. }
  188. .userInfo{
  189. position: absolute;
  190. top: 7%;
  191. left: 32%;
  192. font-weight: 700;
  193. font-size: 18px;
  194. color: #fff;
  195. }
  196. .userInfo text {
  197. display: block;
  198. margin-top: 11%;
  199. font-size: 15px;
  200. font-weight: 100;
  201. }
  202. </style>