index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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 class="avatar cross-center" @click="handleGetWechatUserInfo">
  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. <view v-if="!userInfo.nickname" class="nickname cross-center" @click="handleGetWechatUserInfo">未授权登陆</view>
  22. <!-- #endif -->
  23. <view v-if="userInfo.nickname" class="nickname cross-center">{{ userInfo.nickname }}</view>
  24. <view v-if="userInfo.info.is_vip" class="vip cross-center">
  25. VIP到期时间: {{ userInfo.info.end_at }}
  26. </view>
  27. </view>
  28. </view>
  29. <!-- #ifdef MP-KUAISHOU | MP-TOUTIAO -->
  30. <button open-type="getUserInfo" class="refresh" @click="handleGetUserInfo">刷新</button>
  31. <!-- #endif -->
  32. <!-- #ifdef MP-WEIXIN -->
  33. <button open-type="getUserInfo" class="refresh" @click="handleGetWechatUserInfo">刷新</button>
  34. <!-- #endif -->
  35. </view>
  36. <!--充值-->
  37. <view class="recharge main-between cross-center">
  38. <view class="static-box main-left cross-center">
  39. <view class="icon">
  40. <image src="/static/image/gold-bag.png" mode="aspectFill" />
  41. </view>
  42. <view class="overage">{{ userInfo.info.integral }}金币</view>
  43. </view>
  44. <view class="recharge-btn" @click="recharge.show = true">充值</view>
  45. </view>
  46. <!--历史-->
  47. <view class="history" @click="$u.route('/pages/my/history')">
  48. <view class="header main-between cross-center">
  49. <text>历史观看记录</text>
  50. <u-icon name="arrow-right" :color="$colors.infoColor" bold />
  51. </view>
  52. <view class="content dir-left-nowrap cross-center">
  53. <view
  54. v-for="(item,index) in history"
  55. :key="index"
  56. class="episode"
  57. >
  58. <view class="cover-image">
  59. <image :src="item.detail.episode.cover_img" mode="aspectFill" />
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <!--菜单-->
  65. <view class="menu-group">
  66. <template v-for="(menu,index) in menus">
  67. <button
  68. v-if="menu.href !== '/pages/share/index' || (menu.href === '/pages/share/index' && userInfo.is_share !== '0')"
  69. :key="index"
  70. class="menu-item main-between cross-center"
  71. :open-type="menu.type ? menu.type : ''"
  72. @bindcontact="handleMenu"
  73. @click="handleMenu(menu)"
  74. >
  75. <view class="left-box dir-left-nowrap cross-center">
  76. <view class="icon">
  77. <image :src="menu.icon" />
  78. </view>
  79. <text>{{ menu.name }}</text>
  80. </view>
  81. <u-icon name="arrow-right" :color="$colors.infoColor" bold />
  82. </button>
  83. </template>
  84. </view>
  85. <!--tab bar-->
  86. <tab-bar />
  87. <!--充值-->
  88. <recharge :show.sync="recharge.show" />
  89. <!-- #ifdef MP-WEIXIN -->
  90. <u-modal
  91. :show="modal.show"
  92. :title="modal.title"
  93. :show-confirm-button="false"
  94. >
  95. <view class="slot-content dir-top-wrap cross-center">
  96. <button open-type="chooseAvatar" class="avatar cross-center" @chooseavatar="handleChooseAvatar">
  97. <image :src="modal.avatar?modal.avatar:'/static/image/default-head-img.png'" />
  98. </button>
  99. <input
  100. class="nickname cross-center"
  101. type="nickname"
  102. :value="modal.nickname"
  103. placeholder="填写昵称"
  104. @change="handleChangeNickname"
  105. >
  106. <button class="confirm" @click="handleConfirmWechatUserInfo">提交</button>
  107. </view>
  108. </u-modal>
  109. <!-- #endif -->
  110. </view>
  111. </template>
  112. <script>
  113. import TabBar from '../../components/TabBar/index'
  114. import { mapState } from 'vuex'
  115. import Recharge from '../../components/Recharge/index'
  116. export default {
  117. name: 'My',
  118. components: { Recharge, TabBar },
  119. data() {
  120. return {
  121. history: [],
  122. menus: [
  123. { icon: '/static/image/my-page/order.png', name: '消费记录', href: '/pages/my/consume' },
  124. { icon: '/static/image/my-page/recharge.png', name: '充值记录', href: '/pages/my/recharge' },
  125. { icon: '/static/image/my-page/contact.png', name: '联系客服', type: 'contact' },
  126. { icon: '/static/image/my-page/share.png', name: '分享中心', href: '/pages/share/index' },
  127. { icon: '/static/image/my-page/protocol.png', name: '用户协议', href: '/pages/my/protocol' }
  128. ],
  129. recharge: {
  130. show: false
  131. },
  132. code: null,
  133. config: {},
  134. modal: {
  135. show: false,
  136. title: '用户信息获取',
  137. nickname: '',
  138. avatar: ''
  139. }
  140. }
  141. },
  142. computed: {
  143. ...mapState({
  144. userInfo: seate => seate.user.info
  145. })
  146. },
  147. methods: {
  148. getHistory() {
  149. this.$api.user.episode.record({ limit: 3 }).then(res => {
  150. this.history = res.data
  151. })
  152. },
  153. handleMenu(menu) {
  154. // #ifdef MP-KUAISHOU
  155. if (menu.type === 'contact') {
  156. ks.makePhoneCall({
  157. phoneNumber: this.config.contact,
  158. success(res) {
  159. console.log('-->success', res)
  160. },
  161. fail(err) {
  162. console.log('-->error', err)
  163. }
  164. })
  165. }
  166. // #endif
  167. if (menu.href) {
  168. this.$u.route(menu.href)
  169. }
  170. },
  171. // 微信获取头像
  172. handleGetWechatUserInfo() {
  173. this.modal.show = true
  174. this.modal.nickname = this.userInfo.nickname
  175. this.modal.avatar = this.userInfo.avatar
  176. },
  177. // 微信获取头像
  178. handleChooseAvatar({ detail }) {
  179. this.modal.avatar = detail.avatarUrl
  180. },
  181. handleChangeNickname(res) {
  182. this.modal.nickname = res.detail.value
  183. },
  184. // 微信获取头像
  185. handleConfirmWechatUserInfo() {
  186. console.log('-->data', this.modal)
  187. if (!this.modal.avatar) {
  188. this.$u.toast('请上传头像')
  189. return
  190. }
  191. if (!this.modal.nickname) {
  192. this.$u.toast('请填写昵称')
  193. return
  194. }
  195. this.$loading('数据提交中...')
  196. this.$api.user.update({ avatar: this.modal.avatar, nickname: this.modal.nickname }).then(res => {
  197. this.code = null
  198. this.$hideLoading()
  199. this.$store.dispatch('user/info', res.data)
  200. this.modal.show = false
  201. }).catch(() => {
  202. this.$hideLoading()
  203. })
  204. },
  205. handleGetUserInfo(res) {
  206. // #ifdef MP-KUAISHOU
  207. this.$loading('数据刷新中...')
  208. uni.authorize({
  209. scope: 'scope.userInfo',
  210. success: () => {
  211. uni.getUserInfo({
  212. withCredentials: true,
  213. success: res => {
  214. this.getCode().then(code => {
  215. const params = {
  216. encryptedData: res.encryptedData,
  217. iv: res.iv,
  218. signature: res.signature,
  219. code: code
  220. }
  221. this.$api.user.update(params).then(res => {
  222. this.code = null
  223. this.$hideLoading()
  224. this.$store.dispatch('user/info', res.data)
  225. }).catch(() => {
  226. this.$hideLoading()
  227. })
  228. })
  229. }
  230. })
  231. }
  232. })
  233. // #endif
  234. // #ifdef MP-TOUTIAO
  235. uni.getUserProfile({
  236. success: res => {
  237. this.getCode().then(code => {
  238. const params = {
  239. encryptedData: res.encryptedData,
  240. iv: res.iv,
  241. signature: res.signature,
  242. code: code
  243. }
  244. this.$loading('数据刷新中...')
  245. this.$api.user.update(params).then(res => {
  246. this.code = null
  247. this.$hideLoading()
  248. this.$store.dispatch('user/info', res.data)
  249. }).catch(() => {
  250. this.$hideLoading()
  251. })
  252. })
  253. }
  254. })
  255. // #endif
  256. },
  257. getCode() {
  258. return new Promise(resolve => {
  259. if (this.code) {
  260. return resolve(this.code)
  261. }
  262. uni.login({
  263. provider: uni.$u.platform,
  264. success: loginRes => {
  265. this.code = loginRes.code
  266. // 四分钟失效
  267. setTimeout(() => {
  268. this.code = null
  269. }, 1000 * 4 * 60)
  270. resolve(this.code)
  271. }
  272. })
  273. })
  274. },
  275. getConfig() {
  276. this.$api.setting.config().then(res => {
  277. this.config = res.data
  278. })
  279. }
  280. },
  281. onShow() {
  282. this.getHistory()
  283. this.getConfig()
  284. },
  285. onShareAppMessage() {
  286. console.log('-->data', this.$util.shareMessage(this.userInfo))
  287. return this.$util.shareMessage(this.userInfo)
  288. }
  289. }
  290. </script>
  291. <style lang="scss" scoped>
  292. .container {
  293. padding: 20px 20rpx 180rpx;
  294. font-size: 30rpx;
  295. >.header{
  296. .user-box{
  297. .head-img{
  298. .avatar{
  299. background: transparent;
  300. }
  301. image{
  302. width: 100rpx;
  303. height: 100rpx;
  304. border-radius: 50%;
  305. }
  306. }
  307. .base{
  308. margin-left: 30rpx;
  309. .nickname{
  310. color: $primary-color;
  311. font-size: 32rpx;
  312. }
  313. .vip{
  314. font-size: 22rpx;
  315. color: #fff;
  316. margin-top: 6rpx;
  317. }
  318. }
  319. }
  320. .refresh{
  321. background: $primary-color;
  322. color: #fff;
  323. border-radius: 30rpx;
  324. padding: 10rpx 0;
  325. width: 140rpx;
  326. text-align: center;
  327. letter-spacing: .1rem;
  328. line-height: initial;
  329. }
  330. }
  331. .recharge{
  332. background: url("/static/image/my-recharge-bg.png") no-repeat center;
  333. background-size: 100%;
  334. height: 200rpx;
  335. margin-top: 20rpx;
  336. margin-bottom: 10rpx;
  337. .static-box{
  338. margin-left: 30rpx;
  339. .icon{
  340. border-radius: 20rpx;
  341. image{
  342. width: 100rpx;
  343. height: 100rpx;
  344. }
  345. }
  346. .overage{
  347. font-weight: 800;
  348. margin-left: 20rpx;
  349. font-size: 32rpx;
  350. }
  351. }
  352. .recharge-btn{
  353. border: 1rpx solid #fff;
  354. padding: 10rpx 0 ;
  355. text-align: center;
  356. width: 140rpx;
  357. margin-right: 20rpx;
  358. border-radius: 30rpx;
  359. color: #ffffff;
  360. }
  361. }
  362. .history{
  363. background: $bg-op-color;
  364. height: 300rpx;
  365. border-radius: 15rpx;
  366. padding: 20rpx 30rpx;
  367. margin-bottom: 40rpx;
  368. >.header{
  369. text{
  370. color: $info-color;
  371. font-weight: 600;
  372. }
  373. }
  374. .content{
  375. margin-top: 20rpx;
  376. .episode{
  377. width: calc(100%/4);
  378. margin-left: 20rpx;
  379. &:first-child{
  380. margin-left: 0;
  381. }
  382. .cover-image{
  383. image{
  384. width: 100%;
  385. height: 200rpx;
  386. border-radius: 16rpx;
  387. }
  388. }
  389. }
  390. }
  391. }
  392. .menu-group{
  393. .menu-item{
  394. padding: 20rpx 0;
  395. background: transparent;
  396. border: none;
  397. text-align: unset;
  398. width: 100%;
  399. line-height: initial;
  400. font-size: initial;
  401. justify-content: space-between;
  402. &:after{
  403. content: unset;
  404. }
  405. .left-box{
  406. flex: 1;
  407. .icon{
  408. transform: translateY(4rpx);
  409. image{
  410. width: 55rpx;
  411. height: 55rpx;
  412. }
  413. }
  414. text{
  415. color: #fff;
  416. margin-left: 10rpx;
  417. }
  418. }
  419. }
  420. }
  421. /* 微信获取用户信息 弹窗*/
  422. .slot-content{
  423. width: 100%;
  424. .avatar{
  425. background: transparent;
  426. &:after{
  427. content: unset;
  428. }
  429. image{
  430. width: 140rpx;
  431. height: 140rpx;
  432. border-radius: 50%;
  433. }
  434. }
  435. .nickname{
  436. width: 100%;
  437. margin: 30rpx 0 50rpx;
  438. border: 1rpx solid #ccc;
  439. padding: 0 20rpx;
  440. height: 76rpx;
  441. line-height: 76rpx;
  442. border-radius: 10rpx;
  443. }
  444. .confirm{
  445. background: $primary-color;
  446. color: #fff;
  447. border-radius: 30rpx;
  448. padding: 12rpx 0;
  449. width: 100%;
  450. text-align: center;
  451. letter-spacing: .1rem;
  452. line-height: initial;
  453. }
  454. }
  455. }
  456. </style>