index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <template>
  2. <view>
  3. <!--#ifdef APP-PLUS-->
  4. <view class="lz-status_bar">
  5. <view class="lz-top_view"></view>
  6. </view>
  7. <!--#endif-->
  8. <view class="kaoshi-head">
  9. <view class="kaoshi-head-top">
  10. <view class="kaoshi-head-left" @tap="$openrul('/pages/auth/choiceSubject/index')">
  11. <view class="kaoshi-head-kemu">{{subject.subject_name}}</view>
  12. <view class="iconfont icon-weibiaoti"></view>
  13. </view>
  14. <view class="kaoshi-head-right">
  15. <text class="iconfont icon-sousuo" @tap="gotoSearch"></text>
  16. <text class="iconfont icon-lingdang" @tap="$openrul('/pages/article/notice')"
  17. style="margin-left: 12px;"></text>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="kaoshi-index-content">
  22. <view class="kaoshi-head-banner">
  23. <swiper class="swiper" :indicator-dots="swiper_config.indicatorDots" :autoplay="swiper_config.autoplay"
  24. indicator-active-color="#3c7bfc" :interval="swiper_config.interval"
  25. :duration="swiper_config.duration">
  26. <swiper-item v-for="(item, index) in swiper_list" :key="index">
  27. <view @tap="windowopen(item.url)"><img :src="item.image" /></view>
  28. </swiper-item>
  29. </swiper>
  30. </view>
  31. <view class="notice" v-if="noticeList.length > 0">
  32. <an-notice-bar :message_list="noticeList" style="width: 100%;"></an-notice-bar>
  33. </view>
  34. <view class="kaoshi-index-nav" v-if="navList && navList.length > 0">
  35. <view class="kaoshi-index-nav-flex" @tap="windowopen(item.url)" v-for="(item,index) in navList"
  36. :key="index">
  37. <image :src="item.image" class="kaoshi-index-nav-img"></image>
  38. <view class="kaoshi-index-nav-title">{{item.title}}</view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="home-title" v-if="list.length > 0">
  43. <view class="home-title-l">最新题库</view>
  44. <navigator open-type="switchTab" url="/pages/questionBank/index" hover-class="none" class="home-title-r">
  45. <view>更多</view>
  46. <view class="iconfont icon-arrow"></view>
  47. </navigator>
  48. </view>
  49. <view class="home-box">
  50. <view v-for="(item, index) in list" :key="index" class="kaoshi-tiku">
  51. <view class="kaoshi-tiku-content" @tap="goto_detail(item,'1')">
  52. <view class="kaoshi-tiku-content-flex">
  53. <view class="kaoshi-tiku-content-top">
  54. <view>{{item.name}}
  55. <view v-if="item.is_vip == 1 && !subjectVip" class="vip">
  56. <image src="../../static/img/vip.png" mode=""></image>
  57. <view>VIP</view>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. <view class="kaoshi-tiku-content-flex">
  63. <view class="kaoshi-tiku-content-bottom">
  64. <view class="iconfont icon-dui2"></view>
  65. <view class="pub-gray">共{{item.total_num}}题</view>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. <view class="home-title" v-if="articleList.length > 0">
  72. <view class="home-title-l">新闻资讯</view>
  73. <navigator open-type="switchTab" url="/pages/article/index" hover-class="none" class="home-title-r">
  74. <view>更多</view>
  75. <view class="iconfont icon-arrow"></view>
  76. </navigator>
  77. </view>
  78. <view class="home-box">
  79. <view class="news-content-box" v-if="articleList.length > 0">
  80. <view class="news-content">
  81. <view class="news-list" v-for="(item, index) in articleList" :key="index"
  82. @tap="gotoNoticeDetail(item)">
  83. <view class="news-flex">
  84. <image :src="item.image == '' ? '../../static/img/pic.jpg' : item.image"
  85. class="news-list-img"></image>
  86. <view class="news-list-r">
  87. <view class="news-list-title">{{item.title}}</view>
  88. <view class="news-list-time">
  89. <view>{{item.noticetime}}</view>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. <view style="height: 10px;"></view>
  98. <authVip v-if="showAuthVip" @hideAuthVip="showAuthVip = false"></authVip>
  99. </view>
  100. </template>
  101. <script>
  102. import {
  103. mapState
  104. } from 'vuex';
  105. import Error from '@/core/untils/error/index';
  106. import authVip from '@/components/authVip.vue'
  107. export default {
  108. data() {
  109. return {
  110. showAuthVip: false, //是否显示认证vip
  111. swiper_list: [], //轮播图
  112. swiper_config: {
  113. indicatorDots: true,
  114. autoplay: true,
  115. interval: 2000,
  116. duration: 500
  117. },
  118. list: [], //最新题库
  119. subList: [], //科目列表
  120. noticeList: [], //通知公告
  121. articleList: [], //新闻
  122. navList: [], //首页导航图标
  123. };
  124. },
  125. async onShow() {
  126. this.get_lunbo_list();
  127. if (this.subject.id != undefined) {
  128. this.get_tiku_list();
  129. this.canReset && this.getNoticeList()
  130. this.canReset && this.getArticleList()
  131. this.canReset = true
  132. }
  133. if (this.userinfo.user_id !== undefined) {
  134. await this.$myUserLogin.getSubvip(this.subject.id)
  135. }
  136. // #ifdef MP-WEIXIN
  137. this.getUpdate()
  138. // #endif
  139. },
  140. onLoad() {
  141. if (this.subject.id == undefined) {
  142. this.getSub();
  143. } else {
  144. this.getNoticeList()
  145. this.getArticleList()
  146. }
  147. // #ifdef MP-WEIXIN
  148. wx.showShareMenu({
  149. withShareTicket: true,
  150. menus: ["shareAppMessage", "shareTimeline"]
  151. })
  152. // #endif
  153. this.getNavList()
  154. },
  155. computed: {
  156. ...mapState(['subject', 'userinfo', 'subjectVip'])
  157. },
  158. components: {
  159. authVip
  160. },
  161. methods: {
  162. getUpdate() {
  163. const updateManager = wx.getUpdateManager()
  164. updateManager.onCheckForUpdate(function(res) {
  165. // 请求完新版本信息的回调
  166. console.log(res.hasUpdate)
  167. })
  168. updateManager.onUpdateReady(function() {
  169. wx.showModal({
  170. title: '更新提示',
  171. content: '新版本已经准备好,是否重启应用?',
  172. success(res) {
  173. if (res.confirm) {
  174. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  175. updateManager.applyUpdate()
  176. }
  177. }
  178. })
  179. })
  180. updateManager.onUpdateFailed(function() {
  181. // 新版本下载失败
  182. })
  183. },
  184. //首页导航图标
  185. async getNavList() {
  186. let res = await this.$myHttp.post({
  187. url: this.$myHttp.urlMap.navList,
  188. data: {},
  189. needLogin: false,
  190. })
  191. if (res.code == 1) {
  192. this.navList = res.data.data
  193. }
  194. },
  195. //通知公告
  196. async getNoticeList() {
  197. let res = await this.$myHttp.post({
  198. url: this.$myHttp.urlMap.noticeList,
  199. data: {
  200. page: 1,
  201. limit: 10,
  202. subject_id: this.subject.id || this.subList[0].id,
  203. cate_id: 1,
  204. },
  205. needLogin: false,
  206. })
  207. if (res.code == 1) {
  208. this.noticeList = res.data.data
  209. }
  210. },
  211. //新闻
  212. async getArticleList() {
  213. let res = await this.$myHttp.post({
  214. url: this.$myHttp.urlMap.noticeList,
  215. data: {
  216. page: 1,
  217. limit: 10,
  218. subject_id: this.subject.id || this.subList[0].id,
  219. cate_id: 2,
  220. },
  221. needLogin: false,
  222. })
  223. if (res.code == 1) {
  224. this.articleList = res.data.data
  225. }
  226. },
  227. //获取科目列表
  228. async getSub() {
  229. let res = await this.$myHttp.post({
  230. url: this.$myHttp.urlMap.subjectList,
  231. data: {
  232. page: 1,
  233. limit: 0
  234. }
  235. })
  236. if (res.code === 1) {
  237. this.subList = res.data
  238. this.$store.commit('setSubject', {
  239. subject: {
  240. id: this.subList[0].childlist[0].id,
  241. subject_name: this.subList[0].childlist[0].subject_name
  242. }
  243. })
  244. this.get_tiku_list();
  245. }
  246. },
  247. // 轮播图
  248. async get_lunbo_list() {
  249. let res = await this.$myHttp.post({
  250. url: this.$myHttp.urlMap.swiper,
  251. data: {
  252. searchdb: {
  253. code: 'shouye'
  254. }
  255. }
  256. });
  257. if (res.code === 1) {
  258. let rows = res.data.data || [];
  259. this.swiper_list = rows;
  260. }
  261. },
  262. // 最新题库
  263. async get_tiku_list() {
  264. let res = await this.$myHttp.post({
  265. url: this.$myHttp.urlMap.unitList,
  266. data: {
  267. subject_id: this.subject.id || this.subList[0].id,
  268. unit_id: 0,
  269. page: 1,
  270. limit: 10
  271. },
  272. });
  273. if (res.code === 1) {
  274. this.list = res.data.data;
  275. }
  276. },
  277. // 题库跳转
  278. goto_detail(item, type) {
  279. if (item.total_num == 0) { //如果目录下没有题目,提示用户
  280. this.$myUtils.$prompt.showToast({
  281. icon: 'none',
  282. title: '当前目录下没有题目,请联系老师'
  283. });
  284. return
  285. }
  286. if (!this.subjectVip && item.is_vip) {
  287. if (this.$myUserLogin.getToken()) {
  288. this.showAuthVip = true
  289. return
  290. } else {
  291. Error.errorNotLoggedIn();
  292. return
  293. }
  294. }
  295. if (type == '1') {
  296. if (item.is_last == 0) {
  297. //非终极栏目,点击进入下级栏目
  298. this.$openrul('/pages/questionBank/detail/index?id=' + item.id + '&from_type=1' + '&name=' + item
  299. .name)
  300. } else if (item.is_last == 1) {
  301. if (this.$myUserLogin.getToken()) {
  302. //终极栏目,点击进入答题页
  303. this.$openrul('/pages/questionBank/questionBankAnswer/index?id=' + item.id + '&from_type=1' +
  304. '&name=' + item.name)
  305. } else {
  306. Error.errorNotLoggedIn();
  307. }
  308. }
  309. } else if (type == '2') {
  310. if (this.$myUserLogin.getToken()) {
  311. //历年真题都是终极栏目,点击进入答题页
  312. this.$openrul('/pages/questionBank/questionBankAnswer/index?id=' + item.id + '&from_type=2' +
  313. '&name=' + item.name)
  314. } else {
  315. Error.errorNotLoggedIn();
  316. }
  317. }
  318. },
  319. //跳转前需要登录
  320. navTo(url) {
  321. if (this.$myUserLogin.getToken()) {
  322. this.$openrul(url)
  323. } else {
  324. Error.errorNotLoggedIn();
  325. }
  326. },
  327. // 搜索跳转
  328. gotoSearch() {
  329. uni.navigateTo({
  330. url: '/pages/questionSearch/searchList'
  331. })
  332. },
  333. // 新闻跳转
  334. gotoNoticeDetail(item) {
  335. if (item.url == '') {
  336. uni.navigateTo({
  337. url: '/pages/article/detail?id=' + item.id + '&type=1'
  338. })
  339. } else {
  340. uni.navigateTo({
  341. url: '/pages/webview/webview?url=' + item.url + '&title=' + item.title
  342. })
  343. }
  344. },
  345. // 轮播图跳转
  346. windowopen(url) {
  347. if (url.startsWith('http')) {
  348. uni.navigateTo({
  349. url: '/pages/webview/webview?url=' + url
  350. })
  351. } else {
  352. if (url == '/pages/index/index' || url == '/pages/questionBank/index' || url ==
  353. '/pages/examination/index' ||
  354. url == '/pages/article/index' || url == '/pages/my/index') {
  355. uni.switchTab({
  356. url
  357. })
  358. } else {
  359. uni.navigateTo({
  360. url
  361. })
  362. }
  363. }
  364. }
  365. }
  366. };
  367. </script>
  368. <style>
  369. page {
  370. background-image: linear-gradient(#026aef 0, #fff 180px, #fff 200px, #f9f9f9 230px, #f9f9f9 100%);
  371. background-repeat: no-repeat;
  372. background-color: #f9f9f9;
  373. }
  374. /* 首页头部 */
  375. .kaoshi-head {
  376. background: none;
  377. position: relative;
  378. top: 0;
  379. border-bottom: none;
  380. }
  381. .kaoshi-head-top {
  382. color: #fff;
  383. line-height: 58px;
  384. }
  385. .kaoshi-head-top .kaoshi-head-left {
  386. flex: 1;
  387. display: flex;
  388. align-items: center;
  389. }
  390. .kaoshi-head-top .kaoshi-head-left .icon-weibiaoti {
  391. padding-left: 4px;
  392. font-size: 18px;
  393. }
  394. .kaoshi-head-top .kaoshi-head-kemu {
  395. font-size: 16px;
  396. text-align: center;
  397. }
  398. .kaoshi-head-top .kaoshi-head-right {
  399. width: 18%;
  400. text-align: right;
  401. }
  402. .kaoshi-head-top .kaoshi-head-right .icon-datiqia {
  403. font-size: 22px;
  404. }
  405. .kaoshi-index-content {
  406. overflow: hidden;
  407. }
  408. /* 首页轮播图 */
  409. .kaoshi-head-banner {
  410. border-radius: 10px;
  411. width: 92%;
  412. margin: 6px auto;
  413. box-shadow: 0 3px 8px rgb(0 0 0 / 11%);
  414. margin-bottom: 19px;
  415. }
  416. .kaoshi-head-banner img {
  417. width: 100%;
  418. height: 140px;
  419. border-radius: 10px;
  420. }
  421. .kaoshi-head-banner .uni-swiper-dot-active::before {
  422. background: #3c7bfc !important;
  423. }
  424. .kaoshi-head-banner .swiper {
  425. height: 140px !important;
  426. }
  427. /* 首页通知 */
  428. .notice {
  429. box-sizing: border-box;
  430. display: flex;
  431. justify-content: space-between;
  432. align-items: center;
  433. width: 92%;
  434. margin: 15px auto;
  435. padding: 0 10px;
  436. border-radius: 5px;
  437. line-height: 42px;
  438. background-color: #d1e5fe;
  439. }
  440. /* 首页导航 */
  441. .kaoshi-index-nav {
  442. box-sizing: border-box;
  443. display: flex;
  444. justify-content: flex-start;
  445. align-items: center;
  446. flex-wrap: wrap;
  447. text-align: center;
  448. font-size: 14px;
  449. color: #605d70;
  450. width: 92%;
  451. margin: 0 auto;
  452. background-color: #fff;
  453. border-radius: 8px;
  454. padding-bottom: 14px;
  455. }
  456. .kaoshi-index-nav .kaoshi-index-nav-flex {
  457. width: 25%;
  458. height: 70px;
  459. padding-top: 14px;
  460. }
  461. .kaoshi-index-nav .kaoshi-index-nav-title {
  462. margin: 7px auto 0;
  463. }
  464. .kaoshi-index-nav-img {
  465. width: 38px;
  466. height: 38px;
  467. border-radius: 5px;
  468. }
  469. .home-title {
  470. width: 92%;
  471. margin: 0 auto;
  472. padding: 12px 0;
  473. display: flex;
  474. align-items: center;
  475. justify-content: space-between;
  476. }
  477. .home-title-l {
  478. display: flex;
  479. font-weight: bold;
  480. font-size: 18px;
  481. }
  482. .home-title-r {
  483. display: flex;
  484. align-items: center;
  485. color: #bbb;
  486. font-size: 14px;
  487. }
  488. .home-title-r .iconfont {
  489. font-size: 11px;
  490. }
  491. .home-box {
  492. width: 92%;
  493. margin: 0 auto;
  494. border-radius: 8px;
  495. overflow: hidden;
  496. background: #fff;
  497. }
  498. .kaoshi-tiku-content {
  499. width: 92%;
  500. margin: 0 auto;
  501. display: flex;
  502. flex-direction: column;
  503. font-size: 14px;
  504. padding: 10px 0;
  505. border-bottom: solid 1px #f5f5f5;
  506. }
  507. .kaoshi-tiku-content-flex {
  508. width: 100%;
  509. display: flex;
  510. justify-content: space-between;
  511. align-items: inherit;
  512. }
  513. .kaoshi-tiku-content .kaoshi-tiku-content-flex:first-child {
  514. padding-bottom: 6px;
  515. }
  516. .kaoshi-tiku-content .kaoshi-tiku-content-flex:last-child {
  517. font-size: 14px;
  518. }
  519. .kaoshi-tiku-content-top {
  520. display: flex;
  521. align-items: center;
  522. flex: 1;
  523. font-size: 16px;
  524. }
  525. .kaoshi-tiku-content-top img {
  526. width: 20px;
  527. height: 22px;
  528. margin-right: 10px;
  529. }
  530. .kaoshi-tiku-content-bottom {
  531. font-size: 13px;
  532. display: flex;
  533. align-items: center;
  534. }
  535. .kaoshi-tiku-content-flex .icon-dui2 {
  536. margin: 2px 2px 0 0;
  537. color: #3c7bfc;
  538. }
  539. /* 新闻资讯 */
  540. .news-content-box {
  541. background: #fff;
  542. padding: 1px 0;
  543. }
  544. .news-content {
  545. width: 94%;
  546. margin: 0 auto;
  547. }
  548. .news-flex {
  549. display: flex;
  550. align-items: flex-start;
  551. margin-bottom: 12px;
  552. }
  553. .news-list-img {
  554. width: 66px;
  555. height: 66px;
  556. border-radius: 6px;
  557. border: solid 1px #f1f1f1;
  558. }
  559. .news-list-r {
  560. margin-left: 10px;
  561. flex: 1;
  562. height: 66px;
  563. display: flex;
  564. flex-direction: column;
  565. justify-content: space-between;
  566. }
  567. .news-list-title {
  568. font-size: 16px;
  569. line-height: 21px;
  570. padding-top: 4px;
  571. text-overflow: ellipsis;
  572. display: -webkit-box;
  573. -webkit-line-clamp: 2;
  574. -webkit-box-orient: vertical;
  575. display: -moz-box;
  576. -moz-line-clamp: 2;
  577. -moz-box-orient: vertical;
  578. overflow-wrap: break-word;
  579. word-break: break-all;
  580. white-space: normal;
  581. overflow: hidden;
  582. }
  583. .news-list-time {
  584. display: flex;
  585. flex-direction: column;
  586. align-items: flex-start;
  587. color: #999;
  588. font-size: 13px;
  589. line-height: 21px;
  590. }
  591. .news-list {
  592. margin-top: 12px;
  593. border-bottom: solid 1px #f1f1f1;
  594. }
  595. .news-content .news-list:last-child {
  596. margin-bottom: 0;
  597. border-bottom: none
  598. }
  599. </style>