index.vue 8.1 KB

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