index.vue 15 KB

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