Skip to content

Commit c58e021

Browse files
authored
Create app_table.vue
1 parent e3a3951 commit c58e021

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

client/app_table.vue

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<template>
2+
<div class="container">
3+
<table class="table" style="">
4+
<caption><strong>app详情</strong></caption>
5+
<thead>
6+
<tr>
7+
<th>id</th>
8+
<th>app名字</th>
9+
<th>创建时间</th>
10+
<th>更新时间</th>
11+
<th>操作</th>
12+
</tr>
13+
</thead>
14+
<tbody>
15+
<tr class="success">
16+
<td><input v-model="editing_app.id" placeholder="必须填写,且为不重复数字"/></td>
17+
<td><input v-model="editing_app.name" placeholder="必须填写"/></td>
18+
<td><input v-model="editing_app.createTime" placeholder="必须为时间date格式" type="datetime-local"/></td>
19+
<td><input v-model="editing_app.updateTime" placeholder="必须为时间date格式" type="datetime-local"/></td>
20+
<td><button class="btn btn-info" v-on:click="addAppId" >添加</button></td>
21+
</tr>
22+
23+
<tr class="info" v-for="app in apps">
24+
<td><input v-model="app.id" @keyup="updateApp(app) | debounce 500"/>
25+
<td><input v-model="app.name" @keyup="updateApp(app) | debounce 500"/>
26+
<td><input v-model="app.createTime" @keyup="updateApp(app) | debounce 500"/>
27+
<td><input v-model="app.updateTime" @keyup="updateApp(app) | debounce 500"/>
28+
<td>
29+
<button class="btn btn-danger" @click="remove(app)">删除</button>
30+
</td>
31+
</tr>
32+
<!--<browser-item v-for="app in apps" :app="app" @click="selectApp(app)"-->
33+
<!--:editing_app-id="editing_app.id"></browser-item>-->
34+
</tbody>
35+
</table>
36+
</div>
37+
<version></version>
38+
</template>
39+
40+
<script>
41+
var apps;
42+
43+
module.exports = {
44+
http: {
45+
root: '/api/v1',
46+
},
47+
events: {
48+
"remove-app": function (app) {
49+
var self = this;
50+
if (confirm(app.name + "确定删除?")) {
51+
apps.delete({id: app.id}, function (data, status, request) {
52+
self.fetchApps();
53+
});
54+
}
55+
},
56+
"add-app": function() {
57+
var self = this;
58+
var id = self.editing_app.id;
59+
var name = self.editing_app.name;
60+
var createTime = self.editing_app.createTime;
61+
var updateTime = self.editing_app.updateTime;
62+
63+
console.log("id:" + id + ", name: " + name + ",create:" + createTime + ",update:" + updateTime);
64+
if (confirm("id:" + id + ", name: " + name + ",create:" + createTime + ",update:" + updateTime)) {
65+
if (id && name) {
66+
if (!createTime) {
67+
createTime = new Date();
68+
}
69+
if (!updateTime) {
70+
updateTime = new Date();
71+
}
72+
apps.save({}, {
73+
id: id,
74+
name: name,
75+
createTime: createTime,
76+
updateTime: updateTime
77+
}, function (data, status, request) {
78+
console.log('data: ' + data + ', status: ' + status);
79+
self.editing_app = data;
80+
self.fetchApps();
81+
});
82+
}
83+
}
84+
}
85+
},
86+
data: function () {
87+
return {
88+
msg: 'Replaceing',
89+
apps: [],
90+
editing_app: {
91+
id: "",
92+
name: "",
93+
createTime: "",
94+
updateTime: ""
95+
}
96+
}
97+
},
98+
methods: {
99+
addAppId: function () {
100+
console.log('add-app');
101+
this.$dispatch("add-app");
102+
},
103+
updateApp: function (app) {
104+
if (app.id || app.id.length > 0) {
105+
apps.update({id: app.id}, app, function (data, status, request) {
106+
console.log("saved");
107+
})
108+
}
109+
},
110+
selectApp: function (app) {
111+
this.editing_app = app;
112+
113+
},
114+
fetchApps: function () {
115+
var self = this;
116+
apps.query({}, function (items, status, request) {
117+
self.apps = items;
118+
})
119+
},
120+
remove: function (app) {
121+
this.$dispatch("remove-app", app);
122+
}
123+
},
124+
ready: function () {
125+
var access_token = localStorage.getItem('access_token');
126+
apps = this.$resource('apps/:id?access_token=' + access_token);
127+
this.fetchApps();
128+
},
129+
components: {
130+
version: require("./app_version.vue")
131+
}
132+
133+
134+
}
135+
</script>

0 commit comments

Comments
 (0)