index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <Container
  3. class="body-content"
  4. title="首页"
  5. bgColor="#F8F8F8"
  6. :showBack="false"
  7. >
  8. <view class="home">
  9. <!-- 倒计时 -->
  10. <view class="time" v-if="(splitDays != '') & (splitDays != null)">
  11. <view>倒计时</view>
  12. <!-- 将天数拆分为单个数字显示 -->
  13. <view
  14. class="exam-countdown-tiem-item"
  15. v-for="(digit, index) in splitDays"
  16. :key="index"
  17. >{{ digit }}</view
  18. >
  19. <view>天</view>
  20. </view>
  21. <!-- 轮播图 -->
  22. <swiper class="swiper" circular autoplay>
  23. <swiper-item v-for="(item, index) in banner_list" :key="index">
  24. <view class="swiper-item"
  25. ><image
  26. class="swiper-item-image"
  27. :src="item.image_url"
  28. mode="aspectFill"
  29. @load="onImageLoad($event, item, index)"
  30. @click="goto_notice_list(item.link_url)"
  31. ></image
  32. ></view>
  33. </swiper-item>
  34. </swiper>
  35. <!-- 公告 -->
  36. <view class="notice" v-if="notice_list != '' && notice_list != null">
  37. <view class="title-lable">公告</view>
  38. <view class="notice-title">{{ notice_list[0]["title"] }}</view>
  39. <navigator url="/pages/notice/list">
  40. <view class="notice-more">{{ "更多 >" }}</view>
  41. </navigator>
  42. </view>
  43. <!-- 2025新大纲 -->
  44. <view class="new_outline">
  45. <uni-section title="基础用法" type="line">
  46. <view class="p-20">
  47. <uni-segmented-control
  48. :flex="false"
  49. :current="current"
  50. :values="list.map((item) => item.name)"
  51. style-type="text"
  52. @clickItem="(e) => (current = e.currentIndex)"
  53. />
  54. <!-- 执业药师 -->
  55. <template v-for="(item, index) in list" :key="item.id">
  56. <view v-if="current === index" class="grid">
  57. <view
  58. v-for="i in item?.children"
  59. :key="i.id"
  60. class="flex"
  61. @click="clickClass(i)"
  62. >
  63. <image :src="i.chapter_image_url" class="img_small"></image>
  64. <view>{{ i.name }}</view>
  65. </view>
  66. </view>
  67. </template>
  68. </view>
  69. </uni-section>
  70. </view>
  71. <view class="p-20">
  72. <uni-section title="往年真题" type="line">
  73. <!-- 往年真题 -->
  74. <view class="grid-3">
  75. <view
  76. v-for="item in rightList"
  77. :key="item.originName"
  78. class="flex"
  79. @click="
  80. toReal({
  81. title: item.name + '真题',
  82. origin: item.originName,
  83. })
  84. "
  85. >
  86. <view class="bg-red">
  87. <view class="text">{{ item.name }}真题</view>
  88. </view>
  89. </view>
  90. </view>
  91. </uni-section>
  92. </view>
  93. <view></view>
  94. </view>
  95. </Container>
  96. </template>
  97. <script setup>
  98. import { ref, onMounted, computed, onBeforeUnmount } from "vue";
  99. import Container from "../../components/Container/Container.vue";
  100. import { router } from "../../utils/router";
  101. import { request } from "../../utils/request";
  102. import { arrayToTree } from "../../utils";
  103. const current = ref(0);
  104. const list = ref([]);
  105. const banner_list = ref([]);
  106. const notice_list = ref([]);
  107. const imgHeight = ref("auto"); // 初始高度
  108. const rightList = ref([]);
  109. const days = ref("000"); // 默认值设为100,确保有3位数
  110. let timer = null;
  111. const exam_time = ref(""); //考试时间
  112. // 将天数拆分为单个数字数组
  113. const splitDays = computed(() => {
  114. // 将数字转为字符串,然后拆分为字符数组
  115. const str = days.value.toString();
  116. // 如果不足3位数,前面补0(例如5变成["0","0","5"])
  117. return str.padStart(3, "0").split("");
  118. });
  119. const calculateDays = () => {
  120. // const targetDate = new Date('2025-12-31');
  121. const targetDate = new Date(Number(exam_time.value * 1000));
  122. const currentDate = new Date();
  123. const diffTime = targetDate - currentDate;
  124. const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
  125. days.value = diffDays > 0 ? diffDays : 0;
  126. };
  127. const clickClass = ({ id, name }) => {
  128. router.push({
  129. url: "/pages/regulations/index",
  130. params: {
  131. id,
  132. title: name,
  133. },
  134. });
  135. };
  136. const toReal = (item) => {
  137. router.push({
  138. url: "/pages/real/index",
  139. params: item,
  140. });
  141. };
  142. const onImageLoad = (e, item, index) => {
  143. const { width, height } = e.detail;
  144. const ratio = height / width;
  145. const systemInfo = uni.getSystemInfoSync();
  146. const imgHeightValue = systemInfo.windowWidth * ratio;
  147. imgHeight.value = imgHeightValue + "px";
  148. };
  149. onBeforeUnmount(() => {
  150. if (timer) clearInterval(timer);
  151. });
  152. const goto_notice_list = (link_url) => {
  153. uni.navigateTo({
  154. url: link_url,
  155. });
  156. };
  157. onMounted(async () => {
  158. const res = await request(
  159. "api/question_bank/question_reception/chapter/get",
  160. {},
  161. "POST"
  162. );
  163. list.value = arrayToTree({
  164. list: res.data,
  165. });
  166. // 首页轮播
  167. const banner_res = await request(
  168. "api/question_bank/question_reception/banner/list",
  169. { page: 1, limit: 10 },
  170. "POST"
  171. );
  172. banner_list.value = banner_res.data.data;
  173. //系统公告
  174. const notice_res = await request(
  175. "api/question_bank/question_reception/notice/list",
  176. { page: 1, limit: 1 },
  177. "POST"
  178. );
  179. notice_list.value = notice_res.data.data;
  180. //获取考试倒计时
  181. const examination_res = await request(
  182. "api/question_bank/question_reception/common_config/detail",
  183. { content_code: "examination_countdown" },
  184. "POST"
  185. );
  186. exam_time.value =
  187. examination_res != "" ? examination_res.data.content_detail : "";
  188. // 获取历年真题
  189. const rightListRes = await request(
  190. "api/question_bank/question_reception/real_catalogue/get_year",
  191. {},
  192. "post"
  193. );
  194. rightList.value = rightListRes.data.map((i) => {
  195. const newItem = {
  196. name: i + "年",
  197. originName: i,
  198. };
  199. if (i.includes("(")) {
  200. // 2022(1)变成 2022年(一)
  201. newItem.name = i.replace(/\((\d+)\)/g, (text, number) => {
  202. const chineseNumber = [
  203. "一",
  204. "二",
  205. "三",
  206. "四",
  207. "五",
  208. "六",
  209. "七",
  210. "八",
  211. "九",
  212. ];
  213. return `年(${chineseNumber[number - 1]})`;
  214. });
  215. }
  216. return newItem;
  217. });
  218. calculateDays();
  219. timer = setInterval(() => {
  220. calculateDays();
  221. }, 24 * 60 * 60 * 1000);
  222. return {
  223. days,
  224. splitDays,
  225. };
  226. });
  227. </script>
  228. <style scoped lang="scss">
  229. @import "@/uni.scss";
  230. .img_small {
  231. width: 112rpx;
  232. height: 112rpx;
  233. }
  234. .body-content {
  235. background: #f8f8f8;
  236. border-radius: 0rpx 0rpx 0rpx 0rpx;
  237. }
  238. .exam-countdown-tiem-item {
  239. width: 24rpx;
  240. height: 34rpx;
  241. background: #ff3c3c;
  242. border-radius: 2rpx 2rpx 2rpx 2rpx;
  243. font-family: PingFang SC, PingFang SC;
  244. font-weight: 500;
  245. font-size: 24rpx;
  246. color: #ffffff;
  247. display: flex;
  248. align-items: center;
  249. justify-content: center;
  250. }
  251. .home {
  252. display: flex;
  253. flex-direction: column;
  254. gap: 20rpx;
  255. .time {
  256. display: flex;
  257. align-items: center;
  258. justify-content: center;
  259. font-family: PingFang SC, PingFang SC;
  260. font-weight: 500;
  261. font-size: 24rpx;
  262. color: #333333;
  263. gap: 8rpx;
  264. .tiem-item {
  265. width: 24rpx;
  266. height: 34rpx;
  267. background: #ff3c3c;
  268. border-radius: 2rpx 2rpx 2rpx 2rpx;
  269. font-family: PingFang SC, PingFang SC;
  270. font-weight: 500;
  271. font-size: 24rpx;
  272. color: #ffffff;
  273. display: flex;
  274. align-items: center;
  275. justify-content: center;
  276. }
  277. }
  278. .swiper {
  279. width: 100%;
  280. height: v-bind(imgHeight);
  281. /* 关键修复样式 */
  282. overflow: hidden;
  283. transform-style: preserve-3d;
  284. .swiper-item {
  285. width: 100%;
  286. height: 100%;
  287. overflow: hidden;
  288. border-radius: 30rpx;
  289. /* 确保变换不影响子元素 */
  290. transform: translateZ(0);
  291. .swiper-item-image {
  292. width: 100%;
  293. height: 100%;
  294. display: block;
  295. border-radius: 30rpx;
  296. /* 防止图片变形 */
  297. object-fit: cover;
  298. /* 确保层级 */
  299. position: relative;
  300. }
  301. }
  302. }
  303. .notice {
  304. display: flex;
  305. align-items: center;
  306. gap: 20rpx;
  307. padding-left: 26rpx;
  308. height: 72rpx;
  309. background: #ffffff;
  310. border-radius: 500rpx 500rpx 500rpx 500rpx;
  311. border: 1rpx solid #f8f8f8;
  312. .title-lable {
  313. padding: 5rpx 15rpx;
  314. border-radius: 8rpx 8rpx 8rpx 8rpx;
  315. border: 1rpx solid #3f75ff;
  316. font-weight: 500;
  317. font-size: 26rpx;
  318. color: #3f75ff;
  319. line-height: 32rpx;
  320. text-align: center;
  321. font-style: normal;
  322. text-transform: none;
  323. }
  324. .notice-title {
  325. width: calc(100% - 225rpx);
  326. color: #333;
  327. font-size: 26rpx;
  328. display: -webkit-box;
  329. -webkit-box-orient: vertical;
  330. -webkit-line-clamp: 1;
  331. overflow: hidden;
  332. text-overflow: ellipsis;
  333. }
  334. .notice-more {
  335. font-size: 26rpx;
  336. }
  337. }
  338. }
  339. .title {
  340. font-family: "PingFang SC, PingFang SC";
  341. font-weight: 700;
  342. font-size: 32rpx;
  343. color: #000000;
  344. }
  345. .p-20 {
  346. display: flex;
  347. flex-direction: column;
  348. gap: 20rpx;
  349. }
  350. .grid {
  351. display: grid;
  352. grid-template-columns: repeat(4, 1fr);
  353. background-color: #ffffff;
  354. padding: 24rpx;
  355. gap: 16rpx;
  356. border-radius: 16rpx;
  357. }
  358. .grid-3 {
  359. display: grid;
  360. grid-template-columns: repeat(3, 1fr);
  361. background-color: #ffffff;
  362. padding: 24rpx;
  363. gap: 16rpx;
  364. border-radius: 16rpx;
  365. height: 100%;
  366. margin-bottom: 20rpx;
  367. }
  368. .flex {
  369. display: flex;
  370. flex-direction: column;
  371. gap: 20rpx;
  372. align-items: center;
  373. justify-content: center;
  374. }
  375. .bg-red {
  376. width: 191.07rpx;
  377. height: 179.61rpx;
  378. background: url("https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/WmhlbORF2q8A62Ytg1RVac8AYSGPkf7F2pEY6jQP.png")
  379. no-repeat;
  380. background-size: cover;
  381. display: flex;
  382. justify-content: center;
  383. .text {
  384. font-family: jiangxizhuokai, jiangxizhuokai;
  385. font-weight: bold;
  386. font-size: 27rpx;
  387. color: #3f75ff;
  388. text-shadow: 0px 2px 4px #bdcfff;
  389. text-align: left;
  390. font-style: normal;
  391. text-transform: none;
  392. margin-top: 16rpx;
  393. width: 95rpx;
  394. height: 70rpx;
  395. }
  396. }
  397. </style>