index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <template>
  2. <template>
  3. <Container
  4. class="body-content"
  5. title="首页"
  6. bgColor="#F8F8F8"
  7. :showBack="false"
  8. >
  9. <view class="home">
  10. <!-- 倒计时 -->
  11. <view class="time" v-if="(splitDays != '') & (splitDays != null)">
  12. <view>距离2025年考试倒计时</view>
  13. <!-- 将天数拆分为单个数字显示 -->
  14. <view
  15. class="exam-countdown-tiem-item"
  16. v-for="(digit, index) in splitDays"
  17. :key="index"
  18. >{{ digit }}</view
  19. >
  20. <view>天</view>
  21. </view>
  22. <!-- 轮播图 -->
  23. <swiper
  24. class="swiper"
  25. :style="{
  26. height: imgHeight,
  27. }"
  28. circular
  29. autoplay
  30. >
  31. <swiper-item v-for="(item, index) in banner_list" :key="index">
  32. <view class="swiper-item"
  33. ><image
  34. class="swiper-item-image"
  35. :src="item.image_url"
  36. mode="aspectFill"
  37. @load="onImageLoad($event, item, index)"
  38. @click="goto_notice_list(item.link_url)"
  39. ></image
  40. ></view>
  41. </swiper-item>
  42. </swiper>
  43. <!-- 公告 -->
  44. <view class="notice" v-if="notice_list != '' && notice_list != null">
  45. <view class="title-lable">公告</view>
  46. <view class="notice-title">{{ notice_list[0]["title"] }}</view>
  47. <navigator url="/pages/notice/list">
  48. <view class="notice-more">{{ "更多 >" }}</view>
  49. </navigator>
  50. </view>
  51. <!-- 2025新大纲 -->
  52. <view class="new_outline">
  53. <uni-section title="基础用法" type="line">
  54. <view class="p-20">
  55. <uni-segmented-control
  56. :flex="false"
  57. :current="current"
  58. :values="list.map((item) => item.name)"
  59. style-type="text"
  60. @clickItem="(e) => (current = e.currentIndex)"
  61. />
  62. <!-- 执业药师 -->
  63. <template v-for="(item, index) in list" :key="item.id">
  64. <view v-if="current === index" class="grid">
  65. <view
  66. v-for="i in item?.children"
  67. :key="i.id"
  68. class="flex"
  69. @click="clickClass(i)"
  70. >
  71. <image :src="i.chapter_image_url" class="img_small"></image>
  72. <view>{{ i.name }}</view>
  73. </view>
  74. </view>
  75. </template>
  76. </view>
  77. </uni-section>
  78. </view>
  79. <view class="p-20">
  80. <uni-section title="往年真题" type="line">
  81. <!-- 往年真题 -->
  82. <view class="grid-3">
  83. <view
  84. v-for="item in rightList"
  85. :key="item.originName"
  86. class="flex"
  87. @click="
  88. toReal({
  89. title: item.name + '真题',
  90. origin: item.originName,
  91. })
  92. "
  93. >
  94. <view class="bg-red">
  95. <view class="text">{{ item.name }}真题</view>
  96. </view>
  97. </view>
  98. </view>
  99. </uni-section>
  100. </view>
  101. <!-- #ifdef MP-WEIXIN -->
  102. <official-account @load="onload"></official-account>
  103. <!-- #endif -->
  104. </view>
  105. </Container>
  106. <view class="service">
  107. <CustomerService>联系客服</CustomerService>
  108. </view>
  109. </template>
  110. <Modal title="ces" :footer="false" v-model:open="showModal">
  111. <template #custom>
  112. <view class="mo">
  113. <uni-icons
  114. type="closeempty"
  115. class="icons"
  116. color="#fff"
  117. @click="showModal = false"
  118. ></uni-icons>
  119. <div class="bgt">
  120. <span>恭喜您获得7天会员</span>
  121. <span>可以免费学习所有课程以及练习题库</span>
  122. <span style="margin-top: 71rpx">戳下方还可以</span>
  123. <span>添加专属助教老师为您答疑解惑</span>
  124. <span>限时领取《药品速记口诀》</span>
  125. <span class="fixed" @click="receive"></span>
  126. </div>
  127. </view>
  128. </template>
  129. </Modal>
  130. </template>
  131. <script setup>
  132. import { ref, onMounted, computed, onBeforeUnmount } from "vue";
  133. import Container from "../../components/Container/Container.vue";
  134. import CustomerService from "../../components/CustomerService/CustomerService.vue";
  135. import Modal from "../../components/Modal/Modal.vue";
  136. import { router, getRoute } from "../../utils/router";
  137. import { request } from "../../utils/request";
  138. import { arrayToTree } from "../../utils";
  139. const current = ref(0);
  140. const list = ref([]);
  141. const banner_list = ref([]);
  142. const notice_list = ref([]);
  143. const imgHeight = ref("auto"); // 初始高度
  144. const rightList = ref([]);
  145. const showModal = ref(false);
  146. const days = ref("000"); // 默认值设为100,确保有3位数
  147. let timer = null;
  148. const exam_time = ref(""); //考试时间
  149. const isLogin = () => {
  150. const userInfo = uni.getStorageSync("userLogin");
  151. return !!userInfo?.is_register;
  152. };
  153. const receive = () => {
  154. if (!isLogin()) {
  155. router.push("/pages/login/index");
  156. return;
  157. }
  158. showModal.value = false;
  159. setTimeout(() => {
  160. router.push("/pages/contant/sub");
  161. }, 0);
  162. };
  163. // 将天数拆分为单个数字数组
  164. const splitDays = computed(() => {
  165. // 将数字转为字符串,然后拆分为字符数组
  166. const str = days.value.toString();
  167. // 如果不足3位数,前面补0(例如5变成["0","0","5"])
  168. return str.padStart(3, "0").split("");
  169. });
  170. const onload = (e) => {
  171. console.log(e);
  172. };
  173. const calculateDays = () => {
  174. // const targetDate = new Date('2025-12-31');
  175. const targetDate = new Date(Number(exam_time.value * 1000));
  176. const currentDate = new Date();
  177. const diffTime = targetDate - currentDate;
  178. const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
  179. days.value = diffDays > 0 ? diffDays : 0;
  180. };
  181. const clickClass = ({ id, name }) => {
  182. router.push({
  183. url: "/pages/regulations/index",
  184. params: {
  185. id,
  186. title: name,
  187. },
  188. });
  189. };
  190. const toReal = (item) => {
  191. router.push({
  192. url: "/pages/real/index",
  193. params: item,
  194. });
  195. };
  196. const onImageLoad = (e, item, index) => {
  197. const { width, height } = e.detail;
  198. const ratio = height / width;
  199. const systemInfo = uni.getSystemInfoSync();
  200. const imgHeightValue = systemInfo.windowWidth * ratio;
  201. imgHeight.value = imgHeightValue + "px";
  202. };
  203. onBeforeUnmount(() => {
  204. if (timer) clearInterval(timer);
  205. });
  206. const goto_notice_list = (link_url) => {
  207. uni.navigateTo({
  208. url: link_url,
  209. });
  210. };
  211. onMounted(async () => {
  212. const params = getRoute().params;
  213. if (params.scene) {
  214. const p = params.scene.split("=");
  215. const value = p[1];
  216. uni.setStorageSync("share_uid", value);
  217. }
  218. const res = await request(
  219. "api/question_bank/question_reception/chapter/get",
  220. {},
  221. "POST"
  222. );
  223. list.value = arrayToTree({
  224. list: res.data,
  225. });
  226. // 首页轮播
  227. const banner_res = await request(
  228. "api/question_bank/question_reception/banner/list",
  229. { page: 1, limit: 10 },
  230. "POST"
  231. );
  232. banner_list.value = banner_res.data.data;
  233. //系统公告
  234. const notice_res = await request(
  235. "api/question_bank/question_reception/notice/list",
  236. { page: 1, limit: 1 },
  237. "POST"
  238. );
  239. notice_list.value = notice_res.data.data;
  240. //获取考试倒计时
  241. const examination_res = await request(
  242. "api/question_bank/question_reception/common_config/detail",
  243. { content_code: "examination_countdown" },
  244. "POST"
  245. );
  246. exam_time.value =
  247. examination_res != "" ? examination_res.data.content_detail : "";
  248. // 获取历年真题
  249. const rightListRes = await request(
  250. "api/question_bank/question_reception/real_catalogue/get_year",
  251. {},
  252. "post"
  253. );
  254. rightList.value = rightListRes.data.map((i) => {
  255. const newItem = {
  256. name: i + "年",
  257. originName: i,
  258. };
  259. if (i.includes("(")) {
  260. // 2022(1)变成 2022年(一)
  261. newItem.name = i.replace(/\((\d+)\)/g, (text, number) => {
  262. const chineseNumber = [
  263. "一",
  264. "二",
  265. "三",
  266. "四",
  267. "五",
  268. "六",
  269. "七",
  270. "八",
  271. "九",
  272. ];
  273. return `年(${chineseNumber[number - 1]})`;
  274. });
  275. }
  276. return newItem;
  277. });
  278. if (!isLogin()) {
  279. showModal.value = true;
  280. }
  281. calculateDays();
  282. timer = setInterval(() => {
  283. calculateDays();
  284. }, 24 * 60 * 60 * 1000);
  285. return {
  286. days,
  287. splitDays,
  288. };
  289. });
  290. </script>
  291. <style scoped lang="scss">
  292. @import "@/uni.scss";
  293. .mo {
  294. display: flex;
  295. flex-direction: column;
  296. align-items: flex-end;
  297. width: 658rpx;
  298. .icons {
  299. background: #8a8a8b;
  300. width: 48rpx;
  301. height: 48rpx;
  302. border-radius: 50%;
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. }
  307. .bgt {
  308. width: 658rpx;
  309. height: 766rpx;
  310. position: relative;
  311. background: url(https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/06/p3qrAPK10tNFOfwy27yryTtwEOsE8x40V0wFvbOW.png);
  312. background-size: 100% 100%;
  313. display: flex;
  314. flex-direction: column;
  315. align-items: center;
  316. font-weight: 600;
  317. font-size: 32rpx;
  318. color: #8b3700;
  319. gap: 16rpx;
  320. box-sizing: border-box;
  321. padding-top: 161rpx;
  322. }
  323. .fixed {
  324. position: absolute;
  325. width: 348rpx;
  326. height: 86rpx;
  327. bottom: 30rpx;
  328. }
  329. }
  330. .service {
  331. position: absolute;
  332. bottom: 20%;
  333. right: 5%;
  334. color: $uni-primary;
  335. font-size: 28rpx;
  336. margin-bottom: 40rpx;
  337. text-align: right;
  338. }
  339. .img_small {
  340. width: 112rpx;
  341. height: 112rpx;
  342. }
  343. .body-content {
  344. background: #f8f8f8;
  345. border-radius: 0rpx 0rpx 0rpx 0rpx;
  346. }
  347. .exam-countdown-tiem-item {
  348. width: 24rpx;
  349. height: 34rpx;
  350. background: #ff3c3c;
  351. border-radius: 2rpx 2rpx 2rpx 2rpx;
  352. font-family: PingFang SC, PingFang SC;
  353. font-weight: 500;
  354. font-size: 24rpx;
  355. color: #ffffff;
  356. display: flex;
  357. align-items: center;
  358. justify-content: center;
  359. }
  360. .home {
  361. display: flex;
  362. flex-direction: column;
  363. gap: 20rpx;
  364. .time {
  365. display: flex;
  366. align-items: center;
  367. justify-content: center;
  368. font-family: PingFang SC, PingFang SC;
  369. font-weight: 500;
  370. font-size: 24rpx;
  371. color: #333333;
  372. gap: 8rpx;
  373. .tiem-item {
  374. width: 24rpx;
  375. height: 34rpx;
  376. background: #ff3c3c;
  377. border-radius: 2rpx 2rpx 2rpx 2rpx;
  378. font-family: PingFang SC, PingFang SC;
  379. font-weight: 500;
  380. font-size: 24rpx;
  381. color: #ffffff;
  382. display: flex;
  383. align-items: center;
  384. justify-content: center;
  385. }
  386. }
  387. .swiper {
  388. width: 100%;
  389. /* 关键修复样式 */
  390. overflow: hidden;
  391. transform-style: preserve-3d;
  392. .swiper-item {
  393. width: 100%;
  394. height: 100%;
  395. overflow: hidden;
  396. border-radius: 30rpx;
  397. /* 确保变换不影响子元素 */
  398. transform: translateZ(0);
  399. .swiper-item-image {
  400. width: 100%;
  401. height: 100%;
  402. display: block;
  403. border-radius: 30rpx;
  404. /* 防止图片变形 */
  405. object-fit: cover;
  406. /* 确保层级 */
  407. position: relative;
  408. }
  409. }
  410. }
  411. .notice {
  412. display: flex;
  413. align-items: center;
  414. gap: 20rpx;
  415. padding-left: 26rpx;
  416. height: 72rpx;
  417. background: #ffffff;
  418. border-radius: 500rpx 500rpx 500rpx 500rpx;
  419. border: 1rpx solid #f8f8f8;
  420. .title-lable {
  421. padding: 5rpx 15rpx;
  422. border-radius: 8rpx 8rpx 8rpx 8rpx;
  423. border: 1rpx solid #3f75ff;
  424. font-weight: 500;
  425. font-size: 26rpx;
  426. color: #3f75ff;
  427. line-height: 32rpx;
  428. text-align: center;
  429. font-style: normal;
  430. text-transform: none;
  431. }
  432. .notice-title {
  433. width: calc(100% - 225rpx);
  434. color: #333;
  435. font-size: 26rpx;
  436. display: -webkit-box;
  437. -webkit-box-orient: vertical;
  438. -webkit-line-clamp: 1;
  439. overflow: hidden;
  440. text-overflow: ellipsis;
  441. }
  442. .notice-more {
  443. font-size: 26rpx;
  444. }
  445. }
  446. }
  447. .title {
  448. font-family: "PingFang SC, PingFang SC";
  449. font-weight: 700;
  450. font-size: 32rpx;
  451. color: #000000;
  452. }
  453. .p-20 {
  454. display: flex;
  455. flex-direction: column;
  456. gap: 20rpx;
  457. }
  458. .grid {
  459. display: grid;
  460. grid-template-columns: repeat(4, 1fr);
  461. background-color: #ffffff;
  462. padding: 24rpx;
  463. gap: 16rpx;
  464. border-radius: 16rpx;
  465. }
  466. .grid-3 {
  467. display: grid;
  468. grid-template-columns: repeat(3, 1fr);
  469. background-color: #ffffff;
  470. padding: 24rpx;
  471. gap: 16rpx;
  472. border-radius: 16rpx;
  473. height: 100%;
  474. margin-bottom: 20rpx;
  475. }
  476. .flex {
  477. display: flex;
  478. flex-direction: column;
  479. gap: 20rpx;
  480. align-items: center;
  481. justify-content: center;
  482. }
  483. .bg-red {
  484. width: 191.07rpx;
  485. height: 179.61rpx;
  486. background: url("https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/WmhlbORF2q8A62Ytg1RVac8AYSGPkf7F2pEY6jQP.png")
  487. no-repeat;
  488. background-size: cover;
  489. display: flex;
  490. justify-content: center;
  491. .text {
  492. font-family: jiangxizhuokai, jiangxizhuokai;
  493. font-weight: bold;
  494. font-size: 27rpx;
  495. color: #3f75ff;
  496. text-shadow: 0px 2px 4px #bdcfff;
  497. text-align: left;
  498. font-style: normal;
  499. text-transform: none;
  500. margin-top: 16rpx;
  501. width: 95rpx;
  502. height: 70rpx;
  503. }
  504. }
  505. </style>