樹的增加修改和編輯

<template>

<div class="center">

<div class="top">


? ? ? ? ? ? <Button type="info" @click="add()" :disabled="!this.addTree">新增目錄</Button>

<Button type="success" @click="edits()">編輯目錄</Button>

</div>

<div class="page_left">

<div>

<Tree ref="treeIns" :data="treeData" @on-select-change="treeSelectedHandler"></Tree>

</div>

<div class="page_center" v-if="addTree ==true">

<div>

<span style="color:red; padding-right:2px;">*</span>

<span class="show_span">名稱</span>

<Input v-model="formNode.title" clearable style="width: 200px"/>

</div>

<div>

<span style="color:red; padding-right:2px;">*</span>

<span class="show_span">排序</span>

<Input v-model="formNode.index" clearable style="width: 200px"/>

</div>

<div>

<span style="color:red; padding-right:2px;position:relative; top:25px;">*</span>

<span style="position:relative; top:25px;" class="show_span">描述</span>

<Input v-model="formNode.desc" type="textarea" :rows="4" style="margin-left:60px;"/>

</div>

<Button :disabled="!currentNodeId || !formNode.title.trim()" type="info"

? ? ? ? ? ? ? ? ? ? ? ? style="margin-left:5px; margin-top:25px;" shape="circle" @click="nodeSaveHandler">立即保存

</Button>

</div>

<div v-else="addTree ==false" class="page_center">

<div>

<span style="color:red; padding-right:2px;">*</span>

<span class="show_span">名稱</span>

<Input v-model="formNode.retitle" clearable style="width: 200px" ref="inputReset"/>

</div>

<Button :disabled="!currentNodeId" type="info" shape="circle" style="margin-left:5px; margin-top:25px;" @click="nodeEditTree">立即保存</Button>

</div>

</div>

</div>

</template>

<script>

// let arr;

// let arrs;

? ? import PreMapfrom './PreMap.vue'

? ? import _Mapfrom '/src/page/content/Map.js';

// 引入樹遍歷的東西---封裝好的

? ? import crawl from "tree-crawl";

export default {

name:'center',

components: {

PreMap

},

data() {

return {

currentNodeId:"",

miaoshu:'',

name:'',

xuhao:'',

searchval:"黃陵",

row_list:1,

addTree:true,

formNode: {

title:"",

desc:"",

index:0,

retitle:""

? ? ? ? ? ? ? ? },

treeData: [],

}

},

computed: {

// 父節(jié)點(diǎn)

? ? ? ? ? ? currentParentNode() {

if (this.currentNodeId) {

return this._nodeParentMap.get(this.currentNodeId)

}else {

return "";

}

},

// 自己

? ? ? ? ? ? currentNode() {

if (this.currentNodeId) {

return this._nodeMap.get(this.currentNodeId)

}else {

return "";

}

}

},

mounted() {

let m =this;

m.list(2)

// 返回的return的東西---賦值的操作

? ? ? ? ? ? ? ? .then(data => {

if (!data)return;

// 數(shù)據(jù)給了list

? ? ? ? ? ? ? ? ? ? let list = data.data;

// 開始遍歷樹的方法

? ? ? ? ? ? ? ? ? ? crawl(

{children:list},

// node-點(diǎn)? ctx--

? ? ? ? ? ? ? ? ? ? ? ? (node, ctx) => {

// 添加索引,避免重復(fù)查找時的繁瑣

? ? ? ? ? ? ? ? ? ? ? ? ? ? m._nodeMap.set(node.id, node);//找到自己的點(diǎn)

? ? ? ? ? ? ? ? ? ? ? ? ? ? m._nodeParentMap.set(node.id, ctx.parent);//找到它的父節(jié)點(diǎn)

? ? ? ? ? ? ? ? ? ? ? ? },

{

// 根據(jù)節(jié)點(diǎn)的不同找到不同的樹

// getchildren是封裝好的方法蔚龙,用來調(diào)取節(jié)點(diǎn)

? ? ? ? ? ? ? ? ? ? ? ? ? ? getChildren(node) {

// 這個地方不能更改

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return node.children;

// return node

? ? ? ? ? ? ? ? ? ? ? ? ? ? },

}

)

debugger

? ? ? ? ? ? ? ? ? ? m.treeData =list;

m.listtotal = data.total;

})

;

// 維護(hù)索引

? ? ? ? ? ? m._nodeMap =new Map();

m._nodeParentMap =new Map();

},

methods: {

list(page) {

let m =this;

console.log(m.addTree);

// return下面的所有數(shù)據(jù)

? ? ? ? ? ? ? ? return m.$http.get('http://47.98.47.90:16666/layermanager/res/resources?', {

params: {

location:m.searchval,

classify:this.row_list,

page: page

}

}

).then(res => {

if (res.data !=null) {

return res.data;

}else {

m.$Message.error(res.data.msg);

}

}).catch(function (error) {

m.$Message.error("獲取數(shù)據(jù)出錯:" + error);

})

},

// 當(dāng)前樹節(jié)點(diǎn)被選中的時候

? ? ? ? ? ? treeSelectedHandler([node]) {

if (node) {

// 如果樹被選中

// node---樹 node.id---id號

? ? ? ? ? ? ? ? ? ? this.currentNodeId = node.id;

// 這個node是被選中的節(jié)點(diǎn)的內(nèi)容

// console.log(node)

? ? ? ? ? ? ? ? }else {

this.currentNodeId ="";

}

},

add(){

const m =this;

m.addTree =true;

},

nodeSaveHandler() {

this.addTree =true;

const m =this;

// node是當(dāng)前輸入的title

? ? ? ? ? ? ? ? let node =Object.assign({},m.formNode);

// 得到子節(jié)點(diǎn)的內(nèi)容

? ? ? ? ? ? ? ? let children =this.currentNode;

// let children = m.currentParentNode.children;

? ? ? ? ? ? ? ? node.index =parseInt(node.index);

if (isNaN(node.index) ||node.index <0 ) {

node.index =children.length;

}

// 添加進(jìn)去

? ? ? ? ? ? ? ? children.children.splice(node.index,0,node);

// 創(chuàng)建索引

? ? ? ? ? ? ? ? m._nodeMap.set(node.id,node);

m._nodeParentMap.set(node.id,m.currentParentNode);

// 清空

? ? ? ? ? ? ? ? Object.keys(m.formNode).map(key => {

m.formNode[key] ="";

})

// m.$set(m.currentParentNode, "selected", false);

// m.currentNodeId = "";

? ? ? ? ? ? },

edits() {

this.formNode.retitle=this.currentNode.title

? ? ? ? ? ? ? ? console.log(this.formNode.retitle)

// this.$refs.inputReset=this.currentNode

? ? ? ? ? ? ? ? const m =this;

m.addTree =false;

},

nodeEditTree(node) {

const m =this;

if (m.currentNode) {

this.currentNode.title=m.formNode.retitle

? ? ? ? ? ? ? ? ? ? console.log(this.currentNode.title)

}

Object.keys(m.formNode).map(key => {

m.formNode[key] ="";

})

this.addTree=true;

}

},

}

</script>

<style lang="less">

.center {

.top {

padding-bottom:12px;

button {

margin-right:6px;

}

.input {

margin-right:12px;

}

}

.page {

margin-top:24px;

}

}

.page_left {

display:flex;

flex-direction:row;

}

.page_center {

margin-left:300px;

.show_span {

font-size:15px;

margin-right:20px;

}

input {

width:200px;

height:40px;

}

}

.page_center >div:nth-child(1) {

margin-top:10px;

}

.page_center >div:nth-child(2) {

margin-top:30px;

}

.page_center >div:nth-child(3) {

margin-top:30px;

input {

height:200px;

width:300px;

}

span {

margin-bottom:160px;

}

}

</style>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末冰评,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子木羹,更是在濱河造成了極大的恐慌甲雅,老刑警劉巖解孙,帶你破解...
    沈念sama閱讀 218,755評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異抛人,居然都是意外死亡弛姜,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評論 3 395
  • 文/潘曉璐 我一進(jìn)店門妖枚,熙熙樓的掌柜王于貴愁眉苦臉地迎上來廷臼,“玉大人,你說我怎么就攤上這事绝页≤蹋” “怎么了?”我有些...
    開封第一講書人閱讀 165,138評論 0 355
  • 文/不壞的土叔 我叫張陵续誉,是天一觀的道長莱没。 經(jīng)常有香客問我,道長酷鸦,這世上最難降的妖魔是什么饰躲? 我笑而不...
    開封第一講書人閱讀 58,791評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮臼隔,結(jié)果婚禮上属铁,老公的妹妹穿的比我還像新娘。我一直安慰自己躬翁,他們只是感情好焦蘑,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,794評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著盒发,像睡著了一般例嘱。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上宁舰,一...
    開封第一講書人閱讀 51,631評論 1 305
  • 那天拼卵,我揣著相機(jī)與錄音,去河邊找鬼蛮艰。 笑死腋腮,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的壤蚜。 我是一名探鬼主播即寡,決...
    沈念sama閱讀 40,362評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼袜刷!你這毒婦竟也來了聪富?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,264評論 0 276
  • 序言:老撾萬榮一對情侶失蹤著蟹,失蹤者是張志新(化名)和其女友劉穎墩蔓,沒想到半個月后梢莽,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,724評論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡奸披,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年昏名,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片阵面。...
    茶點(diǎn)故事閱讀 40,040評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡葡粒,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出膜钓,到底是詐尸還是另有隱情嗽交,我是刑警寧澤,帶...
    沈念sama閱讀 35,742評論 5 346
  • 正文 年R本政府宣布颂斜,位于F島的核電站夫壁,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏沃疮。R本人自食惡果不足惜盒让,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,364評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望司蔬。 院中可真熱鬧邑茄,春花似錦、人聲如沸俊啼。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽授帕。三九已至同木,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間跛十,已是汗流浹背彤路。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留芥映,地道東北人洲尊。 一個月前我還...
    沈念sama閱讀 48,247評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像奈偏,于是被迫代替她去往敵國和親坞嘀。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,979評論 2 355

推薦閱讀更多精彩內(nèi)容