user.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <view class="container">
  3. <view class="top-image">
  4. <image src="../../static/img/user-top.png" mode="widthFix"></image>
  5. <view class="user-wrap">
  6. <image :src="userInfo.avatar" mode="" v-if="userInfo.avatar" class="user-avatar"></image>
  7. <image src="../../static/error/missing-face.png" mode="" class="user-avatar" v-else></image>
  8. <view class="user-name clamp" v-if="userInfo.nickname">
  9. {{ userInfo.nickname}}
  10. </view>
  11. <view class="user-name clamp" v-else>
  12. 游客
  13. </view>
  14. <view class="user-level" v-if="userInfo.nickname">
  15. {{userInfo.level == 0? '普通用户': '会员'}}
  16. </view>
  17. </view>
  18. </view>
  19. <!-- <view class="u-up" @click="navTo('/pages/user/menber')">
  20. <image src="../../static/img/u-up.png" mode="" class="u-up-bg"></image>
  21. <view class="u-up-tit">
  22. 开通会员享受更多权益
  23. </view>
  24. <view class="u-up-btn">
  25. 去申请
  26. </view>
  27. </view> -->
  28. <!-- <view class="my-box" @click="navTo('/pages/user/mytimes')">
  29. <view class="box-tit flex">
  30. <image src="../../static/icon/u1.png" mode="" class="left-img"></image>
  31. <view class="">
  32. 我的次数
  33. </view>
  34. <image src="../../static/icon/back.png" mode="" class="right-img"></image>
  35. </view>
  36. <view class="box-msg flex">
  37. <view class="msg-item flex">
  38. <view class="msg-val">
  39. 0
  40. </view>
  41. <view class="msg-name">
  42. 获得次数
  43. </view>
  44. </view>
  45. <view class="msg-item flex">
  46. <view class="msg-val">
  47. 0
  48. </view>
  49. <view class="msg-name">
  50. 使用次数
  51. </view>
  52. </view>
  53. <view class="msg-item flex">
  54. <view class="msg-val">
  55. 0
  56. </view>
  57. <view class="msg-name">
  58. 可用次数
  59. </view>
  60. </view>
  61. </view>
  62. </view> -->
  63. <view class="user-list flex" @click="navTo('/pages/user/myjslis')">
  64. <image src="../../static/icon/ul1.png" mode="" class="left-img"></image>
  65. <view class="">
  66. 计算记录
  67. </view>
  68. <image src="../../static/icon/back.png" mode="" class="right-img"></image>
  69. </view>
  70. <!-- <view class="user-list flex">
  71. <image src="../../static/icon/ul2.png" mode="" class="left-img"></image>
  72. <view class="">
  73. 关于我们
  74. </view>
  75. <image src="../../static/icon/back.png" mode="" class="right-img"></image>
  76. </view> -->
  77. <view class="user-list flex" @click="navTo('/pages/set/userinfo')">
  78. <image src="../../static/icon/ul3.png" mode="" class="left-img"></image>
  79. <view class="">
  80. 设置
  81. </view>
  82. <image src="../../static/icon/back.png" mode="" class="right-img"></image>
  83. </view>
  84. </view>
  85. </template>
  86. <script>
  87. import {
  88. mapState,
  89. mapMutations
  90. } from 'vuex';
  91. import uniList from '@/components/uni-list/uni-list.vue';
  92. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  93. import {
  94. orderData,
  95. getUserInfo
  96. } from '@/api/user.js';
  97. import {
  98. saveUrl,
  99. interceptor
  100. } from '@/utils/loginUtils.js';
  101. let startY = 0,
  102. moveY = 0,
  103. pageAtTop = true;
  104. export default {
  105. components: {
  106. uniList,
  107. uniListItem
  108. },
  109. data() {
  110. return {
  111. coverTransform: 'translateY(0px)',
  112. coverTransition: '0s',
  113. moving: false,
  114. };
  115. },
  116. onShow() {
  117. // 判断是否已经登录
  118. if (this.hasLogin) {
  119. this.loadBaseData();
  120. }else {
  121. this.loadBaseData();
  122. }
  123. },
  124. computed: {
  125. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
  126. },
  127. methods: {
  128. ...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
  129. // 加载初始数据
  130. loadBaseData() {
  131. getUserInfo({})
  132. .then(({
  133. data
  134. }) => {
  135. this.setUserInfo(data);
  136. // 获取用户数据完毕后在获取订单数据防止多次跳转到登录页
  137. orderData({})
  138. .then(({
  139. data
  140. }) => {
  141. this.setOrderInfo(data);
  142. })
  143. .catch(e => {
  144. this.setOrderInfo({
  145. complete_count: 0, //完成
  146. received_count: 0, //待收货
  147. unshipped_count: 0, //待发货
  148. order_count: 0, //订单总数
  149. unpaid_count: 0 //待付款
  150. });
  151. });
  152. })
  153. .catch(e => {
  154. console.log(e);
  155. });
  156. },
  157. /**
  158. * 统一跳转接口,拦截未登录路由
  159. * navigator标签现在默认没有转场动画,所以用view
  160. */
  161. navTo(url) {
  162. if (!this.hasLogin) {
  163. // 保存地址
  164. saveUrl();
  165. // 登录拦截
  166. interceptor();
  167. } else {
  168. uni.navigateTo({
  169. url
  170. });
  171. }
  172. },
  173. /**
  174. * 会员卡下拉和回弹
  175. * 1.关闭bounce避免ios端下拉冲突
  176. * 2.由于touchmove事件的缺陷(以前做小程序就遇到,比如20跳到40,h5反而好很多),下拉的时候会有掉帧的感觉
  177. * transition设置0.1秒延迟,让css来过渡这段空窗期
  178. * 3.回弹效果可修改曲线值来调整效果,推荐一个好用的bezier生成工具 http://cubic-bezier.com/
  179. */
  180. coverTouchstart(e) {
  181. // console.log(e);
  182. if (pageAtTop === false) {
  183. return;
  184. }
  185. this.coverTransition = 'transform .1s linear';
  186. startY = e.touches[0].clientY;
  187. },
  188. coverTouchmove(e) {
  189. // console.log(e);
  190. moveY = e.touches[0].clientY;
  191. let moveDistance = moveY - startY;
  192. let maxDowm = this.userMaxDowm;
  193. let Dowm = this.userDowm;
  194. if (moveDistance < 0) {
  195. this.moving = false;
  196. return;
  197. }
  198. this.moving = true;
  199. if (moveDistance >= Dowm && moveDistance < maxDowm) {
  200. moveDistance = Dowm;
  201. }
  202. if (moveDistance > 0 && moveDistance <= Dowm) {
  203. this.coverTransform = `translateY(${moveDistance}px)`;
  204. }
  205. },
  206. coverTouchend() {
  207. if (this.moving === false) {
  208. return;
  209. }
  210. this.moving = false;
  211. this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
  212. this.coverTransform = 'translateY(0px)';
  213. }
  214. }
  215. };
  216. </script>
  217. <style lang="scss">
  218. page {
  219. height: 100%;
  220. }
  221. .top-image {
  222. position: relative;
  223. // height: 230rpx;
  224. height: 370rpx;
  225. width: 750rpx;
  226. image {
  227. width: 100%;
  228. // height: 100%;
  229. }
  230. }
  231. .user-wrap {
  232. position: absolute;
  233. width: 692rpx;
  234. height: 293rpx;
  235. background: #FFFFFF;
  236. box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
  237. border-radius: 28rpx;
  238. top: 83rpx;
  239. left: 0;
  240. right: 0;
  241. margin: auto;
  242. display: flex;
  243. flex-direction: column;
  244. justify-content: center;
  245. align-items: center;
  246. .user-avatar {
  247. width: 132rpx;
  248. height: 132rpx;
  249. border-radius: 50%;
  250. }
  251. .user-name {
  252. text-align: center;
  253. width: 300rpx;
  254. font-size: 30rpx;
  255. font-weight: bold;
  256. color: #333333;
  257. padding: 15rpx 0 ;
  258. }
  259. .user-level {
  260. font-size: 20rpx;
  261. font-weight: 500;
  262. color: #FF7E3E;
  263. }
  264. }
  265. .u-up {
  266. width: 690rpx;
  267. height: 90rpx;
  268. margin: 20rpx auto;
  269. position: relative;
  270. image {
  271. width: 690rpx;
  272. height: 90rpx;
  273. }
  274. .u-up-tit {
  275. font-size: 30rpx;
  276. font-weight: bold;
  277. color: #6A4714;
  278. line-height: 90rpx;
  279. position: absolute;
  280. top: 0;
  281. left: 80rpx;
  282. }
  283. .u-up-btn {
  284. position: absolute;
  285. right: 20rpx;
  286. top: 0;
  287. bottom: 0;
  288. margin: auto;
  289. width: 148rpx;
  290. height: 50rpx;
  291. line-height: 50rpx;
  292. border-radius: 25rpx;
  293. font-size: 28rpx;
  294. font-weight: 500;
  295. color: #F0E1C9;
  296. text-align: center;
  297. background: linear-gradient(-90deg, #8C5F1D 0%, #8C5F1C 77%, #875916 99%);
  298. }
  299. }
  300. .my-box {
  301. width: 690rpx;
  302. height: 246rpx;
  303. background: #FFFFFF;
  304. box-shadow: 0px 4rpx 13rpx 0px rgba(229,229,229,0.46);
  305. border-radius: 20rpx;
  306. margin: 20rpx auto;
  307. .box-tit {
  308. font-size: 28rpx;
  309. font-weight: bold;
  310. color: #333333;
  311. padding: 0 25rpx;
  312. height: 80rpx;
  313. .left-img {
  314. width: 33rpx;
  315. height: 32rpx;
  316. }
  317. view {
  318. padding-left: 20rpx;
  319. flex-grow: 1;
  320. }
  321. .right-img {
  322. width: 13rpx;
  323. height: 23rpx;
  324. }
  325. }
  326. .box-msg {
  327. height: 165rpx;
  328. .msg-item {
  329. width: 33%;
  330. flex-direction: column;
  331. justify-content: center;
  332. align-items: center;
  333. .msg-val {
  334. font-size: 36px;
  335. font-weight: bold;
  336. color: #333333;
  337. }
  338. .msg-name {
  339. font-size: 22rpx;
  340. font-weight: 500;
  341. color: #666666;
  342. }
  343. }
  344. }
  345. }
  346. .user-list {
  347. width: 691rpx;
  348. height: 104rpx;
  349. background: #FFFFFF;
  350. box-shadow: 0px 0px 20rpx 0px rgba(50,50,52,0.06);
  351. border-radius: 28rpx;
  352. margin:20rpx auto;
  353. padding: 0 25rpx;
  354. .left-img {
  355. width: 40rpx;
  356. height: 40rpx;
  357. }
  358. view {
  359. padding-left: 20rpx;
  360. flex-grow: 1;
  361. font-size: 29rpx;
  362. font-weight: bold;
  363. color: #5D5D5D;
  364. }
  365. .right-img {
  366. width: 13rpx;
  367. height: 23rpx;
  368. }
  369. }
  370. </style>