index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <view class="container">
  3. <!--用户信息-->
  4. <view class="header main-between cross-center">
  5. <view class="user-box main-left cross-center">
  6. <view class="head-img">
  7. <image :src="userInfo.avatar?userInfo.avatar:'@/static/image/default-head-img.png'" />
  8. </view>
  9. <view class="base">
  10. <view v-if="!userInfo.nickname" class="nickname cross-center" @click="handleGetUserInfo">未授权登陆</view>
  11. <view v-if="userInfo.nickname" class="nickname cross-center">{{ userInfo.nickname }}</view>
  12. <view v-if="userInfo.info.is_vip" class="vip cross-center">
  13. VIP到期时间: {{ userInfo.info.end_at }}
  14. </view>
  15. </view>
  16. </view>
  17. <button open-type="getUserInfo" class="refresh" @click="handleGetUserInfo">刷新</button>
  18. </view>
  19. <!--充值-->
  20. <view class="recharge main-between cross-center">
  21. <view class="static-box main-left cross-center">
  22. <view class="icon">
  23. <image src="/static/image/gold-bag.png" mode="aspectFill" />
  24. </view>
  25. <view class="overage">{{ userInfo.info.integral }}金币</view>
  26. </view>
  27. <view class="recharge-btn" @click="recharge.show = true">充值</view>
  28. </view>
  29. <!--历史-->
  30. <view class="history" @click="$u.route('/pages/my/history')">
  31. <view class="header main-between cross-center">
  32. <text>历史观看记录</text>
  33. <u-icon name="arrow-right" :color="$colors.infoColor" bold />
  34. </view>
  35. <view class="content dir-left-nowrap cross-center">
  36. <view
  37. v-for="(item,index) in history"
  38. :key="index"
  39. class="episode"
  40. >
  41. <view class="cover-image">
  42. <image :src="item.detail.episode.cover_img" mode="aspectFill" />
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <!--菜单-->
  48. <view class="menu-group">
  49. <button
  50. v-for="(menu,index) in menus"
  51. :key="index"
  52. class="menu-item main-between cross-center"
  53. :open-type="menu.type ? menu.type : ''"
  54. @click="handleMenu(menu)"
  55. >
  56. <view class="left-box dir-left-nowrap cross-center">
  57. <view class="icon">
  58. <image :src="menu.icon" />
  59. </view>
  60. <text>{{ menu.name }}</text>
  61. </view>
  62. <u-icon name="arrow-right" :color="$colors.infoColor" bold />
  63. </button>
  64. </view>
  65. <!--tab bar-->
  66. <tab-bar />
  67. <!--充值-->
  68. <recharge :show.sync="recharge.show" />
  69. </view>
  70. </template>
  71. <script>
  72. import TabBar from '../../components/TabBar/index'
  73. import { mapState } from 'vuex'
  74. import Recharge from '../../components/Recharge/index'
  75. export default {
  76. name: 'My',
  77. components: { Recharge, TabBar },
  78. data() {
  79. return {
  80. history: [],
  81. menus: [
  82. { icon: '/static/image/my-page/order.png', name: '消费记录', href: '/pages/my/consume' },
  83. { icon: '/static/image/my-page/recharge.png', name: '充值记录', href: '/pages/my/recharge' },
  84. { icon: '/static/image/my-page/share.png', name: '分享好友', type: 'share' },
  85. { icon: '/static/image/my-page/contact.png', name: '联系客服', type: 'contact' },
  86. { icon: '/static/image/my-page/protocol.png', name: '用户协议', href: '/pages/my/protocol' }
  87. ],
  88. recharge: {
  89. show: false
  90. },
  91. code: null
  92. }
  93. },
  94. computed: {
  95. ...mapState({
  96. userInfo: seate => seate.user.info
  97. })
  98. },
  99. methods: {
  100. getHistory() {
  101. this.$api.user.episode.record().then(res => {
  102. this.history = res.data
  103. })
  104. },
  105. handleMenu(menu) {
  106. if (menu.href) {
  107. this.$u.route(menu.href)
  108. }
  109. },
  110. handleGetUserInfo() {
  111. uni.getUserProfile({
  112. success: res => {
  113. this.getCode().then(code => {
  114. const params = {
  115. encryptedData: res.encryptedData,
  116. iv: res.iv,
  117. signature: res.signature,
  118. code: code
  119. }
  120. this.$loading('数据刷新中...')
  121. this.$api.user.update(params).then(res => {
  122. this.code = null
  123. this.$hideLoading()
  124. this.$store.dispatch('user/info', res.data)
  125. }).catch(() => {
  126. this.$hideLoading()
  127. })
  128. })
  129. }
  130. })
  131. },
  132. getCode() {
  133. return new Promise(resolve => {
  134. if (this.code) {
  135. return resolve(this.code)
  136. }
  137. uni.login({
  138. provider: uni.$u.platform,
  139. success: loginRes => {
  140. this.code = loginRes.code
  141. // 四分钟失效
  142. setTimeout(() => {
  143. this.code = null
  144. }, 1000 * 4 * 60)
  145. resolve(this.code)
  146. }
  147. })
  148. })
  149. }
  150. },
  151. onLoad() {
  152. this.getHistory()
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. .container {
  158. padding: 20px 20rpx 0;
  159. font-size: 30rpx;
  160. >.header{
  161. .user-box{
  162. .head-img{
  163. image{
  164. width: 100rpx;
  165. height: 100rpx;
  166. border-radius: 50%;
  167. }
  168. }
  169. .base{
  170. margin-left: 30rpx;
  171. .nickname{
  172. color: $primary-color;
  173. font-size: 32rpx;
  174. }
  175. .vip{
  176. font-size: 22rpx;
  177. color: #fff;
  178. margin-top: 6rpx;
  179. }
  180. }
  181. }
  182. .refresh{
  183. background: $primary-color;
  184. color: #fff;
  185. border-radius: 30rpx;
  186. padding: 10rpx 0;
  187. width: 140rpx;
  188. text-align: center;
  189. letter-spacing: .1rem;
  190. line-height: initial;
  191. }
  192. }
  193. .recharge{
  194. background: url("/static/image/my-recharge-bg.png") no-repeat center;
  195. background-size: 100%;
  196. height: 200rpx;
  197. margin-top: 20rpx;
  198. margin-bottom: 10rpx;
  199. .static-box{
  200. margin-left: 30rpx;
  201. .icon{
  202. border-radius: 20rpx;
  203. image{
  204. width: 100rpx;
  205. height: 100rpx;
  206. }
  207. }
  208. .overage{
  209. font-weight: 800;
  210. margin-left: 20rpx;
  211. font-size: 32rpx;
  212. }
  213. }
  214. .recharge-btn{
  215. border: 1rpx solid #fff;
  216. padding: 10rpx 0 ;
  217. text-align: center;
  218. width: 140rpx;
  219. margin-right: 20rpx;
  220. border-radius: 30rpx;
  221. color: #ffffff;
  222. }
  223. }
  224. .history{
  225. background: #1B203C;
  226. height: 300rpx;
  227. border-radius: 15rpx;
  228. padding: 20rpx 30rpx;
  229. margin-bottom: 40rpx;
  230. >.header{
  231. text{
  232. color: $info-color;
  233. font-weight: 600;
  234. }
  235. }
  236. .content{
  237. margin-top: 20rpx;
  238. .episode{
  239. width: calc(100%/4);
  240. margin-left: 20rpx;
  241. &:first-child{
  242. margin-left: 0;
  243. }
  244. .cover-image{
  245. image{
  246. width: 100%;
  247. height: 200rpx;
  248. }
  249. }
  250. }
  251. }
  252. }
  253. .menu-group{
  254. .menu-item{
  255. padding: 20rpx 0;
  256. background: transparent;
  257. border: none;
  258. text-align: unset;
  259. width: 100%;
  260. line-height: initial;
  261. font-size: initial;
  262. justify-content: space-between;
  263. &:after{
  264. content: unset;
  265. }
  266. .left-box{
  267. flex: 1;
  268. .icon{
  269. transform: translateY(4rpx);
  270. image{
  271. width: 55rpx;
  272. height: 55rpx;
  273. }
  274. }
  275. text{
  276. color: #fff;
  277. margin-left: 10rpx;
  278. }
  279. }
  280. }
  281. }
  282. }
  283. </style>