index.vue 10 KB

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