|
| 1 | +import { animationOptions, animationValue2Name, firstLevelAnimationOptions } from '@/constants/animation.js' |
| 2 | +import 'animate.css' |
| 3 | + |
| 4 | +export default { |
| 5 | + data: () => ({ |
| 6 | + animationQueue: [], |
| 7 | + activeCollapsePanel: [], |
| 8 | + activePreviewAnimation: '', |
| 9 | + drawerVisible: false |
| 10 | + }), |
| 11 | + methods: { |
| 12 | + addAnimation () { |
| 13 | + this.animationQueue.push({ |
| 14 | + type: '', |
| 15 | + duration: 0, |
| 16 | + delay: 0, |
| 17 | + countNum: 1, |
| 18 | + infinite: false |
| 19 | + }) |
| 20 | + this.activeCollapsePanel = `${this.animationQueue.length - 1}` |
| 21 | + }, |
| 22 | + deleteAnimate (index) { |
| 23 | + this.animationQueue.splice(index, 1) |
| 24 | + }, |
| 25 | + runAnimate () { |
| 26 | + }, |
| 27 | + renderSecondAnimationTabs (animations) { |
| 28 | + return ( |
| 29 | + <a-tabs |
| 30 | + defaultActiveKey={animations[0].value} |
| 31 | + onChange={tab => {}} |
| 32 | + style="width:100%;" |
| 33 | + tabBarStyle={{ marginLeft: '-16px' }} |
| 34 | + size="small" |
| 35 | + tabBarGutter={0} |
| 36 | + tabPosition="left" |
| 37 | + > |
| 38 | + { |
| 39 | + animations.map(group => ( |
| 40 | + <a-tab-pane tab={group.label || group.value} key={group.value}> |
| 41 | + <a-list |
| 42 | + grid={{ gutter: 12, column: 2 }} |
| 43 | + dataSource={group.children} |
| 44 | + renderItem={(item, index) => ( |
| 45 | + // [key point] onMouseover vs onMouseenter |
| 46 | + // https://stackoverflow.com/questions/7286532/jquery-mouseenter-vs-mouseover |
| 47 | + // https://www.quirksmode.org/js/events_mouse.html#mouseenter |
| 48 | + <a-list-item> |
| 49 | + <div |
| 50 | + class={[this.activePreviewAnimation === item.value && item.value + ' animated', 'shortcut-button']} |
| 51 | + onMouseenter={(e) => { |
| 52 | + this.activePreviewAnimation = item.value |
| 53 | + }} |
| 54 | + onMouseleave={() => { |
| 55 | + // [key point] why not set activePreviewAnimation='' after mouseleave, see more here: https://stackoverflow.com/questions/32279782/mouseenter-called-multiple-times |
| 56 | + // this.activePreviewAnimation = '' |
| 57 | + }} |
| 58 | + > |
| 59 | + {item.label} |
| 60 | + </div> |
| 61 | + </a-list-item> |
| 62 | + )} |
| 63 | + > |
| 64 | + </a-list> |
| 65 | + </a-tab-pane> |
| 66 | + )) |
| 67 | + } |
| 68 | + </a-tabs> |
| 69 | + ) |
| 70 | + }, |
| 71 | + renderAvaiableAnimations () { |
| 72 | + return ( |
| 73 | + <a-tabs |
| 74 | + defaultActiveKey={firstLevelAnimationOptions[0].label} |
| 75 | + onChange={tab => {}} |
| 76 | + style="width:100%;" |
| 77 | + tabBarStyle={{}} |
| 78 | + size="small" |
| 79 | + tabBarGutter={0} |
| 80 | + > |
| 81 | + { |
| 82 | + firstLevelAnimationOptions.map(firstGroup => ( |
| 83 | + <a-tab-pane tab={firstGroup.label} key={firstGroup.label}> |
| 84 | + {/* group.label.match(firstGroup.value) <-> !!'abc'.match(/a|e/) === true */} |
| 85 | + {this.renderSecondAnimationTabs(animationOptions.filter(group => !!group.label.match(firstGroup.value)))} |
| 86 | + </a-tab-pane> |
| 87 | + )) |
| 88 | + } |
| 89 | + </a-tabs> |
| 90 | + ) |
| 91 | + }, |
| 92 | + renderAnimationOptions () { |
| 93 | + return ( |
| 94 | + <a-form layout="horizontal"> |
| 95 | + <a-form-item label="动画类型" labelCol={{ span: 5 }} wrapperCol={{ span: 16, offset: 2 }}> |
| 96 | + {/* <a-popover placement="left" title="动画列表" trigger="click"> |
| 97 | + <template slot="content"> |
| 98 | + {this.renderAvaiableAnimations()} |
| 99 | + </template> |
| 100 | + <a-button type="primary">动画列表</a-button> |
| 101 | + </a-popover> */} |
| 102 | + <a-button type="link" size="small" icon="ordered-list" onClick={() => { this.drawerVisible = true }}>动画列表</a-button> |
| 103 | + </a-form-item> |
| 104 | + <a-form-item label="动画时间" labelCol={{ span: 5 }} wrapperCol={{ span: 16, offset: 2 }} style="margin-bottom:0;"> |
| 105 | + <a-form-item style={{ display: 'inline-block', width: 'calc(50% - 12px)' }}> |
| 106 | + <a-slider id="test" defaultValue={30} /> |
| 107 | + </a-form-item> |
| 108 | + <a-form-item style={{ display: 'inline-block', width: 'calc(50% - 12px)' }}> |
| 109 | + <a-input-number min={1} max={20} size="small" formatter={value => `${value}秒`}/> |
| 110 | + </a-form-item> |
| 111 | + </a-form-item> |
| 112 | + <a-form-item label="循环播放" labelCol={{ span: 5 }} wrapperCol={{ span: 16, offset: 2 }} style="margin-bottom:0;"> |
| 113 | + <a-switch v-decorator="['switch', { valuePropName: 'checked' }]" /> |
| 114 | + </a-form-item> |
| 115 | + </a-form> |
| 116 | + ) |
| 117 | + } |
| 118 | + }, |
| 119 | + render (h) { |
| 120 | + return ( |
| 121 | + <div class="main-animate widget" id="animation-edit-panel"> |
| 122 | + <a-button-group> |
| 123 | + <a-button type="primary" onClick={this.addAnimation}><a-icon type="plus" />添加动画</a-button> |
| 124 | + <a-button type="primary" onClick={this.runAnimate}>运行动画<a-icon type="right-circle" /></a-button> |
| 125 | + </a-button-group> |
| 126 | + { |
| 127 | + this.animationQueue.length && |
| 128 | + <a-collapse activeKey={this.activeCollapsePanel} onChange={(val) => { this.activeCollapsePanel = val }} class="collapse-wrapper"> |
| 129 | + { |
| 130 | + this.animationQueue.map((addedAnimation, index) => ( |
| 131 | + <a-collapse-panel key={`${index}`}> |
| 132 | + <template slot="header"> |
| 133 | + <span>动画{index + 1}</span> |
| 134 | + <a-tag color="orange">{animationValue2Name[addedAnimation.type] }</a-tag> |
| 135 | + {/* <a-icon onClick={this.deleteAnimate(index)}></a-icon> */} |
| 136 | + </template> |
| 137 | + {this.renderAnimationOptions()} |
| 138 | + </a-collapse-panel> |
| 139 | + )) |
| 140 | + } |
| 141 | + </a-collapse> |
| 142 | + } |
| 143 | + |
| 144 | + <a-drawer |
| 145 | + title="请选择动画" |
| 146 | + placement="left" |
| 147 | + closable={true} |
| 148 | + onClose={() => { this.drawerVisible = false }} |
| 149 | + visible={this.drawerVisible} |
| 150 | + width={400} |
| 151 | + wrapStyle={{ margin: '-16px' }} |
| 152 | + > |
| 153 | + <div style="width: 100%;"> |
| 154 | + {this.renderAvaiableAnimations()} |
| 155 | + </div> |
| 156 | + </a-drawer> |
| 157 | + </div> |
| 158 | + ) |
| 159 | + } |
| 160 | +} |
0 commit comments