index.vue 16 KB

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