index.vue 11 KB

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