index.vue 11 KB

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