index.vue 16 KB

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