2023-11-22 09:37:30 +08:00
|
|
|
import { driver } from "driver.js";
|
|
|
|
|
import "driver.js/dist/driver.css";
|
2023-11-22 15:41:46 +08:00
|
|
|
import { useStore } from "vuex";
|
2023-11-22 09:37:30 +08:00
|
|
|
//版本一
|
2023-11-22 15:41:46 +08:00
|
|
|
let driverIndex__ = 0
|
|
|
|
|
let store
|
2023-11-22 09:37:30 +08:00
|
|
|
const driverObj__ = driver({
|
|
|
|
|
steps: [
|
|
|
|
|
{ element: '#Guide_1_1', popover: { title: 'Title', description: 'Description' } },
|
|
|
|
|
{ element: '.Guide_1_2', popover: { title: 'Title', description: 'Description' } },
|
|
|
|
|
{ element: '.Guide_1_2', popover: { title: 'Title', description: 'Description' } },
|
|
|
|
|
{ element: '.Guide_1_4', popover: { title: 'Title', description: 'Description' } },
|
2023-11-22 17:05:09 +08:00
|
|
|
{ element: '.Guide_1_5', popover: { title: 'Title', description: 'Description' } },
|
|
|
|
|
{ element: '.Guide_1_6', popover: { title: 'Title', description: 'Description' } },
|
2023-11-23 11:15:10 +08:00
|
|
|
{ element: '.Guide_1_7', popover: { title: 'Title', description: 'Description' } },
|
|
|
|
|
{ element: '.Guide_1_8', popover: { title: 'Title', description: 'Description' } },
|
|
|
|
|
{ element: '.Guide_1_2', popover: { title: 'Title', description: 'Description' } },
|
2023-11-22 09:37:30 +08:00
|
|
|
],
|
|
|
|
|
// showProgress: true,//控制总页数和当前页数是否显示
|
|
|
|
|
allowClose:false,
|
|
|
|
|
showButtons:false,
|
|
|
|
|
stagePadding:10,//切口到元素的距离
|
|
|
|
|
stageRadius:5,//切口圆弧度
|
|
|
|
|
allowKeyboardControl:true,//控制是否可以键盘控制下一步
|
|
|
|
|
disableActiveInteraction:false,//是否禁用显示元素的交互
|
2023-11-22 15:41:46 +08:00
|
|
|
overlayOpacity:.4,
|
|
|
|
|
overlay: true,
|
2023-11-22 09:37:30 +08:00
|
|
|
onPopoverRender: (popover, options) => {//每个步骤的元素和所有信息
|
2023-11-22 15:41:46 +08:00
|
|
|
// console.log(popover,options);
|
|
|
|
|
popover.previousButton.style.display = 'none'
|
|
|
|
|
if(options.state.activeIndex >= 1 && options.state.activeIndex <= 2){
|
2023-11-22 09:37:30 +08:00
|
|
|
popover.footer.style.display = 'block'
|
2023-11-22 15:41:46 +08:00
|
|
|
addDiv(options.state.activeElement)
|
2023-11-22 09:37:30 +08:00
|
|
|
}else{
|
|
|
|
|
popover.footer.style.display = 'none'
|
2023-11-22 15:41:46 +08:00
|
|
|
removeDiv(options.state.activeElement)
|
|
|
|
|
}
|
|
|
|
|
// console.log(options.state.activeIndex);
|
|
|
|
|
driverIndex__ = driverObj__.getState().activeIndex
|
|
|
|
|
let data = {
|
2023-11-23 11:15:10 +08:00
|
|
|
index:driverIndex__,
|
|
|
|
|
driver:true,
|
2023-11-22 09:37:30 +08:00
|
|
|
}
|
2023-11-22 15:41:46 +08:00
|
|
|
store?.commit("setGuide", data);
|
2023-11-22 09:37:30 +08:00
|
|
|
},
|
2023-11-22 15:41:46 +08:00
|
|
|
// onNextClick:(element, step, options) =>{
|
|
|
|
|
// console.log(element,step,options);
|
|
|
|
|
// driverObj__.moveNext()
|
|
|
|
|
// // element.style.posiiton = 'relative'
|
|
|
|
|
// // const mask = document.createElement('div');
|
|
|
|
|
// // mask.style.position = 'absolute';
|
|
|
|
|
// // mask.style.top = '0';
|
|
|
|
|
// // mask.style.left = '0';
|
|
|
|
|
// // mask.style.width = '100%';
|
|
|
|
|
// // mask.style.height = '100%';
|
|
|
|
|
// // mask.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
|
|
|
|
|
// // mask.style.zIndex = '9999';
|
|
|
|
|
// // element.appendChild(mask);
|
|
|
|
|
// }
|
2023-11-22 09:37:30 +08:00
|
|
|
});
|
2023-11-22 15:41:46 +08:00
|
|
|
function addDiv(element){
|
|
|
|
|
element.style.posiiton = 'relative'
|
2023-11-22 17:05:09 +08:00
|
|
|
const mask = document.getElementsByClassName('driver-mask__')?.[0]
|
2023-11-22 15:41:46 +08:00
|
|
|
if(mask){
|
|
|
|
|
}else{
|
|
|
|
|
const mask = document.createElement('div');
|
|
|
|
|
mask.style.position = 'absolute';
|
|
|
|
|
mask.style.top = '0';
|
|
|
|
|
mask.style.left = '0';
|
|
|
|
|
mask.style.width = '100%';
|
|
|
|
|
mask.style.height = '100%';
|
2023-11-22 17:05:09 +08:00
|
|
|
mask.style.backgroundColor = 'rgba(0, 0, 0, 0)';
|
2023-11-22 15:41:46 +08:00
|
|
|
mask.style.zIndex = '9999';
|
2023-11-22 17:05:09 +08:00
|
|
|
mask.classList.add('driver-mask__')
|
2023-11-22 15:41:46 +08:00
|
|
|
element.appendChild(mask);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function removeDiv(element){
|
2023-11-22 17:05:09 +08:00
|
|
|
const mask = document.getElementsByClassName('driver-mask__')?.[0]
|
2023-11-22 15:41:46 +08:00
|
|
|
if(mask){
|
|
|
|
|
// element.removeChild(mask);
|
|
|
|
|
mask.remove()
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-22 09:37:30 +08:00
|
|
|
const openGuide = () =>{
|
|
|
|
|
// driverObj__.drive();
|
2023-11-22 15:41:46 +08:00
|
|
|
store = useStore()
|
|
|
|
|
|
|
|
|
|
// driverObj__.moveNext();
|
|
|
|
|
// driverObj__.movePrevious();
|
2023-11-22 09:37:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export{
|
|
|
|
|
openGuide,
|
|
|
|
|
driverObj__,
|
2023-11-22 15:41:46 +08:00
|
|
|
driverIndex__,
|
2023-11-22 09:37:30 +08:00
|
|
|
}
|