index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. btnLock: false
  141. }
  142. },
  143. computed: {
  144. ...mapState({
  145. userInfo: seate => seate.user.info
  146. })
  147. },
  148. methods: {
  149. getHistory() {
  150. this.$api.user.episode.record({ limit: 3 }).then(res => {
  151. this.history = res.data
  152. })
  153. },
  154. handleMenu(menu) {
  155. // #ifdef MP-KUAISHOU
  156. if (menu.type === 'contact') {
  157. ks.makePhoneCall({
  158. phoneNumber: this.config.contact,
  159. success(res) {
  160. console.log('-->success', res)
  161. },
  162. fail(err) {
  163. console.log('-->error', err)
  164. }
  165. })
  166. }
  167. // #endif
  168. if (menu.href) {
  169. this.$u.route(menu.href)
  170. }
  171. },
  172. // 微信获取头像
  173. handleGetWechatUserInfo() {
  174. this.modal.show = true
  175. this.modal.nickname = this.userInfo.nickname
  176. this.modal.avatar = this.userInfo.avatar
  177. },
  178. // 微信获取头像
  179. handleChooseAvatar({ detail }) {
  180. this.modal.avatar = detail.avatarUrl
  181. },
  182. handleChangeNickname(res) {
  183. this.modal.nickname = res.detail.value
  184. },
  185. // 微信获取头像
  186. handleConfirmWechatUserInfo() {
  187. console.log('-->data', this.modal)
  188. if (!this.modal.avatar) {
  189. this.$u.toast('请上传头像')
  190. return
  191. }
  192. if (!this.modal.nickname) {
  193. this.$u.toast('请填写昵称')
  194. return
  195. }
  196. this.$loading('数据提交中...')
  197. this.$api.user.update({ avatar: this.modal.avatar, nickname: this.modal.nickname }).then(res => {
  198. this.code = null
  199. this.$hideLoading()
  200. this.$store.dispatch('user/info', res.data)
  201. this.modal.show = false
  202. }).catch(() => {
  203. this.$hideLoading()
  204. })
  205. },
  206. handleGetUserInfo(res) {
  207. if (this.btnLock) return
  208. this.btnLock = true
  209. // #ifdef MP-KUAISHOU
  210. this.$loading('数据刷新中...')
  211. uni.authorize({
  212. scope: 'scope.userInfo',
  213. success: () => {
  214. uni.getUserInfo({
  215. withCredentials: true,
  216. success: res => {
  217. this.getCode().then(code => {
  218. const params = {
  219. encryptedData: res.encryptedData,
  220. iv: res.iv,
  221. signature: res.signature,
  222. code: code
  223. }
  224. this.$api.user.update(params).then(res => {
  225. this.btnLock = false
  226. this.code = null
  227. this.$hideLoading()
  228. this.$store.dispatch('user/info', res.data)
  229. }).catch(() => {
  230. this.code = null
  231. this.btnLock = false
  232. this.$hideLoading()
  233. })
  234. })
  235. },
  236. fail: () => {
  237. this.btnLock = false
  238. }
  239. })
  240. },
  241. fail: () => {
  242. this.btnLock = false
  243. }
  244. })
  245. // #endif
  246. // #ifdef MP-TOUTIAO
  247. uni.getUserProfile({
  248. success: res => {
  249. this.getCode().then(code => {
  250. const params = {
  251. encryptedData: res.encryptedData,
  252. iv: res.iv,
  253. signature: res.signature,
  254. code: code
  255. }
  256. this.$loading('数据刷新中...')
  257. this.$api.user.update(params).then(res => {
  258. this.btnLock = false
  259. this.code = null
  260. this.$hideLoading()
  261. this.$store.dispatch('user/info', res.data)
  262. }).catch(() => {
  263. this.code = null
  264. this.btnLock = false
  265. this.$hideLoading()
  266. })
  267. })
  268. },
  269. fail: () => {
  270. this.btnLock = false
  271. }
  272. })
  273. // #endif
  274. },
  275. getCode() {
  276. return new Promise((resolve, reject) => {
  277. if (this.code) {
  278. return resolve(this.code)
  279. }
  280. uni.login({
  281. provider: uni.$u.platform,
  282. success: loginRes => {
  283. this.code = loginRes.code
  284. // 四分钟失效
  285. setTimeout(() => {
  286. this.code = null
  287. }, 1000 * 4 * 60)
  288. resolve(this.code)
  289. },
  290. fail: () => {
  291. this.btnLock = false
  292. reject()
  293. }
  294. })
  295. })
  296. },
  297. getConfig() {
  298. this.$api.setting.config().then(res => {
  299. this.config = res.data
  300. })
  301. }
  302. },
  303. onShow() {
  304. this.getHistory()
  305. this.getConfig()
  306. }
  307. }
  308. </script>
  309. <style lang="scss" scoped>
  310. .container {
  311. padding: 20px 20rpx 180rpx;
  312. font-size: 30rpx;
  313. >.header{
  314. .user-box{
  315. .head-img{
  316. .avatar{
  317. background: transparent;
  318. }
  319. image{
  320. width: 100rpx;
  321. height: 100rpx;
  322. border-radius: 50%;
  323. }
  324. }
  325. .base{
  326. margin-left: 30rpx;
  327. .nickname{
  328. color: $primary-color;
  329. font-size: 32rpx;
  330. }
  331. .vip{
  332. font-size: 22rpx;
  333. color: #fff;
  334. margin-top: 6rpx;
  335. }
  336. }
  337. }
  338. .refresh{
  339. background: $primary-color;
  340. color: #fff;
  341. border-radius: 30rpx;
  342. padding: 10rpx 0;
  343. width: 140rpx;
  344. text-align: center;
  345. letter-spacing: .1rem;
  346. line-height: initial;
  347. }
  348. }
  349. .recharge{
  350. background: url("/static/image/my-recharge-bg.png") no-repeat center;
  351. background-size: 100%;
  352. height: 200rpx;
  353. margin-top: 20rpx;
  354. margin-bottom: 10rpx;
  355. .static-box{
  356. margin-left: 30rpx;
  357. .icon{
  358. border-radius: 20rpx;
  359. image{
  360. width: 100rpx;
  361. height: 100rpx;
  362. }
  363. }
  364. .overage{
  365. font-weight: 800;
  366. margin-left: 20rpx;
  367. font-size: 32rpx;
  368. }
  369. }
  370. .recharge-btn{
  371. border: 1rpx solid #fff;
  372. padding: 10rpx 0 ;
  373. text-align: center;
  374. width: 140rpx;
  375. margin-right: 20rpx;
  376. border-radius: 30rpx;
  377. color: #ffffff;
  378. }
  379. }
  380. .history{
  381. background: $bg-op-color;
  382. height: 300rpx;
  383. border-radius: 15rpx;
  384. padding: 20rpx 30rpx;
  385. margin-bottom: 40rpx;
  386. >.header{
  387. text{
  388. color: $info-color;
  389. font-weight: 600;
  390. }
  391. }
  392. .content{
  393. margin-top: 20rpx;
  394. .episode{
  395. width: calc(100%/4);
  396. margin-left: 20rpx;
  397. &:first-child{
  398. margin-left: 0;
  399. }
  400. .cover-image{
  401. image{
  402. width: 100%;
  403. height: 200rpx;
  404. border-radius: 16rpx;
  405. }
  406. }
  407. }
  408. }
  409. }
  410. .menu-group{
  411. .menu-item{
  412. padding: 20rpx 0;
  413. background: transparent;
  414. border: none;
  415. text-align: unset;
  416. width: 100%;
  417. line-height: initial;
  418. font-size: initial;
  419. justify-content: space-between;
  420. &:after{
  421. content: unset;
  422. }
  423. .left-box{
  424. flex: 1;
  425. .icon{
  426. transform: translateY(4rpx);
  427. image{
  428. width: 55rpx;
  429. height: 55rpx;
  430. }
  431. }
  432. text{
  433. color: #fff;
  434. margin-left: 10rpx;
  435. }
  436. }
  437. }
  438. }
  439. /* 微信获取用户信息 弹窗*/
  440. .slot-content{
  441. width: 100%;
  442. .avatar{
  443. background: transparent;
  444. &:after{
  445. content: unset;
  446. }
  447. image{
  448. width: 140rpx;
  449. height: 140rpx;
  450. border-radius: 50%;
  451. }
  452. }
  453. .nickname{
  454. width: 100%;
  455. margin: 30rpx 0 50rpx;
  456. border: 1rpx solid #ccc;
  457. padding: 0 20rpx;
  458. height: 76rpx;
  459. line-height: 76rpx;
  460. border-radius: 10rpx;
  461. }
  462. .confirm{
  463. background: $primary-color;
  464. color: #fff;
  465. border-radius: 30rpx;
  466. padding: 12rpx 0;
  467. width: 100%;
  468. text-align: center;
  469. letter-spacing: .1rem;
  470. line-height: initial;
  471. }
  472. }
  473. }
  474. </style>