index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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)" @click="goto_notice_list(item.link_url)"></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. const goto_notice_list=(link_url)=>{
  125. uni.navigateTo({
  126. url:link_url
  127. });
  128. };
  129. onMounted(async () => {
  130. const res = await request('api/question_bank/question_reception/chapter/get', {}, 'POST');
  131. list.value = arrayToTree({
  132. list: res.data
  133. });
  134. // 首页轮播
  135. const banner_res = await request('api/question_bank/question_reception/banner/list', { page: 1, limit: 10 }, 'POST');
  136. banner_list.value = banner_res.data.data;
  137. //系统公告
  138. const notice_res = await request('api/question_bank/question_reception/notice/list', { page: 1, limit: 1 }, 'POST');
  139. notice_list.value = notice_res.data.data;
  140. //获取考试倒计时
  141. const examination_res = await request('api/question_bank/question_reception/common_config/detail', { content_code: 'examination_countdown' }, 'POST');
  142. exam_time.value=examination_res !='' ? examination_res.data.content_detail:'';
  143. calculateDays();
  144. timer = setInterval(() => {
  145. calculateDays();
  146. }, 24 * 60 * 60 * 1000);
  147. return {
  148. days,
  149. splitDays
  150. };
  151. });
  152. </script>
  153. <style scoped lang="scss">
  154. @import '@/uni.scss';
  155. .img_small {
  156. width: 112rpx;
  157. height: 112rpx;
  158. }
  159. .body-content {
  160. background: #f8f8f8;
  161. border-radius: 0rpx 0rpx 0rpx 0rpx;
  162. }
  163. .exam-countdown-tiem-item {
  164. width: 24rpx;
  165. height: 34rpx;
  166. background: #ff3c3c;
  167. border-radius: 2rpx 2rpx 2rpx 2rpx;
  168. font-family: PingFang SC, PingFang SC;
  169. font-weight: 500;
  170. font-size: 24rpx;
  171. color: #ffffff;
  172. display: flex;
  173. align-items: center;
  174. justify-content: center;
  175. }
  176. .home {
  177. display: flex;
  178. flex-direction: column;
  179. gap: 20rpx;
  180. .time {
  181. display: flex;
  182. align-items: center;
  183. justify-content: center;
  184. font-family: PingFang SC, PingFang SC;
  185. font-weight: 500;
  186. font-size: 24rpx;
  187. color: #333333;
  188. gap: 8rpx;
  189. .tiem-item {
  190. width: 24rpx;
  191. height: 34rpx;
  192. background: #ff3c3c;
  193. border-radius: 2rpx 2rpx 2rpx 2rpx;
  194. font-family: PingFang SC, PingFang SC;
  195. font-weight: 500;
  196. font-size: 24rpx;
  197. color: #ffffff;
  198. display: flex;
  199. align-items: center;
  200. justify-content: center;
  201. }
  202. }
  203. .swiper {
  204. width: 100%;
  205. height: v-bind(imgHeight);
  206. /* 关键修复样式 */
  207. overflow: hidden;
  208. transform-style: preserve-3d;
  209. .swiper-item {
  210. width: 100%;
  211. height: 100%;
  212. overflow: hidden;
  213. border-radius: 30rpx;
  214. /* 确保变换不影响子元素 */
  215. transform: translateZ(0);
  216. .swiper-item-image {
  217. width: 100%;
  218. height: 100%;
  219. display: block;
  220. border-radius: 30rpx;
  221. /* 防止图片变形 */
  222. object-fit: cover;
  223. /* 确保层级 */
  224. position: relative;
  225. }
  226. }
  227. }
  228. .notice {
  229. display: flex;
  230. align-items: center;
  231. gap: 20rpx;
  232. padding-left: 26rpx;
  233. height: 72rpx;
  234. background: #ffffff;
  235. border-radius: 500rpx 500rpx 500rpx 500rpx;
  236. border: 1rpx solid #f8f8f8;
  237. .title-lable {
  238. padding: 5rpx 15rpx;
  239. border-radius: 8rpx 8rpx 8rpx 8rpx;
  240. border: 1rpx solid #3f75ff;
  241. font-weight: 500;
  242. font-size: 26rpx;
  243. color: #3f75ff;
  244. line-height: 32rpx;
  245. text-align: center;
  246. font-style: normal;
  247. text-transform: none;
  248. }
  249. .notice-title {
  250. width: calc(100% - 225rpx);
  251. color: #333;
  252. font-size: 26rpx;
  253. display: -webkit-box;
  254. -webkit-box-orient: vertical;
  255. -webkit-line-clamp: 1;
  256. overflow: hidden;
  257. text-overflow: ellipsis;
  258. }
  259. .notice-more {
  260. font-size: 26rpx;
  261. }
  262. }
  263. }
  264. .title {
  265. font-family: 'PingFang SC, PingFang SC';
  266. font-weight: 700;
  267. font-size: 32rpx;
  268. color: #000000;
  269. }
  270. .p-20 {
  271. display: flex;
  272. flex-direction: column;
  273. gap: 20rpx;
  274. }
  275. .grid {
  276. display: grid;
  277. grid-template-columns: repeat(4, 1fr);
  278. background-color: #ffffff;
  279. padding: 24rpx;
  280. gap: 16rpx;
  281. border-radius: 16rpx;
  282. }
  283. .grid-3 {
  284. display: grid;
  285. grid-template-columns: repeat(3, 1fr);
  286. background-color: #ffffff;
  287. padding: 24rpx;
  288. gap: 16rpx;
  289. border-radius: 16rpx;
  290. height: 100%;
  291. }
  292. .flex {
  293. display: flex;
  294. flex-direction: column;
  295. gap: 20rpx;
  296. align-items: center;
  297. justify-content: center;
  298. }
  299. .bg-red {
  300. width: 191.07rpx;
  301. height: 179.61rpx;
  302. background: url('https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/WmhlbORF2q8A62Ytg1RVac8AYSGPkf7F2pEY6jQP.png') no-repeat;
  303. background-size: cover;
  304. display: flex;
  305. justify-content: center;
  306. .text {
  307. font-family: jiangxizhuokai, jiangxizhuokai;
  308. font-weight: bold;
  309. font-size: 27rpx;
  310. color: #3f75ff;
  311. text-shadow: 0px 2px 4px #bdcfff;
  312. text-align: left;
  313. font-style: normal;
  314. text-transform: none;
  315. margin-top: 16rpx;
  316. width: 95rpx;
  317. height: 70rpx;
  318. }
  319. }
  320. </style>