index.vue 12 KB

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