index.vue
5.81 KB
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
<template>
<LayoutContent :breads="[{title: '资源位列表'}]">
<div>
<i-button type="primary" @click="showAddResourcePannel(true)">添加资源位</i-button>
</div>
<LayoutTable :columns="columns" :data="data">
</LayoutTable>
<!--添加资源位弹出层-->
<div v-if="showAddPan" class="resource-add-container">
<i-card class="resource-add-card">
<p slot="title">添加资源位</p>
<a href="javascript:void(0)" slot="extra" @click="showAddResourcePannel(false)">
<i-icon type="ios-close" size="24"></i-icon>
</a>
<div class="resource-add-content">
<i-row>
<i-col span="8"><label>选择平台:</label></i-col>
<i-col span="16">
<i-select class="platform-select" v-model="platform">
<i-option value="1">App</i-option>
<i-option value="2">小程序</i-option>
</i-select>
</i-col>
</i-row>
<i-row>
<i-col span="8"><label>资源名称:</label></i-col>
<i-col span="16">
<i-input class="name-input" v-model="resourceName" placeholder="请输入资源名称"></i-input>
</i-col>
</i-row>
<i-row>
<i-col span="24">
<i-button type="primary" @click="saveResource">保 存</i-button>
</i-col>
</i-row>
</div>
</i-card>
</div>
</LayoutContent>
</template>
<script>
import {Button} from 'iview'; //eslint-disable-line
import ResourceService from '@/service/resource-service';
import dayjs from 'dayjs';
import util from '@/libs/util';
export default {
name: 'resourcelist',
data() {
return {
data: [],
columns: [{
title: 'ID',
key: 'id',
width: 100
}, {
title: '资源名称',
key: 'name',
width: 200
}, {
title: '平台',
key: 'platform',
width: 100
}, {
title: '位置码',
key: 'code',
width: 300
}, {
title: '创建时间',
key: 'createTime',
width: 200,
render: (h, {row}) => {
/*return (
<div>{dayjs.unix(row.createTime).format('YYYY-MM-DD HH:mm:ss')}</div>
);*/
return h('div', {style: {color: '#999'}}, dayjs.unix(row.createTime).format('YYYY-MM-DD HH:mm:ss'));
}
}, {
title: '操作',
width: 270,
align: 'center',
render: (h, {row}) => {
/*return (
<div>
<i-button type="success" size="small" onClick={() => this.onToEditor(row)}>内容编辑</i-button>
</div>
);*/
return h('div',{},[
h('i-button', {props: {type: 'success', size: 'small'}, on:{click: () => this.onToEditor(row)}}, '内容编辑'),
h('i-button', {props: {type: 'primary', size: 'small'}, style:{marginLeft: '20px', display: row.showEditButton}, on:{click: () => this.onEditResource(row)}}, '修改信息'),
]);
}
}],
showAddPan: false,
platform: '1',
resourceName: '',
editResourceId: 0 // 当前需要修改的resourceId
};
},
created() {
this.resourceService = new ResourceService();
this.fetchData();
},
methods: {
onToEditor({id, name, sortId}) {
if (sortId === 2) {
util.jumpUrl(`resource-edit.html?id=${id}&name=${name}`);
} else if(sortId === 3) {
util.jumpUrl(`resource-edit-new.html?id=${id}&name=${name}`);
}
},
async fetchData() {
this.$Loading.start();
const result = await this.resourceService.list();
if (result.code === 200) {
for (let i = 0; i < result.data.length; i++) {
result.data[i].showEditButton = 'inline-block';
if (result.data[i].sortId === 2) {
result.data[i].showEditButton = 'none';
}
}
this.data = result.data;
this.$Loading.finish();
} else {
result.message && this.$Message.warning(result.message);
this.$Loading.error();
}
},
showAddResourcePannel(show) {
this.showAddPan = show;
},
saveResource() {
let self = this;
if (this.resourceName) {
let data = {
name: this.resourceName,
platformId: this.platform,
sortId: 3
};
if (this.editResourceId) {
Object.assign(data, {}, {id: this.editResourceId});
}
this.resourceService.addOrUpdateResource(data).then(result => {
if (result && result.code === 200) {
self.showAddPan = false;
self.$Message.success('保存成功!');
self.fetchData();
self.platform = '1';
self.editResourceId = 0;
self.resourceName = '';
} else {
self.$Message.error(result.message);
}
});
}
},
onEditResource(data) {
console.log(data);
this.platform = ['0', 'APP', '小程序'].indexOf(data.platform).toString();
this.resourceName = data.name;
this.editResourceId = data.id;
this.showAddResourcePannel(true);
}
}
};
</script>
<style>
.resource-add-container {
position: absolute;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
}
.resource-add-card {
position: absolute;
width: 600px;
margin-top: 30px;
left: 50%;
margin-left: -300px;
}
.platform-select, .name-input {
width: 200px;
margin: 0 auto;
}
.ivu-row {
border-bottom: 1px solid #e3e3e3;
}
.ivu-row:hover {
background-color: #aefdff;
}
.ivu-col {
text-align: center;
height: 50px;
line-height: 50px;
}
.ivu-col:nth-child(odd) {
border-right: 1px solid #e4e4e4;
}
.ivu-card-body {
margin: 0;
padding: 0;
}
</style>