index.vue 10 KB

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