index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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-shangchuanchenggong',
  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. // jlrzsUrl.value = 'https://www.gzrea.cn:8089/start/534C6DA13FDBAD13479F099E9FC873DF/4D3433353936/'
  299. const src = encodeURIComponent(jlrzsUrl.value);
  300. uni.navigateTo({
  301. url: `/pages/webview/webview?url=${src}`
  302. });
  303. // uni.setClipboardData({
  304. // data: jlrzsUrl.value,
  305. // success: function () {
  306. // msg("链接已复制,请在浏览器中打开")
  307. // }
  308. // });
  309. return
  310. }
  311. uni.navigateTo({
  312. url: data.url
  313. })
  314. }
  315. // 确认跳转至登录
  316. const confirmModal = () => {
  317. uni.navigateTo({
  318. url: "/pages/initial/initial"
  319. })
  320. }
  321. const toPage = (url) => {
  322. if (!authStore.isAuthenticated) {
  323. loginModal.value = true
  324. return
  325. }
  326. uni.navigateTo({
  327. url: url
  328. })
  329. }
  330. const itemClick = (data) => {
  331. // console.log("轮播图swiper", data)
  332. if (!authStore.isAuthenticated) {
  333. loginModal.value = true
  334. return
  335. }
  336. uni.navigateTo({
  337. url: "/pages/swiperDetail/swiperDetail?id=" + data.id
  338. })
  339. }
  340. const swiperClick = (data) => {
  341. // console.log(data, "课程预告数据")
  342. if (!authStore.isAuthenticated) {
  343. loginModal.value = true
  344. return
  345. }
  346. uni.navigateTo({
  347. url: `/pages/goOnEdu/course/courseDetail/courseDetail?id=${data.id}&title=${data.courseName}`
  348. });
  349. }
  350. function initUser() {
  351. me().then(res => {
  352. if (res?.data) {
  353. authStore.setUserInfo(res.data);
  354. isMember.value = res.data.isMember;
  355. }
  356. })
  357. }
  358. function init() {
  359. homeSwiperList().then(res => {
  360. if (res?.data) {
  361. swiperList.value = res.data
  362. }
  363. })
  364. homeCourseList().then(res => {
  365. // console.log(1000, res.data)
  366. if (res?.data) {
  367. courseList.value = res.data
  368. }
  369. })
  370. initReport()
  371. // homeSetting().then(res=>{
  372. // console.log(res)
  373. // })
  374. }
  375. function initReport() {
  376. homeReportList().then(res => {
  377. if (res?.data) {
  378. reportList.value = res.data
  379. }
  380. })
  381. }
  382. function getCharCount() {
  383. count().then(res => {
  384. if (res && res.message === 'success') {
  385. tabbarStore.setMessageCount(res.data.amount)
  386. uni.setTabBarBadge({ //显示数字
  387. index: 1, //tabbar下标
  388. text: `${res.data.amount}` ?? '0' //数字
  389. })
  390. }
  391. })
  392. }
  393. function toReport(id, title) {
  394. if (!authStore.isAuthenticated) {
  395. loginModal.value = true
  396. return
  397. }
  398. uni.navigateTo({
  399. url: "/pages/reportDetail/reportDetail?id=" + id + "&title=" + title
  400. })
  401. }
  402. function loadUrl() {
  403. loadJlrzsUrl().then(res => {
  404. if (res && res.code === 0) {
  405. jlrzsUrl.value = res.data.url
  406. }
  407. })
  408. }
  409. onReady(() => {
  410. uni.getSystemInfo({
  411. success(e) {
  412. statusBarHeight.value = e.statusBarHeight;
  413. let custom = uni.getMenuButtonBoundingClientRect();
  414. navBarHeight.value = custom.height + (custom.top - e.statusBarHeight) * 2;
  415. }
  416. })
  417. })
  418. onLoad(() => {
  419. init()
  420. // uni.setBackgroundColor({
  421. // backgroundColor: '#ffff7f',
  422. // });
  423. // initUser()
  424. })
  425. onShow(() => {
  426. const isLogin = authStore.isAuthenticated;
  427. const isUserInfo = authStore.isUserInfo;
  428. if (isLogin) {
  429. // 登录后才请求消息数量
  430. getCharCount()
  431. initReport()
  432. if(!jlrzsUrl.value){
  433. loadUrl()
  434. }
  435. // 没有用户信息就加载一边
  436. if (!isUserInfo) {
  437. initUser();
  438. } else {
  439. isMember.value = authStore.userInfo.isMember === '0' ? false : true;
  440. }
  441. }
  442. })
  443. </script>
  444. <style lang="scss" scoped>
  445. .container {
  446. width: 100vw;
  447. // background-color: $uni-bg-color;
  448. padding: 0 20rpx 5rpx;
  449. }
  450. .slot-wrap {
  451. padding-left: 20rpx;
  452. }
  453. .menu-item {
  454. .iconfont {
  455. font-size: 60rpx;
  456. }
  457. }
  458. .grid-text {
  459. font-size: 28rpx;
  460. margin-top: 4rpx;
  461. color: $uni-text-color;
  462. }
  463. .u-card-wrap {
  464. background-color: $u-bg-color;
  465. padding: 1px;
  466. }
  467. .u-body-item {
  468. font-size: 32rpx;
  469. color: #333;
  470. margin-bottom: 30rpx;
  471. height: 140rpx;
  472. &:last-of-type {
  473. margin-bottom: 0;
  474. }
  475. .u-body-item-content {
  476. position: relative;
  477. flex: 1;
  478. /* 剩余空间占用 Flex 规则 */
  479. min-width: 0;
  480. // width: 100%;
  481. height: inherit;
  482. .item-content text {
  483. width: inherit;
  484. font-size: $uni-font-size-2;
  485. display: block;
  486. margin: 10rpx;
  487. color: $uni-text-color;
  488. }
  489. .item-content .item-content-title {
  490. font-size: $uni-title-font-size-2;
  491. }
  492. .item-content .item-content-price {
  493. color: $uni-color-error;
  494. // font-weight: bold;
  495. }
  496. .item-button {
  497. width: 100%;
  498. .item-button-huiyuan {
  499. padding: 15rpx 0 5rpx;
  500. text-align: center;
  501. width: 150rpx;
  502. background-image: url('http://www.gzrea.org.cn:8543/icon/wxmp/bg-label.png');
  503. background-size: cover;
  504. background-repeat: no-repeat;
  505. // background-position: center;
  506. }
  507. .item-button-goumai {
  508. padding: 5rpx 0;
  509. text-align: center;
  510. width: 150rpx;
  511. background-color: #fe0000;
  512. border-radius: 30rpx;
  513. color: #fff;
  514. }
  515. .item-button-yiGouMai {
  516. text-align: center;
  517. width: 150rpx;
  518. padding: 5rpx 0;
  519. background-color: #006af4;
  520. border-radius: 30rpx;
  521. color: #fff;
  522. }
  523. }
  524. }
  525. image {
  526. width: 200rpx;
  527. flex: 0 0 200rpx;
  528. height: 100%;
  529. border-radius: 20rpx;
  530. margin-right: 12rpx;
  531. }
  532. }
  533. .course-swiper {
  534. height: 200px;
  535. .swiper-item {
  536. width: 33.33%;
  537. height: 200px;
  538. /* 三个一排,宽度为三分之一 */
  539. transition: transform 0.3s ease;
  540. /* 加入过渡效果 */
  541. display: flex;
  542. flex-direction: column;
  543. align-items: center;
  544. justify-content: center;
  545. }
  546. .swiper-item.active {
  547. transform: scale(2);
  548. /* 主项放大 */
  549. }
  550. image {
  551. width: 80%;
  552. /* 图片宽度 */
  553. height: auto;
  554. }
  555. text {
  556. margin-top: 10px;
  557. }
  558. }
  559. .text-ellipsis {
  560. overflow: hidden;
  561. /* 隐藏超出内容 */
  562. white-space: nowrap;
  563. /* 禁止换行 */
  564. text-overflow: ellipsis;
  565. }
  566. .swiper-container {
  567. perspective: 1000px;
  568. }
  569. .swiper-item {
  570. transition: transform 0.5s;
  571. transform-style: preserve-3d;
  572. /* 其他样式 */
  573. }
  574. .content {
  575. backface-visibility: hidden;
  576. /* 确保背面不可见 */
  577. display: flex;
  578. justify-content: center;
  579. align-items: center;
  580. height: 200px;
  581. /* 设置高度 */
  582. font-size: 24px;
  583. color: white;
  584. background: linear-gradient(45deg, #ff5858, #f09819);
  585. /* 示例背景 */
  586. }
  587. // 登录模拟态
  588. .modal {
  589. .modal-content {
  590. padding: 50rpx;
  591. .content-a {
  592. color: #2979ff;
  593. }
  594. }
  595. }
  596. .item-button {
  597. display: flex;
  598. justify-content: space-between;
  599. align-items: flex-end;
  600. font-size: $uni-font-size-2;
  601. font-weight: bold;
  602. margin-top: 10rpx;
  603. .func-box {
  604. display: flex;
  605. justify-content: space-between;
  606. width: 100%;
  607. align-items: center;
  608. }
  609. .button {
  610. text-align: center;
  611. width: 130rpx;
  612. }
  613. .price {
  614. color: $uni-color-error;
  615. font-size: $uni-title-font-size-3;
  616. }
  617. .not-member-price {
  618. font-size: $uni-font-size-4;
  619. color: $uni-text-color-grey;
  620. text-align: end;
  621. }
  622. .buy {
  623. padding: 6rpx 25rpx;
  624. background-color: $uni-color-error;
  625. border-radius: $uni-card-border-radius;
  626. color: $uni-text-color-inverse;
  627. }
  628. .free {
  629. padding: 6rpx 25rpx;
  630. background-color: $uni-color-primary;
  631. border-radius: $uni-card-border-radius;
  632. color: $uni-text-color-inverse;
  633. }
  634. .member-free {
  635. padding: 10rpx 20rpx;
  636. @include backgroundImg('http://www.gzrea.org.cn:8543/icon/wxmp/bg-label.png');
  637. color: $uni-text-color;
  638. }
  639. }
  640. </style>