1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<template>
<div id="app">
<b-navbar class="Widget">
<b-dropdown id="dropdown-1" text="Add Widget" class="m-md-2" variant="primary">
<b-dropdown-item v-for="(availableWidget,index) in availableWidgets" :key="index">
<div v-on:click="addWidget(availableWidget)">{{availableWidget}}</div>
</b-dropdown-item>
</b-dropdown>
<b-button @click="saveWidgetList" style="margin-left:2%" variant="primary">Save</b-button>
<b-button @click="UIGenerateAutomatic" style="margin-left:2%" variant="primary">test</b-button>
<b-form-file
id="file"
type="file"
@change="loadTextFromFile"
placeholder="Choose a widgetTemplate file to laod"
accept=".json"
style="width:30%;margin-left:2%"
/>
</b-navbar>
<grid-layout
:layout.sync="widgetList"
:col-num="12"
:row-height="30"
:is-draggable="true"
:is-resizable="true"
:is-mirrored="false"
:vertical-compact="true"
:margin="[10, 10]"
:use-css-transforms="true"
>
<grid-item
v-for="(widget) in widgetList"
:x="widget.x"
:y="widget.y"
:w="widget.w"
:h="widget.h"
:i="widget.i"
:key="widget.i"
>
<div style="border-color: rgb(206, 212, 218);">
<div style="height:20px;background-color:rgb(0, 123, 255)"></div>
<component :is="widget.widgetComponentName" :ref="widget.ref"></component>
</div>
</grid-item>
</grid-layout>
</div>
</template>
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import axios from "axios";
import { GridItemData,GridLayout,GridItem} from 'vue-grid-layout';
import { WidgetRef } from "./models/WidgetRef";
import { WidgetConfig, AllWidgetConfig } from "./models/WidgetConfig";
import { Action, UpdatePayload } from "./models/UpdatePayload";
import { Widget } from "./models/wiget";
//when add more available widgets add ref to the widgets
import Status from "./components/Status/Status.vue";
import WaveView from "./components/WaveView/WaveView.vue";
import Method from "./components/Method/Method.vue";
import Config from "./components/Config/Config.vue";
//this is the view selecotr class
@Component({
components: {
//when add more available widgets add ref to the widgets
Status,
WaveView,
Method,
Config,
GridLayout,
GridItem
}
})
export default class App extends Vue {
widgetList: WidgetRef[] = [];
fileName: string = "config.json";
private lastWidgetIndex: number = 0;
isShowAddWidget: Boolean = false;
text: string = "";
//when add more available widgets add its name here
availableWidgets = ["Status", "Config", "WaveView", "Method"];
toggleShowAddWidget(): void {
this.isShowAddWidget = !this.isShowAddWidget;
}
UIGenerateAutomatic() {
// var fragment = window.location.hash;
var fragment = "#/card";
if (fragment != "#") {
fragment = fragment.substring(1,fragment.length);
var customViewURL = "customView/template" + fragment;
axios.get(customViewURL).then(response => {
if(response.data.CFET2CORE_SAMPLE_ISVALID == false || response.data.CFET2CORE_SAMPLE_VAL == null)
{
//直接访问对应的值
var dataURL = fragment;
axios.get(fragment).then(response => {
}
}
else{
//返回有值的customview template,进行load处理
var customviewTemplate:string;
customviewTemplate = response.data.CFET2CORE_SAMPLE_VAL;
console.log(customviewTemplate);
var widgets;
widgets = Object.assign(
new AllWidgetConfig(),
JSON.parse(customviewTemplate));
console.log(widgets);
this.widgetList = widgets.widgetList;
this.lastWidgetIndex = Number(widgets.currentRef);
this.$forceUpdate();
Vue.nextTick(() => {
fragment = fragment.substring(1,fragment.length);
for (var wid of this.widgetList) {
((this.$refs[wid.ref] as Array<Widget>)[0] as Widget).replaceStartPath( fragment as string);
}
this.importActiveWidgetList();
});
}
})
}
}
exportActiveWidgetList(): AllWidgetConfig {
for (var widget of this.widgetList) {
widget.widgetConfig = ((this.$refs[widget.ref] as Array<Widget>)[0] as Widget).getConfig();
}
var widgetConfigList = new AllWidgetConfig();
widgetConfigList.widgetList = this.widgetList;
widgetConfigList.currentRef = this.lastWidgetIndex.toString();
console.log(widgetConfigList);
return widgetConfigList;
}
importActiveWidgetList() {
for (var wid of this.widgetList) {
((this.$refs[wid.ref] as Array<Widget>)[0] as Widget).setConfig( wid.widgetConfig as WidgetConfig);
}
}
loadTextFromFile(ev: any) {
const file = ev.target.files[0];
const reader = new FileReader();
reader.readAsText(file);
var widgets;
// console.log(this.$refs);
reader.onload = e => {
widgets = Object.assign(
new AllWidgetConfig(),
JSON.parse((e.target as any).result)
);
// console.log(widgets);
this.widgetList = widgets.widgetList;
this.lastWidgetIndex = Number(widgets.currentRef);
this.$forceUpdate();
Vue.nextTick(() => { // changed here
this.importActiveWidgetList();
});
// console.log(this.$refs);
};
}
saveWidgetList(): void {
var data = JSON.stringify(this.exportActiveWidgetList());
console.log(data);
const blob = new Blob([data]);
if (window.navigator.msSaveOrOpenBlob) {
// 兼容IE10
navigator.msSaveBlob(blob, this.fileName);
} else {
// chrome/firefox
let aTag = document.createElement("a");
aTag.download = this.fileName;
aTag.href = URL.createObjectURL(blob);
aTag.click();
URL.revokeObjectURL(aTag.href);
}
}
addWidget(widgetName: string): void {
var newWidget = new WidgetRef();
newWidget.widgetComponentName = widgetName;
newWidget.ref = this.lastWidgetIndex.toString();
newWidget.y=this.lastWidgetIndex*4;
newWidget.i=Number(newWidget.ref);
this.lastWidgetIndex++;
this.widgetList = [...this.widgetList, newWidget];
}
update(payload: UpdatePayload) {
for (var wid of this.widgetList) {
(this.$refs[wid.ref] as Widget).parentUpdate(payload);
}
if (payload.action == "") {
for (var wid of this.widgetList) {
(this.$refs[wid.ref] as Widget).refresh();
}
}
}
}
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
.Widget {
width: 100%;
border-color: rgb(206, 212, 218);
}
</style>