index.vue 12 KB

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