index.vue 16 KB

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