index.vue 16 KB

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