index.vue 10 KB

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