2023-11-22 09:37:30 +08:00
import { driver } from "driver.js" ;
2023-11-30 10:54:22 +08:00
import { setCookie , getCookie , WriteCookie } from "@/tool/cookie" ;
2023-11-22 09:37:30 +08:00
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-23 15:31:40 +08:00
let element
2023-11-24 16:18:44 +08:00
let data = {
index : driverIndex _ _ ,
driver : true ,
}
2023-11-22 09:37:30 +08:00
const driverObj _ _ = driver ( {
steps : [
2023-12-01 15:02:37 +08:00
{ element : '.Guide_1_1' , popover : { title : '' , description : 'Begin your creative journey here.' } } ,
// { element: '.Guide_1_2', popover: { title: '', description: 'Description' } },
// { element: '.Guide_1_2', popover: { title: '', description: 'Description' } },
{ element : '.Guide_1_4' , popover : { title : '' , description : 'Click here to try the latest image generation technology to create your mood board.' } } ,
{ element : '.Guide_1_5' , popover : { title : '' , description : "Enter keywords that capture the mood you wish to express and then click the 'Generate' button." } } ,
{ element : '.Guide_1_6' , popover : { title : '' , description : 'Select three images for your moodboard.' } } ,
{ element : '.Guide_1_7' , popover : { title : '' , description : 'Click here to layout your moodboard.' } } ,
{ element : '.Guide_1_8' , popover : { title : '' , description : 'Click here for next step.' } } ,
//以上moodboard
{ element : '.Guide_1_2' , popover : { title : '' , description : 'Upload two print images here' } } ,
{ element : '.Guide_1_8' , popover : { title : '' , description : 'Click here for next step.' } } ,
{ element : '.Guide_1_10' , popover : { title : '' , description : 'Click here to extract primary colors from image.' } } ,
{ element : '.Guide_1_11' , popover : { title : '' , description : 'Select the color you want from these color blocks as the first color.' } } ,
2023-11-28 17:07:38 +08:00
2023-12-01 15:02:37 +08:00
{ element : '.Guide_1_11_1' , popover : { title : '' , description : 'Click on this block to select the second color.' } } ,
{ element : '.Guide_1_11_2' , popover : { title : '' , description : 'Choose the color you want from these color blocks.' } } ,
2023-11-28 17:07:38 +08:00
2023-12-01 15:02:37 +08:00
{ element : '.Guide_1_8' , popover : { title : '' , description : 'Click here for next step.' } } ,
{ element : '.Guide_1_2' , popover : { title : '' , description : 'Upload two sketches for your collection on this page' } } ,
{ element : '.Guide_1_14' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_13' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_13' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_13' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_14' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_15' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_16' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_17' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_18' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_19' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_20' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_21' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_22' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_23' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_24' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_25' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_26' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_27' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_28' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_29' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_30' , popover : { title : '' , description : 'Description' } } ,
{ element : '.Guide_1_16' , popover : { 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-30 17:02:15 +08:00
// nextBtnText: '—›',
// prevBtnText: '‹—',
doneBtnText : '✕' ,
2023-11-22 09:37:30 +08:00
onPopoverRender : ( popover , options ) => { //每个步骤的元素和所有信息
2023-12-01 15:02:37 +08:00
console . log ( popover , options ) ;
2023-11-23 15:31:40 +08:00
if ( element ) {
element . classList . remove ( 'Guide_' )
}
2023-11-22 15:41:46 +08:00
popover . previousButton . style . display = 'none'
2023-11-28 17:07:38 +08:00
let driver = document . querySelector ( 'body' )
2023-11-29 16:30:17 +08:00
if ( options . state . activeIndex >= 2 && options . state . activeIndex < 3 ) {
options . config . stagePadding = 0
} else {
options . config . stagePadding = 10
}
2023-11-24 16:18:44 +08:00
if (
2023-11-29 16:30:17 +08:00
// options.state.activeIndex >= 1 && options.state.activeIndex <= 2 ||
options . state . activeIndex >= 18 && options . state . activeIndex < 19 ||
2023-11-30 10:54:22 +08:00
options . state . activeIndex >= 24 && options . state . activeIndex < 25 ||
driverObj _ _ . isLastStep ( )
2023-11-24 16:18:44 +08:00
) {
2023-11-22 09:37:30 +08:00
popover . footer . style . display = 'block'
2023-11-28 16:21:00 +08:00
driver . classList . add ( 'showEvents' )
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 )
2023-11-28 16:21:00 +08:00
driver . classList . remove ( 'showEvents' )
2023-11-22 15:41:46 +08:00
}
// console.log(options.state.activeIndex);
driverIndex _ _ = driverObj _ _ . getState ( ) . activeIndex
2023-11-28 16:21:00 +08:00
data = {
index : driverIndex _ _ ,
driver : true ,
}
2023-11-22 15:41:46 +08:00
store ? . commit ( "setGuide" , data ) ;
2023-11-23 15:31:40 +08:00
element = options . state . activeElement
element . classList . add ( 'Guide_' )
2023-11-22 09:37:30 +08:00
} ,
2023-11-24 16:18:44 +08:00
//销毁前
onDestroyStarted : ( ) => {
2023-11-29 16:30:17 +08:00
data = {
index : driverIndex _ _ ,
driver : false ,
}
2023-11-24 16:18:44 +08:00
store ? . commit ( "setGuide" , data ) ;
2023-11-30 10:54:22 +08:00
setCookie ( "isBeginner" , false ) ;
2023-11-24 16:18:44 +08:00
driverObj _ _ . destroy ( ) ; //销毁方法
} ,
//销毁前
onDestroyed : ( ) => {
} ,
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-30 10:54:22 +08:00
2023-11-22 09:37:30 +08:00
const openGuide = ( ) => {
2023-11-30 10:54:22 +08:00
let isBeginner = JSON . parse ( getCookie ( 'isBeginner' ) )
2023-12-01 15:02:37 +08:00
console . log ( isBeginner ) ;
2023-11-30 10:54:22 +08:00
let data
// console.log(isBeginner);
2023-11-30 11:02:33 +08:00
if ( isBeginner ) {
2023-11-30 17:02:15 +08:00
driverObj _ _ . drive ( ) ;
2023-11-30 10:54:22 +08:00
data = {
index : driverIndex _ _ ,
driver : true ,
}
} else {
driverObj _ _ . destroy ( ) ;
data = {
index : driverIndex _ _ ,
driver : false ,
}
}
2023-12-01 15:02:37 +08:00
driverObj _ _ . destroy ( ) ;
// driverObj__.drive();
2023-11-30 17:02:15 +08:00
2023-11-30 11:02:33 +08:00
data = {
index : driverIndex _ _ ,
2023-12-01 15:02:37 +08:00
driver : false ,
2023-11-30 11:02:33 +08:00
}
2023-11-22 15:41:46 +08:00
store = useStore ( )
2023-11-24 16:18:44 +08:00
// driverObj__.moveTo(18);
store ? . commit ( "setGuide" , data ) ;
2023-11-22 15:41:46 +08:00
// 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
}