提交 71a3a8e1 编写于 作者: sq3536's avatar sq3536

model

上级 45e338d4
......@@ -6,229 +6,12 @@ import { Http,Util } from '@/utils';
import JSONEditor from "@json-editor/json-editor";
import BootstrapVue from "bootstrap-vue";
import "bootstrap/dist/css/bootstrap.css";
import "bootstrap-vue/dist/bootstrap-vue.css";
import CodeListService from "@/codelist/codelist-service";
import AppFormJson from './app-form-json.vue';
import "./app-form-json-da-chart.less";
JSONEditor.defaults.resolvers.unshift(schema => {
if(schema.type === "selectnew" ) {
return "selectnew";
}
// If no valid editor is returned, the next resolver function will be used
});
JSONEditor.defaults.editors.selectnew = JSONEditor.defaults.editors.select.extend({
onWatchedFieldChange: function() {
var self = this, vars, j;
// If this editor uses a dynamic select box
if(this.enumSource) {
vars = this.getWatchedFieldValues();
var select_options = [];
var select_titles = [];
for(var i=0; i<this.enumSource.length; i++) {
// Constant values
if(Array.isArray(this.enumSource[i])) {
select_options = select_options.concat(this.enumSource[i]);
select_titles = select_titles.concat(this.enumSource[i]);
}
else {
var items = [];
// Static list of items
if(Array.isArray(this.enumSource[i].source)) {
items = this.enumSource[i].source;
// A watched field
} else {
items = vars[this.enumSource[i].source];
}
if(items) {
// Only use a predefined part of the array
if(this.enumSource[i].slice) {
items = Array.prototype.slice.apply(items,this.enumSource[i].slice);
}
// Filter the items
if(this.enumSource[i].filter) {
var new_items = [];
for(j=0; j<items.length; j++) {
if(this.enumSource[i].filter({i:j,item:items[j],watched:vars})) new_items.push(items[j]);
}
items = new_items;
}
if(this.enumSource[i].filter2)
{
var xxx=vars[this.enumSource[i].filter2];
if(xxx)
{
var new_items = [];
new_items=items.filter(item22 => (item22.value&&item22.value.indexOf(xxx)>=0));
new_items.unshift({text:"--",id:""});
items = new_items;
}
}
if(this.enumSource[i].filter3)
{
var xxx=vars[this.enumSource[i].filter3];
var new_items = [];
if(xxx)
{
Http.getInstance().get(`/dabuilds/${xxx}/dametrics/fetchdefault`,{},false)
.then((response: any) => {
if(response.status === 200 && response.data) {
response.data.forEach((item: any)=>{
new_items.push(item);
});
}
}).catch((error: any) => {
console.log(error)
})
}
new_items.unshift({text:"--",id:""});
items = new_items;
}
if(this.enumSource[i].filterText)
{
var xxx=vars[this.enumSource[i].filterText];
if(xxx)
{
var new_items = [];
new_items=items.filter(item22 => (item22.text&&item22.text.indexOf(xxx)>=0));
new_items.unshift({text:"--",id:""});
items = new_items;
}
}
var item_titles = [];
var item_values = [];
for(j=0; j<items.length; j++) {
var item = items[j];
// Rendered value
if(this.enumSource[i].value) {
item_values[j] = this.typecast(this.enumSource[i].value({
i: j,
item: item
}));
}
// Use value directly
else {
item_values[j] = items[j];
}
// Rendered title
if(this.enumSource[i].title) {
item_titles[j] = this.enumSource[i].title({
i: j,
item: item
});
}
// Use value as the title also
else {
item_titles[j] = item_values[j];
}
}
// TODO: sort
select_options = select_options.concat(item_values);
select_titles = select_titles.concat(item_titles);
}
}
}
var prev_value = this.value;
this.theme.setSelectOptions(this.input, select_options, select_titles);
this.enum_options = select_options;
this.enum_display = select_titles;
this.enum_values = select_options;
if(this.select2) {
this.select2.select2('destroy');
}
// If the previous value is still in the new select options, stick with it
if(select_options.indexOf(prev_value) !== -1) {
this.input.value = prev_value;
this.value = prev_value;
}
// Otherwise, set the value to the first select option
else {
this.input.value = select_options[0];
this.value = this.typecast(select_options[0] || "");
if(this.parent) this.parent.onChildEditorChange(this);
else this.jsoneditor.onChange();
this.jsoneditor.notifyWatchers(this.path);
}
this.setupSelect2();
}
this._super();
},
getLink: function(data) {
var holder, link;
// Get mime type of the link
var mime = data.mediaType || 'application/javascript';
var type = mime.split('/')[0];
// Template to generate the link href
var href = this.jsoneditor.compileTemplate(data.href,this.template_engine);
var relTemplate = this.jsoneditor.compileTemplate(data.rel ? data.rel : data.href,this.template_engine);
// Template to generate the link's download attribute
var download = null;
if(data.download) download = data.download;
if(download && download !== true) {
download = this.jsoneditor.compileTemplate(download, this.template_engine);
}
{
link = holder = this.theme.getBlockLink();
//holder.setAttribute('target','_blank');
holder.textContent = data.rel;
// When a watched field changes, update the url
this.link_watchers.push(function(vars) {
var url = href(vars);
var rel = relTemplate(vars);
holder.setAttribute('href',url);
holder.textContent = rel || url;
});
}
if(download && link) {
if(download === true) {
link.setAttribute('download','');
}
else {
this.link_watchers.push(function(vars) {
link.setAttribute('download',download(vars));
});
}
}
if(data.class) link.classList.add(data.class);
if(this.jsoneditor.options.no_link_holder){
holder.hidden = true;
}else{
holder.hidden = false;
}
return holder;
}
});
@Component({
components: {
......@@ -285,7 +68,7 @@ export default class AppFormJsonDaChart extends AppFormJson {
"links": [
{
"rel": "查看",
"href": "javascript:window.showfield('{{self}}')"// "/dstweb/index.html#/common_index/analyse_dametriceditview/srfkey={{self}}"
"href": "javascript:window.showdetail('dametric-edit-view',{'dametrics':'{{self}}'})"// "/dstweb/index.html#/common_index/analyse_dametriceditview/srfkey={{self}}"
}
],
options: {
......@@ -294,9 +77,9 @@ export default class AppFormJsonDaChart extends AppFormJson {
value: ''
}
},
"enumSource":[{"source":[...[{text:"--",value:""}]],
"url":"/",
"filter3":"entity12" , "title": "{{item.text}}", "value": "{{item.value}}"}]
"enumSource":[{"source":[...[{metric_name:"--",metric_id:""}]],
"p0":"entity12" ,"url":'/dabuilds/${p0}/dametrics/fetchdefault',
"title": "{{item.metric_name}}", "value": "{{item.metric_id}}"}]
},
"children": {
"type": "array",
......@@ -347,23 +130,5 @@ export default class AppFormJsonDaChart extends AppFormJson {
return _schema;
}
public showfield(arg:any)
{
const data: any = {"srfkey":arg};
const view: any = {
viewname: 'dametric-edit-view',
height: 0,
width: 0,
title: '指标编辑视图',
};
this.$appmodal.openModal(view, {"dametrics":arg},{});
}
}
</script>
\ No newline at end of file
......@@ -9,6 +9,7 @@
import { Component, Vue, Prop, Model, Watch } from "vue-property-decorator";
import { VNode, CreateElement } from "vue";
import { interval, Subject, Subscription } from "rxjs";
import { Http,Util } from '@/utils';
import JSONEditor from "@json-editor/json-editor";
import BootstrapVue from "bootstrap-vue";
import "bootstrap/dist/css/bootstrap.css";
......@@ -16,6 +17,250 @@ import "bootstrap/dist/css/bootstrap.css";
import "bootstrap-vue/dist/bootstrap-vue.css";
import "../app-form-json/app-form-json.less";
JSONEditor.defaults.resolvers.unshift(schema => {
if(schema.type === "selectnew" ) {
return "selectnew";
}
else if(schema.type === "link" ) {
return "link";
}
// If no valid editor is returned, the next resolver function will be used
});
JSONEditor.defaults.editors.selectnew = JSONEditor.defaults.editors.select.extend({
onWatchedFieldChange: function() {
var self = this, vars, j;
// If this editor uses a dynamic select box
if(this.enumSource) {
vars = this.getWatchedFieldValues();
var select_options = [];
var select_titles = [];
for(var i=0; i<this.enumSource.length; i++) {
// Constant values
if(Array.isArray(this.enumSource[i])) {
select_options = select_options.concat(this.enumSource[i]);
select_titles = select_titles.concat(this.enumSource[i]);
}
else {
var items = [];
// Static list of items
if(Array.isArray(this.enumSource[i].source)) {
items = this.enumSource[i].source;
// A watched field
} else {
items = vars[this.enumSource[i].source];
}
if(items) {
// Only use a predefined part of the array
if(this.enumSource[i].slice) {
items = Array.prototype.slice.apply(items,this.enumSource[i].slice);
}
// Filter the items
if(this.enumSource[i].filter) {
var new_items = [];
for(j=0; j<items.length; j++) {
if(this.enumSource[i].filter({i:j,item:items[j],watched:vars})) new_items.push(items[j]);
}
items = new_items;
}
if(this.enumSource[i].codelist)
{
var codelist=this.enumSource[i].codelist;
if(codelist&&items.length<=1)
{
var new_items = [];
Http.getInstance().get(url,{},false)
.then((response: any) => {
if(response.status === 200 && response.data) {
response.data.forEach((item: any)=>{
new_items.push(item);
});
}
}).catch((error: any) => {
console.log(error)
})
new_items.unshift(JSON.parse(JSON.stringify(items[0])));
items = new_items;
}
}
if(this.enumSource[i].url)
{
var url=this.enumSource[i].url;
var p0=vars[this.enumSource[i].p0];
var p1=vars[this.enumSource[i].p1];
var p2=vars[this.enumSource[i].p2];
if(p0)
url=url.replace('${p0}',p0);
if(p1)
url=url.replace('${p1}',p1);
if(p2)
url=url.replace('${p2}',p2);
var new_items = [];
if(p0)
{
Http.getInstance().get(url,{},false)
.then((response: any) => {
if(response.status === 200 && response.data) {
response.data.forEach((item: any)=>{
new_items.push(item);
});
}
}).catch((error: any) => {
console.log(error)
})
}
new_items.unshift(JSON.parse(JSON.stringify(items[0])));
items = new_items;
}
if(this.enumSource[i].filterText)
{
var filterText=vars[this.enumSource[i].filterText];
if(filterText)
{
var new_items = [];
new_items=items.filter(item22 => ((item22.text&&item22.text.indexOf(filterText)>=0)||
(item22.value&&item22.value.indexOf(filterText)>=0)||
(item22.filter&&item22.filter.indexOf(filterText)>=0)));
new_items.unshift({text:"--",id:""});
items = new_items;
}
}
var item_titles = [];
var item_values = [];
for(j=0; j<items.length; j++) {
var item = items[j];
// Rendered value
if(this.enumSource[i].value) {
item_values[j] = this.typecast(this.enumSource[i].value({
i: j,
item: item
}));
}
// Use value directly
else {
item_values[j] = items[j];
}
// Rendered title
if(this.enumSource[i].title) {
item_titles[j] = this.enumSource[i].title({
i: j,
item: item
});
}
// Use value as the title also
else {
item_titles[j] = item_values[j];
}
}
// TODO: sort
select_options = select_options.concat(item_values);
select_titles = select_titles.concat(item_titles);
}
}
}
var prev_value = this.value;
this.theme.setSelectOptions(this.input, select_options, select_titles);
this.enum_options = select_options;
this.enum_display = select_titles;
this.enum_values = select_options;
if(this.select2) {
this.select2.select2('destroy');
}
// If the previous value is still in the new select options, stick with it
if(select_options.indexOf(prev_value) !== -1) {
this.input.value = prev_value;
this.value = prev_value;
}
// Otherwise, set the value to the first select option
else {
this.input.value = select_options[0];
this.value = this.typecast(select_options[0] || "");
if(this.parent) this.parent.onChildEditorChange(this);
else this.jsoneditor.onChange();
this.jsoneditor.notifyWatchers(this.path);
}
this.setupSelect2();
}
this._super();
},
getLink: function(data) {
var holder, link;
// Get mime type of the link
var mime = data.mediaType || 'application/javascript';
var type = mime.split('/')[0];
// Template to generate the link href
var href = this.jsoneditor.compileTemplate(data.href,this.template_engine);
var relTemplate = this.jsoneditor.compileTemplate(data.rel ? data.rel : data.href,this.template_engine);
// Template to generate the link's download attribute
var download = null;
if(data.download) download = data.download;
if(download && download !== true) {
download = this.jsoneditor.compileTemplate(download, this.template_engine);
}
{
link = holder = this.theme.getBlockLink();
//holder.setAttribute('target','_blank');
holder.textContent = data.rel;
// When a watched field changes, update the url
this.link_watchers.push(function(vars) {
var url = href(vars);
var rel = relTemplate(vars);
holder.setAttribute('href',url);
holder.textContent = rel || url;
});
}
if(download && link) {
if(download === true) {
link.setAttribute('download','');
}
else {
this.link_watchers.push(function(vars) {
link.setAttribute('download',download(vars));
});
}
}
if(data.class) link.classList.add(data.class);
if(this.jsoneditor.options.no_link_holder){
holder.hidden = true;
}else{
holder.hidden = false;
}
return holder;
}
});
JSONEditor.defaults.editors.link = JSONEditor.defaults.editors.string.extend({
getLink: function(data) {
var holder, link;
......@@ -188,6 +433,7 @@ export default class AppFormJson extends Vue {
*/
public destroyed() {
if (this.editor) this.editor = null;
window["showdetail"]=null;
}
/**
......@@ -204,6 +450,7 @@ export default class AppFormJson extends Vue {
this.renderJsoneditor();
}
});
window["showdetail"]=this.showdetail;
}
/**
......@@ -280,5 +527,18 @@ export default class AppFormJson extends Vue {
this.editor.setValue({});
}
}
public showdetail(path:any,arg:any)
{
const view: any = {
viewname: path,
height: 0,
width: 0,
title: '查看',
};
this.$appmodal.openModal(view, arg,{});
}
}
</script>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册