list.vue
8.71 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<template>
<div class="tablePage">
<!-- 筛选参数 -->
<el-header>
<el-form :inline="true" style="display:flex">
<el-form-item>
<el-input @change="getList" v-model="queryForm.query" placeholder="请输入标题名称"></el-input>
</el-form-item>
<el-form-item style="flex-grow: 1">
<el-select
@change="getList"
class="maxItem"
v-model="queryForm.classifyCode"
placeholder="请选择分类"
clearable
>
<el-option
v-for="item in classifyList"
:key="item.classifyCode"
:label="item.classifyName"
:value="item.classifyCode"
></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleShowEdit(null)" type="primary" icon="el-icon-plus">新建</el-button>
</el-form-item>
</el-form>
</el-header>
<!-- 表格 -->
<el-container>
<el-table :data="list" :loading="loading">
<el-table-column type="index" min-width="50"></el-table-column>
<el-table-column
:show-overflow-tooltip="true"
label="标题"
prop="articleTitle"
min-width="200"
></el-table-column>
<el-table-column>
<template slot="header" slot-scope="scope">
排序值
<el-tooltip effect="dark" content="值越大排序越前" placement="top">
<i :data="scope" class="el-icon-question" style="cursor: pointer;"></i>
</el-tooltip>
</template>
<template slot-scope="scope">{{scope.row.orderId}}</template>
</el-table-column>
<el-table-column :show-overflow-tooltip="false" label="浏览次数" prop="viewNumber" width="130"></el-table-column>
<el-table-column label="状态">
<template slot-scope="scope">
<el-tag
v-if="scope.row.onlineStatus==1"
type="success"
class="pointer"
:class="{'not-allowed' : scope.row.sysList}"
@click="scope.row.sysList ? '' : handleChangeStatue(scope.row, 0)"
>在线</el-tag>
<el-tag
v-else
type="info"
class="pointer"
:class="{'not-allowed' : scope.row.sysList}"
@click="scope.row.sysList ? '' : handleChangeStatue(scope.row, 1)"
>下线</el-tag>
</template>
</el-table-column>
<el-table-column label="是否置顶" min-width="100">
<template slot-scope="scope">
<el-switch
@change="setList(scope.row)"
v-model="scope.row.inTop"
active-color="rgb(102,177,255)"
inactive-color="rgb(234,236,240)"
></el-switch>
</template>
</el-table-column>
<el-table-column label="操作" min-width="100">
<template slot-scope="scope">
<el-button type="text" @click="handleShowEdit(scope.row.articleCode)">编辑</el-button>
<el-button type="text" @click="handleDelete(scope.row.articleCode)">删除</el-button>
</template>
</el-table-column>
</el-table>
</el-container>
<!-- 分页 -->
<el-footer class="fixed-bottom">
<el-pagination
background
layout="total, sizes, prev, pager, next, jumper"
:current-page="queryForm.page"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:page-sizes="[10,20,30,50]"
:page-size="queryForm.size"
:total="total"
></el-pagination>
</el-footer>
</div>
</template>
<script>
import { timestampFormat } from "@/utils/utils";
const getListApi = app.api.getArticleList;
const setListApi = app.api.setArticleList;
export default {
props: [],
components: {},
data() {
return {
queryForm: {
page: 1,
size: 10,
query: "",
classifyCode: ""
}, //列表默认传参
list: [], //列表数据
total: 0, //列表总数
loading: true, //表格加载状态
keyword: "accountCode",
pojo: null,
showEdit: false,
showChangePwd: false,
classifyList: []
};
},
created() {
this.initData();
},
methods: {
timestampFormat,
// 初始化数据
async initData() {
this.getList();
this.getClassifyList();
},
// 获取列表
getList(resize) {
if (resize && resize != undefined) {
this.queryForm.page = 1;
}
this.loading = true;
app
.get({
url: getListApi,
data: this.queryForm
})
.then(res => {
this.loading = false;
res.list.forEach(item => {
item.onlineStatus = item.onlineStatus == 1 ? true : false;
item.inTop = item.inTop == 1 ? true : false;
});
this.list = res.list;
this.total = res.total;
})
.catch(err => {
this.loading = false;
});
},
getClassifyList() {
app
.get({ url: app.api.getArticleClassify, data: null })
.then(res => {
this.classifyList = res.list;
})
.catch(e => {});
},
// 更新内容
setList(item) {
let editForm = JSON.parse(JSON.stringify(item));
editForm.inTop = item.inTop ? 1 : 0;
editForm.onlineStatus = item.onlineStatus ? 1 : 0;
app
.post({
url: setListApi,
data: editForm
})
.then(res => {
this.$message({
message: "更新成功",
type: "success"
});
// this.getList();
})
.catch(err => {});
},
setOrderType(val) {
if (!val.order) {
this.queryForm.orderType = "";
this.getList(true);
return;
}
switch (val.prop) {
case "createAt":
if (val.order == "descending") {
this.queryForm.orderType = "id:desc";
} else {
this.queryForm.orderType = "id:asc";
}
this.getList(true);
break;
case "viewNumber":
if (val.order == "descending") {
this.queryForm.orderType = "viewNumber:desc";
} else {
this.queryForm.orderType = "viewNumber:asc";
}
this.getList(true);
break;
default:
break;
}
},
// 上下架
setOnlineStatus(item) {
item.onlineStatus = item.onlineStatus == 0 ? 1 : 0;
this.setList(item);
},
// 置顶
setOrderId(item) {
item.inTop = item.inTop == 1 ? 0 : 1;
this.setList(item);
},
// 切换页码大小
handleSizeChange(val) {
this.queryForm.size = val;
this.queryForm.page = 1;
this.initData();
},
// 切换页码
handleCurrentChange(val) {
this.queryForm.page = val;
this.initData();
},
handleShowEdit(articleCode) {
this.$router.push({
name: "articleDetail",
query: {
articleCode: articleCode
}
});
},
handleChangePwd(pojo) {
this.pojo = pojo;
this.showChangePwd = true;
},
handleDelete(articleCode) {
this.$confirm("删除后,不可恢复 是否继续?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
this.loading = true;
app
.delete({
url: setListApi,
data: { articleCode }
})
.then(res => {
this.$message({
message: "更新成功",
type: "success"
});
this.getList();
})
.catch(err => {});
})
.catch(() => {
this.loading = true;
});
},
handleChangeStatue(row, status) {
let msg = status == 1 ? "是否上线当前文章?" : "是否下线当前文章?";
let data = JSON.parse(JSON.stringify(row));
data.onlineStatus = status;
data.inTop = data.inTop ? 1 : 0;
this.$confirm(msg, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
this.loading = true;
app.post({ url: setListApi, data }).then(res => {
this.getList();
this.$notify({
title: "成功",
message: "操作成功",
type: "success"
});
});
})
.catch(() => {
this.loading = true;
});
}
}
};
</script>
<style lang="scss" scoped>
/deep/ .el-dialog__wrapper {
overflow: hidden;
}
</style>