app-user-center-top.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <view class="app-user-center-top cross-center" :style="{'background-image': 'url('+topPicUrl+')'}">
  3. <!-- style 3 start -->
  4. <view class="style-3 box-grow-1 main-center" v-if="topStyle == '3'">
  5. <view class="style-3-container dir-left-nowrap cross-center"
  6. :style="userCenter.style_bg_pic_url?`background-image: url(${userCenter.style_bg_pic_url})`:``">
  7. <view class="box-grow-0 avatar-container">
  8. <image :src="avatar" :class="[userInfo.is_vip_card_user && is_icon_super_vip == '1' ? 'avatar is_vip' : 'avatar']"></image>
  9. <image v-if="userInfo.is_vip_card_user && is_icon_super_vip == '1'" src="/static/image/vip_icon.png" class="vip_icon"></image>
  10. </view>
  11. <view class="box-grow-1 info-container">
  12. <template v-if="isLogin">
  13. <view class="dir-left-nowrap cross-center">
  14. <view class="nickname t-omit">{{userInfo.nickname}}</view>
  15. <!--#ifdef MP-WEIXIN-->
  16. <button class="u-refresh dir-left-nowrap main-between cross-center member-margin"
  17. open-type="getUserInfo"
  18. scope="userInfo"
  19. @getAuthorize="getUserInfo"
  20. @getuserinfo="getUserInfo"
  21. >
  22. <icon class="u-icon"></icon>
  23. <text>刷新</text>
  24. </button>
  25. <!-- #endif-->
  26. </view>
  27. <app-form-id @click="goMember" v-if="mall.setting.is_icon_members_grade == 1">
  28. <view class="member-info inline-flex cross-center dir-left-nowrap">
  29. <view>
  30. <image :src="getMemberPicUrl" class="member-icon" mode="aspectFill"></image>
  31. </view>
  32. <view class="t-omit">{{userInfo.identity.level_name}}</view>
  33. </view>
  34. </app-form-id>
  35. </template>
  36. <template v-else>
  37. <app-form-id>
  38. <view class="login-btn" @click="callLogin">点击登录</view>
  39. </app-form-id>
  40. </template>
  41. </view>
  42. <view class="box-grow-0 address-container">
  43. <app-jump-button form url="/pages/address/address">
  44. <view class="address-btn-3" >
  45. <image class="address-btn-icon" src="/static/image/icon/address-gray.png"></image>
  46. <view>收货地址</view>
  47. </view>
  48. </app-jump-button>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- style 3 end -->
  53. <!-- style 2 start -->
  54. <view class="style-2 box-grow-1" v-else-if="topStyle == '2'">
  55. <view class="avatar-container">
  56. <image :src="avatar" :class="[userInfo.is_vip_card_user && is_icon_super_vip == '1' ? 'avatar is_vip' : 'avatar']"></image>
  57. <image v-if="userInfo.is_vip_card_user && is_icon_super_vip == '1'" src="/static/image/vip_icon.png" class="vip_icon"></image>
  58. </view>
  59. <view class="info-container">
  60. <template v-if="isLogin">
  61. <app-form-id @click="goMember" v-if="mall.setting.is_icon_members_grade == 1">
  62. <view class="member-info inline-flex cross-center dir-left-nowrap">
  63. <view>
  64. <image :src="getMemberPicUrl" class="member-icon" mode="aspectFill"></image>
  65. </view>
  66. <view class="t-omit">{{userInfo.identity.level_name}}</view>
  67. </view>
  68. </app-form-id>
  69. <view class="dir-left-nowrap cross-center main-center">
  70. <view class="nickname t-omit"
  71. :class="[mall.setting.is_icon_members_grade != 1 ? 'no-member-icon' : '',]">
  72. {{userInfo.nickname}}</view>
  73. <!--#ifdef MP-WEIXIN-->
  74. <button class="u-refresh dir-left-nowrap main-between cross-center"
  75. :class="[mall.setting.is_icon_members_grade != 1 ? 'no-member-icon' : '',]"
  76. open-type="getUserInfo"
  77. scope="userInfo"
  78. @getAuthorize="getUserInfo"
  79. @getuserinfo="getUserInfo"
  80. >
  81. <icon class="u-icon"></icon>
  82. <text>刷新</text>
  83. </button>
  84. <!-- #endif-->
  85. </view>
  86. </template>
  87. <template v-else>
  88. <app-form-id>
  89. <view class="login-btn" @click="callLogin">点击登录</view>
  90. </app-form-id>
  91. </template>
  92. </view>
  93. </view>
  94. <!-- style 2 end -->
  95. <!-- style 1 start -->
  96. <view class="style-1 dir-left-nowrap cross-center box-grow-1" v-else-if="topStyle == '1'">
  97. <view class="box-grow-0 avatar-container">
  98. <image :src="avatar" :class="[userInfo.is_vip_card_user && is_icon_super_vip == '1' ? 'avatar is_vip' : 'avatar']"></image>
  99. <image v-if="userInfo.is_vip_card_user && is_icon_super_vip == '1'" src="/static/image/vip_icon.png" class="vip_icon"></image>
  100. </view>
  101. <view class="box-grow-1 info-container">
  102. <template v-if="isLogin">
  103. <view class="dir-left-nowrap cross-center">
  104. <view class="nickname t-omit">{{userInfo.nickname}}</view>
  105. <!--#ifdef MP-WEIXIN-->
  106. <button class="u-refresh dir-left-nowrap main-between cross-center member-margin" open-type="getUserInfo"
  107. scope="userInfo"
  108. @getAuthorize="getUserInfo"
  109. @getuserinfo="getUserInfo">
  110. <icon class="u-icon"></icon>
  111. <text>刷新</text>
  112. </button>
  113. <!-- #endif-->
  114. </view>
  115. <app-form-id @click="goMember" v-if="mall.setting.is_icon_members_grade == 1">
  116. <view class="member-info inline-flex cross-center dir-left-nowrap">
  117. <view>
  118. <image :src="getMemberPicUrl" class="member-icon" mode="aspectFill"></image>
  119. </view>
  120. <view class="t-omit">{{userInfo.identity.level_name}}</view>
  121. </view>
  122. </app-form-id>
  123. </template>
  124. <template v-else>
  125. <app-form-id>
  126. <view class="login-btn" @click="callLogin">点击登录</view>
  127. </app-form-id>
  128. </template>
  129. </view>
  130. <view class="box-grow-0 address-container">
  131. <app-jump-button form url="/pages/address/address">
  132. <view class="address-btn-1 dir-left-nowrap cross-center" style="background-color:#F84469;">
  133. <view>
  134. <image class="address-btn-icon" src="/static/image/icon/address-white.png"></image>
  135. </view>
  136. <view>收货地址</view>
  137. </view>
  138. </app-jump-button>
  139. </view>
  140. </view>
  141. <!-- style 1 end -->
  142. </view>
  143. </template>
  144. <script>
  145. import {mapState, mapGetters} from 'vuex';
  146. export default {
  147. name: 'app-user-center-top',
  148. props: {
  149. topStyle: String,
  150. topPicUrl: String,
  151. memberPicUrl: String,
  152. is_icon_super_vip: {
  153. type: String,
  154. default() {
  155. return '0';
  156. }
  157. },
  158. },
  159. computed: {
  160. isLogin() {
  161. return this.$user.isLogin();
  162. },
  163. ...mapState({
  164. mall: state => state.mallConfig.mall,
  165. }),
  166. ...mapGetters({
  167. userCenter: 'mallConfig/getUserCenter',
  168. userInfo: 'user/info',
  169. }),
  170. avatar() {
  171. if (this.isLogin && this.userInfo) {
  172. return this.userInfo.avatar;
  173. } else {
  174. return '/static/image/user-default-avatar.png';
  175. }
  176. },
  177. getMemberPicUrl() {
  178. return this.memberPicUrl;
  179. // todo 此处选哪个图标待确认
  180. if (this.memberPicUrl) {
  181. return this.memberPicUrl;
  182. } else {
  183. return this.userInfo.identity.member_pic_url;
  184. }
  185. },
  186. },
  187. created() {
  188. if (this.isLogin) {
  189. this.$store.dispatch('user/info', {refresh: true});
  190. } else {
  191. }
  192. },
  193. methods: {
  194. callLogin() {
  195. this.$store.dispatch('user/accessToken');
  196. },
  197. goMember() {
  198. uni.navigateTo({
  199. url: '/pages/member/index/index',
  200. });
  201. },
  202. getUserInfo(userInfoResult) {
  203. let _this = this;
  204. uni.login({
  205. scopes: 'auth_user',
  206. success(loginResult) {
  207. const data = {
  208. encryptedData: userInfoResult.detail.encryptedData,
  209. iv: userInfoResult.detail.iv,
  210. rawData: userInfoResult.detail.rawData,
  211. signature: userInfoResult.detail.signature,
  212. code: loginResult.code,
  213. };
  214. _this.$request({
  215. url: _this.$api.passport.login,
  216. method: 'post',
  217. data: data
  218. }).then(response => {
  219. uni.hideLoading();
  220. if (response.code === 0) {
  221. uni.showToast({
  222. title: '资料已更新',
  223. icon: 'none'
  224. });
  225. uni.setStorageSync('_USER_ACCESS_TOKEN', response.data.access_token);
  226. } else {
  227. return reject(response.msg);
  228. }
  229. });
  230. }
  231. });
  232. }
  233. },
  234. }
  235. </script>
  236. <style scoped lang="scss">
  237. .app-user-center-top {
  238. width: #{750rpx};
  239. height: #{300rpx};
  240. background-repeat: no-repeat;
  241. background-size: cover;
  242. background-position: center;
  243. overflow: hidden;
  244. }
  245. .avatar {
  246. width: #{132rpx};
  247. height: #{132rpx};
  248. border-radius: #{1000rpx};
  249. }
  250. .avatar.is_vip {
  251. border: #{8rpx} solid #ffe993;
  252. }
  253. .login-btn {
  254. display: inline-block;
  255. padding: #{12rpx} #{24rpx};
  256. font-size: $uni-font-size-import-one;
  257. }
  258. .avatar-container {
  259. padding: #{24rpx};
  260. position: relative;
  261. }
  262. .style-2 .vip_icon {
  263. left: 50%;
  264. margin-left: 29rpx;
  265. }
  266. .vip_icon {
  267. position: absolute;
  268. right: 0;
  269. top: 0;
  270. width: 58rpx;
  271. height: 57rpx;
  272. }
  273. .info-container {
  274. padding: #{0rpx};
  275. position: relative;
  276. z-index: 1000;
  277. }
  278. .address-container {
  279. padding: #{24rpx};
  280. }
  281. .member-info {
  282. background: #3c3642;
  283. color: #fff;
  284. font-size: $uni-font-size-weak-two;
  285. padding: #{6rpx} #{12rpx};
  286. border-radius: #{1000rpx};
  287. height: #{36rpx};
  288. line-height: #{36rpx};
  289. .member-icon {
  290. display: block;
  291. width: #{44rpx};
  292. height: #{44rpx};
  293. margin-top: -#{6rpx};
  294. margin-bottom: -#{6rpx};
  295. margin-left: -#{12rpx};
  296. margin-right: #{6rpx};
  297. border-radius: #{1000rpx};
  298. overflow: hidden;
  299. }
  300. }
  301. .address-btn-3 {
  302. text-align: center;
  303. font-size: $uni-font-size-general-two;
  304. color: $uni-general-color-two;
  305. .address-btn-icon {
  306. width: #{56rpx};
  307. height: #{56rpx};
  308. }
  309. }
  310. .address-btn-1 {
  311. padding: #{16rpx} #{18rpx};
  312. border-radius: #{1000rpx} 0 0 #{1000rpx};
  313. margin-right: -#{48rpx};
  314. background: #ff4544;
  315. color: #ffffff;
  316. .address-btn-icon {
  317. width: #{44rpx};
  318. height: #{44rpx};
  319. margin-right: #{12rpx};
  320. display: block;
  321. }
  322. }
  323. .style-3 {
  324. .style-3-container {
  325. background-color: #fff;
  326. border-radius: #{12rpx};
  327. width: #{656rpx};
  328. height: #{220rpx};
  329. background-size: 100% 100%;
  330. .nickname {
  331. margin-bottom: #{12rpx};
  332. color: $uni-important-color-black;
  333. }
  334. }
  335. .u-refresh.member-margin {
  336. margin-bottom: 12upx;
  337. }
  338. }
  339. .style-2 {
  340. text-align: center;
  341. .info-container {
  342. margin-top: -#{50rpx};
  343. }
  344. .nickname {
  345. color: #fff;
  346. }
  347. .nickname.no-member-icon {
  348. margin-top: #{30rpx};
  349. }
  350. .u-refresh.no-member-icon {
  351. margin-top: #{30rpx};
  352. }
  353. .login-btn {
  354. color: #fff;
  355. margin-top: #{40rpx};
  356. }
  357. }
  358. .style-1 {
  359. padding: 0 #{24rpx};
  360. .nickname {
  361. color: #fff;
  362. margin-bottom: #{12rpx};
  363. }
  364. .u-refresh.member-margin {
  365. margin-bottom: 12upx;
  366. }
  367. }
  368. .u-refresh {
  369. border-radius: 18upx;
  370. border: 1upx solid #ffffff;
  371. min-width: 69upx;
  372. margin:0 0 0 10upx;
  373. box-sizing: content-box;
  374. height: 37upx;
  375. padding: 0 13upx;
  376. background-color: transparent;
  377. transform: rotateZ(360deg);
  378. .u-icon {
  379. width: 21upx;
  380. height: 21upx;
  381. background-image: url('../../../static/image/icon/refresh.png');
  382. background-size: 100% 100%;
  383. background-repeat: no-repeat;
  384. margin-right: 5upx;
  385. }
  386. text {
  387. line-height: 1;
  388. color: #ffffff;
  389. font-size: 21upx;
  390. }
  391. }
  392. </style>