|
@@ -1,44 +1,98 @@
|
|
|
import { css } from "@linaria/core";
|
|
|
-import { defineComponent, reactive, ref } from "vue";
|
|
|
+import { defineComponent, reactive, ref, nextTick } from "vue";
|
|
|
import { Swiper, SwiperSlide } from "swiper/vue";
|
|
|
import { Autoplay } from "swiper";
|
|
|
import "swiper/css";
|
|
|
+import { useArticle, useCategory } from "@/modules";
|
|
|
+import loading from "@/components/Provider/Loading";
|
|
|
+import Image from "@/components/Image";
|
|
|
+import { message } from "ant-design-vue";
|
|
|
+import { useRouter } from "vue-router";
|
|
|
+
|
|
|
export default defineComponent({
|
|
|
setup() {
|
|
|
+ const store = useArticle();
|
|
|
+ const storeCategory = useCategory();
|
|
|
+ const router = useRouter();
|
|
|
const state = reactive({
|
|
|
active: 0,
|
|
|
+ images: [] as any,
|
|
|
});
|
|
|
const swiperRef = ref();
|
|
|
- const images = [
|
|
|
- {
|
|
|
- url: getImageUrl("banner/banner.png"),
|
|
|
- },
|
|
|
- {
|
|
|
- url: getImageUrl("banner/banner.png"),
|
|
|
- },
|
|
|
- ];
|
|
|
+ const initBanner = async () => {
|
|
|
+ loading.show("");
|
|
|
+ await store.bannerList.loadPage(1);
|
|
|
+ state.images = store.bannerList.state.list;
|
|
|
+
|
|
|
+ nextTick(() => {
|
|
|
+ if (swiperRef.value) {
|
|
|
+ swiperRef.value.update();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ loading.hidden();
|
|
|
+ };
|
|
|
+ initBanner();
|
|
|
const initSwiper = (swiper: any) => {
|
|
|
swiperRef.value = swiper;
|
|
|
};
|
|
|
+ const bannerClick = async (item: any) => {
|
|
|
+ if (item.url) {
|
|
|
+ window.open(item.url);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!item.aid) return;
|
|
|
+ const detRes = await store.listController.itemDetail(item.aid);
|
|
|
+ if (detRes.errorNo != 200) {
|
|
|
+ message.warn("未查询到数据!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const artDetail = detRes.result;
|
|
|
+ const currCate = storeCategory.listController.state.list.find((e) => {
|
|
|
+ return e._id == artDetail.cid;
|
|
|
+ });
|
|
|
+ if (!currCate) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const currParent = storeCategory.listController.state.list.find((e) => {
|
|
|
+ return e._id == currCate?.pid;
|
|
|
+ });
|
|
|
+ if (currParent?.pid == "top") {
|
|
|
+ router.push({
|
|
|
+ name: "article",
|
|
|
+ params: { id: currCate._id },
|
|
|
+ query: { aid: artDetail._id },
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ router.push({
|
|
|
+ name: "article",
|
|
|
+ params: { id: currParent?._id },
|
|
|
+ query: { aid: artDetail._id },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
return () => (
|
|
|
<div class={page}>
|
|
|
<Swiper
|
|
|
class={"banner_swiper"}
|
|
|
modules={[Autoplay]}
|
|
|
- autoplay={{
|
|
|
- delay: 5000,
|
|
|
- disableOnInteraction: false,
|
|
|
- }}
|
|
|
+ autoplay={false}
|
|
|
loop={true}
|
|
|
onSwiper={initSwiper}
|
|
|
onSlideChange={(e) => {
|
|
|
state.active = e.realIndex;
|
|
|
}}
|
|
|
>
|
|
|
- {images.map((e) => {
|
|
|
+ {state.images.map((item: any) => {
|
|
|
return (
|
|
|
<SwiperSlide>
|
|
|
- <img src={e.url} />
|
|
|
+ <div
|
|
|
+ class={"banner_item"}
|
|
|
+ onClick={() => {
|
|
|
+ bannerClick(item);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Image src={item.cover} />
|
|
|
+ </div>
|
|
|
</SwiperSlide>
|
|
|
);
|
|
|
})}
|
|
@@ -60,9 +114,9 @@ export default defineComponent({
|
|
|
/>
|
|
|
</div>
|
|
|
<div class={"swiper_pagination"}>
|
|
|
- {images.length > 0 && (
|
|
|
+ {state.images.length > 0 && (
|
|
|
<div class={"page_dots_box"}>
|
|
|
- {images.map((_, i) => {
|
|
|
+ {state.images.map((_: any, i: number) => {
|
|
|
return (
|
|
|
<div
|
|
|
class={["page_dot", state.active == i ? "active" : null]}
|
|
@@ -87,11 +141,14 @@ const page = css`
|
|
|
.banner_swiper {
|
|
|
height: 100%;
|
|
|
img {
|
|
|
- height: 100%;
|
|
|
+ height: 600px;
|
|
|
width: 100%;
|
|
|
object-fit: cover;
|
|
|
user-select: none;
|
|
|
}
|
|
|
+ .banner_item {
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
}
|
|
|
.swiper_prev,
|
|
|
.swiper_next {
|