当前位置:   article > 正文

Vue-SplitPane可拖拽分隔面板(随意拖动div)_el-split-pane

el-split-pane
npm install vue-splitpane

一、使用

(1)局部使用:

vue文件中

  1. import splitPane from 'vue-splitpane'
  2. export default {
  3. componnets: { splitPane }
  4. }

(2)全局使用:

在main.js文件注册

  1. import splitPane from 'vue-splitpane'
  2. // 注册为全局组件
  3. Vue.component('split-pane', splitPane);

二、使用局部在vue文件中使用例子

先分割成左右(注意只能两个两个分割,自由选择竖直还是水平分割)

重点是:

  1. <split-pane
  2. split="vertical"
  3. @resize="resizeSplit"
  4. :default-percent="defaultPercent1"
  5. >
  6. <template slot="paneL"></template>
  7. <template slot="paneR"></template>
  8. </split-pane>

html:代码

data代码:

  1. defaultPercent1:
  2. sessionStorage.getItem("defaultPercent1") == null
  3. ? 50
  4. : parseFloat(sessionStorage.getItem("defaultPercent1")),
  5. defaultPercent2:
  6. sessionStorage.getItem("defaultPercent2") == null
  7. ? 20
  8. : parseFloat(sessionStorage.getItem("defaultPercent2")),
  9. defaultPercent3:
  10. sessionStorage.getItem("defaultPercent3") == null
  11. ? 20
  12. : parseFloat(sessionStorage.getItem("defaultPercent3")),
  13. defaultPercent4:
  14. sessionStorage.getItem("defaultPercent4") == null
  15. ? 25
  16. : parseFloat(sessionStorage.getItem("defaultPercent4")),

method代码:

所有代码

  1. <!--
  2. * @Author: GGbond
  3. * @Description:
  4. * @Date: 2023-11-01 10:35:05
  5. * @LastEditTime: 2023-11-06 19:50:21
  6. -->
  7. <template>
  8. <div id="container">
  9. <split-pane
  10. split="vertical"
  11. @resize="resizeSplit"
  12. :default-percent="defaultPercent1"
  13. >
  14. <template slot="paneL">
  15. <split-pane
  16. split="horizontal"
  17. :default-percent="defaultPercent2"
  18. @resize="resizeSplit2"
  19. >
  20. <template slot="paneL">
  21. <div class="topLeft">
  22. <div class="title">空域</div>
  23. <div class="contentTable">
  24. <el-table
  25. :data="maneuverTable"
  26. border
  27. height="100%"
  28. :cell-style="customCellStyle"
  29. >
  30. <el-table-column
  31. prop="beginTime"
  32. align="center"
  33. label="日期"
  34. width="100"
  35. >
  36. </el-table-column>
  37. <el-table-column prop="content" align="center" label="内容">
  38. </el-table-column>
  39. <el-table-column
  40. prop="source"
  41. align="center"
  42. label="通报单位"
  43. width="100"
  44. >
  45. </el-table-column>
  46. </el-table>
  47. </div>
  48. </div>
  49. </template>
  50. <template slot="paneR">
  51. <div class="bottomLeft">
  52. <div class="title">军方活动</div>
  53. <div class="contentTable">
  54. <el-table
  55. :data="militaryTable"
  56. border
  57. height="100%"
  58. :cell-style="customCellStyle"
  59. >
  60. <el-table-column
  61. prop="beginTime"
  62. align="center"
  63. label="日期"
  64. width="100"
  65. >
  66. </el-table-column>
  67. <el-table-column prop="content" align="center" label="内容">
  68. </el-table-column>
  69. <el-table-column
  70. prop="source"
  71. align="center"
  72. label="通报单位"
  73. width="100"
  74. >
  75. </el-table-column>
  76. </el-table>
  77. </div>
  78. </div>
  79. </template>
  80. </split-pane>
  81. </template>
  82. <template slot="paneR">
  83. <split-pane
  84. split="horizontal"
  85. :default-percent="defaultPercent3"
  86. @resize="resizeSplit3"
  87. >
  88. <template slot="paneL">
  89. <div class="topRight">
  90. <div class="title">设备</div>
  91. <div class="contentTable multi-rmk-col">
  92. <el-table
  93. :data="deviceTable"
  94. border
  95. height="100%"
  96. :cell-style="customCellStyle"
  97. >
  98. <el-table-column
  99. prop="beginTime"
  100. align="center"
  101. label="日期"
  102. width="100"
  103. >
  104. </el-table-column>
  105. <el-table-column prop="content" align="center" label="内容">
  106. </el-table-column>
  107. <el-table-column
  108. prop="source"
  109. align="center"
  110. label="通报单位"
  111. width="100"
  112. >
  113. </el-table-column>
  114. </el-table>
  115. </div>
  116. </div>
  117. </template>
  118. <template slot="paneR">
  119. <split-pane
  120. split="horizontal"
  121. :default-percent="defaultPercent4"
  122. @resize="resizeSplit4"
  123. >
  124. <template slot="paneL">
  125. <div class="brTop">
  126. <div class="title">限制</div>
  127. <div class="contentTable">
  128. <el-table
  129. :data="limitationTable"
  130. border
  131. height="100% "
  132. :cell-style="customCellStyle"
  133. >
  134. <el-table-column
  135. prop="beginTime"
  136. align="center"
  137. label="日期"
  138. width="100"
  139. >
  140. </el-table-column>
  141. <el-table-column prop="content" align="center" label="内容">
  142. </el-table-column>
  143. <el-table-column
  144. prop="source"
  145. align="center"
  146. label="通报单位"
  147. width="100"
  148. >
  149. </el-table-column>
  150. </el-table>
  151. </div>
  152. </div>
  153. </template>
  154. <template slot="paneR">
  155. <div class="brBottom">
  156. <div class="title">通航</div>
  157. <div class="contentTable">
  158. <el-table
  159. :data="airTable"
  160. border
  161. height="100%"
  162. :cell-style="customCellStyle"
  163. >
  164. <el-table-column
  165. prop="beginTime"
  166. align="center"
  167. label="日期"
  168. width="100"
  169. >
  170. </el-table-column>
  171. <el-table-column prop="content" align="center" label="内容">
  172. </el-table-column>
  173. <el-table-column
  174. prop="source"
  175. align="center"
  176. label="通报单位"
  177. width="100"
  178. >
  179. </el-table-column>
  180. </el-table>
  181. </div>
  182. </div>
  183. </template>
  184. </split-pane>
  185. </template>
  186. </split-pane>
  187. </template>
  188. </split-pane>
  189. </div>
  190. </template>
  191. <script>
  192. import splitPane from "vue-splitpane";
  193. import axios from "axios";
  194. import { getAtcRecord } from "@/api/operationInformation.js";
  195. let getDataInt = null; //获取各业务数据定时返回的ID
  196. export default {
  197. components: { splitPane },
  198. data() {
  199. return {
  200. items: "",
  201. airTable: [],
  202. limitationTable: [],
  203. deviceTable: [],
  204. militaryTable: [],
  205. maneuverTable: [],
  206. // div变动
  207. defaultPercent1:
  208. sessionStorage.getItem("defaultPercent1") == null
  209. ? 50
  210. : parseFloat(sessionStorage.getItem("defaultPercent1")),
  211. defaultPercent2:
  212. sessionStorage.getItem("defaultPercent2") == null
  213. ? 20
  214. : parseFloat(sessionStorage.getItem("defaultPercent2")),
  215. defaultPercent3:
  216. sessionStorage.getItem("defaultPercent3") == null
  217. ? 20
  218. : parseFloat(sessionStorage.getItem("defaultPercent3")),
  219. defaultPercent4:
  220. sessionStorage.getItem("defaultPercent4") == null
  221. ? 25
  222. : parseFloat(sessionStorage.getItem("defaultPercent4")),
  223. };
  224. },
  225. mounted() {
  226. //监听页面显隐状态
  227. window.addEventListener("message", (event) => {
  228. let topic = event.data.closeIframe;
  229. if (topic) {
  230. window.clearInterval(getDataInt);
  231. } else if (topic == false) {
  232. if (getDataInt) {
  233. window.clearInterval(getDataInt);
  234. }
  235. //开启轮询模式
  236. this.setIntervalMethod();
  237. }
  238. });
  239. //开启轮询模式
  240. this.setIntervalMethod();
  241. },
  242. methods: {
  243. //开启轮询模式
  244. setIntervalMethod() {
  245. this.onQuery();
  246. //定时每2秒获取一次各业务数据
  247. this.$nextTick(() => {
  248. getDataInt = setInterval(() => {
  249. this.onQuery();
  250. }, 2000);
  251. });
  252. },
  253. onQuery() {
  254. axios
  255. .get(window.operationInformationPath)
  256. .then((res) => {
  257. this.items = res.data.data;
  258. if (Array.isArray(this.items)) {
  259. for (let x of this.items) {
  260. x.beginTime = this.parseTime(x.beginTime);
  261. }
  262. const filteredData = this.items.filter(
  263. (item) => item.dept === "进近管制室"
  264. );
  265. this.limitationTable = filteredData.filter(
  266. (record) => record.type === "限制相邻"
  267. );
  268. this.deviceTable = filteredData.filter(
  269. (record) => record.type === "设备"
  270. );
  271. this.militaryTable = filteredData.filter(
  272. (record) => record.type === "军航活动"
  273. );
  274. this.airTable = filteredData.filter(
  275. (record) => record.type === "通用航空"
  276. );
  277. this.maneuverTable = filteredData.filter(
  278. (record) => record.type === "机动空域"
  279. );
  280. }
  281. })
  282. .catch((error) => {
  283. console.log(error);
  284. });
  285. // getAtcRecord().then((res) => {
  286. // console.log(res)
  287. // })
  288. },
  289. parseTime(originalDateString) {
  290. // 创建日期对象
  291. const date = new Date(originalDateString);
  292. // 获取日期、小时和分钟
  293. const month = (date.getMonth() + 1).toString().padStart(2, "0"); // 月份从0开始,需要加1
  294. const day = date.getDate().toString().padStart(2, "0");
  295. const hours = date.getHours().toString().padStart(2, "0");
  296. const minutes = date.getMinutes().toString().padStart(2, "0");
  297. // 格式化日期
  298. const formattedDate = `${month}-${day} ${hours}:${minutes}`;
  299. return formattedDate;
  300. },
  301. customCellStyle({ row, column }) {
  302. if (column.property === "source") {
  303. return {
  304. "text-align": "center", // 设置内容水平居中
  305. };
  306. } else {
  307. return {
  308. "text-align": "left", // 设置内容左对齐
  309. };
  310. }
  311. },
  312. // div随意变动
  313. resizeSplit(val) {
  314. this.defaultPercent1 = val;
  315. sessionStorage.setItem("defaultPercent1", this.defaultPercent1);
  316. },
  317. resizeSplit2(val) {
  318. this.defaultPercent2 = val;
  319. sessionStorage.setItem("defaultPercent2", this.defaultPercent2);
  320. },
  321. resizeSplit3(val) {
  322. this.defaultPercent3 = val;
  323. sessionStorage.setItem("defaultPercent3", this.defaultPercent3);
  324. },
  325. resizeSplit4(val) {
  326. this.defaultPercent4 = val;
  327. sessionStorage.setItem("defaultPercent4", this.defaultPercent4);
  328. },
  329. },
  330. };
  331. </script>
  332. <style scoped>
  333. #container {
  334. width: 100%;
  335. height: 100%;
  336. padding: 10px;
  337. }
  338. .topLeft {
  339. height: 100%;
  340. width: calc(100% - 4px);
  341. margin-right: 4px;
  342. display: flex;
  343. flex-direction: column;
  344. padding: 10px;
  345. background-color: #4a4a4a;
  346. }
  347. .topRight {
  348. height: 100%;
  349. display: flex;
  350. flex-direction: column;
  351. padding: 10px;
  352. background-color: #4a4a4a;
  353. }
  354. .bottomLeft {
  355. width: calc(100% - 4px);
  356. margin-right: 4px;
  357. height: calc(100% - 8px);
  358. margin-top: 8px;
  359. display: flex;
  360. flex-direction: column;
  361. padding: 10px;
  362. background-color: #4a4a4a;
  363. }
  364. .brTop {
  365. height: calc(100% - 8px);
  366. margin-top: 8px;
  367. display: flex;
  368. flex-direction: column;
  369. padding: 10px;
  370. background-color: #4a4a4a;
  371. }
  372. .brBottom {
  373. height: calc(100% - 8px);
  374. margin-top: 8px;
  375. display: flex;
  376. flex-direction: column;
  377. padding: 10px;
  378. background-color: #4a4a4a;
  379. }
  380. .title {
  381. height: 26px;
  382. color: #9fe1f9;
  383. font-weight: 700;
  384. font-size: 16px;
  385. padding-left: 5px;
  386. }
  387. .contentTable {
  388. flex: 1;
  389. height: calc(100% - 26px);
  390. overflow: auto;
  391. }
  392. .contentTable >>> .el-table__body-wrapper::-webkit-scrollbar {
  393. width: 10px;
  394. height: 8px;
  395. }
  396. /* 修改每行高度 */
  397. /* .topRight >>> .el-table__row {
  398. height: 100px !important;
  399. } */
  400. /* .splitter-pane-resizer {
  401. background: transparent!important;
  402. } */
  403. .vue-splitter-container >>> .splitter-pane-resizer{
  404. background: transparent!important;
  405. }
  406. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/76851
推荐阅读
相关标签
  

闽ICP备14008679号