• element-ui tree组件实现在线增删改


    这里要实现一个tree 增删改

    1. <!--oracle巡检项-->
    2. <template>
    3. <div class="oracle_instanceType">
    4. <el-row type="flex" align="middle" justify="space-between">
    5. <i
    6. class="el-icon-s-fold iBox"
    7. @click="handleFolder(false)"
    8. v-if="folderOpen"
    9. ></i>
    10. <i
    11. class="el-icon-s-unfold iBox"
    12. v-if="!folderOpen"
    13. @click="handleFolder(true)"
    14. ></i>
    15. <pageHeader title="Oracle巡检项" style="flex: 1">
    16. <template v-slot:right>
    17. <el-button type="primary" @click="setInspectionTypeFn"
    18. >定义巡检项</el-button
    19. >
    20. </template>
    21. </pageHeader>
    22. </el-row>
    23. <div class="mainContent">
    24. <div class="leftBox" id="leftContainer" v-if="folderOpen">
    25. <el-container>
    26. <div style="width: 100%">
    27. <p class="treeName">
    28. <span>巡检项分类</span>
    29. </p>
    30. <el-aside
    31. class="aside-left"
    32. style="
    33. width: 100%;
    34. margin-top: 10px;
    35. height: calc(100vh - 86px);
    36. position: relative;
    37. "
    38. :class="folderOpen ? 'openStyle' : 'folderStyle'"
    39. >
    40. <el-tree
    41. ref="typeTree"
    42. :data="folderData"
    43. node-key="id"
    44. default-expand-all
    45. :expand-on-click-node="false"
    46. >
    47. <span class="custom-tree-node" slot-scope="{ node, data }">
    48. <span>{{ data.name }}</span>
    49. <span>
    50. <i
    51. class="el-icon-edit-outline icon-size"
    52. @click="() => edit(data)"
    53. ></i>
    54. <i
    55. class="el-icon-circle-plus icon-size"
    56. @click="() => append(data)"
    57. ></i>
    58. <i
    59. v-if="data.parentId !== '0'"
    60. class="el-icon-remove icon-size"
    61. @click="() => remove(node, data)"
    62. ></i>
    63. </span>
    64. </span>
    65. </el-tree>
    66. </el-aside>
    67. </div>
    68. <el-main> </el-main>
    69. </el-container>
    70. <div class="resize" title="缩放侧边栏" @mousedown="dragTree"></div>
    71. </div>
    72. <div class="rightBox" id="rightContainer">
    73. <div class="ts-middle-part">
    74. <el-row type="flex">
    75. <el-col :span="24">
    76. <div class="flexBox">
    77. <div class="doneButtonDiv">
    78. <el-button type="primary" @click="setInspectionType"
    79. >巡检项归类</el-button
    80. >
    81. </div>
    82. <div class="searchDiv">
    83. <enumSearch
    84. :theItems="'vm'"
    85. :serviceType="'vmware'"
    86. :theUrl="'/v1/vmware/api/search_items'"
    87. @searchContdition="searchContdition"
    88. @toSearch="toSearch"
    89. ></enumSearch>
    90. </div>
    91. <div class="defButtonDiv">
    92. <el-tooltip
    93. class="item"
    94. effect="dark"
    95. content="自定义列表项"
    96. placement="top"
    97. >
    98. <span
    99. class="el-icon-s-tools defBtn"
    100. @click="defHeadList"
    101. ></span>
    102. </el-tooltip>
    103. </div>
    104. </div>
    105. </el-col>
    106. </el-row>
    107. </div>
    108. <div class="ts-body-part">
    109. <el-table
    110. ref="multipleTable"
    111. :data="dataList"
    112. v-loading="loading"
    113. border
    114. >
    115. <template slot="empty">
    116. <empty-in-table
    117. v-if="dataList.length < 1 && !loading"
    118. ></empty-in-table>
    119. </template>
    120. <el-table-column
    121. v-for="(item, index) in tableHeader"
    122. :key="item.key + index"
    123. :label="item.label"
    124. :prop="item.key"
    125. :min-width="item.minWidth"
    126. :fixed="index == 0"
    127. :sortable="item.sortable"
    128. show-overflow-tooltip
    129. >
    130. <!-- 自定义内容 -->
    131. <template slot-scope="scope">
    132. <!-- 名称列 -->
    133. <div v-if="item.key == 'app_name'" class="nameAndIcon">
    134. <!-- 文字跳转部分 -->
    135. <el-button
    136. class="button"
    137. @click="showDetails(scope.row)"
    138. type="text"
    139. >{{ scope.row.app_name }}
    140. </el-button>
    141. </div>
    142. <!-- 关联能力模板,资源分类 -->
    143. <div v-else-if="item.key == 'model' || item.key == 'source'">
    144. <p v-for="(a, index) in scope.row[item.key]" :key="index">
    145. {{ a }}
    146. </p>
    147. </div>
    148. <!-- 其他简单文字列 -->
    149. <div v-else class="online">
    150. <span>{{ scope.row[item.key] }}</span>
    151. </div>
    152. </template>
    153. </el-table-column>
    154. <el-table-column
    155. label="操作"
    156. align="center"
    157. width="130"
    158. fixed="right"
    159. >
    160. <template slot-scope="scope">
    161. <el-button
    162. type="text"
    163. v-permission="'inspection_resourceManage_host_editHostBtn'"
    164. >编辑</el-button
    165. >
    166. <el-button
    167. type="text"
    168. v-permission="'inspection_resourceManage_host_deleteHostBtn'"
    169. >删除</el-button
    170. >
    171. </template>
    172. </el-table-column>
    173. </el-table>
    174. <pagination
    175. :paginationData="pagination"
    176. @handleCurrentChange="handleCurrentChange"
    177. @handleSizeChange="handleSizeChange"
    178. ></pagination>
    179. </div>
    180. </div>
    181. </div>
    182. </div>
    183. </template>
    184. <script>
    185. import { tableHeader } from "./utils/index.js";
    186. import { getSession, setSession } from "@/commons/js/searchFresh.js";
    187. import DefHeadList from "@/components/customColumns.vue";
    188. import setInspectionType from "./components/setInspectionType.vue";
    189. import * as requestMethod from "@/api/inspection/inspectionType/index.js";
    190. let id = 1000;
    191. export default {
    192. name: "oracleManage",
    193. components: {
    194. DefHeadList,
    195. setInspectionType,
    196. },
    197. data() {
    198. return {
    199. folderOpen: true,
    200. addOracleInstanceDrawerVisible: false,
    201. excelImportVisible: false,
    202. defaultProps: {
    203. children: "children",
    204. label: "name",
    205. },
    206. defaultSearch: null,
    207. loading: false,
    208. dataList: [],
    209. // 左侧树数据
    210. folderData: [
    211. {
    212. id: 0,
    213. label: "全部",
    214. children: [
    215. {
    216. id: 1,
    217. label: "一级 1",
    218. children: [
    219. {
    220. id: 4,
    221. label: "二级 1-1",
    222. children: [
    223. {
    224. id: 9,
    225. label: "三级 1-1-1",
    226. },
    227. {
    228. id: 10,
    229. label: "三级 1-1-2",
    230. },
    231. ],
    232. },
    233. ],
    234. },
    235. {
    236. id: 2,
    237. label: "一级 2",
    238. children: [
    239. {
    240. id: 5,
    241. label: "二级 2-1",
    242. },
    243. {
    244. id: 6,
    245. label: "二级 2-2",
    246. },
    247. ],
    248. },
    249. {
    250. id: 3,
    251. label: "一级 3",
    252. children: [
    253. {
    254. id: 7,
    255. label: "二级 3-1",
    256. },
    257. {
    258. id: 8,
    259. label: "二级 3-2",
    260. },
    261. ],
    262. },
    263. ],
    264. },
    265. ],
    266. parentId: null,
    267. organizationId: null,
    268. editLabel: "",
    269. pagination: {
    270. current_page: 1, // 当前位于哪页
    271. per_page: 10, //每页显示多少条
    272. total_count: 0,
    273. total_page: 1, //总页码
    274. },
    275. currentNodeKey: "",
    276. //自定义列
    277. tableHeader: JSON.parse(JSON.stringify(tableHeader)), // 初始化表头本地配置
    278. tableHeaderRpa: [],
    279. headVisible: false,
    280. headData: {},
    281. // 定义巡检项
    282. setDialog: false,
    283. };
    284. },
    285. mounted() {
    286. this.dataList = [
    287. {
    288. id: 1,
    289. app_name: "测试巡检项001",
    290. status: "正常",
    291. ex_system_id: "资源分类A",
    292. catalog_app_name: "Windows命令",
    293. app_architecture: "80能力",
    294. dept_belong: "判定结果成功",
    295. bus_name: "秦小藏",
    296. bus_time: "2023-08-15 13:25:34",
    297. editor_name: "研发",
    298. editDate: "2023-08-18 13:25:34",
    299. },
    300. ];
    301. // 获取巡检项分类树
    302. this.getLeftTree();
    303. },
    304. methods: {
    305. getLeftTree() {
    306. requestMethod.getCategoryTree("get").then((res) => {
    307. if (res.status) {
    308. console.log("getLeftTree", res.data);
    309. this.folderData = res.data;
    310. }
    311. });
    312. },
    313. // 详情跳转
    314. showDetails(row) {
    315. this.$router.push({
    316. path: "/inspection/inspectionTask/inspectionTypeDetails",
    317. query: { id: row.id },
    318. });
    319. },
    320. closeDialog() {
    321. this.addOracleInstanceDrawerVisible = false;
    322. this.excelImportVisible = false;
    323. },
    324. //控制左侧菜单展开折叠
    325. handleFolder(is_open) {
    326. if (is_open) {
    327. this.folderOpen = true;
    328. } else {
    329. this.folderOpen = false;
    330. }
    331. },
    332. // 左侧树新增,
    333. append(data) {
    334. console.log("nodeData", data);
    335. this.organizationId = data.id;
    336. // console.log("全部树的菜单信息", this.folderData);
    337. this.$prompt("请输入名称", "添加巡检项分类", {
    338. confirmButtonText: "确定",
    339. cancelButtonText: "取消",
    340. inputPattern:
    341. /^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z])(([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[-_a-zA-Z0-9]){0,31})$/,
    342. inputErrorMessage:
    343. "支持以中文或英文开头,由中文、英文、数字及特殊字符_-组成,1-32位",
    344. })
    345. .then(({ value }) => {
    346. // 请求接口保存, 需要参数
    347. /**
    348. {
    349. "description": "string",
    350. "name": "string",
    351. "parentId": "string",
    352. "sort": 0
    353. }
    354. */
    355. // 本地测试
    356. // let newChild = { id: id++, label: value, children: [] };
    357. // if (!data.children) {
    358. // this.$set(data, "children", []);
    359. // }
    360. // data.children.push(newChild);
    361. // 走在线接口参数:name, parentId, sort, description
    362. let sortNumber = data.children.length;
    363. this.appendType(value, data.id, sortNumber);
    364. })
    365. .catch(() => {
    366. this.$message({
    367. type: "info",
    368. message: "取消添加",
    369. });
    370. });
    371. },
    372. appendType(name, id, sortNumber, description = "") {
    373. let vo = {
    374. name: name,
    375. parentId: id,
    376. sort: sortNumber,
    377. description: description,
    378. };
    379. requestMethod.addCategoryTree("post", vo).then((res) => {
    380. if (res.status) {
    381. // 重新渲染树
    382. this.getLeftTree();
    383. }
    384. });
    385. },
    386. // 左侧树编辑
    387. edit(data) {
    388. console.log("nodeData", data);
    389. // console.log("全部树的菜单信息", this.folderData);
    390. this.$prompt("请输入名称", "添加巡检项分类", {
    391. confirmButtonText: "确定",
    392. cancelButtonText: "取消",
    393. inputPattern:
    394. /^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z])(([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[-_a-zA-Z0-9]){0,31})$/,
    395. inputErrorMessage:
    396. "支持以中文或英文开头,由中文、英文、数字及特殊字符_-组成,1-32位",
    397. inputValue: data.name,
    398. })
    399. .then(({ value }) => {
    400. // 参数:name, parentId, sort, description
    401. this.editType(
    402. value,
    403. data.parentId,
    404. data.id,
    405. data.sort,
    406. data.description
    407. );
    408. })
    409. .catch(() => {
    410. this.$message({
    411. type: "info",
    412. message: "取消输入",
    413. });
    414. });
    415. },
    416. editType(name, parentId, selfId, sortNumber, description) {
    417. let parm = {
    418. name: name,
    419. parentId: parentId,
    420. selfId: id,
    421. sort: sortNumber,
    422. description: description,
    423. };
    424. requestMethod.editCategoryTree("put", parm).then((res) => {
    425. if (res.status) {
    426. // 重新渲染树
    427. this.getLeftTree();
    428. }
    429. });
    430. },
    431. // 左侧树删除
    432. remove(node, data) {
    433. const parent = node.parent;
    434. const children = parent.data.children || parent.data;
    435. const index = children.findIndex((d) => d.id === data.id);
    436. children.splice(index, 1);
    437. },
    438. mousedown() {},
    439. getDataList() {},
    440. handleSortChange() {},
    441. clickNode() {},
    442. toSearch(val) {
    443. this.getDataList(
    444. getSession("searchFresh").keyword,
    445. getSession("searchFresh").pageNo,
    446. getSession("searchFresh").pageSize,
    447. true
    448. );
    449. },
    450. searchContdition() {},
    451. // 上下分页
    452. handleCurrentChange(val) {
    453. this.getDataList(
    454. getSession("searchFresh").keyword,
    455. val,
    456. getSession("searchFresh").pageSize,
    457. true
    458. );
    459. },
    460. // 每页显示多少条
    461. handleSizeChange(val) {
    462. this.getDataList(
    463. getSession("searchFresh").keyword,
    464. getSession("searchFresh").pageNo,
    465. val,
    466. true
    467. );
    468. },
    469. addOracleInstance() {
    470. this.addOracleInstanceDrawerVisible = true;
    471. },
    472. setInspectionType() {
    473. this.excelImportVisible = true;
    474. },
    475. // 拖动
    476. dragTree(e) {
    477. let leftViewContainer = document.getElementById("leftContainer");
    478. let rightViewContainer = document.getElementById("rightContainer");
    479. //得到点击时该容器的宽高:
    480. let leftViewContainerWidth = leftViewContainer.offsetWidth;
    481. let startX = e.clientX;
    482. let startY = e.clientY;
    483. document.onmousemove = function (e) {
    484. e.preventDefault();
    485. //得到鼠标拖动的宽高距离:取绝对值
    486. let distX = Math.abs(e.clientX - startX);
    487. //往右方拖动:
    488. if (e.clientX > startX) {
    489. leftViewContainer.style.width = leftViewContainerWidth + distX + "px";
    490. rightViewContainer.style.width =
    491. leftViewContainerWidth - distX + "px";
    492. }
    493. //往左方拖动:
    494. if (e.clientX < startX && e.clientY > startY) {
    495. leftViewContainer.style.width = leftViewContainerWidth - distX + "px";
    496. rightViewContainer.style.width =
    497. leftViewContainerWidth + distX + "px";
    498. }
    499. if (parseInt(leftViewContainer.style.width) >= 600) {
    500. leftViewContainer.style.width = 600 + "px";
    501. }
    502. if (parseInt(leftViewContainer.style.width) <= 20) {
    503. leftViewContainer.style.width = 20 + "px";
    504. }
    505. };
    506. document.onmouseup = function () {
    507. document.onmousemove = null;
    508. };
    509. },
    510. },
    511. };
    512. </script>
    513. <style src="./index.less" lang='less' scoped>
    514. </style>

  • 相关阅读:
    【TA-霜狼_may-《百人计划》】图形5.2 光线追踪、路径追踪、光线投射、光线步进介绍
    ESP8266-Arduino编程实例-TM1637-驱动4位7段数码管
    CLS-PEG-DBCO,胆固醇-聚乙二醇-二苯基环辛炔,可用于改善循环时间
    java开发学习框架
    信奥中的数学:约数
    数据备份与恢复
    整数转罗马数字
    2023年9月电子学会Python等级考试试卷(四级)答案解析
    Jquery学习笔记
    [附源码]计算机毕业设计JAVA科院垃圾分类系统
  • 原文地址:https://blog.csdn.net/yufengaotian/article/details/132904774