index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. // #ifdef MP-KUAISHOU
  112. this.$loading('数据刷新中...')
  113. uni.authorize({
  114. scope: 'scope.userInfo',
  115. success: () => {
  116. uni.getUserInfo({
  117. withCredentials: true,
  118. success: res => {
  119. this.getCode().then(code => {
  120. const params = {
  121. encryptedData: res.encryptedData,
  122. iv: res.iv,
  123. signature: res.signature,
  124. code: code
  125. }
  126. this.$api.user.update(params).then(res => {
  127. this.code = null
  128. this.$hideLoading()
  129. this.$store.dispatch('user/info', res.data)
  130. }).catch(() => {
  131. this.$hideLoading()
  132. })
  133. })
  134. }
  135. })
  136. }
  137. })
  138. // #endif
  139. // #ifdef MP-TOUTIAO
  140. uni.getUserProfile({
  141. success: res => {
  142. this.getCode().then(code => {
  143. const params = {
  144. encryptedData: res.encryptedData,
  145. iv: res.iv,
  146. signature: res.signature,
  147. code: code
  148. }
  149. this.$loading('数据刷新中...')
  150. this.$api.user.update(params).then(res => {
  151. this.code = null
  152. this.$hideLoading()
  153. this.$store.dispatch('user/info', res.data)
  154. }).catch(() => {
  155. this.$hideLoading()
  156. })
  157. })
  158. }
  159. })
  160. // #endif
  161. },
  162. getCode() {
  163. return new Promise(resolve => {
  164. if (this.code) {
  165. return resolve(this.code)
  166. }
  167. uni.login({
  168. provider: uni.$u.platform,
  169. success: loginRes => {
  170. this.code = loginRes.code
  171. // 四分钟失效
  172. setTimeout(() => {
  173. this.code = null
  174. }, 1000 * 4 * 60)
  175. resolve(this.code)
  176. }
  177. })
  178. })
  179. }
  180. },
  181. onLoad() {
  182. this.getHistory()
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. .container {
  188. padding: 20px 20rpx 0;
  189. font-size: 30rpx;
  190. >.header{
  191. .user-box{
  192. .head-img{
  193. image{
  194. width: 100rpx;
  195. height: 100rpx;
  196. border-radius: 50%;
  197. }
  198. }
  199. .base{
  200. margin-left: 30rpx;
  201. .nickname{
  202. color: $primary-color;
  203. font-size: 32rpx;
  204. }
  205. .vip{
  206. font-size: 22rpx;
  207. color: #fff;
  208. margin-top: 6rpx;
  209. }
  210. }
  211. }
  212. .refresh{
  213. background: $primary-color;
  214. color: #fff;
  215. border-radius: 30rpx;
  216. padding: 10rpx 0;
  217. width: 140rpx;
  218. text-align: center;
  219. letter-spacing: .1rem;
  220. line-height: initial;
  221. }
  222. }
  223. .recharge{
  224. background: url("/static/image/my-recharge-bg.png") no-repeat center;
  225. background-size: 100%;
  226. height: 200rpx;
  227. margin-top: 20rpx;
  228. margin-bottom: 10rpx;
  229. .static-box{
  230. margin-left: 30rpx;
  231. .icon{
  232. border-radius: 20rpx;
  233. image{
  234. width: 100rpx;
  235. height: 100rpx;
  236. }
  237. }
  238. .overage{
  239. font-weight: 800;
  240. margin-left: 20rpx;
  241. font-size: 32rpx;
  242. }
  243. }
  244. .recharge-btn{
  245. border: 1rpx solid #fff;
  246. padding: 10rpx 0 ;
  247. text-align: center;
  248. width: 140rpx;
  249. margin-right: 20rpx;
  250. border-radius: 30rpx;
  251. color: #ffffff;
  252. }
  253. }
  254. .history{
  255. background: #1B203C;
  256. height: 300rpx;
  257. border-radius: 15rpx;
  258. padding: 20rpx 30rpx;
  259. margin-bottom: 40rpx;
  260. >.header{
  261. text{
  262. color: $info-color;
  263. font-weight: 600;
  264. }
  265. }
  266. .content{
  267. margin-top: 20rpx;
  268. .episode{
  269. width: calc(100%/4);
  270. margin-left: 20rpx;
  271. &:first-child{
  272. margin-left: 0;
  273. }
  274. .cover-image{
  275. image{
  276. width: 100%;
  277. height: 200rpx;
  278. }
  279. }
  280. }
  281. }
  282. }
  283. .menu-group{
  284. .menu-item{
  285. padding: 20rpx 0;
  286. background: transparent;
  287. border: none;
  288. text-align: unset;
  289. width: 100%;
  290. line-height: initial;
  291. font-size: initial;
  292. justify-content: space-between;
  293. &:after{
  294. content: unset;
  295. }
  296. .left-box{
  297. flex: 1;
  298. .icon{
  299. transform: translateY(4rpx);
  300. image{
  301. width: 55rpx;
  302. height: 55rpx;
  303. }
  304. }
  305. text{
  306. color: #fff;
  307. margin-left: 10rpx;
  308. }
  309. }
  310. }
  311. }
  312. }
  313. </style>