fix: 优化swriper
This commit is contained in:
parent
850b34545a
commit
28b15a22b4
|
@ -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, // 修改swiper自己或子元素时,自动初始化swiper
|
||||||
|
observeParents: false, // 修改swiper的父元素时,自动初始化swiper
|
||||||
|
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>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
Loading…
Reference in New Issue