1、支持列表自定义表头

2、业务完事,代码优化
This commit is contained in:
2019-04-23 20:54:42 +08:00
parent 8a03b03888
commit 211e59ea3b
8 changed files with 104 additions and 116 deletions

View File

@@ -18,16 +18,6 @@ const meta = {
},
getServiceInfo({name}, callback) {
red.getJSON("/meta/service_info",{name}, res => {
/*let row = red.replacePoint(res)
console.log(row)
//let [name, comment, table, edits, imports, shows, exports, filters] = red.replacePoint(res);
row.shows = row.shows || [];
row.exports = row.exports || [];
row.imports = row.imports || [];
row.filters = row.filters || [];*/
let {name, comment, table, edits, imports, shows, exports, filters} = red.replacePoint(res)
@@ -67,6 +57,12 @@ const meta = {
return red.postX('/meta/tableinfo', {name, alias})
},
//meta-service
showSave({name, shows}) {
shows = red.replace$(shows);
return red.postX('/meta/showsort', {name, shows: JSON.stringify(shows)})
},
// Meta-Table
itemSort({alias, items}) {
return red.postX('/meta/itemsort', {alias, items: JSON.stringify(items)})

View File

@@ -83,7 +83,7 @@
<thead>
<tr>
<th v-for="field in cfg.shows"
v-text="getFieldLabel(field.col)"
v-text="field.label || getFieldLabel(field.col)"
:class="{'sort':field.order>0, 'sort-up':field.col==order.col && order.desc==1, 'sort-down':field.col==order.col && order.desc!=1}"
@click="sortEvent(field.col)"
>

View File

@@ -106,7 +106,7 @@
<tr v-for="(item, index) in serviceDetail['tables'][sheet].items">
<td v-show="status==3"><input type="checkbox" v-model="serviceInfo.exports" :value="sheet + '$' + item.name"></td>
<td v-show="status==4"><input type="checkbox" v-model="serviceInfo.imports" :value="sheet + '$' + item.name"></td>
<td v-show="status==5"><input type="checkbox" v-model="serviceInfo.shows" :value="sheet + '$' + item.name"></td>
<td v-show="status==5"><input type="checkbox" v-model="showFields" :value="sheet + '$' + item.name"></td>
<td v-show="status==6"><input type="checkbox" v-model="filterArr" :value="sheet + '$' + item.name"></td>
<td v-text="item.name" style="background-color: rgb(235, 235, 228);"></td>
@@ -122,23 +122,23 @@
<div class="col-md-5" style="padding-left: 0px;padding-right: 0px;">
<!-- shows -->
<div id="show" v-show="status==5">
<div style="padding-left: 10px;background-color: #ccc;width: 100%"> 展示字段配置</div>
<div style="padding-left: 10px;background-color: #ccc;width: 100%"> 列表配置</div>
<table class="table table-bordered table-auto" style="width: 100%;background-color: #fff;">
<thead>
<tr>
<th></th>
<th>字段</th>
<th>中文名</th>
<th>数据字段</th>
<th>表头名称</th>
<!--<th>支持排序</th>-->
</tr>
</thead>
<tr v-for="(item, index) in serviceInfo.shows">
<td class="icon icon-move">
<input name="name" :value="item" type="hidden">
<input name="col" :value="item.col" type="hidden">
<input name="label" :value="item.label" type="hidden">
</td>
<td v-text="item" style="background-color: rgb(235, 235, 228);"></td>
<td v-text="">{{getFieldLabel(item)}}</td>
<td v-show="false"><input v-model="item.label" style="width: 100px;"></td>
<td v-text="item.col" style="background-color: rgb(235, 235, 228);"></td>
<td ><input v-model="item.label" class="form-control" style="width: 100px;padding: 0px"></td>
</tr>
</table>
</div>
@@ -274,9 +274,7 @@
</row>
<script>
//import { login } from '../api/user.js'
//import { getServiceInfo, getServiceDetail, getServiceList } from '/api/meta.js'
let { getServiceInfo, getServiceDetail, getServiceList, tableLinkList, serviceSave } = meta;
let { getServiceInfo, getServiceDetail, getServiceList, tableLinkList, serviceSave, showSave } = meta;
let { showOk } = red
var vm = new Vue({
@@ -323,6 +321,9 @@
createRow: {},
tables: [],
//shows
showFields: []
},
watch: {
status: function (v) {
@@ -346,6 +347,13 @@
});
this.filterMap = map;
this.filterArr = arr;
//shows
let showFields = []
for (let i in v.shows) {
showFields.push(v.shows[i]['col'])
}
this.showFields = showFields
},
serviceDetail: function (v) {
var arr = [];
@@ -376,6 +384,36 @@
}
this.filterMap = map;
},
showFields(v) {
let shows = this.serviceInfo.shows
//添加新增的
a:for(let i in v) {
b:for(let j in shows) {
if (v[i] == shows[j]['col']) {
if (!shows[j]['label']) {
shows[j]['label'] = this.getFieldLabel(v[i])
}
continue a
}
}
let label = this.getFieldLabel(v[i])
shows.push({col: v[i], label: label})
}
//去除删除的
let _shows = []
a:for(let i in shows) {
b:for (let j in v) {
if (shows[i]['col'] == v[j]) {
_shows.push(shows[i])
continue a;
}
}
}
this.serviceInfo.shows = _shows
}
},
methods: {
loadInfo(name) {
@@ -398,9 +436,9 @@
return "";
}
var tableInfo = vm.serviceDetail['tables'][col.split("$")[0]];
let tableInfo = vm.serviceDetail['tables'][col.split("$")[0]];
if (tableInfo) {
for (var i = 0; i < tableInfo.items.length; i++) {
for (let i = 0; i < tableInfo.items.length; i++) {
if (tableInfo.items[i].name == col.split("$")[1]) {
return tableInfo.items[i].label;
}
@@ -409,14 +447,6 @@
}
return '';
},
/*catalogs: function() {
var dbPlats = this.dbPlats;
for (i in dbPlats) {
if (dbPlats[i].key == this.row.dbPlatId) {
return dbPlats[i]["catalogs"]
}
}
},*/
setMove: function () {
if (this.status == 1) {
$('#sortableList,table>tbody').sortable({
@@ -435,15 +465,8 @@
else if (this.status == 5) {
$('#show>table>tbody').sortable({
selector: 'tr',
finish: function (e) {
var rows = e.list;
var shows = [];
for (var i = 0; i < rows.length; i++) {
var item = $(rows[i]).find("input[name='name']").val();
shows.push(item);
}
vm.serviceInfo.shows = shows;
}
trigger: '.icon',
finish: function (e) {}
});
} else if (this.status == 4) {
$('#import>table>tbody').sortable({
@@ -538,12 +561,15 @@
}
else if (vm.status == 5) {
let dataStr = JSON.stringify(red.replace$(vm.serviceInfo.shows));
console.log("dataStr", dataStr);
red.postX("/meta/showsort", {
serviceKey: vm.service,
items: dataStr
}).then(() => showOk());
let doms = $("#show>table>tbody>tr")
let shows = []
for (let i = 0; i < doms.length; i++) {
let col = $(doms[i]).find("input[name='col']").val();
let label = $(doms[i]).find("input[name='label']").val();
shows.push({col, label})
}
showSave({name: this.service, shows}).then(res => {red.showOk()})
}
else if (vm.status == 6) {
@@ -595,44 +621,8 @@
},
mounted: function (){
//dbPlats 列表初始化
/*red.dbPlats(function (json) {
vm.dbPlats = json;
});*/
this.serviceList();
}
});
</script>
<!--
<row class="">
</row>
<script>
var vm = new Vue({
el: ".meta-service",
data: {
},
watch: {
},
methods: {
},
mounted: function () {
var m = {"a.name": "lxyer", "a.`age`": 11}
console.log(m["a.name"])
console.log("-&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;")
for (var k in m) {
console.log(k)
}
}
});
</script>-->
</script>

View File

@@ -174,4 +174,13 @@ th{
.tlist>li>a:hover {
background-color: #e2effc;
border-radius: 2px 0 0 2px;
}
/* 为可拖动的条目应用可移动光标类型 */
tr {cursor: move}
/* 为正在被拖动的条目应用半透明外观 */
tr.dragging {
visibility: visible;
opacity: .3;
}