FrameElement.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <div class='element' @mousedown="mousedown" @mouseup="mouseup" @mouseover="mouseover" @mouseleave="mouseleave">
  3. <!--<div style="height: 100%;width: 100%;" @dragstart="dragstart">-->
  4. <!--2134654867-->
  5. <!--</div>-->
  6. <Operate class="operate" v-show="element === editingElement || show" :element="element"
  7. @mousedown.native.stop="scaleMousedown" @mouseup.native.stop="scaleMouseup" @mousemove.native.stop="scaleMousemove"/>
  8. <section class="content">
  9. <div :class="'animated ' + this.element['animatedName']" :style="styleAnime">
  10. <div :style="styleBasic">{{ element.text }}</div>
  11. <template v-for="element in element.children">
  12. <div>
  13. <!-- 单图元素 -->
  14. <PicElement :stopEvent="true" :type="type" v-if="element.type==='pic'" :class="[element.playing?'animated ' + element.animatedName:'',element.loop?'infinite':'']" :element="element"
  15. :style="{transform:'rotate('+element.transform+'deg)','z-index':element.zindex,opacity:element.opacity/100,width:element.width+'px',height:element.height+'px',top:element.top+'px',left:element.left + 'px','animation-duration':element.duration + 's','-webkit-animation-duration':element.duration + 's','animation-delay':element.delay + 's','-webkit-animation-delay':element.delay + 's'}">
  16. <img style="width:100%;height:100%;" :src="element.imgSrc">
  17. </PicElement>
  18. <!-- 字体元素 -->
  19. <FontElement :stopEvent="true" class="element" v-if="element.type === 'text'" :element="element" :style="elementPosition(element)"></FontElement>
  20. <!-- 形状元素 -->
  21. <ShapesElement :stopEvent="true" v-if="element.type==='icon'" :iconKey="element.iconKey" :element="element" :style="{fill:'#fff',transform:'rotate('+element.transform+'deg)','z-index':element.zindex,opacity:element.opacity/100,width:element.width+'px',height:element.height+'px',top:element.top+'px',left:element.left + 'px','animation-duration':element.duration + 's','-webkit-animation-duration':element.duration + 's','animation-delay':element.delay + 's','-webkit-animation-delay':element.delay + 's'}" :class="[element.playing?'animated ' + element.animatedName:'']"></ShapesElement>
  22. <!-- 多图左右滑动元素 -->
  23. <MorePicElement :stopEvent="true" :type="type" v-if="element.type==='morePic'" :class="[element.playing?'animated ' + element.animatedName:'',element.loop?'infinite':'']" :element="element"
  24. :style="{transform:'rotate('+element.transform+'deg)','z-index':element.zindex,opacity:element.opacity/100,width:element.width+'px',height:element.height+'px',top:element.top+'px',left:element.left + 'px','animation-duration':element.duration + 's','-webkit-animation-duration':element.duration + 's','animation-delay':element.delay + 's','-webkit-animation-delay':element.delay + 's'}">
  25. <mt-swipe :auto="4000" class="swiper-img data-img3 data-img" style="height: 100%;width: 100%">
  26. <mt-swipe-item v-for="pic in element.morePic">
  27. <img :src="pic.filePath" style='height: 100%;width: 100%'/>
  28. </mt-swipe-item>
  29. </mt-swipe>
  30. <!--<img style="width:100%;height:100%;" :src="element.imgSrc">-->
  31. </MorePicElement>
  32. <!-- 单图元素 -->
  33. <ButtonElement :stopEvent="true" :type="type" v-if="element.type==='button'" :class="[element.playing?'animated ' + element.animatedName:'',element.loop?'infinite':'']" :element="element"
  34. :style="{transform:'rotate('+element.transform+'deg)','z-index':element.zindex,opacity:element.opacity/100,width:element.width+'px',height:element.height+'px',top:element.top+'px',left:element.left + 'px','animation-duration':element.duration + 's','-webkit-animation-duration':element.duration + 's','animation-delay':element.delay + 's','-webkit-animation-delay':element.delay + 's'}">
  35. <img style="width:100%;height:100%;" :src="element.imgSrc">
  36. </ButtonElement>
  37. <!--<FrameElement :stopEvent="true" class="element" v-if="element.type === 'frame'" :element="element" :children="element.children" :style="elementPosition(element)">-->
  38. <!--<div style="width:394px;height:394px;"></div>-->
  39. <!--</FrameElement>-->
  40. </div>
  41. </template>
  42. </div>
  43. </section>
  44. </div>
  45. </template>
  46. <script>
  47. import Operate from '../Operate'
  48. import appConst from '../../util/appConst'
  49. import PicElement from './PicElement'
  50. import ButtonElement from './ButtonElement'
  51. import FontElement from './FontElement'
  52. import ShapesElement from './ShapesElement'
  53. import MorePicElement from './morePicElement'
  54. export default{
  55. props: {
  56. element: {
  57. type: Object,
  58. require: true
  59. },
  60. showOperate: {
  61. type: Boolean
  62. },
  63. children: {
  64. type: Array
  65. },
  66. stopEvent: {
  67. type: Boolean
  68. },
  69. type: ''
  70. },
  71. computed: {
  72. elementPosition () {
  73. return (ele) => {
  74. return {
  75. zIndex: ele['zindex'],
  76. top: ele['top'] + 'px',
  77. left: ele['left'] + 'px'
  78. }
  79. }
  80. },
  81. editingElement () {
  82. return this.$store.getters['editingElement']
  83. },
  84. styleAnime () {
  85. return {
  86. animationIterationCount: this.element['loop'] ? 'infinite' : 'initial',
  87. animationDuration: this.element['duration'] + 's',
  88. animationDelay: this.element['delay'] + 's'
  89. }
  90. },
  91. styleBasic () {
  92. return {
  93. height: this.element['height'] + 'px',
  94. width: this.element['width'] + 'px',
  95. lineHeight: this.element['lineHeight'],
  96. color: this.element['color'],
  97. backgroundColor: this.element['allTransparent'] || this.element['backgroundColor'],
  98. textAlign: this.element['textAlign'],
  99. fontSize: this.element['fontSize'] + 'px',
  100. fontWeight: this.element['fontWeight'],
  101. 'font-family': this.element['fontFamily'],
  102. opacity: this.element['opacity'] / 100,
  103. transform: 'rotate(' + this.element['transform'] + 'deg' + ')',
  104. border: this.element['border'],
  105. 'vertical-align': this.element['verticalAlign'],
  106. display: this.element['display'],
  107. 'text-indent': this.element['textIndent'] + 'em',
  108. 'letter-spacing': this.element['letterSpacing'] + 'em'
  109. }
  110. }
  111. },
  112. data () {
  113. return {
  114. left: 0,
  115. top: 0,
  116. width: 0,
  117. height: 0,
  118. currentX: 0,
  119. currentY: 0,
  120. flag: false,
  121. scaleFlag: false,
  122. direction: '',
  123. http: appConst.BACKEND_DOMAIN,
  124. show:false
  125. }
  126. },
  127. methods: {
  128. // 处理元素拖动
  129. move () {
  130. document.querySelector('.editor').onmousemove = (event) => {
  131. var e = event || window.event
  132. if (this.flag) {
  133. let nowX = e.clientX
  134. let nowY = e.clientY
  135. let disX = nowX - this.currentX
  136. let disY = nowY - this.currentY
  137. if(this.$store.state.editor.complexEditorElement.indexOf(this.element)>-1&&this.$store.state.editor.complexEditorElement.length>1){
  138. this.$store.state.editor.complexEditorElement.forEach((ele,index)=>{
  139. ele['top'] = disY + this.startTopArr[index]
  140. ele['left'] = ele.type=='frame'?0:disX + this.startLeftArr[index]
  141. });
  142. return;
  143. }
  144. this.element.top = parseInt(this.top) + disY
  145. // this.element.left = parseInt(this.left) + disX
  146. this.element.left = 0
  147. }
  148. }
  149. },
  150. // 处理元素伸缩
  151. scaleMousemove () {
  152. document.querySelector('.editor').onmouseup = (event) => {
  153. this.scaleFlag = false
  154. }
  155. document.querySelector('.editor').onmousemove = (event) => {
  156. var e = event || window.event
  157. if (this.scaleFlag) {
  158. let nowX = e.clientX
  159. let nowY = e.clientY
  160. let disX = nowX - this.currentX
  161. let disY = nowY - this.currentY
  162. switch (this.direction) {
  163. // 左边
  164. case 'w':
  165. // var percentage= this.element.width/(parseInt(this.width) - disX)
  166. // this.element.children.forEach(function (child) {
  167. // child.width=child.width/percentage
  168. // child.left=child.left/percentage
  169. // // child.fontSize=child.fontSize/percentage
  170. // })
  171. // this.element.width = parseInt(this.width) - disX
  172. // this.element.left = parseInt(this.left) + disX
  173. break
  174. // 右边
  175. case 'e':
  176. // var percentage= this.element.width/(parseInt(this.width) + disX)
  177. // this.element.children.forEach(function (child) {
  178. // child.width=child.width/percentage
  179. // child.left=child.left/percentage
  180. // // child.fontSize=child.fontSize/percentage
  181. // })
  182. // this.element.width = parseInt(this.width) + disX
  183. break
  184. // 上边
  185. case 'n':
  186. // var percentage= this.element.height/(parseInt(this.height) - disY)
  187. // this.element.children.forEach(function (child) {
  188. // child.height=child.height/percentage
  189. // child.top=child.top/percentage
  190. // child.fontSize=child.fontSize/percentage
  191. // })
  192. this.element.height = parseInt(this.height) - disY
  193. this.element.top = parseInt(this.top) + disY
  194. break
  195. // 下边
  196. case 's':
  197. // var percentage= this.element.height/(parseInt(this.height) + disY)
  198. // this.element.children.forEach(function (child) {
  199. // child.height=child.height/percentage
  200. // child.top=child.top/percentage
  201. // child.fontSize=child.fontSize/percentage
  202. // })
  203. this.element.height = parseInt(this.height) + disY
  204. break
  205. // 左上
  206. case 'nw':
  207. // var percentage1= this.element.height/(parseInt(this.height) - disY)
  208. // var percentage2= this.element.width/(parseInt(this.width) - disX)
  209. // this.element.children.forEach(function (child) {
  210. // child.height=child.height/percentage1
  211. // child.top=child.top/percentage1
  212. // child.width=child.width/percentage2
  213. // child.left=child.left/percentage2
  214. // child.fontSize=child.fontSize/percentage1
  215. // })
  216. // this.element.width = parseInt(this.width) - disX
  217. // this.element.left = parseInt(this.left) + disX
  218. this.element.height = parseInt(this.height) - disY
  219. this.element.top = parseInt(this.top) + disY
  220. break
  221. // 左下
  222. case 'sw':
  223. // var percentage1= this.element.width/(parseInt(this.width) - disX)
  224. // var percentage2= this.element.height/(parseInt(this.height) + disY)
  225. // this.element.children.forEach(function (child) {
  226. // child.height=child.height/percentage2
  227. // child.top=child.top/percentage2
  228. // child.width=child.width/percentage1
  229. // child.left=child.left/percentage1
  230. // child.fontSize=child.fontSize/percentage2
  231. // })
  232. // this.element.width = parseInt(this.width) - disX
  233. // this.element.left = parseInt(this.left) + disX
  234. this.element.height = parseInt(this.height) + disY
  235. break
  236. // 右上
  237. case 'ne':
  238. // var percentage1= this.element.width/(parseInt(this.width) + disX)
  239. // var percentage2= this.element.height/(parseInt(this.height) - disY)
  240. // this.element.children.forEach(function (child) {
  241. // child.height=child.height/percentage2
  242. // child.top=child.top/percentage2
  243. // child.width=child.width/percentage1
  244. // child.left=child.left/percentage1
  245. // child.fontSize=child.fontSize/percentage2
  246. // })
  247. this.element.height = parseInt(this.height) - disY
  248. this.element.top = parseInt(this.top) + disY
  249. // this.element.width = parseInt(this.width) + disX
  250. break
  251. // 右下
  252. case 'se':
  253. // var percentage1= this.element.width/(parseInt(this.width) + disX)
  254. // var percentage2= this.element.height/(parseInt(this.height) + disY)
  255. // this.element.children.forEach(function (child) {
  256. // child.height=child.height/percentage2
  257. // child.top=child.top/percentage2
  258. // child.width=child.width/percentage1
  259. // child.left=child.left/percentage1
  260. // child.fontSize=child.fontSize/percentage2
  261. // })
  262. this.element.height = parseInt(this.height) + disY
  263. // this.element.width = parseInt(this.width) + disX
  264. break
  265. }
  266. }
  267. }
  268. },
  269. mousedown (e) {
  270. this.$store.state.user.operationFlag=false;
  271. if(this.element.locked){
  272. return false;
  273. }
  274. if(this.stopEvent){
  275. return false
  276. }
  277. this.flag = true
  278. this.currentX = e.clientX
  279. this.currentY = e.clientY
  280. if(this.$store.state.editor.complexEditorElement.indexOf(this.element)>-1&&this.$store.state.editor.complexEditorElement.length>1){
  281. this.startTopArr=this.$store.state.editor.complexEditorElement.map(v=>v.top)
  282. this.startLeftArr=this.$store.state.editor.complexEditorElement.map(v=>v.left)
  283. }
  284. this.top = this.element.top
  285. this.left = this.element.left
  286. this.move()
  287. document.addEventListener('mouseup', this.mouseup)
  288. },
  289. mouseup (e) {
  290. this.$store.state.user.operationFlag=true;
  291. this.flag = false
  292. this.scaleFlag = false
  293. document.querySelector('.editor').onmousemove=null;
  294. document.removeEventListener('mouseup', this.mouseup)
  295. },
  296. mouseover (e) {
  297. this.show = true
  298. },
  299. mouseleave(e){
  300. this.show = false
  301. },
  302. scaleMousedown (e) {
  303. this.$store.state.user.operationFlag=false;
  304. this.scaleFlag = true
  305. this.currentX = e.clientX
  306. this.currentY = e.clientY
  307. this.top = this.element.top
  308. this.left = this.element.left
  309. this.width = this.element.width
  310. this.height = this.element.height
  311. this.direction = e.target.getAttribute('data-direction')
  312. this.scaleMousemove()
  313. },
  314. scaleMouseup (e) {
  315. this.$store.state.user.operationFlag=true;
  316. this.scaleFlag = false
  317. },
  318. dragstart (event) {
  319. event.preventDefault()
  320. }
  321. },
  322. components: {
  323. Operate,PicElement, FontElement, ShapesElement, MorePicElement,ButtonElement
  324. }
  325. }
  326. </script>
  327. <style lang='less' scoped>
  328. .wrap {
  329. position: absolute;
  330. cursor: move;
  331. }
  332. .wrap img {
  333. position: absolute;
  334. user-select: none;
  335. /*-webkit-user-drag: none;*/
  336. }
  337. div{
  338. -webkit-animation-fill-mode:none
  339. }
  340. .canvas {
  341. background-color: #fff;
  342. margin: 0 auto;
  343. position: relative;
  344. }
  345. .bg-layer{
  346. position:relative;
  347. width: 100%;
  348. height: 100%;
  349. overflow: hidden;
  350. z-index: 0;
  351. }
  352. .element {
  353. position: absolute;
  354. }
  355. </style>