index.vue 10.0 KB

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