111 lines
2.7 KiB
JavaScript
111 lines
2.7 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const _sfc_main = {
|
|
__name: "donghua",
|
|
props: {
|
|
links: {
|
|
type: Array,
|
|
default: () => []
|
|
},
|
|
width: {
|
|
type: String,
|
|
default: "65rpx"
|
|
},
|
|
height: {
|
|
type: String,
|
|
default: "65rpx"
|
|
},
|
|
objectFit: {
|
|
type: String,
|
|
default: "aspectFill"
|
|
},
|
|
defaultImage: {
|
|
type: String,
|
|
default: ""
|
|
},
|
|
interval: {
|
|
type: Number,
|
|
default: 80
|
|
},
|
|
playing: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
showButton: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
loop: {
|
|
type: Boolean,
|
|
default: false
|
|
}
|
|
},
|
|
emits: ["update:playing"],
|
|
setup(__props, { emit: __emit }) {
|
|
const props = __props;
|
|
const currentIndex = common_vendor.ref(0);
|
|
const isPlaying = common_vendor.ref(false);
|
|
const isError = common_vendor.ref(false);
|
|
let timer = null;
|
|
const startPlay = () => {
|
|
if (isPlaying.value)
|
|
return;
|
|
isPlaying.value = true;
|
|
timer = setInterval(() => {
|
|
if (props.loop) {
|
|
currentIndex.value = (currentIndex.value + 1) % props.links.length;
|
|
isError.value = false;
|
|
} else {
|
|
if (currentIndex.value < props.links.length - 1) {
|
|
currentIndex.value++;
|
|
isError.value = false;
|
|
} else {
|
|
stopPlay();
|
|
}
|
|
}
|
|
}, props.interval);
|
|
};
|
|
const stopPlay = () => {
|
|
isPlaying.value = false;
|
|
clearInterval(timer);
|
|
};
|
|
common_vendor.watch(() => props.playing, (val) => {
|
|
currentIndex.value = 0;
|
|
if (val) {
|
|
startPlay();
|
|
} else {
|
|
stopPlay();
|
|
setTimeout(() => currentIndex.value = 0, 50);
|
|
}
|
|
});
|
|
common_vendor.watch(() => props.links, () => {
|
|
currentIndex.value = 0;
|
|
isError.value = false;
|
|
if (isPlaying.value) {
|
|
stopPlay();
|
|
}
|
|
}, {
|
|
deep: true
|
|
});
|
|
common_vendor.onUnmounted(() => {
|
|
stopPlay();
|
|
});
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: isError.value ? __props.defaultImage : __props.links[currentIndex.value],
|
|
b: __props.width,
|
|
c: __props.height,
|
|
d: __props.objectFit,
|
|
e: common_vendor.o(($event) => isError.value = true),
|
|
f: common_vendor.o(($event) => isError.value = false),
|
|
g: __props.showButton
|
|
}, __props.showButton ? {
|
|
h: common_vendor.t(__props.playing ? "停止播放" : "开始播放"),
|
|
i: common_vendor.o(($event) => _ctx.$emit("update:playing", !__props.playing))
|
|
} : {});
|
|
};
|
|
}
|
|
};
|
|
wx.createComponent(_sfc_main);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/component/public/donghua.js.map
|