index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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/share.png', name: '分销中心', href: '/pages/share/index' },
  110. { icon: '/static/image/my-page/protocol.png', name: '用户协议', href: '/pages/my/protocol' }
  111. ],
  112. recharge: {
  113. show: false
  114. },
  115. code: null
  116. }
  117. },
  118. computed: {
  119. ...mapState({
  120. userInfo: seate => seate.user.info
  121. })
  122. },
  123. methods: {
  124. getHistory() {
  125. this.$api.user.episode.record({ limit: 3 }).then(res => {
  126. this.history = res.data
  127. })
  128. },
  129. handleMenu(menu) {
  130. if (menu.href) {
  131. this.$u.route(menu.href)
  132. }
  133. },
  134. handleGetUserInfo(res) {
  135. // #ifdef MP-KUAISHOU
  136. this.$loading('数据刷新中...')
  137. uni.authorize({
  138. scope: 'scope.userInfo',
  139. success: () => {
  140. uni.getUserInfo({
  141. withCredentials: true,
  142. success: res => {
  143. this.getCode().then(code => {
  144. const params = {
  145. encryptedData: res.encryptedData,
  146. iv: res.iv,
  147. signature: res.signature,
  148. code: code
  149. }
  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. }
  161. })
  162. // #endif
  163. // #ifdef MP-TOUTIAO
  164. uni.getUserProfile({
  165. success: res => {
  166. this.getCode().then(code => {
  167. const params = {
  168. encryptedData: res.encryptedData,
  169. iv: res.iv,
  170. signature: res.signature,
  171. code: code
  172. }
  173. this.$loading('数据刷新中...')
  174. this.$api.user.update(params).then(res => {
  175. this.code = null
  176. this.$hideLoading()
  177. this.$store.dispatch('user/info', res.data)
  178. }).catch(() => {
  179. this.$hideLoading()
  180. })
  181. })
  182. }
  183. })
  184. // #endif
  185. // #ifdef MP-WEIXIN
  186. this.$api.user.update({ avatar: res.detail.avatarUrl }).then(res => {
  187. this.code = null
  188. this.$hideLoading()
  189. this.$store.dispatch('user/info', res.data)
  190. }).catch(() => {
  191. this.$hideLoading()
  192. })
  193. // #endif
  194. },
  195. handleNickname(res) {
  196. if (res.detail.value === '填写昵称') {
  197. return
  198. }
  199. this.$api.user.update({ nickname: res.detail.value }).then(res => {
  200. this.code = null
  201. this.$hideLoading()
  202. this.$store.dispatch('user/info', res.data)
  203. }).catch(() => {
  204. this.$hideLoading()
  205. })
  206. },
  207. getCode() {
  208. return new Promise(resolve => {
  209. if (this.code) {
  210. return resolve(this.code)
  211. }
  212. uni.login({
  213. provider: uni.$u.platform,
  214. success: loginRes => {
  215. this.code = loginRes.code
  216. // 四分钟失效
  217. setTimeout(() => {
  218. this.code = null
  219. }, 1000 * 4 * 60)
  220. resolve(this.code)
  221. }
  222. })
  223. })
  224. }
  225. },
  226. onShow() {
  227. this.getHistory()
  228. }
  229. }
  230. </script>
  231. <style lang="scss" scoped>
  232. .container {
  233. padding: 20px 20rpx 180rpx;
  234. font-size: 30rpx;
  235. >.header{
  236. .user-box{
  237. .head-img{
  238. .avatar{
  239. background: transparent;
  240. }
  241. image{
  242. width: 100rpx;
  243. height: 100rpx;
  244. border-radius: 50%;
  245. }
  246. }
  247. .base{
  248. margin-left: 30rpx;
  249. .nickname{
  250. color: $primary-color;
  251. font-size: 32rpx;
  252. }
  253. .vip{
  254. font-size: 22rpx;
  255. color: #fff;
  256. margin-top: 6rpx;
  257. }
  258. }
  259. }
  260. .refresh{
  261. background: $primary-color;
  262. color: #fff;
  263. border-radius: 30rpx;
  264. padding: 10rpx 0;
  265. width: 140rpx;
  266. text-align: center;
  267. letter-spacing: .1rem;
  268. line-height: initial;
  269. }
  270. }
  271. .recharge{
  272. background: url("/static/image/my-recharge-bg.png") no-repeat center;
  273. background-size: 100%;
  274. height: 200rpx;
  275. margin-top: 20rpx;
  276. margin-bottom: 10rpx;
  277. .static-box{
  278. margin-left: 30rpx;
  279. .icon{
  280. border-radius: 20rpx;
  281. image{
  282. width: 100rpx;
  283. height: 100rpx;
  284. }
  285. }
  286. .overage{
  287. font-weight: 800;
  288. margin-left: 20rpx;
  289. font-size: 32rpx;
  290. }
  291. }
  292. .recharge-btn{
  293. border: 1rpx solid #fff;
  294. padding: 10rpx 0 ;
  295. text-align: center;
  296. width: 140rpx;
  297. margin-right: 20rpx;
  298. border-radius: 30rpx;
  299. color: #ffffff;
  300. }
  301. }
  302. .history{
  303. background: #1B203C;
  304. height: 300rpx;
  305. border-radius: 15rpx;
  306. padding: 20rpx 30rpx;
  307. margin-bottom: 40rpx;
  308. >.header{
  309. text{
  310. color: $info-color;
  311. font-weight: 600;
  312. }
  313. }
  314. .content{
  315. margin-top: 20rpx;
  316. .episode{
  317. width: calc(100%/4);
  318. margin-left: 20rpx;
  319. &:first-child{
  320. margin-left: 0;
  321. }
  322. .cover-image{
  323. image{
  324. width: 100%;
  325. height: 200rpx;
  326. border-radius: 16rpx;
  327. }
  328. }
  329. }
  330. }
  331. }
  332. .menu-group{
  333. .menu-item{
  334. padding: 20rpx 0;
  335. background: transparent;
  336. border: none;
  337. text-align: unset;
  338. width: 100%;
  339. line-height: initial;
  340. font-size: initial;
  341. justify-content: space-between;
  342. &:after{
  343. content: unset;
  344. }
  345. .left-box{
  346. flex: 1;
  347. .icon{
  348. transform: translateY(4rpx);
  349. image{
  350. width: 55rpx;
  351. height: 55rpx;
  352. }
  353. }
  354. text{
  355. color: #fff;
  356. margin-left: 10rpx;
  357. }
  358. }
  359. }
  360. }
  361. }
  362. </style>