index.vue
4.08 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
<template>
<div class="app-container">
<el-header height>
<el-button type="primary" @click="createLive">创建</el-button>
</el-header>
<el-main>
<el-table
:data="liveList"
style="width: 100%"
stripe
highlight-current-row
v-loading="loading"
>
<el-table-column label="时间" prop="liveTime">
<template slot-scope="scope">
{{timestampToTime(scope.row.liveTime)}}
</template>
</el-table-column>
<el-table-column label="直播内容" prop="liveContent"></el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-link type="primary" @click="editLive(scope.row)">编辑 </el-link>
<el-link type="primary" @click="deleteLive(scope.row.liveCode)">删除</el-link>
</template>
</el-table-column>
</el-table>
</el-main>
<el-footer height>
<div style="text-align:right;">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="queryForm.page"
:page-size="queryForm.size"
layout="total, prev, pager, next"
:total="total">
</el-pagination>
</div>
</el-footer>
<live-save-dialog
v-if="dialogVisible"
:dialog-visible="dialogVisible"
:live-temp="liveTemp"
@closedialog="closedialog"
@initLive="initLive">
</live-save-dialog>
</div>
</template>
<script>
import {request} from '@/api/fetch-api'
import liveSaveDialog from './components/liveSaveDialog'
let urls = {
liveListUrl: '/tianbao_edu_api/admin/live/list',
liveSaveUrl: '/tianbao_edu_api/admin/live/save',
liveDelUrl:'/tianbao_edu_api/admin/live/delete'
}
export default {
components: {liveSaveDialog},
data() {
return {
liveList: [],
total: 0,
loading: false,
queryForm: {
page: 1,
size: 10
},
dialogVisible:false,
liveTemp:{},
}
},
methods: {
initLive() {
this.loading = true
request.get(urls.liveListUrl, this.queryForm).then(data => {
this.loading = false
this.liveList = data.content.list
this.total = data.content.total
}).catch(() => {
})
},
editLive(row){
this.liveTemp=row
this.dialogVisible=true
},
createLive(){
this.liveTemp=null
this.dialogVisible=true
},
closedialog() {
this.dialogVisible = false
},
deleteLive(code){
this.$confirm('是否永远删除, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
request.post(urls.liveDelUrl, {liveCode: code}).then(data => {
this.$message.success("删除成")
this.initLive()
}).catch(() => {
})
}).catch(() => {
})
},
timestampToTime(row) {
if (row === 0) {
return ''
}
var date = new Date(row)
var Y = date.getFullYear() + '-'
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
return Y + M + D + h + m + s
},
/*分页*/
handleSizeChange(val) {
console.log(`每页 ${val} 条`)
this.queryForm.size = val
this.queryForm.page = 1
this.initLive()
},
handleCurrentChange(val) {
console.log(`当前页: ${val}`)
this.queryForm.page = val
this.initLive()
},
},
created() {
this.initLive()
}
}
</script>
<style scoped>
</style>