Commit 3da3304b authored by 周远喜's avatar 周远喜

树接口更新

parent 5939502d
//-------------蓝色----------- //-------------蓝色-----------
@Theme: rgba(38, 128, 235, 1);
//滚动条颜色 //滚动条颜色
@scrollbar-track-bg-color: rgb(239, 239, 239); @scrollbar-track-bg-color: rgb(239, 239, 239);
@scrollbar-thumb-bg-color: rgba(38, 128, 235, 0.5); @scrollbar-thumb-bg-color: rgba(38, 128, 235, 0.5);
......
...@@ -14,7 +14,11 @@ ...@@ -14,7 +14,11 @@
<table> <table>
<thead> <thead>
<tr> <tr>
<th v-for="(column, index) in columns" :key="index" :style="tdStyle(column)"> <th
v-for="(column, index) in columns"
:key="index"
:style="tdStyle(column)"
>
<label v-if="column.type === 'selection'"> <label v-if="column.type === 'selection'">
<Checkbox v-model="all"></Checkbox> <Checkbox v-model="all"></Checkbox>
</label> </label>
...@@ -40,9 +44,9 @@ ...@@ -40,9 +44,9 @@
<tr <tr
v-for="(item, index) in trs" v-for="(item, index) in trs"
:key="item.id" :key="item.id"
v-show="show(item)"
class="treetr" class="treetr"
:id="'tr' + index" :id="'tr' + index"
v-show="show(item)"
:draggable="drag && !item._drag" :draggable="drag && !item._drag"
@dragstart="dragstart($event, index, item)" @dragstart="dragstart($event, index, item)"
@drop="dragdrop($event, index, item)" @drop="dragdrop($event, index, item)"
...@@ -50,6 +54,7 @@ ...@@ -50,6 +54,7 @@
@dragover="dragover($event, index, item)" @dragover="dragover($event, index, item)"
@dragleave="dragleave($event, index, item)" @dragleave="dragleave($event, index, item)"
> >
<!-- -->
<td <td
v-for="(column, snum) in columns" v-for="(column, snum) in columns"
:key="column.key" :key="column.key"
...@@ -62,31 +67,25 @@ ...@@ -62,31 +67,25 @@
> >
<Checkbox v-model="item.checked"></Checkbox> <Checkbox v-model="item.checked"></Checkbox>
</label> </label>
<!-- 图标 -->
<div v-if="column.type === 'icon'"> <Icon v-if="column.type === 'drag'" type="md-more" class="drag" />
<i <DTSpan v-if="column.type == 'date'" :value="item[column.key]" />
class="icon-set" <div v-if="column.type == 'user'">
size="small" <User :value="item[column.key]" />
@click="RowClick(item, $event, index, action.text)"
v-for="action in column.actions"
:key="action.text"
>
<Icon
:type="action.type"
:title="action.text"
:style="action.style"
/>
</i>
</div>
<div v-if="column.type === 'icons'">
<Icon :type="item[column.key]" size="20" />
</div>
<DTSpan v-if="column.type=='date'" :value="item[column.key]"/>
<div v-if="column.type=='user'">
<User :value="item[column.key]"/>
</div> </div>
<div v-if="column.type=='users'&&item[column.key]&&item[column.key].length>0"> <div
<User v-for="li in item[column.key]" :value="li" :key="li" class="ml10"/> v-if="
column.type == 'users' &&
item[column.key] &&
item[column.key].length > 0
"
>
<User
v-for="li in item[column.key]"
:value="li"
:key="li"
class="ml10"
/>
</div> </div>
<state <state
v-if="column.code" v-if="column.code"
...@@ -94,17 +93,13 @@ ...@@ -94,17 +93,13 @@
:value="item[column.key]" :value="item[column.key]"
/> />
<!-- 树图标 --> <!-- 树图标 -->
<span @click="toggle(index, item)" v-if="snum == iconRow()"> <span @click="toggle(index, item)" v-if="snum == treeColumn()">
<span v-html="item.spaceHtml"></span> <span class="ib" v-width="spaceWidth * item._level"></span>
<a v-if="item.children && item.children.length > 0"> <a v-if="item._count > 0" class="expand"
<i ><Icon :type="item._expanded ? 'ios-add' : 'ios-remove'" /> </a
class="ivu-icon" ><i v-else class="ms-tree-space"></i> {{ item._level }}v{{
:class="{ item._count
'ivu-icon-ios-arrow-forward': !item.expanded, }}:{{ show(item) }}
'ivu-icon-ios-arrow-down': item.expanded,
}"
></i> </a
><i v-else class="ms-tree-space"></i>
</span> </span>
<!-- 菜单名称、排序、请求地址 --> <!-- 菜单名称、排序、请求地址 -->
<label <label
...@@ -115,7 +110,7 @@ ...@@ -115,7 +110,7 @@
{{ renderBody(item, column) }} {{ renderBody(item, column) }}
</label> </label>
<table-expand <table-expand
v-if="column.render && !column.type&&!column.solt" v-if="column.render && !column.type && !column.solt"
:row="item" :row="item"
:column="column" :column="column"
:index="snum" :index="snum"
...@@ -235,9 +230,7 @@ export default { ...@@ -235,9 +230,7 @@ export default {
watch: { watch: {
items() { items() {
if (this.items) { if (this.items) {
this.trs = []; this.trs = this.treeToList(this.items);
this.dataLength = this.Length(this.items);
this.initData(this.deepCopy(this.items), 1, null);
this.checkGroup = this.renderCheck(this.items); this.checkGroup = this.renderCheck(this.items);
if (this.checkGroup.length == this.dataLength) { if (this.checkGroup.length == this.dataLength) {
this.checks = true; this.checks = true;
...@@ -245,6 +238,7 @@ export default { ...@@ -245,6 +238,7 @@ export default {
this.checks = false; this.checks = false;
} }
} }
console.warn("tree", this.trs);
}, },
columns: { columns: {
handler() { handler() {
...@@ -258,8 +252,7 @@ export default { ...@@ -258,8 +252,7 @@ export default {
}, },
mounted() { mounted() {
if (this.items && this.items.length > 0) { if (this.items && this.items.length > 0) {
this.dataLength = this.Length(this.items); this.trs = this.treeToList(this.items);
this.initData(this.deepCopy(this.items), 1, null);
this.cloneColumns = this.makeColumns(); this.cloneColumns = this.makeColumns();
this.checkGroup = this.renderCheck(this.items); this.checkGroup = this.renderCheck(this.items);
if (this.checkGroup.length == this.dataLength) { if (this.checkGroup.length == this.dataLength) {
...@@ -268,10 +261,9 @@ export default { ...@@ -268,10 +261,9 @@ export default {
this.checks = false; this.checks = false;
} }
} }
//this.initData(); console.warn("tree", this.trs);
}, },
methods: { methods: {
initData() {},
slots() { slots() {
return this.$scopedSlots; return this.$scopedSlots;
}, },
...@@ -299,10 +291,10 @@ export default { ...@@ -299,10 +291,10 @@ export default {
var my = e.offsetY; var my = e.offsetY;
var h = e.toElement.clientHeight; var h = e.toElement.clientHeight;
var tr = document.getElementById("tr" + index); var tr = document.getElementById("tr" + index);
if (this.dragIndex > index && my/h<0.5) { if (this.dragIndex > index && my / h < 0.5) {
tr.className = tr.className.replace(" move", " sort"); tr.className = tr.className.replace(" move", " sort");
} }
if (this.dragIndex < index && my/h>0.5) { if (this.dragIndex < index && my / h > 0.5) {
tr.className = tr.className.replace(" sort", " move"); tr.className = tr.className.replace(" sort", " move");
} }
}, },
...@@ -319,14 +311,14 @@ export default { ...@@ -319,14 +311,14 @@ export default {
if (index != this.dragIndex) { if (index != this.dragIndex) {
this.$emit("on-drag-drop", this.dragIndex, index, this.trs, e); this.$emit("on-drag-drop", this.dragIndex, index, this.trs, e);
} }
console.log(e.offsetY/ e.toElement.clientHeight); console.log(e.offsetY / e.toElement.clientHeight);
}, },
/** /**
* @dragover="dragover($event, index, item)" * @dragover="dragover($event, index, item)"
@dragleave="dragleave($event,index,item)" @dragleave="dragleave($event,index,item)"
*/ */
// 有无多选框折叠位置优化 // 有无多选框折叠位置优化
iconRow() { treeColumn() {
var num = 0; var num = 0;
for (let i = 0, len = this.columns.length; i < len; i++) { for (let i = 0, len = this.columns.length; i < len; i++) {
if (this.columns[i].tree) { if (this.columns[i].tree) {
...@@ -347,7 +339,6 @@ export default { ...@@ -347,7 +339,6 @@ export default {
} }
return style; return style;
}, },
// 排序事件 // 排序事件
handleSort(index, type) { handleSort(index, type) {
this.cloneColumns.forEach((col) => (col._sortType = "normal")); this.cloneColumns.forEach((col) => (col._sortType = "normal"));
...@@ -364,50 +355,12 @@ export default { ...@@ -364,50 +355,12 @@ export default {
}, },
// 点击某一行事件 // 点击某一行事件
RowClick(data, event, index, text) { RowClick(data, event, index, text) {
// this.iconName = true; this.$emit("on-row-click", data, event, index, text);
const result = this.makeData(data);
this.$emit("on-row-click", result, event, index, text);
},
//点击图标
RowClickIcon(event, index, text) {
this.$emit("on-icon-click", event, index, text);
}, },
// 点击事件 返回数据处理 // 点击事件 返回数据处理
makeData(data) {
const t = this.type(data);
let o;
if (t === "array") {
o = [];
} else if (t === "object") {
o = {};
} else {
return data;
}
if (t === "array") {
for (let i = 0; i < data.length; i++) {
o.push(this.makeData(data[i]));
}
} else if (t === "object") {
for (const i in data) {
if (
i != "spaceHtml" &&
i != "parent" &&
i != "level" &&
i != "expanded" &&
i != "isShow" &&
i != "load"
) {
o[i] = this.makeData(data[i]);
}
}
}
return o;
},
// 处理表头数据 // 处理表头数据
makeColumns() { makeColumns() {
const columns = this.deepCopy(this.columns); const columns = this.$u.clone(this.columns);
this.tdsWidth = 0; this.tdsWidth = 0;
columns.forEach((column, index) => { columns.forEach((column, index) => {
column._index = index; column._index = index;
...@@ -417,82 +370,42 @@ export default { ...@@ -417,82 +370,42 @@ export default {
}); });
return columns; return columns;
}, },
// 数据处理 增加自定义属性监听 // // 隐藏显示
initData(items, level, parent) {
// this.trs = [] toggle(index, item) {
let spaceHtml = ""; if (item._count > 0) {
for (let i = 1; i < level; i++) { this.$set(this.trs[index], "_expanded", !item._expanded);
spaceHtml += "<i class='ms-tree-space'></i>"; this.trs.forEach((u,i)=>{
if(u["upId"]===item.id){
this.$set(this.trs[i], "_show", !item._expanded);
}
})
} }
items.forEach((item, index) => { console.warn(index, item._expanded, item);
item = Object.assign({}, item, {
parent,
level,
spaceHtml,
});
if (typeof item.expanded === "undefined") {
item = Object.assign({}, item, {
expanded: true,
});
}
if (typeof item.show === "undefined") {
item = Object.assign({}, item, {
isShow: true,
});
}
if (typeof item.isChecked === "undefined") {
item = Object.assign({}, item, {
isChecked: false,
});
}
item = Object.assign({}, item, {
load: !!item.expanded,
});
this.trs.push(item);
if (item.children && item.expanded) {
this.initData(item.children, level + 1, item);
}
items.splice(index, 1, item);
});
}, },
// 隐藏显示
show(item) { show(item) {
return ( if (item._level == 0) {
item.level == 1 || (item.parent && item.parent.expanded && item.isShow) return true;
); } else {
}, var parents = this.getRoots(item);
toggle(index, item) { console.log(parents)
const level = item.level + 1; return parents.filter(u=>{
let spaceHtml = ""; return !u._expanded
for (let i = 1; i < level; i++) { }).length==0;
spaceHtml += "<i class='ms-tree-space'></i>";
} }
if (item.children) { },
if (item.expanded) { getRoots(item){
item.expanded = !item.expanded; var parents = [];
this.close(index, item); var root=this.trs.filter(u=>{
} else { return u["id"]==item["upId"];
item.expanded = !item.expanded; })
if (item.load) { while(root.length==1){
this.open(index, item); parents.push(root[0]);
} else { root=this.trs.filter(u=>{
item.load = true; return u["id"]===root["upId"];
item.children.forEach((child, childIndex) => { })
this.trs.splice(index + childIndex + 1, 0, child);
// 设置监听属性
this.$set(this.trs[index + childIndex + 1], "parent", item);
this.$set(this.trs[index + childIndex + 1], "level", level);
this.$set(
this.trs[index + childIndex + 1],
"spaceHtml",
spaceHtml
);
this.$set(this.trs[index + childIndex + 1], "isShow", true);
this.$set(this.trs[index + childIndex + 1], "expanded", false);
});
}
}
} }
return parents;
}, },
open(index, item) { open(index, item) {
if (item.children) { if (item.children) {
...@@ -582,16 +495,7 @@ export default { ...@@ -582,16 +495,7 @@ export default {
}); });
return arr; return arr;
}, },
// 返回树形数据长度
Length(data) {
let { length } = data;
data.forEach((child) => {
if (child.children) {
length += this.Length(child.children);
}
});
return length;
},
// 返回表头 // 返回表头
renderHeader(column, $index) { renderHeader(column, $index) {
if ("renderHeader" in this.columns[$index]) { if ("renderHeader" in this.columns[$index]) {
...@@ -599,6 +503,27 @@ export default { ...@@ -599,6 +503,27 @@ export default {
} }
return column.title || "#"; return column.title || "#";
}, },
treeToList(tree) {
var that = this;
let list = [];
function treeToList(data, level) {
data.map((u) => {
let copy = that.$u.clone(u);
copy._count = 0;
copy._level = level;
copy._expanded = false;
copy._show = true;
list.push(copy);
if (u.children) {
treeToList(u.children, level + 1);
copy._count = u.children.length;
delete copy.children;
}
});
}
treeToList(tree, 0);
return list;
},
// 返回内容 // 返回内容
renderBody(row, column, index) { renderBody(row, column, index) {
...@@ -617,57 +542,16 @@ export default { ...@@ -617,57 +542,16 @@ export default {
}); });
return arr; return arr;
}, },
// 深度拷贝函数
deepCopy(data) {
const t = this.type(data);
let o;
let i;
let ni;
if (t === "array") {
o = [];
} else if (t === "object") {
o = {};
} else {
return data;
}
if (t === "array") {
for (i = 0, ni = data.length; i < ni; i++) {
o.push(this.deepCopy(data[i]));
}
return o;
}
if (t === "object") {
for (i in data) {
o[i] = this.deepCopy(data[i]);
}
return o;
}
},
type(obj) {
const { toString } = Object.prototype;
const map = {
"[object Boolean]": "boolean",
"[object Number]": "number",
"[object String]": "string",
"[object Function]": "function",
"[object Array]": "array",
"[object Date]": "date",
"[object RegExp]": "regExp",
"[object Undefined]": "undefined",
"[object Null]": "null",
"[object Object]": "object",
};
return map[toString.call(obj)];
},
},
beforeDestroy() {
window.onresize = null;
}, },
}; };
</script> </script>
<style lang="less"> <style lang="less">
@import "../../../assets/css/custom.less"; @import "../../../assets/css/custom.less";
@table_theme: #2680eb;
@table_head: #e9f2fd;
@table_line_height: 50px;
@table_hover: #f2f8fe;
@table_border: #accef7;
.treeTbale { .treeTbale {
overflow: 0 auto; overflow: 0 auto;
width: 100% !important; width: 100% !important;
...@@ -701,28 +585,57 @@ export default { ...@@ -701,28 +585,57 @@ export default {
border-collapse: collapse; border-collapse: collapse;
margin: 0 auto; margin: 0 auto;
width: 100%; width: 100%;
border: 1px solid @table_border;
th { th {
background: #f8f8f9; background: @table_head;
} }
td, td,
th { th {
border: #dcdee2 solid 1px; border-left: @table_border solid 1px;
line-height: 40px; border-right: @table_border solid 1px;
border-bottom: #e8e9eb solid 1px;
line-height: 50px;
padding: 0 5px; padding: 0 5px;
.drag:hover {
cursor: move;
}
.expand {
width: 18px;
height: 18px;
border: 1px solid @table_border;
text-align: center;
padding: 0 1px;
font-size: 14px;
font-weight: bold;
}
.expand:hover{
background: @table_theme;
color:white;
}
.ib {
display: inline-block;
}
}
th {
border-top: @table_border solid 1px;
} }
tr.treetr:hover td { tr.treetr:hover td {
background: #f7f7f7; background: @table_hover;
} }
tr.move { tr.move {
td { td {
background-color: blue; background-color: #d3e6fb;
} }
} }
tr.sort { tr.sort {
td { td {
border-top: 2px solid blue; border-top: 2px solid #3b8ded;
} }
} }
tbody {
border-bottom: @table_border solid 1px;
}
.ms-tree-space { .ms-tree-space {
position: relative; position: relative;
top: 1px; top: 1px;
......
...@@ -2,30 +2,48 @@ import XLSX from 'xlsx'; ...@@ -2,30 +2,48 @@ import XLSX from 'xlsx';
import Api from '@/plugins/request' import Api from '@/plugins/request'
let henq = {}; let henq = {};
let pdfInfo = '' let pdfInfo = ''
henq.clone = (obj) => { henq.clone = (data)=> {
var that = henq var that = henq
var o const t = that.type(data);
if (typeof obj === 'object') { let o;
if (obj === null) { let i;
o = null let ni;
} else { if (t === "array") {
if (obj instanceof Array) { o = [];
o = [] } else if (t === "object") {
for (var i = 0, len = obj.length; i < len; i++) { o = {};
o.push(that.clone(obj[i]))
}
} else {
o = {}
for (var j in obj) {
o[j] = that.clone(obj[j])
}
}
}
} else { } else {
o = obj return data;
}
if (t === "array") {
for (i = 0, ni = data.length; i < ni; i++) {
o.push(that.clone(data[i]));
}
return o;
}
if (t === "object") {
for (i in data) {
o[i] = that.clone(data[i]);
}
return o;
} }
return o
} }
henq.type=(obj) =>{
const { toString } = Object.prototype;
const map = {
"[object Boolean]": "boolean",
"[object Number]": "number",
"[object String]": "string",
"[object Function]": "function",
"[object Array]": "array",
"[object Date]": "date",
"[object RegExp]": "regExp",
"[object Undefined]": "undefined",
"[object Null]": "null",
"[object Object]": "object",
};
return map[toString.call(obj)];
},
henq.merge = () => { henq.merge = () => {
Object.assign(argments) Object.assign(argments)
} }
......
<template> <template>
<div> <div>
<Card> <Card>
<EditGrid :columns="columns" ref="grid" :items="list"> <EditGrid :columns="columns" ref="grid" :items="list" :drag="true">
<template slot="easySearch" <template slot="easySearch"
><Form ref="formInline" :model="easySearch" inline ><Form ref="formInline" :model="easySearch" inline
><FormItem prop="keys" ><FormItem prop="keys"
...@@ -86,6 +86,26 @@ export default { ...@@ -86,6 +86,26 @@ export default {
// { key:"projectId",title:this.l("projectId") ,align:"left" ,high:true }, // { key:"projectId",title:this.l("projectId") ,align:"left" ,high:true },
// { key:"upId",title:this.l("upId") ,align:"left" ,high:true }, // { key:"upId",title:this.l("upId") ,align:"left" ,high:true },
// { type: "selection", width: 80, align: "center" }, // { type: "selection", width: 80, align: "center" },
{
key:"drag",
type:"drag",
width:50,
align:'center'
},
{
key: "upId",
width: 400,
title: this.l("upId"),
},
{
key: "title",
title: this.l("title"),
align: "left",
tree: true,
easy: true,
high: true,
},
{ {
key: "type", key: "type",
width: 90, width: 90,
...@@ -106,14 +126,7 @@ export default { ...@@ -106,14 +126,7 @@ export default {
easy: true, easy: true,
high: true, high: true,
}, },
{
key: "title",
title: this.l("title"),
align: "left",
tree: true,
easy: true,
high: true,
},
{ {
key: "status", key: "status",
title: this.l("status"), title: this.l("status"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment