近期改版RXEditor,把改版程序,用到的技術點,記錄下來,昨天完成了靜態頁面的制作,制作程序并未詳細記錄,后期已經不愿再補了,有些遺憾,不過作業成果完整保留在github上,地址:https://github.com/vularsoft/studio-ui
這個專案下面的html-demo.html,便是靜態檔案,
話不多說,今天就把昨天的HTML轉化成VUE,
先看效果:

布局原理
頁面采用純彈性盒子flex box布局,無float postion等,頁面分成如下幾個區域:

細實線描述的是各個DIV之間的嵌套關系,粗黑線是獨立的DIV,我稱它們為把手(HADLE),主要用來接受滑鼠拖動事件,以完成拖動操作,handle非為兩種,橫向x-handle,縱向y-handle,css中定義x-handle寬度為3px,高度為100%,y-handle高度為3px,寬度為100%,滑鼠游標也相應設定一下:
.vular-studio .x-handle{ width: 3px; cursor: w-resize; z-index: 10; } .vular-studio .y-handle{ height: 3px; cursor: s-resize; z-index: 10; }
拖動原理
帶有把手的區域固定大小(固定寬度或者高度),不帶把手的部分跟隨彈性盒子變化,把手handle是一個獨立的VUE組件,它把拖動資訊傳遞給父視窗,父視窗改變自身大小,以bottom-area為例,這是一個可以改變自身大小的DIV:
<template>
<div :style="{height:height + 'px'}">
<YHandle @heightChange="heightChange"></YHandle>
<div >
<slot></slot>
</div>
</div>
</template>
<script>
import YHandle from './YHandle.vue'
export default {
name: 'BottomArea',
components:{
YHandle,
},
data () {
return {
height:220,
}
},
methods: {
heightChange(movement){
this.height += movement
if(this.height < 30){
this.height = 30
}
if(this.height > 600){
this.height = 600
}
},
},
}
</script>
它對應的把手代碼:
<template> <div @mousedown="mouseDown" ></div> </template> <script> export default { name: 'YHandle', data () { return { lastY:'' } }, created () { document.addEventListener('mouseup', this.mouseUp) }, destroyed() { document.removeEventListener('mouseup', this.mouseUp) }, methods: { mouseDown(event){ document.addEventListener('mousemove', this.mouseMove) this.lastY = event.screenY }, mouseMove(event){ console.log('move') this.$emit('heightChange', this.lastY - event.screenY) this.lastY = event.screenY }, mouseUp(event){ this.lastY = '' document.removeEventListener('mousemove', this.mouseMove) }, }, } </script>
制作步驟
先建一個VUE專案:
1、安裝node
2、安裝webpack
3、安裝VUE
4、新建VUE專案:vue init webpack-simple
5、根據相應布局制作VUE組件
具體代碼,請參考:https://github.com/vularsoft/studio-ui,根據標注,獲取相應的版本記錄即可,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/145148.html
標籤:JavaScript
