index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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
  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 }}</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="">客服电话:18133054315</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. myList(i) {
  182. uni.navigateTo({
  183. url: this.items[i].path
  184. });
  185. },
  186. // 获取头像
  187. onChooseAvatar(e) {
  188. this.mainBodyUserInfo.avatar = e.detail.avatarUrl;
  189. // this.avatarUrl = e.detail.avatarUrl;
  190. },
  191. // 获取昵称
  192. blurname(e) {
  193. this.wxnickname = e.detail.value;
  194. this.mainBodyUserInfo.nickname = e.detail.value;
  195. },
  196. isOk() {
  197. if (this.wxnickname == '' || this.wxnickname == undefined) {
  198. this.$common.errorToShow('请输入昵称');
  199. } else {
  200. this.modifyShow = false;
  201. let userToken = '';
  202. let auth = this.$db.get('auth');
  203. userToken = auth.token;
  204. // 准备formData,无论filePath是否存在都添加
  205. let formData = {
  206. nickname: this.wxnickname
  207. };
  208. // 如果有图片路径,则准备上传
  209. let uploadPromise = Promise.resolve();
  210. if (this.mainBodyUserInfo.avatar) {
  211. uploadPromise = new Promise((resolve, reject) => {
  212. uni.uploadFile({
  213. url: this.$config.baseUrl + 'api/common/upload?token=' + userToken,
  214. filePath: this.mainBodyUserInfo.avatar,
  215. fileType: 'image',
  216. name: 'file',
  217. headers: {
  218. Accept: 'application/json',
  219. 'Content-Type': 'multipart/form-data'
  220. },
  221. formData: formData,
  222. success: (uploadFileRes) => {
  223. var dataimg = JSON.parse(uploadFileRes.data);
  224. formData.avatar = dataimg.data.fullurl; // 若上传成功,更新formData中的avatar
  225. resolve(); // 成功后调用resolve
  226. },
  227. fail: (err) => {
  228. console.error('图片上传失败', err);
  229. reject(err); // 失败后调用reject,但后续操作仍会执行
  230. },
  231. complete: () => {
  232. // 无论成功还是失败,都继续执行编辑用户信息的API调用
  233. _this.$api.editMainBodyUser(
  234. {
  235. avatar: formData.avatar || '', // 确保有值,即使上传失败也尝试提交
  236. main_body_id: 1,
  237. main_body_user_id: this.mainBodyUserInfo.id,
  238. nickname: this.wxnickname
  239. },
  240. (data) => {
  241. _this.$common.successToShow('修改成功');
  242. if (formData.avatar) {
  243. // 只有上传成功才更新
  244. _this.mainBodyUserInfo.avatar = formData.avatar;
  245. }
  246. _this.mainBodyUserInfo.nickname = _this.wxnickname;
  247. _this.$db.set('mainBodyUserInfo', _this.mainBodyUserInfo);
  248. // console.log(_this.mainBodyUserInfo,56456456);
  249. }
  250. );
  251. }
  252. });
  253. });
  254. }
  255. }
  256. }
  257. // isOk() {
  258. // this.modifyShow = false;
  259. // let userToken = '';
  260. // let auth = this.$db.get('auth');
  261. // userToken = auth.token;
  262. // uni.uploadFile({
  263. // url: this.$config.baseUrl + 'api/common/upload?token=' + userToken,
  264. // filePath: this.mainBodyUserInfo.avatar,
  265. // fileType: 'image',
  266. // name: 'file',
  267. // headers: {
  268. // Accept: 'application/json',
  269. // 'Content-Type': 'multipart/form-data'
  270. // },
  271. // formData: { nickname: this.wxnickname },
  272. // success: (uploadFileRes) => {
  273. // console.log(9999)
  274. // // console.log(JSON.parse(uploadFileRes.data), 6666);
  275. // var dataimg = JSON.parse(uploadFileRes.data);
  276. // // console.log(dataimg.data.fullurl, 6666);
  277. // _this.$api.editMainBodyUser(
  278. // {
  279. // avatar: dataimg.data.fullurl,
  280. // main_body_id: 1,
  281. // main_body_user_id: this.mainBodyUserInfo.id,
  282. // nickname: this.wxnickname
  283. // },
  284. // (data) => {
  285. // _this.$common.successToShow('修改成功');
  286. // _this.mainBodyUserInfo.avatar =dataimg.data.fullurl;
  287. // _this.mainBodyUserInfo.nickname = _this.wxnickname;
  288. // _this.$db.set('mainBodyUserInfo', _this.mainBodyUserInfo);
  289. // console.log(_this.mainBodyUserInfo,56456456)
  290. // }
  291. // );
  292. // }
  293. // });
  294. // }
  295. }
  296. };
  297. </script>
  298. <style>
  299. .box {
  300. /* height: 100%; */
  301. /* background-color: #f3e2c8; */
  302. }
  303. button {
  304. border: none !important;
  305. border: transparent !important;
  306. padding: 0 !important;
  307. }
  308. .bg_box {
  309. width: 100%;
  310. height: 800rpx;
  311. position: relative;
  312. top: -182rpx;
  313. background: url('https://huli-app.wenlvti.net/app_static/WenWuGuanJia/image/user_bg.png') no-repeat;
  314. background-size: 100% 100%;
  315. }
  316. .top_box {
  317. width: 90%;
  318. height: 450rpx;
  319. margin-left: 40rpx;
  320. display: flex;
  321. align-items: center;
  322. justify-content: space-between;
  323. }
  324. .img {
  325. width: 108rpx;
  326. height: 108rpx;
  327. border: 4rpx solid #af7e44;
  328. border-radius: 50%;
  329. }
  330. .img_box {
  331. display: flex;
  332. align-items: center;
  333. }
  334. .name {
  335. font-size: 44rpx;
  336. margin-left: 30rpx;
  337. line-height: 60rpx;
  338. color: #444444;
  339. }
  340. .btm_box {
  341. margin-top: -620rpx;
  342. width: 750rpx;
  343. height: 100vh;
  344. position: relative;
  345. padding: 40rpx;
  346. z-index: 2;
  347. border-radius: 24rpx 24rpx 0rpx 0rpx;
  348. background-color: #fff9e9;
  349. }
  350. .item {
  351. height: 80rpx;
  352. display: flex;
  353. align-items: center;
  354. justify-content: space-between;
  355. }
  356. .item_tit {
  357. margin-left: 20rpx;
  358. font-size: 32rpx;
  359. font-weight: 900;
  360. line-height: 48rpx;
  361. background: linear-gradient(180deg, #af7e44 0%, #934b36 100%);
  362. -webkit-background-clip: text;
  363. -webkit-text-fill-color: transparent;
  364. }
  365. </style>