index.vue 10 KB

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