fix: 优化swriper

This commit is contained in:
zhangds 2022-10-21 16:48:16 +08:00
parent 850b34545a
commit 28b15a22b4
1 changed files with 39 additions and 7 deletions

View File

@ -3,6 +3,7 @@ import React, {
useEffect, useEffect,
useImperativeHandle, useImperativeHandle,
useRef, useRef,
useState,
} from "react"; } from "react";
import { Select, ImageUpload, RadioButton, RadioGroup, Notify } from "zent"; import { Select, ImageUpload, RadioButton, RadioGroup, Notify } from "zent";
import { useSetState } from "ahooks"; import { useSetState } from "ahooks";
@ -19,6 +20,9 @@ import {
uploadImg, uploadImg,
} from "@/assets/api.js"; } from "@/assets/api.js";
import Swiper from "swiper/dist/js/swiper.js";
import "swiper/dist/css/swiper.min.css";
// //
const formRules = { const formRules = {
product: [{ type: "required", message: "请选择映射商品" }], product: [{ type: "required", message: "请选择映射商品" }],
@ -63,9 +67,9 @@ const UseProductPop = forwardRef((props, ref) => {
const [state, setState] = useSetState({ const [state, setState] = useSetState({
productOption: [], productOption: [],
productPic: [],
productDataAll: [], // productDataAll: [], //
goodsImgList: [], productPic: [],
isUpdatePic: false,
}); });
const [model, setModel] = useSetState({ const [model, setModel] = useSetState({
cur_product: {}, cur_product: {},
@ -89,6 +93,28 @@ const UseProductPop = forwardRef((props, ref) => {
getProductData(); getProductData();
}, [model.product_type]); }, [model.product_type]);
useEffect(() => {
setState({
productPic: model.describe_url,
});
}, [state.isUpdatePic]);
let [mySwiper, setMySwiper] = useState(null);
useEffect(() => {
let mySwiper = new Swiper(".swiper-container", {
slidesPerView: 1,
centeredSlides: true,
loop: true,
autoplay: 3000,
initialSlide: 0,
observer: true, // swiperswiper
observeParents: false, // swiperswiper
pagination: ".swiper-pagination",
paginationClickable: true,
});
setMySwiper(mySwiper);
}, []);
// //
const getProductData = () => { const getProductData = () => {
if (directResellerId) { if (directResellerId) {
@ -150,6 +176,9 @@ const UseProductPop = forwardRef((props, ref) => {
account_type: "", account_type: "",
map_product_name: "", map_product_name: "",
}); });
setTimeout(() => {
setState({ isUpdatePic: !state.isUpdatePic });
}, 300);
}; };
// //
const getFormModel = () => { const getFormModel = () => {
@ -178,15 +207,12 @@ const UseProductPop = forwardRef((props, ref) => {
Notify.error(`请上传商品Logo`); Notify.error(`请上传商品Logo`);
return; return;
} }
if (model.describe_url.length <= 0) { if (model.describe_url.length <= 0) {
Notify.error(`请上传商品Logo`); Notify.error(`请上传商品图片`);
return; return;
} }
visible = true; visible = true;
} }
return visible; return visible;
}; };
@ -237,6 +263,9 @@ const UseProductPop = forwardRef((props, ref) => {
describe_url: [], describe_url: [],
}); });
} }
setTimeout(() => {
setState({ isUpdatePic: !state.isUpdatePic });
}, 300);
}; };
const onTypeChange = (e) => { const onTypeChange = (e) => {
clearForm(); clearForm();
@ -338,6 +367,9 @@ const UseProductPop = forwardRef((props, ref) => {
describe_url: files, describe_url: files,
}); });
} }
setTimeout(() => {
setState({ isUpdatePic: !state.isUpdatePic });
}, 300);
}; };
const exchangeCodeH5El = () => { const exchangeCodeH5El = () => {
return ( return (
@ -541,7 +573,7 @@ const UseProductPop = forwardRef((props, ref) => {
{state.productPic.map((item, index) => { {state.productPic.map((item, index) => {
return ( return (
<div className="swiper-slide" key={index}> <div className="swiper-slide" key={index}>
<img src={item.url} alt="" /> <img src={item.src} alt="" />
</div> </div>
); );
})} })}