index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. // {
  180. // imgUrl: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.YKoZzgmubNBxQ8j-mmoTKAHaEK?rs=1&pid=ImgDetMain',
  181. // id: 1
  182. // },
  183. // {
  184. // imgUrl: 'https://pic3.zhimg.com/v2-e52354ffdbd94a8e0a7649eacd34a788_r.jpg?source=1940ef5c',
  185. // id: 2
  186. // },
  187. // {
  188. // imgUrl: 'https://desk-fd.zol-img.com.cn/t_s960x600c5/g4/M03/00/0C/Cg-4zFS8bC-Ie9zBADCvovJAqiEAATJ8wDX__cAMK-6184.jpg',
  189. // id: 3
  190. // },
  191. ])
  192. const courseList = ref([{
  193. courseImg: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.YKoZzgmubNBxQ8j-mmoTKAHaEK?rs=1&pid=ImgDetMain',
  194. id: 1,
  195. courseName: '【8月8日】房地产经纪进阶培训班'
  196. },
  197. {
  198. courseImg: 'https://pic3.zhimg.com/v2-e52354ffdbd94a8e0a7649eacd34a788_r.jpg?source=1940ef5c',
  199. id: 2,
  200. courseName: '【8月9日】《房地产中介服务规范》培训'
  201. },
  202. {
  203. courseImg: 'https://desk-fd.zol-img.com.cn/t_s960x600c5/g4/M03/00/0C/Cg-4zFS8bC-Ie9zBADCvovJAqiEAATJ8wDX__cAMK-6184.jpg',
  204. id: 3,
  205. courseName: '【已结束】《广州市房屋租赁管理规定》'
  206. },
  207. ])
  208. // 首页-导航栏
  209. const navList = ref([{
  210. id: 'notice',
  211. isLogin: false,
  212. title: '通知公告',
  213. icon: 'icon-xiaoxitongzhi',
  214. url: '/pages/notice/notice/notice',
  215. toOtherApp: false,
  216. otherAppId: '其他小程序的appid'
  217. },
  218. {
  219. id: 'dynamic',
  220. title: '协会动态',
  221. isLogin: false,
  222. icon: 'icon-xinxisousuo-01',
  223. url: '/pages/dynamic/dynamic/dynamic',
  224. toOtherApp: false,
  225. otherAppId: '其他小程序的appid'
  226. },
  227. {
  228. id: 'guide',
  229. title: '办事指引',
  230. isLogin: false,
  231. icon: 'icon-caidanguanli',
  232. url: '/pages/guide/guide/guide',
  233. toOtherApp: false,
  234. otherAppId: '其他小程序的appid'
  235. },
  236. {
  237. id: 'edu',
  238. title: '继续教育',
  239. isLogin: true,
  240. icon: 'icon-xueshimao1',
  241. url: '/pages/goOnEdu/index',
  242. toOtherApp: false,
  243. otherAppId: '其他小程序的appid'
  244. },
  245. {
  246. id: 'level',
  247. isLogin: true,
  248. title: '水平认证',
  249. icon: 'icon-zhengshu-copy',
  250. url: 'pages/index/index',
  251. toOtherApp: true,
  252. otherAppId: 'wx050c17d8b239da86'
  253. },
  254. {
  255. id: 'report',
  256. title: '研究报告',
  257. isLogin: true,
  258. icon: 'icon-circular',
  259. url: '/pages/researchReport/reportHome/reportHome',
  260. toOtherApp: false,
  261. otherAppId: '其他小程序的appid'
  262. },
  263. {
  264. id: 'index',
  265. isLogin: true,
  266. title: '经理人指数',
  267. icon: 'icon-zhishu',
  268. url: '跳转页面的路径',
  269. toOtherApp: true,
  270. otherAppId: '其他小程序的appid'
  271. },
  272. {
  273. id: 'pay',
  274. isLogin: true,
  275. title: '会费缴交',
  276. icon: 'icon-jinqian-jiage',
  277. url: '/pages/huiFeiJiaoJiao/huiFeiJiaoJiao',
  278. toOtherApp: false,
  279. otherAppId: '其他小程序的appid'
  280. }
  281. ])
  282. const reportList = ref(
  283. [])
  284. // 跳转页面
  285. const jumpToPage = (data) => {
  286. if (data.toOtherApp) {
  287. // 跳转其他小程序
  288. wx.navigateToMiniProgram({
  289. appId: data.otherAppId, // 例如:wx1234567890abcdef
  290. path: data.url, // 跳转路径
  291. envVersion: 'release', // 版本(develop/trial/release)
  292. success(res) {
  293. console.log('跳转成功');
  294. },
  295. fail(err) {
  296. console.error('跳转失败', err);
  297. }
  298. });
  299. return
  300. }
  301. if (data.isLogin) {
  302. if (!authStore.isAuthenticated) {
  303. loginModal.value = true
  304. return
  305. }
  306. }
  307. uni.navigateTo({
  308. url: data.url
  309. })
  310. }
  311. // 确认跳转至登录
  312. const confirmModal = () => {
  313. uni.navigateTo({
  314. url: "/pages/initial/initial"
  315. })
  316. }
  317. const toPage = (url) => {
  318. if (!authStore.isAuthenticated) {
  319. loginModal.value = true
  320. return
  321. }
  322. uni.navigateTo({
  323. url: url
  324. })
  325. }
  326. const itemClick = (data) => {
  327. // console.log("轮播图swiper", data)
  328. if (!authStore.isAuthenticated) {
  329. loginModal.value = true
  330. return
  331. }
  332. uni.navigateTo({
  333. url: "/pages/swiperDetail/swiperDetail?id=" + data.id
  334. })
  335. }
  336. const swiperClick = (data) => {
  337. // console.log(data, "课程预告数据")
  338. if (!authStore.isAuthenticated) {
  339. loginModal.value = true
  340. return
  341. }
  342. uni.navigateTo({
  343. url: `/pages/goOnEdu/course/courseDetail/courseDetail?id=${data.id}&name=${data.courseName}`
  344. });
  345. }
  346. function initUser() {
  347. me().then(res => {
  348. if (res?.data) {
  349. authStore.setUserInfo(res.data);
  350. isMember.value = res.data.isMember;
  351. }
  352. })
  353. }
  354. function init() {
  355. homeSwiperList().then(res => {
  356. if (res?.data) {
  357. swiperList.value = res.data
  358. }
  359. })
  360. homeCourseList().then(res => {
  361. // console.log(1000, res.data)
  362. if (res?.data) {
  363. courseList.value = res.data
  364. }
  365. })
  366. initReport()
  367. // homeSetting().then(res=>{
  368. // console.log(res)
  369. // })
  370. }
  371. function initReport (){
  372. homeReportList().then(res => {
  373. if (res?.data) {
  374. reportList.value = res.data
  375. }
  376. })
  377. }
  378. function getCharCount() {
  379. count().then(res => {
  380. if (res && res.message === 'success') {
  381. tabbarStore.setMessageCount(res.data.amount)
  382. uni.setTabBarBadge({ //显示数字
  383. index: 1, //tabbar下标
  384. text: `${res.data.amount}` ?? '0' //数字
  385. })
  386. }
  387. })
  388. }
  389. function toReport(id, title) {
  390. if (!authStore.isAuthenticated) {
  391. loginModal.value = true
  392. return
  393. }
  394. uni.navigateTo({
  395. url: "/pages/reportDetail/reportDetail?id=" + id + "&title=" + title
  396. })
  397. }
  398. onReady(() => {
  399. uni.getSystemInfo({
  400. success(e) {
  401. statusBarHeight.value = e.statusBarHeight;
  402. let custom = uni.getMenuButtonBoundingClientRect();
  403. navBarHeight.value = custom.height + (custom.top - e.statusBarHeight) * 2;
  404. }
  405. })
  406. })
  407. onLoad(() => {
  408. init()
  409. // uni.setBackgroundColor({
  410. // backgroundColor: '#ffff7f',
  411. // });
  412. // initUser()
  413. })
  414. onShow(() => {
  415. const isLogin = authStore.isAuthenticated;
  416. const isUserInfo = authStore.isUserInfo;
  417. if (isLogin) {
  418. // 登录后才请求消息数量
  419. getCharCount()
  420. initReport()
  421. // 没有用户信息就加载一边
  422. if (!isUserInfo) {
  423. initUser();
  424. } else {
  425. isMember.value = authStore.userInfo.isMember === '0' ? false : true;
  426. }
  427. }
  428. })
  429. </script>
  430. <style lang="scss" scoped>
  431. .container {
  432. width: 100vw;
  433. // background-color: $uni-bg-color;
  434. padding: 0 20rpx 5rpx;
  435. }
  436. .slot-wrap {
  437. padding-left: 20rpx;
  438. }
  439. .menu-item {
  440. .iconfont {
  441. font-size: 60rpx;
  442. }
  443. }
  444. .grid-text {
  445. font-size: 28rpx;
  446. margin-top: 4rpx;
  447. color: $uni-text-color;
  448. }
  449. .u-card-wrap {
  450. background-color: $u-bg-color;
  451. padding: 1px;
  452. }
  453. .u-body-item {
  454. font-size: 32rpx;
  455. color: #333;
  456. margin-bottom: 30rpx;
  457. height: 140rpx;
  458. &:last-of-type {
  459. margin-bottom: 0;
  460. }
  461. .u-body-item-content {
  462. position: relative;
  463. flex: 1;
  464. /* 剩余空间占用 Flex 规则 */
  465. min-width: 0;
  466. // width: 100%;
  467. height: inherit;
  468. .item-content text {
  469. width: inherit;
  470. font-size: $uni-font-size-2;
  471. display: block;
  472. margin: 10rpx;
  473. color: $uni-text-color;
  474. }
  475. .item-content .item-content-title {
  476. font-size: $uni-title-font-size-2;
  477. }
  478. .item-content .item-content-price {
  479. color: $uni-color-error;
  480. // font-weight: bold;
  481. }
  482. .item-button {
  483. width: 100%;
  484. .item-button-huiyuan {
  485. padding: 15rpx 0 5rpx;
  486. text-align: center;
  487. width: 150rpx;
  488. background-image: url('http://www.gzrea.org.cn:8543/icon/wxmp/bg-label.png');
  489. background-size: cover;
  490. background-repeat: no-repeat;
  491. // background-position: center;
  492. }
  493. .item-button-goumai {
  494. padding: 5rpx 0;
  495. text-align: center;
  496. width: 150rpx;
  497. background-color: #fe0000;
  498. border-radius: 30rpx;
  499. color: #fff;
  500. }
  501. .item-button-yiGouMai {
  502. text-align: center;
  503. width: 150rpx;
  504. padding: 5rpx 0;
  505. background-color: #006af4;
  506. border-radius: 30rpx;
  507. color: #fff;
  508. }
  509. }
  510. }
  511. image {
  512. width: 200rpx;
  513. flex: 0 0 200rpx;
  514. height: 100%;
  515. border-radius: 20rpx;
  516. margin-right: 12rpx;
  517. }
  518. }
  519. .course-swiper {
  520. height: 200px;
  521. .swiper-item {
  522. width: 33.33%;
  523. height: 200px;
  524. /* 三个一排,宽度为三分之一 */
  525. transition: transform 0.3s ease;
  526. /* 加入过渡效果 */
  527. display: flex;
  528. flex-direction: column;
  529. align-items: center;
  530. justify-content: center;
  531. }
  532. .swiper-item.active {
  533. transform: scale(2);
  534. /* 主项放大 */
  535. }
  536. image {
  537. width: 80%;
  538. /* 图片宽度 */
  539. height: auto;
  540. }
  541. text {
  542. margin-top: 10px;
  543. }
  544. }
  545. .text-ellipsis {
  546. overflow: hidden;
  547. /* 隐藏超出内容 */
  548. white-space: nowrap;
  549. /* 禁止换行 */
  550. text-overflow: ellipsis;
  551. }
  552. .swiper-container {
  553. perspective: 1000px;
  554. }
  555. .swiper-item {
  556. transition: transform 0.5s;
  557. transform-style: preserve-3d;
  558. /* 其他样式 */
  559. }
  560. .content {
  561. backface-visibility: hidden;
  562. /* 确保背面不可见 */
  563. display: flex;
  564. justify-content: center;
  565. align-items: center;
  566. height: 200px;
  567. /* 设置高度 */
  568. font-size: 24px;
  569. color: white;
  570. background: linear-gradient(45deg, #ff5858, #f09819);
  571. /* 示例背景 */
  572. }
  573. // 登录模拟态
  574. .modal {
  575. .modal-content {
  576. padding: 50rpx;
  577. .content-a {
  578. color: #2979ff;
  579. }
  580. }
  581. }
  582. .item-button {
  583. display: flex;
  584. justify-content: space-between;
  585. align-items: flex-end;
  586. font-size: $uni-font-size-2;
  587. font-weight: bold;
  588. margin-top: 10rpx;
  589. .func-box {
  590. display: flex;
  591. justify-content: space-between;
  592. width: 100%;
  593. align-items: center;
  594. }
  595. .button {
  596. text-align: center;
  597. width: 130rpx;
  598. }
  599. .price {
  600. color: $uni-color-error;
  601. font-size: $uni-title-font-size-3;
  602. }
  603. .not-member-price {
  604. font-size: $uni-font-size-4;
  605. color: $uni-text-color-grey;
  606. text-align: end;
  607. }
  608. .buy {
  609. padding: 6rpx 25rpx;
  610. background-color: $uni-color-error;
  611. border-radius: $uni-card-border-radius;
  612. color: $uni-text-color-inverse;
  613. }
  614. .free {
  615. padding: 6rpx 25rpx;
  616. background-color: $uni-color-primary;
  617. border-radius: $uni-card-border-radius;
  618. color: $uni-text-color-inverse;
  619. }
  620. .member-free {
  621. padding: 10rpx 20rpx;
  622. @include backgroundImg('http://www.gzrea.org.cn:8543/icon/wxmp/bg-label.png');
  623. color: $uni-text-color;
  624. }
  625. }
  626. </style>