index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. // title: '报名',
  138. // img: '/static/img/icon_u1.png',
  139. // path: '/index_fenbao/SaoMaBaoMing/job'
  140. // }
  141. ]
  142. };
  143. },
  144. onShow() {
  145. /* 调用userInfo()从本地获取用户信息 */
  146. this.user = this.$common.userInfo();
  147. if (this.user && this.user.nickname.indexOf('微信') >= 0) {
  148. this.getFace = true;
  149. }
  150. this.mainBodyUserInfo = this.$db.get('mainBodyUserInfo');
  151. // console.log(this.user);
  152. if (this.user === 'undefined' || this.user === '' || this.user === [] || this.user === null || this.user === false) {
  153. /* 跳转到登录页 */
  154. // this.$common.toLogin();
  155. this.loginShow=true;
  156. } else {
  157. /* 刷新 */
  158. if(this.loginShow){
  159. this.$api.refreshUser(
  160. {
  161. main_body_id: 1
  162. },
  163. (val) => {
  164. console.log(val, 999);
  165. if (val.code == 401) {
  166. this.$common.navigateTo('/pages/user/login');
  167. return;
  168. }
  169. this.user = val.data.user;
  170. // this.avatarUrl = this.user.avatar;
  171. this.auth = val.data.auth;
  172. this.$db.set('user', val.data.user);
  173. this.$db.set('auth', val.data.auth);
  174. _this.$db.set('mainBodyUserInfo', val.data.mainBodyUserInfo);
  175. this.mainBodyUserInfo = this.$db.get('mainBodyUserInfo');
  176. this.loginShow=false;
  177. }
  178. );
  179. }
  180. }
  181. },
  182. onLoad(option) {
  183. /* 来到我的页面判断用户是否登录 */
  184. _this = this;
  185. // this.getMainBodyUser()
  186. },
  187. methods: {
  188. // getMainBodyUser(){
  189. // this.$api.getMainBodyUser({main_body_id:1,main_body_user_id:this.mainBodyUserInfo.},function(res){
  190. // console.log(res,78787878)
  191. // })
  192. // },
  193. loginPopUp(){
  194. this.$common.toLogin();
  195. },
  196. handleTopBoxClick() {
  197. // 检查登录状态
  198. this.user = this.$common.userInfo();
  199. if (!this.user || typeof this.user === 'undefined' || this.user === '' || this.user === null) {
  200. // 未登录,跳转到登录页面
  201. this.$common.toLogin();
  202. } else {
  203. // 已登录,显示修改资料弹窗
  204. this.modifyShow = true;
  205. }
  206. },
  207. myList(i) {
  208. uni.navigateTo({
  209. url: this.items[i].path
  210. });
  211. },
  212. // 获取头像
  213. onChooseAvatar(e) {
  214. this.mainBodyUserInfo.avatar = e.detail.avatarUrl;
  215. // this.avatarUrl = e.detail.avatarUrl;
  216. },
  217. // 获取昵称
  218. blurname(e) {
  219. this.wxnickname = e.detail.value;
  220. this.mainBodyUserInfo.nickname = e.detail.value;
  221. },
  222. isOk() {
  223. if (this.wxnickname == '' || this.wxnickname == undefined) {
  224. this.$common.errorToShow('请输入昵称');
  225. } else {
  226. this.modifyShow = false;
  227. let userToken = '';
  228. let auth = this.$db.get('auth');
  229. userToken = auth.token;
  230. // 准备formData,无论filePath是否存在都添加
  231. let formData = {
  232. nickname: this.wxnickname
  233. };
  234. // 如果有图片路径,则准备上传
  235. let uploadPromise = Promise.resolve();
  236. if (this.mainBodyUserInfo.avatar) {
  237. uploadPromise = new Promise((resolve, reject) => {
  238. uni.uploadFile({
  239. url: this.$config.baseUrl + 'api/common/upload?token=' + userToken,
  240. filePath: this.mainBodyUserInfo.avatar,
  241. fileType: 'image',
  242. name: 'file',
  243. headers: {
  244. Accept: 'application/json',
  245. 'Content-Type': 'multipart/form-data'
  246. },
  247. formData: formData,
  248. success: (uploadFileRes) => {
  249. var dataimg = JSON.parse(uploadFileRes.data);
  250. formData.avatar = dataimg.data.fullurl; // 若上传成功,更新formData中的avatar
  251. resolve(); // 成功后调用resolve
  252. },
  253. fail: (err) => {
  254. console.error('图片上传失败', err);
  255. reject(err); // 失败后调用reject,但后续操作仍会执行
  256. },
  257. complete: () => {
  258. // 无论成功还是失败,都继续执行编辑用户信息的API调用
  259. _this.$api.editMainBodyUser(
  260. {
  261. avatar: formData.avatar || '', // 确保有值,即使上传失败也尝试提交
  262. main_body_id: 1,
  263. main_body_user_id: this.mainBodyUserInfo.id,
  264. nickname: this.wxnickname
  265. },
  266. (data) => {
  267. _this.$common.successToShow('修改成功');
  268. if (formData.avatar) {
  269. // 只有上传成功才更新
  270. _this.mainBodyUserInfo.avatar = formData.avatar;
  271. }
  272. _this.mainBodyUserInfo.nickname = _this.wxnickname;
  273. _this.$db.set('mainBodyUserInfo', _this.mainBodyUserInfo);
  274. // console.log(_this.mainBodyUserInfo,56456456);
  275. }
  276. );
  277. }
  278. });
  279. });
  280. }
  281. }
  282. }
  283. // isOk() {
  284. // this.modifyShow = false;
  285. // let userToken = '';
  286. // let auth = this.$db.get('auth');
  287. // userToken = auth.token;
  288. // uni.uploadFile({
  289. // url: this.$config.baseUrl + 'api/common/upload?token=' + userToken,
  290. // filePath: this.mainBodyUserInfo.avatar,
  291. // fileType: 'image',
  292. // name: 'file',
  293. // headers: {
  294. // Accept: 'application/json',
  295. // 'Content-Type': 'multipart/form-data'
  296. // },
  297. // formData: { nickname: this.wxnickname },
  298. // success: (uploadFileRes) => {
  299. // console.log(9999)
  300. // // console.log(JSON.parse(uploadFileRes.data), 6666);
  301. // var dataimg = JSON.parse(uploadFileRes.data);
  302. // // console.log(dataimg.data.fullurl, 6666);
  303. // _this.$api.editMainBodyUser(
  304. // {
  305. // avatar: dataimg.data.fullurl,
  306. // main_body_id: 1,
  307. // main_body_user_id: this.mainBodyUserInfo.id,
  308. // nickname: this.wxnickname
  309. // },
  310. // (data) => {
  311. // _this.$common.successToShow('修改成功');
  312. // _this.mainBodyUserInfo.avatar =dataimg.data.fullurl;
  313. // _this.mainBodyUserInfo.nickname = _this.wxnickname;
  314. // _this.$db.set('mainBodyUserInfo', _this.mainBodyUserInfo);
  315. // console.log(_this.mainBodyUserInfo,56456456)
  316. // }
  317. // );
  318. // }
  319. // });
  320. // }
  321. }
  322. };
  323. </script>
  324. <style>
  325. .box {
  326. /* height: 100%; */
  327. /* background-color: #f3e2c8; */
  328. }
  329. button {
  330. border: none !important;
  331. border: transparent !important;
  332. padding: 0 !important;
  333. }
  334. .bg_box {
  335. width: 100%;
  336. height: 800rpx;
  337. position: relative;
  338. top: -182rpx;
  339. background: url('https://huli-app.wenlvti.net/app_static/WenWuGuanJia/image/user_bg.png') no-repeat;
  340. background-size: 100% 100%;
  341. }
  342. .top_box {
  343. width: 90%;
  344. height: 450rpx;
  345. margin-left: 40rpx;
  346. display: flex;
  347. align-items: center;
  348. justify-content: space-between;
  349. }
  350. .img {
  351. width: 108rpx;
  352. height: 108rpx;
  353. border: 4rpx solid #af7e44;
  354. border-radius: 50%;
  355. }
  356. .img_box {
  357. display: flex;
  358. align-items: center;
  359. }
  360. .name {
  361. font-size: 44rpx;
  362. margin-left: 30rpx;
  363. line-height: 60rpx;
  364. color: #444444;
  365. }
  366. .btm_box {
  367. margin-top: -620rpx;
  368. width: 750rpx;
  369. height: 100vh;
  370. position: relative;
  371. padding: 40rpx;
  372. z-index: 2;
  373. border-radius: 24rpx 24rpx 0rpx 0rpx;
  374. background-color: #fff9e9;
  375. }
  376. .item {
  377. height: 80rpx;
  378. display: flex;
  379. align-items: center;
  380. justify-content: space-between;
  381. }
  382. .item_tit {
  383. margin-left: 20rpx;
  384. font-size: 32rpx;
  385. font-weight: 900;
  386. line-height: 48rpx;
  387. background: linear-gradient(180deg, #af7e44 0%, #934b36 100%);
  388. -webkit-background-clip: text;
  389. -webkit-text-fill-color: transparent;
  390. }
  391. .box-guanzhu3{
  392. background-image: linear-gradient(160deg, rgba(162, 255, 146, 1.0) 0, rgba(84, 218, 255, 1.0) 100%);
  393. border-radius: 52rpx;
  394. height: 55rpx;
  395. display: flex;
  396. flex-direction: row;
  397. justify-self: center;
  398. width: 80%;
  399. position: fixed;
  400. bottom: 95rpx;
  401. right: 66rpx;
  402. z-index:999;
  403. }
  404. .guanzhu-1{
  405. flex-grow: 5;
  406. text-align: center;
  407. margin-top: 10rpx;
  408. }
  409. </style>