index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view class="box">
  3. <u-navbar :placeholder="true" bgColor="rgba(255,255,255,0.0)" :leftIconSize="0"></u-navbar>
  4. <view class="bg_box">
  5. <view class="top_box" @click="modifyShow = true">
  6. <view class="img_box" style="display: flex">
  7. <image class="img" :src="mainBodyUserInfo.avatar? mainBodyUserInfo.avatar:'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'"></image>
  8. <view class="">
  9. <view v-if="mainBodyUserInfo.nickname=='微信用户'" class="name">{{ mainBodyUserInfo.nickname}}{{mainBodyUserInfo.id}}</view>
  10. <view v-else class="name">{{ mainBodyUserInfo.nickname}}</view>
  11. <view class="" style="display: flex;align-items: center;">
  12. <view style="margin-left: 32rpx; font-size: 28rpx; color: rgba(68, 68, 68, 0.6)">总积分:{{mainBodyUserInfo.score}}</view>
  13. <view style="margin-left: 32rpx; font-size: 28rpx; color: rgba(68, 68, 68, 0.6)">id:{{mainBodyUserInfo.id}}</view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="">
  18. <image style="width: 40rpx; height: 40rpx" src="/static/img/more.png"></image>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- -->
  23. <view class="btm_box">
  24. <view class="item" @click="myList(index)" v-for="(item, index) in items" :key="item.index">
  25. <view class="" style="display: flex">
  26. <image style="width: 48rpx; height: 48rpx" :src="item.img"></image>
  27. <view class="item_tit">{{ item.title }}</view>
  28. </view>
  29. <image style="width: 40rpx; height: 40rpx" src="/static/img/more.png"></image>
  30. </view>
  31. <button style="border: node; background-color: transparent" open-type="contact" plain="true">
  32. <view class="item">
  33. <view class="" style="display: flex">
  34. <image style="width: 48rpx; height: 48rpx" src="/static/img/icon_u2.png"></image>
  35. <text class="item_tit">联系客服</text>
  36. </view>
  37. <image style="width: 40rpx; height: 40rpx" src="/static/img/more.png"></image>
  38. </view>
  39. </button>
  40. <view style="width: 90%; margin: auto; margin-top: 240rpx; text-align: center; font-size: 26rpx; color: #abaab2">
  41. <view class="">客服电话:18649931391</view>
  42. </view>
  43. </view>
  44. <u-modal :show="modifyShow" title="修改昵称和头像" @close="modifyShow = false" :showCancelButton="true" @cancel="modifyShow = false" @confirm="isOk">
  45. <view class="slot-content" style="text-align: center">
  46. <view>
  47. <text>点击以下头像获取微信默认头像</text>
  48. <button open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  49. <image style="width: 150rpx; height: 150rpx; margin-top: 20rpx" :src="mainBodyUserInfo.avatar? mainBodyUserInfo.avatar:'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'"></image>
  50. </button>
  51. </view>
  52. <view style="margin-top: 20rpx">
  53. <input class="ipt" @change="blurname" v-model="wxnickname" type="nickname" placeholder="请输入昵称" />
  54. </view>
  55. <view style="margin-top: 40rpx">
  56. <input placeholder="请输入邮箱(非必填)" border="surround" v-model="mailbox"></input>
  57. </view>
  58. </view>
  59. </u-modal>
  60. </view>
  61. </template>
  62. <script>
  63. var _token = '';
  64. var _this;
  65. import { baseUrl, baseApiUrl } from '@/config/config.js';
  66. export default {
  67. data() {
  68. return {
  69. modifyShow: false /*修改资料 */,
  70. face: '',
  71. mainBodyUserInfo: {
  72. nickname: '',
  73. avatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  74. },
  75. avatarUrl: '',
  76. wxnickname: '',
  77. mailbox:"",/*邮箱 */
  78. getFace: false,
  79. userdata: {
  80. friendsLists: [],
  81. friendsTotal: 0,
  82. user: {
  83. score: '0',
  84. exp: '0'
  85. }
  86. },
  87. items: [
  88. {
  89. title: '积分商城',
  90. img: '/static/img/icon_u5.png',
  91. path: '/answer_pages/gift/index'
  92. },
  93. {
  94. title: '我的投稿',
  95. img: '/static/img/icon_u1.png',
  96. path: '/user_fenbao/myTouGao/myTouGao'
  97. },
  98. {
  99. title: '积分日志',
  100. img: '/static/img/icon_u1.png',
  101. path: '/user_fenbao/rongYu/JiFen'
  102. },
  103. {
  104. title: '学习记录',
  105. img: '/static/img/icon_u3.png',
  106. path: '/pages/user/learn'
  107. },
  108. {
  109. title: '我的荣誉',
  110. img: '/static/img/icon_u4.png',
  111. path: '/user_fenbao/rongYu/rongYu'
  112. },
  113. {
  114. title: '我的活动',
  115. img: '/static/img/icon_u5.png',
  116. path: '/user_fenbao/huoDong/huoDong'
  117. }
  118. ]
  119. };
  120. },
  121. onShow() {
  122. /* 调用userInfo()从本地获取用户信息 */
  123. this.user = this.$common.userInfo();
  124. if (this.user && this.user.nickname.indexOf('微信') >= 0) {
  125. this.getFace = true;
  126. }
  127. },
  128. onLoad(option) {
  129. /* 来到我的页面判断用户是否登录 */
  130. _this = this;
  131. this.user = this.$common.userInfo();
  132. this.mainBodyUserInfo= this.$db.get('mainBodyUserInfo');
  133. // console.log(this.user);
  134. if (this.user === 'undefined' || this.user === '' || this.user === [] || this.user === null) {
  135. /* 跳转到登录页 */
  136. this.$common.toLogin();
  137. } else {
  138. /* 刷新 */
  139. this.$api.refreshUser(
  140. {
  141. main_body_id: 1,
  142. },
  143. (val) => {
  144. console.log(val, 999);
  145. if (val.code == 401) {
  146. this.$common.navigateTo('/pages/user/login');
  147. return;
  148. }
  149. this.user = val.data.user;
  150. // this.avatarUrl = this.user.avatar;
  151. this.auth = val.data.auth;
  152. this.$db.set('user', val.data.user);
  153. this.$db.set('auth', val.data.auth);
  154. _this.$db.set('mainBodyUserInfo',val.data.mainBodyUserInfo);
  155. this.mainBodyUserInfo= this.$db.get('mainBodyUserInfo');
  156. }
  157. );
  158. }
  159. // this.getMainBodyUser()
  160. },
  161. methods: {
  162. // getMainBodyUser(){
  163. // this.$api.getMainBodyUser({main_body_id:1,main_body_user_id:this.mainBodyUserInfo.},function(res){
  164. // console.log(res,78787878)
  165. // })
  166. // },
  167. myList(i) {
  168. uni.navigateTo({
  169. url: this.items[i].path
  170. });
  171. },
  172. // 获取头像
  173. onChooseAvatar(e) {
  174. this.mainBodyUserInfo.avatar=e.detail.avatarUrl
  175. // this.avatarUrl = e.detail.avatarUrl;
  176. },
  177. // 获取昵称
  178. blurname(e) {
  179. this.wxnickname = e.detail.value;
  180. this.mainBodyUserInfo.nickname = e.detail.value;
  181. },
  182. isOk() {
  183. this.modifyShow = false;
  184. let userToken = '';
  185. let auth = this.$db.get('auth');
  186. userToken = auth.token;
  187. // 准备formData,无论filePath是否存在都添加
  188. let formData = {
  189. nickname: this.wxnickname
  190. };
  191. // 如果有图片路径,则准备上传
  192. let uploadPromise = Promise.resolve();
  193. if (this.mainBodyUserInfo.avatar) {
  194. uploadPromise = new Promise((resolve, reject) => {
  195. uni.uploadFile({
  196. url: this.$config.baseUrl + 'api/common/upload?token=' + userToken,
  197. filePath: this.mainBodyUserInfo.avatar,
  198. fileType: 'image',
  199. name: 'file',
  200. headers: {
  201. Accept: 'application/json',
  202. 'Content-Type': 'multipart/form-data'
  203. },
  204. formData: formData,
  205. success: (uploadFileRes) => {
  206. var dataimg = JSON.parse(uploadFileRes.data);
  207. formData.avatar = dataimg.data.fullurl; // 若上传成功,更新formData中的avatar
  208. resolve(); // 成功后调用resolve
  209. },
  210. fail: (err) => {
  211. console.error('图片上传失败', err);
  212. reject(err); // 失败后调用reject,但后续操作仍会执行
  213. },
  214. complete: () => {
  215. // 无论成功还是失败,都继续执行编辑用户信息的API调用
  216. _this.$api.editMainBodyUser({
  217. avatar: formData.avatar || '', // 确保有值,即使上传失败也尝试提交
  218. main_body_id: 1,
  219. main_body_user_id: this.mainBodyUserInfo.id,
  220. nickname: this.wxnickname
  221. }, (data) => {
  222. _this.$common.successToShow('修改成功');
  223. if (formData.avatar) {
  224. // 只有上传成功才更新
  225. _this.mainBodyUserInfo.avatar = formData.avatar;
  226. }
  227. _this.mainBodyUserInfo.nickname = _this.wxnickname;
  228. _this.$db.set('mainBodyUserInfo', _this.mainBodyUserInfo);
  229. console.log(_this.mainBodyUserInfo,56456456);
  230. });
  231. }
  232. });
  233. });
  234. }
  235. }
  236. // isOk() {
  237. // this.modifyShow = false;
  238. // let userToken = '';
  239. // let auth = this.$db.get('auth');
  240. // userToken = auth.token;
  241. // uni.uploadFile({
  242. // url: this.$config.baseUrl + 'api/common/upload?token=' + userToken,
  243. // filePath: this.mainBodyUserInfo.avatar,
  244. // fileType: 'image',
  245. // name: 'file',
  246. // headers: {
  247. // Accept: 'application/json',
  248. // 'Content-Type': 'multipart/form-data'
  249. // },
  250. // formData: { nickname: this.wxnickname },
  251. // success: (uploadFileRes) => {
  252. // console.log(9999)
  253. // // console.log(JSON.parse(uploadFileRes.data), 6666);
  254. // var dataimg = JSON.parse(uploadFileRes.data);
  255. // // console.log(dataimg.data.fullurl, 6666);
  256. // _this.$api.editMainBodyUser(
  257. // {
  258. // avatar: dataimg.data.fullurl,
  259. // main_body_id: 1,
  260. // main_body_user_id: this.mainBodyUserInfo.id,
  261. // nickname: this.wxnickname
  262. // },
  263. // (data) => {
  264. // _this.$common.successToShow('修改成功');
  265. // _this.mainBodyUserInfo.avatar =dataimg.data.fullurl;
  266. // _this.mainBodyUserInfo.nickname = _this.wxnickname;
  267. // _this.$db.set('mainBodyUserInfo', _this.mainBodyUserInfo);
  268. // console.log(_this.mainBodyUserInfo,56456456)
  269. // }
  270. // );
  271. // }
  272. // });
  273. // }
  274. }
  275. };
  276. </script>
  277. <style>
  278. .box {
  279. /* height: 100%; */
  280. /* background-color: #f3e2c8; */
  281. }
  282. button {
  283. border: none !important;
  284. border: transparent !important;
  285. padding: 0 !important;
  286. }
  287. .bg_box {
  288. width: 100%;
  289. height: 800rpx;
  290. position: relative;
  291. top: -182rpx;
  292. background: url('https://huli-app.wenlvti.net/app_static/WenWuGuanJia/image/user_bg.png') no-repeat;
  293. background-size: 100% 100%;
  294. }
  295. .top_box {
  296. width: 90%;
  297. height: 450rpx;
  298. margin-left: 40rpx;
  299. display: flex;
  300. align-items: center;
  301. justify-content: space-between;
  302. }
  303. .img {
  304. width: 108rpx;
  305. height: 108rpx;
  306. border: 4rpx solid #af7e44;
  307. border-radius: 50%;
  308. }
  309. .img_box {
  310. display: flex;
  311. align-items: center;
  312. }
  313. .name {
  314. font-size: 44rpx;
  315. margin-left: 30rpx;
  316. line-height: 60rpx;
  317. color: #444444;
  318. }
  319. .btm_box {
  320. margin-top: -620rpx;
  321. width: 750rpx;
  322. height: 100vh;
  323. position: relative;
  324. padding: 40rpx;
  325. z-index: 2;
  326. border-radius: 24rpx 24rpx 0rpx 0rpx;
  327. background-color: #fff9e9;
  328. }
  329. .item {
  330. height: 80rpx;
  331. display: flex;
  332. align-items: center;
  333. justify-content: space-between;
  334. }
  335. .item_tit {
  336. margin-left: 20rpx;
  337. font-size: 32rpx;
  338. font-weight: 900;
  339. line-height: 48rpx;
  340. background: linear-gradient(180deg, #af7e44 0%, #934b36 100%);
  341. -webkit-background-clip: text;
  342. -webkit-text-fill-color: transparent;
  343. }
  344. </style>