index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <template>
  2. <view class="container">
  3. <u-navbar :is-back="false" title="" :background="{ background: '#f7f7f7' }" :border-bottom="false">
  4. <view class="slot-wrap">
  5. <image src="https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/login-icon.png"
  6. mode="aspectFit" style="width: 300rpx;"></image>
  7. </view>
  8. </u-navbar>
  9. <view class="page-content">
  10. <swiper class="swiper" circular indicator-dots style="border-radius: 20rpx;overflow: hidden;height: 200px">
  11. <swiper-item v-for="(data, index) in swiperList" style="width: 100%;height: 100%;" :key="index">
  12. <view class="swiper-item" style="width: 100%;height: 100%;" @click="itemClick(data)">
  13. <image :src="data.imgUrl" mode="aspectFill" style="width: 100%;height: 100%;"></image>
  14. </view>
  15. </swiper-item>
  16. </swiper>
  17. <u-grid :col="4" :border="false" style="margin: 10rpx 0 ;">
  18. <template v-for="(item,index) in navList" :key="index">
  19. <u-grid-item bg-color="none" @click="jumpToPage(item)">
  20. <image
  21. :src="`https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/index-icon/${item.image}.png`"
  22. style="height: 70rpx;width: 70rpx;">
  23. </image>
  24. <view class="grid-text">{{item.title}}</view>
  25. </u-grid-item>
  26. </template>
  27. </u-grid>
  28. <u-card padding="20" margin="0rpx 0rpx 30rpx" border-radius="20"
  29. box-shadow="0px 2px 5px rgba(0, 0, 0, 0.1)">
  30. <template v-slot:head>
  31. <u-section title="课程预告" sub-title="查看更多" sub-color="#000000" @click="toPage('/pages/goOnEdu/index')"></u-section>
  32. </template>
  33. <template v-slot:body>
  34. <lg-swiper v-if="courseList.length!=0"
  35. :sildeItems="courseList"
  36. @swiperClick="swiperClick"
  37. image="courseImg" title="courseName"></lg-swiper>
  38. <u-empty text="暂无内容" mode="data" v-else></u-empty>
  39. </template>
  40. </u-card>
  41. <u-card padding="30" margin="0rpx 0rpx 30rpx" border-radius="20"
  42. box-shadow="0px 2px 5px rgba(0, 0, 0, 0.1)">
  43. <template v-slot:head>
  44. <u-section title="研究报告" sub-title="查看更多" sub-color="#000000" @click="toPage('/pages/researchReport/reportHome/reportHome')"></u-section>
  45. </template>
  46. <template v-slot:body>
  47. <view v-if="reportList.length!=0">
  48. <view v-for="(data,index) in reportList" :key="index" class="u-body-item u-flex u-p-t-0 "
  49. style="align-items: inherit;" @click="toReport(data.id, data.title)">
  50. <image :src="data.imgUrl" mode="aspectFill"></image>
  51. <view class="u-body-item-content">
  52. <view class="item-content">
  53. <text class="item-content-title text-ellipsis">{{data.title}}</text>
  54. <text class="item-content-type">{{data.type}}</text>
  55. </view>
  56. <view class="item-button">
  57. <view v-if="data.viewMode==='1'" class="func-box" style="justify-content: flex-end;">
  58. <view class="button free" >免费</view>
  59. </view>
  60. <view v-else-if="data.viewMode==='2' && isMember" class="func-box">
  61. <view class="price">¥{{ data.price }}元</view>
  62. <view class="button member-free">会员免费</view>
  63. </view>
  64. <view v-else-if="data.viewMode==='2' && !isMember" class="func-box">
  65. <view style="flex: 0 0 auto;display: flex;align-items: center;">
  66. <view class="member-free">
  67. 会员免费
  68. </view>
  69. <view class="not-member-price">
  70. 非会员:¥{{data.price}}元
  71. </view>
  72. </view>
  73. <view :class="['button', data.hasBuy ? 'free' : 'buy']">
  74. {{data.hasBuy ? '已购买' : '立即购买'}}
  75. </view>
  76. </view>
  77. <view v-else-if="data.viewMode==='3' && data.price===data.priceMember" class="func-box">
  78. <view class="price">¥{{ data.price }}元</view>
  79. <view :class="['button', data.hasBuy ? 'free' : 'buy']">
  80. {{data.hasBuy ? '已购买' : '立即购买'}}
  81. </view>
  82. </view>
  83. <view v-else-if="data.viewMode==='3' && data.price!==data.priceMember" class="func-box">
  84. <view style="flex: 0 0 auto;display: flex;align-items: center;">
  85. <view class="member-free">
  86. {{`会员:${data.priceMember}元`}}
  87. </view>
  88. <view class="not-member-price">
  89. 非会员:¥{{data.price}}元
  90. </view>
  91. </view>
  92. <view :class="['button', data.hasBuy ? 'free' : 'buy']">
  93. {{data.hasBuy ? '已购买' : '立即购买'}}
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. </view>
  100. <u-empty text="暂无内容" mode="data" v-else></u-empty>
  101. </template>
  102. </u-card>
  103. </view>
  104. <u-modal v-model="loginModal" mask-close-able class="modal" show-cancel-button
  105. :title-style="{fontWeight: 'bold'}" @confirm="confirmModal">
  106. <view class="modal-content">
  107. <text>请登录后使用该功能</text>
  108. </view>
  109. </u-modal>
  110. <!-- 与包裹页面所有内容的元素u-page同级,且在它的下方 -->
  111. <u-tabbar v-model="tabbarCurrentIndex" :list="tabbarList" icon-size="50" :active-color="tabbarActiveColor" :inactive-color="tabbarInactiveColor"></u-tabbar>
  112. </view>
  113. </template>
  114. <script setup>
  115. import lgSwiper from '@/components/lgSwiper.vue'
  116. import {
  117. onMounted,
  118. ref,
  119. computed
  120. } from 'vue'
  121. import {
  122. onReady,
  123. onLoad,
  124. onShow
  125. } from '@dcloudio/uni-app'
  126. import {
  127. useAuthStore
  128. } from '@/store/authStore'
  129. import {
  130. count
  131. } from '@/api/chat.js'
  132. import {
  133. homeCourseList,
  134. homeReportList,
  135. homeSetting,
  136. homeSwiperList
  137. } from '@/api/home.js'
  138. import {
  139. me
  140. } from '@/api/user.js'
  141. import { useTabbarStore } from '@/store/tabbarStore.js'
  142. const tabbarStore = useTabbarStore()
  143. // 底部导航栏数据
  144. const tabbarList = computed(() => {
  145. return tabbarStore.list
  146. })
  147. // 底部导航栏选中颜色
  148. const tabbarActiveColor = computed(() => {
  149. return tabbarStore.activeColor
  150. })
  151. // 底部导航栏未选中颜色
  152. const tabbarInactiveColor = computed(() => {
  153. return tabbarStore.inactiveColor
  154. })
  155. const tabbarCurrentIndex = 0
  156. const authStore = useAuthStore()
  157. // 屏幕状态栏高度
  158. const statusBarHeight = ref(0)
  159. // 顶部导航栏高度
  160. const navBarHeight = ref(0)
  161. // 是否登录
  162. const loginModal = ref(false)
  163. // 是否为会员,从缓存里拿取用户信息
  164. // const userInfo = uni.getStorageSync("userinfo") || {}
  165. const isMemberMap = {
  166. 0: true,
  167. 1: false
  168. }
  169. const isMember = ref(false)
  170. // 首页-轮播图
  171. const swiperList = ref([{
  172. imgUrl: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.YKoZzgmubNBxQ8j-mmoTKAHaEK?rs=1&pid=ImgDetMain',
  173. id: 1
  174. },
  175. {
  176. imgUrl: 'https://pic3.zhimg.com/v2-e52354ffdbd94a8e0a7649eacd34a788_r.jpg?source=1940ef5c',
  177. id: 2
  178. },
  179. {
  180. imgUrl: 'https://desk-fd.zol-img.com.cn/t_s960x600c5/g4/M03/00/0C/Cg-4zFS8bC-Ie9zBADCvovJAqiEAATJ8wDX__cAMK-6184.jpg',
  181. id: 3
  182. },
  183. ])
  184. const courseList = ref([{
  185. courseImg: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.YKoZzgmubNBxQ8j-mmoTKAHaEK?rs=1&pid=ImgDetMain',
  186. id: 1,
  187. courseName: '【8月8日】房地产经纪进阶培训班'
  188. },
  189. {
  190. courseImg: 'https://pic3.zhimg.com/v2-e52354ffdbd94a8e0a7649eacd34a788_r.jpg?source=1940ef5c',
  191. id: 2,
  192. courseName: '【8月9日】《房地产中介服务规范》培训'
  193. },
  194. {
  195. courseImg: 'https://desk-fd.zol-img.com.cn/t_s960x600c5/g4/M03/00/0C/Cg-4zFS8bC-Ie9zBADCvovJAqiEAATJ8wDX__cAMK-6184.jpg',
  196. id: 3,
  197. courseName: '【已结束】《广州市房屋租赁管理规定》'
  198. },
  199. ])
  200. // 首页-导航栏
  201. const navList = ref([{
  202. id: 'notice',
  203. title: '通知公告',
  204. image: 'notice',
  205. url: '/pages/notice/notice/notice',
  206. toOtherApp: false,
  207. otherAppId: '其他小程序的appid'
  208. },
  209. {
  210. id: 'dynamic',
  211. title: '协会动态',
  212. image: 'dynamic',
  213. url: '/pages/dynamic/dynamic/dynamic',
  214. toOtherApp: false,
  215. otherAppId: '其他小程序的appid'
  216. },
  217. {
  218. id: 'guide',
  219. title: '办事指引',
  220. image: 'guide',
  221. url: '/pages/guide/guide/guide',
  222. toOtherApp: false,
  223. otherAppId: '其他小程序的appid'
  224. },
  225. {
  226. id: 'edu',
  227. title: '继续教育',
  228. image: 'edu',
  229. url: '/pages/goOnEdu/index',
  230. toOtherApp: false,
  231. otherAppId: '其他小程序的appid'
  232. },
  233. {
  234. id: 'level',
  235. title: '水平认证',
  236. image: 'level',
  237. url: '跳转页面的路径',
  238. toOtherApp: true,
  239. otherAppId: '其他小程序的appid'
  240. },
  241. {
  242. id: 'report',
  243. title: '研究报告',
  244. image: 'report',
  245. url: '/pages/researchReport/reportHome/reportHome',
  246. toOtherApp: false,
  247. otherAppId: '其他小程序的appid'
  248. },
  249. {
  250. id: 'index',
  251. title: '经理人指数',
  252. image: 'index',
  253. url: '跳转页面的路径',
  254. toOtherApp: true,
  255. otherAppId: '其他小程序的appid'
  256. },
  257. {
  258. id: 'pay',
  259. title: '会费缴交',
  260. image: 'pay',
  261. url: '跳转页面的路径',
  262. toOtherApp: true,
  263. otherAppId: '其他小程序的appid'
  264. }
  265. ])
  266. const reportList = ref(
  267. [])
  268. // 跳转页面
  269. const jumpToPage = (data) => {
  270. if (data.toOtherApp) {
  271. // 跳转其他小程序
  272. console.log("跳转至其他小程序", data.otherAppId)
  273. return
  274. }
  275. if (!authStore.isAuthenticated) {
  276. loginModal.value = true
  277. return
  278. }
  279. uni.navigateTo({
  280. url: data.url
  281. })
  282. }
  283. // 确认跳转至登录
  284. const confirmModal = () => {
  285. uni.navigateTo({
  286. url: "/pages/initial/initial"
  287. })
  288. }
  289. const toPage = (url) => {
  290. if (!authStore.isAuthenticated) {
  291. loginModal.value = true
  292. return
  293. }
  294. uni.navigateTo({
  295. url: url
  296. })
  297. }
  298. const itemClick = (data) =>{
  299. // console.log("轮播图swiper", data)
  300. if (!authStore.isAuthenticated) {
  301. loginModal.value = true
  302. return
  303. }
  304. uni.navigateTo({
  305. url: "/pages/swiperDetail/swiperDetail?id=" + data.id
  306. })
  307. }
  308. const swiperClick = (data) => {
  309. // console.log(data, "课程预告数据")
  310. if (!authStore.isAuthenticated) {
  311. loginModal.value = true
  312. return
  313. }
  314. uni.navigateTo({
  315. url: `/pages/goOnEdu/course/courseDetail/courseDetail?id=${data.id}&name=${data.courseName}`
  316. });
  317. }
  318. function initUser() {
  319. me().then(res => {
  320. if (res?.data) {
  321. authStore.setUserInfo(res.data);
  322. isMember.value = res.data.isMember;
  323. }
  324. })
  325. }
  326. function init() {
  327. homeSwiperList().then(res => {
  328. if (res?.data) {
  329. swiperList.value = res.data
  330. }
  331. })
  332. homeCourseList().then(res => {
  333. // console.log(1000, res.data)
  334. if (res?.data) {
  335. courseList.value = res.data
  336. console.log(courseList.value)
  337. }
  338. })
  339. homeReportList().then(res => {
  340. if (res?.data) {
  341. reportList.value = res.data
  342. }
  343. })
  344. // homeSetting().then(res=>{
  345. // console.log(res)
  346. // })
  347. }
  348. function getCharCount() {
  349. count().then(res => {
  350. if (res && res.message === 'success') {
  351. tabbarStore.setMessageCount(res.data.amount)
  352. uni.setTabBarBadge({ //显示数字
  353. index: 1, //tabbar下标
  354. text: `${res.data.amount}` ?? '0' //数字
  355. })
  356. }
  357. })
  358. }
  359. function toReport(id, title){
  360. if (!authStore.isAuthenticated) {
  361. loginModal.value = true
  362. return
  363. }
  364. uni.navigateTo({
  365. url:"/pages/reportDetail/reportDetail?id="+id+"&title="+title
  366. })
  367. }
  368. onReady(() => {
  369. uni.getSystemInfo({
  370. success(e) {
  371. statusBarHeight.value = e.statusBarHeight;
  372. let custom = uni.getMenuButtonBoundingClientRect();
  373. navBarHeight.value = custom.height + (custom.top - e.statusBarHeight) * 2;
  374. }
  375. })
  376. })
  377. onLoad(() => {
  378. init()
  379. // initUser()
  380. })
  381. onShow(() => {
  382. const isLogin = authStore.isAuthenticated;
  383. const isUserInfo = authStore.isUserInfo;
  384. if (isLogin) {
  385. // 登录后才请求消息数量
  386. getCharCount()
  387. // 没有用户信息就加载一边
  388. if (!isUserInfo) {
  389. initUser();
  390. } else {
  391. isMember.value = authStore.userInfo.isMember==='0'?false:true;
  392. }
  393. }
  394. })
  395. </script>
  396. <style lang="scss" scoped>
  397. .container {
  398. width: 100vw;
  399. background-color: $uni-bg-color;
  400. padding: 0 20rpx 5rpx;
  401. }
  402. .slot-wrap {
  403. padding-left: 20rpx;
  404. }
  405. .grid-text {
  406. font-size: 28rpx;
  407. margin-top: 4rpx;
  408. color: $uni-text-color;
  409. }
  410. .u-card-wrap {
  411. background-color: $u-bg-color;
  412. padding: 1px;
  413. }
  414. .u-body-item {
  415. font-size: 32rpx;
  416. color: #333;
  417. margin-bottom: 30rpx;
  418. height: 140rpx;
  419. &:last-of-type {
  420. margin-bottom: 0;
  421. }
  422. .u-body-item-content {
  423. position: relative;
  424. flex: 1;
  425. /* 剩余空间占用 Flex 规则 */
  426. min-width: 0;
  427. // width: 100%;
  428. height: inherit;
  429. .item-content text {
  430. width: inherit;
  431. font-size: $uni-font-size-2;
  432. display: block;
  433. margin: 10rpx;
  434. color: $uni-text-color;
  435. }
  436. .item-content .item-content-title {
  437. font-size: $uni-title-font-size-2;
  438. }
  439. .item-content .item-content-price {
  440. color: $uni-color-error;
  441. // font-weight: bold;
  442. }
  443. .item-button {
  444. width: 100%;
  445. .item-button-huiyuan {
  446. padding: 15rpx 0 5rpx;
  447. text-align: center;
  448. width: 150rpx;
  449. background-image: url('https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/bg-label.png');
  450. background-size: cover;
  451. background-repeat: no-repeat;
  452. // background-position: center;
  453. }
  454. .item-button-goumai {
  455. padding: 5rpx 0;
  456. text-align: center;
  457. width: 150rpx;
  458. background-color: #fe0000;
  459. border-radius: 30rpx;
  460. color: #fff;
  461. }
  462. .item-button-yiGouMai {
  463. text-align: center;
  464. width: 150rpx;
  465. padding: 5rpx 0;
  466. background-color: #006af4;
  467. border-radius: 30rpx;
  468. color: #fff;
  469. }
  470. }
  471. }
  472. image {
  473. width: 200rpx;
  474. flex: 0 0 200rpx;
  475. height: 100%;
  476. border-radius: 20rpx;
  477. margin-right: 12rpx;
  478. }
  479. }
  480. .course-swiper {
  481. height: 200px;
  482. .swiper-item {
  483. width: 33.33%;
  484. height: 200px;
  485. /* 三个一排,宽度为三分之一 */
  486. transition: transform 0.3s ease;
  487. /* 加入过渡效果 */
  488. display: flex;
  489. flex-direction: column;
  490. align-items: center;
  491. justify-content: center;
  492. }
  493. .swiper-item.active {
  494. transform: scale(2);
  495. /* 主项放大 */
  496. }
  497. image {
  498. width: 80%;
  499. /* 图片宽度 */
  500. height: auto;
  501. }
  502. text {
  503. margin-top: 10px;
  504. }
  505. }
  506. .text-ellipsis {
  507. overflow: hidden;
  508. /* 隐藏超出内容 */
  509. white-space: nowrap;
  510. /* 禁止换行 */
  511. text-overflow: ellipsis;
  512. }
  513. .swiper-container {
  514. perspective: 1000px;
  515. }
  516. .swiper-item {
  517. transition: transform 0.5s;
  518. transform-style: preserve-3d;
  519. /* 其他样式 */
  520. }
  521. .content {
  522. backface-visibility: hidden;
  523. /* 确保背面不可见 */
  524. display: flex;
  525. justify-content: center;
  526. align-items: center;
  527. height: 200px;
  528. /* 设置高度 */
  529. font-size: 24px;
  530. color: white;
  531. background: linear-gradient(45deg, #ff5858, #f09819);
  532. /* 示例背景 */
  533. }
  534. // 登录模拟态
  535. .modal {
  536. .modal-content {
  537. padding: 50rpx;
  538. .content-a {
  539. color: #2979ff;
  540. }
  541. }
  542. }
  543. .item-button {
  544. display: flex;
  545. justify-content: space-between;
  546. align-items: flex-end;
  547. font-size: $uni-font-size-2;
  548. font-weight: bold;
  549. margin-top: 10rpx;
  550. .func-box {
  551. display: flex;
  552. justify-content: space-between;
  553. width: 100%;
  554. align-items: center;
  555. }
  556. .button {
  557. text-align: center;
  558. width: 130rpx;
  559. }
  560. .price {
  561. color: $uni-color-error;
  562. font-size: $uni-title-font-size-3;
  563. }
  564. .not-member-price {
  565. font-size: $uni-font-size-4;
  566. color: $uni-text-color-grey;
  567. text-align: end;
  568. }
  569. .buy {
  570. padding: 6rpx 25rpx;
  571. background-color: $uni-color-error;
  572. border-radius: $uni-card-border-radius;
  573. color: $uni-text-color-inverse;
  574. }
  575. .free {
  576. padding: 6rpx 25rpx;
  577. background-color: $uni-color-primary;
  578. border-radius: $uni-card-border-radius;
  579. color: $uni-text-color-inverse;
  580. }
  581. .member-free {
  582. padding: 10rpx 20rpx;
  583. @include backgroundImg('https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/bg-label.png');
  584. color: $uni-text-color;
  585. }
  586. }
  587. </style>