index.vue 16 KB

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