1 line
6.5 KiB
JavaScript
1 line
6.5 KiB
JavaScript
|
|
import{__awaiter,__decorate}from"tslib";import{SuperComponent,wxComponent}from"../common/src/index";import props from"./props";import config from"../common/config";import{isFunction,isNumber}from"../common/validator";import{debounce,getRect,rpx2px,styles,unitConvert,nextTick,systemInfo}from"../common/utils";const{prefix:prefix}=config,name=`${prefix}-guide`;let Guide=class extends SuperComponent{constructor(){super(...arguments),this.externalClasses=[`${prefix}-class`,`${prefix}-class-reference`,`${prefix}-class-popover`,`${prefix}-class-tooltip`,`${prefix}-class-title`,`${prefix}-class-body`,`${prefix}-class-footer`,`${prefix}-class-skip`,`${prefix}-class-next`,`${prefix}-class-back`,`${prefix}-class-finish`],this.properties=props,this.options={pureDataPattern:/^_/,multipleSlots:!0},this.data={prefix:prefix,classPrefix:name,visible:!1,_current:-1,_steps:[],buttonProps:{},referenceStyle:"",popoverStyle:"",title:"",body:"",nonOverlay:!1,modeType:""},this.controlledProps=[{key:"current",event:"change"}],this.observers={"steps, current, showOverlay"(){return __awaiter(this,void 0,void 0,function*(){this._init()})}},this.lifetimes={created(){this._init=debounce(()=>this.init(),20),this._getPlacement=this.getPlacement()},attached(){this._init()}},this.methods={init(){var t,e,i,s,a,o,n;return __awaiter(this,void 0,void 0,function*(){const{steps:r,current:p}=this.properties,{_steps:l,_current:h}=this.data,c=r[p];if(!c)return this.setData({visible:!1});const u="dialog"===(null!==(t=c.mode)&&void 0!==t?t:this.data.mode)?"dialog":"popover",x=null!==(e=c.showOverlay)&&void 0!==e?e:this.data.showOverlay;if(this.setData({nonOverlay:!x,modeType:u}),r!==l||p!==h)if("popover"===u){const t=yield c.element();if(!t)return;const e=rpx2px(null!==(i=c.highlightPadding)&&void 0!==i?i:this.data.highlightPadding),o={top:`${t.top-e}px`,right:`${systemInfo.windowWidth-t.right-e}px`,left:`${t.left-e}px`,width:`${t.width+2*e}px`,height:`${t.height+2*e}px`};this.setData({_steps:this.data.steps,_current:this.data.current,visible:!0,referenceStyle:styles(o),title:null!==(s=c.title)&&void 0!==s?s:"",body:null!==(a=c.body)&&void 0!==a?a:"",buttonProps:this.buttonProps(c,"popover")});const n=yield this.placementOffset(c,o);this.setData({popoverStyle:n})}else this.setData({_steps:this.data.steps,_current:this.data.current,visible:!0,title:null!==(o=c.title)&&void 0!==o?o:"",body:null!==(n=c.body)&&void 0!==n?n:"",buttonProps:this.buttonProps(c,"dialog")})})},placementOffset({placement:t,offset:e},i){var s,a;return __awaiter(this,void 0,void 0,function*(){yield nextTick();const o=yield getRect(this,`.${name}__container`),n=null===(a=(s=this._getPlacement)[t])||void 0===a?void 0:a.call(s,o,i,e);return styles(Object.assign({position:"absolute"},n))})},buttonProps(t,e){var i,s,a,o;let n=null!==(i=t.skipButtonProps)&&void 0!==i?i:this.data.skipButtonProps;const r="popover"===e?"extra-small":"medium";n=Object.assign(Object.assign({theme:"light",content:"跳过",size:r},n),{tClass:`${prefix}-class-skip ${name}__button ${(null==n?void 0:n.class)||""}`,type:"skip"});let p=null!==(s=t.nextButtonProps)&&void 0!==s?s:this.data.nextButtonProps;p=Object.assign(Object.assign({theme:"primary",content:"下一步",size:r},p),{tClass:`${prefix}-class-next ${name}__button ${(null==p?void 0:p.class)||""}`,type:"next"}),p=Object.assign(Object.assign({},p),{content:this.buttonContent(p)});let l=null!==(a=t.backButtonProps)&&void 0!==a?a:this.data.backButtonProps;l=Object.assign(Object.assign({theme:"light",content:"返回",size:r},l),{tClass:`${prefix}-class-back ${name}__button ${(null==l?void 0:l.class)||""}`,type:"back"});let h=null!==(o=t.finishButtonProps)&&void 0!==o?o:this.data.finishButtonProps;return h=Object.assign(Object.assign({theme:"primary",content:"完成",size:r},h),{tClass:`${prefix}-class-finish ${name}__button ${(null==h?void 0:h.class)||""}`,type:"finish"}),h=Object.assign(Object.assign({},h),{content:this.buttonContent(h)}),{skipButton:n,nextButton:p,backButton:l,finishButton:h}},renderCounter(){const{steps:t,current:e,counter:i}=this.data,s=t.length,a=e+1
|