Skip to content

Commit 6e2d884

Browse files
committed
补充优化前端代码
1 parent dc54c32 commit 6e2d884

File tree

6 files changed

+765
-31
lines changed

6 files changed

+765
-31
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import request from '@/utils/request'
2+
3+
export function fetchList(url, query) {
4+
const tempData = Object.assign({}, query)
5+
tempData.page = query.page - 1
6+
tempData.size = query.limit
7+
delete tempData['limit']
8+
return request({
9+
url: url,
10+
method: 'get',
11+
params: tempData
12+
})
13+
}
14+
15+
export function createRecord(url, data) {
16+
return request({
17+
url: url,
18+
method: 'post',
19+
data
20+
})
21+
}
22+
23+
export function updateRecord(url, data) {
24+
return request({
25+
url: url,
26+
method: 'post',
27+
data
28+
})
29+
}
30+
31+
export function deleteRecord(url, id) {
32+
if (id) {
33+
url = url + escape(id)
34+
}
35+
return request({
36+
url: url,
37+
method: 'delete'
38+
})
39+
}
40+
41+
export function recoverRecord(url, id) {
42+
if (id) {
43+
url = url + escape(id)
44+
}
45+
return request({
46+
url: url,
47+
method: 'patch'
48+
})
49+
}
50+
51+
export function putData(url, data) {
52+
return request({
53+
url: url,
54+
method: 'put',
55+
data
56+
})
57+
}
58+
59+
export function getData(url, query) {
60+
const tempData = Object.assign({}, query)
61+
return request({
62+
url: url,
63+
method: 'get',
64+
params: tempData
65+
})
66+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<template>
2+
<div class="common-wrapper">
3+
<el-select v-model="valueMeta" multiple collapse-tags placeholder="请选择标签">
4+
<div class="el-input" style="width:90%;margin-left:5%;">
5+
<input v-model="dropDownValue" type="text" placeholder="请输入" class="el-input__inner" @keyup="dropDownSearch">
6+
</div>
7+
<el-option v-for="item in optionsMetaShow" :value="item" />
8+
</el-select>
9+
</div>
10+
</template>
11+
<script>
12+
export default {
13+
data() {
14+
return {
15+
dropDownValue: '',
16+
optionsMetaAll: ['黄金糕', '双皮奶', '蚵仔煎', '双皮奶2', '龙须面', '北京烤鸭'],
17+
optionsMetaShow: ['黄金糕', '双皮奶', '蚵仔煎', '双皮奶2', '龙须面', '北京烤鸭'],
18+
valueMeta: []
19+
}
20+
},
21+
methods: {
22+
dropDownSearch() {
23+
var _this = this
24+
_this.valueMeta = []
25+
_this.optionsMetaShow = _this.optionsMetaAll.filter(_this.filterSearch)
26+
},
27+
filterSearch(item) {
28+
return item.includes(this.dropDownValue)
29+
}
30+
}
31+
}
32+
</script>
33+
<style lang="">
34+
.el-scrollbar {
35+
display: block !important;
36+
}
37+
</style>
Lines changed: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
<template>
2+
<div class="app-container">
3+
<div class="filter-container">
4+
<el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
5+
Search
6+
</el-button>
7+
<el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">
8+
Add
9+
</el-button>
10+
<el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download" @click="handleDownload">
11+
Export
12+
</el-button>
13+
</div>
14+
15+
<el-table
16+
:key="tableKey"
17+
v-loading="listLoading"
18+
:data="list"
19+
border
20+
fit
21+
highlight-current-row
22+
style="width: 100%;"
23+
@sort-change="sortChange"
24+
>
25+
<el-table-column label="Id" prop="id" align="center">
26+
<template slot-scope="scope">
27+
<span>{{ scope.row.id }}</span>
28+
</template>
29+
</el-table-column>
30+
<el-table-column label="User Id" align="center">
31+
<template slot-scope="scope">
32+
<span>{{ scope.row.userId }}</span>
33+
</template>
34+
</el-table-column>
35+
<el-table-column label="Authority" prop="authorityFlag" align="center">
36+
<template slot-scope="scope">
37+
<span>{{ scope.row.authorityFlag }}</span>
38+
</template>
39+
</el-table-column>
40+
<el-table-column label="Operator" prop="operator" align="center">
41+
<template slot-scope="scope">
42+
<span>{{ scope.row.operator }}</span>
43+
</template>
44+
</el-table-column>
45+
<el-table-column label="Operate Time" prop="operateTime" align="center">
46+
<template slot-scope="scope">
47+
<span>{{ scope.row.operateTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
48+
</template>
49+
</el-table-column>
50+
<el-table-column label="Actions" align="center" width="280" class-name="small-padding fixed-width">
51+
<template slot-scope="{row}">
52+
<el-button size="mini" type="danger" @click="handleDelete(row)">
53+
Delete
54+
</el-button>
55+
</template>
56+
</el-table-column>
57+
</el-table>
58+
59+
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.size" @pagination="getList" />
60+
61+
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
62+
<el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="120px" style="width: 400px; margin-left:50px;">
63+
<!--<el-form-item v-if="true" label="Service Id" prop="serviceId">
64+
<el-input v-model="temp.serviceId" />
65+
</el-form-item>-->
66+
<el-form-item label="User Id" prop="userId">
67+
<el-input v-model="temp.userId" />
68+
</el-form-item>
69+
</el-form>
70+
<div slot="footer" class="dialog-footer">
71+
<el-button @click="dialogFormVisible = false">
72+
Cancel
73+
</el-button>
74+
<el-button type="primary" :disabled.sync="dialogFormConfirmDisabled" @click="dialogStatus==='create'?createData():updateData()">
75+
Confirm
76+
</el-button>
77+
</div>
78+
</el-dialog>
79+
80+
<el-dialog :visible.sync="dialogPvVisible" title="Reading statistics">
81+
<el-table :data="pvData" border fit highlight-current-row style="width: 100%">
82+
<el-table-column prop="key" label="Channel" />
83+
<el-table-column prop="pv" label="Pv" />
84+
</el-table>
85+
<span slot="footer" class="dialog-footer">
86+
<el-button type="primary" @click="dialogPvVisible = false">Confirm</el-button>
87+
</span>
88+
</el-dialog>
89+
</div>
90+
</template>
91+
92+
<script>
93+
import { fetchList, createRecord, deleteRecord } from '@/api/api-request'
94+
import waves from '@/directive/waves' // waves directive
95+
import { parseTime } from '@/utils'
96+
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
97+
98+
export default {
99+
name: 'ComplexTable',
100+
components: { Pagination },
101+
directives: { waves },
102+
data() {
103+
return {
104+
tableKey: 0,
105+
list: null,
106+
total: 0,
107+
listLoading: true,
108+
listQuery: {
109+
resource: this.$route.query.resource || '',
110+
resourceId: this.$route.query.resourceId || '',
111+
delFlag: false,
112+
page: 1,
113+
size: 10
114+
},
115+
importanceOptions: [1, 2, 3],
116+
sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
117+
statusOptions: ['published', 'draft', 'deleted'],
118+
showReviewer: false,
119+
temp: {
120+
resource: this.$route.query.resource || '',
121+
resourceId: this.$route.query.resourceId || '',
122+
userId: ''
123+
},
124+
dialogFormVisible: false,
125+
dialogFormConfirmDisabled: false,
126+
dialogStatus: '',
127+
textMap: {
128+
update: 'Edit',
129+
create: 'Create'
130+
},
131+
dialogPvVisible: false,
132+
pvData: [],
133+
rules: {
134+
userId: [{ required: true, message: 'userId is required', trigger: 'change' }]
135+
},
136+
downloadLoading: false,
137+
tempRoute: {}
138+
}
139+
},
140+
created() {
141+
this.tempRoute = Object.assign({}, this.$route)
142+
this.getList()
143+
this.setTagsViewTitle()
144+
this.setPageTitle()
145+
},
146+
methods: {
147+
setPageTitle() {
148+
var title = '权限'
149+
if (this.listQuery.resourceId) {
150+
title = title + '-' + this.listQuery.resource + '-' + this.listQuery.resourceId
151+
}
152+
document.title = `${title}`
153+
},
154+
setTagsViewTitle() {
155+
var title = '权限'
156+
if (this.listQuery.resourceId) {
157+
title = title + '-' + this.listQuery.resource + '-' + this.listQuery.resourceId
158+
}
159+
const route = Object.assign({}, this.tempRoute, { title: `${title}` })
160+
this.$store.dispatch('tagsView/updateVisitedView', route)
161+
console.log(route)
162+
console.log(this.$store.dispatch)
163+
},
164+
getList() {
165+
this.listLoading = true
166+
// this.listQuery.page = this.listQuery.page - 1
167+
fetchList('/resourceAuthority/page', this.listQuery).then(response => {
168+
this.list = response.data.items
169+
this.total = response.data.total
170+
171+
// Just to simulate the time of the request
172+
setTimeout(() => {
173+
this.listLoading = false
174+
}, 0.2 * 1000)
175+
})
176+
},
177+
handleFilter() {
178+
this.listQuery.page = 1
179+
this.setTagsViewTitle()
180+
this.setPageTitle()
181+
this.getList()
182+
},
183+
sortChange(data) {
184+
const { prop, order } = data
185+
if (prop === 'id') {
186+
this.sortByID(order)
187+
}
188+
},
189+
sortByID(order) {
190+
if (order === 'ascending') {
191+
this.listQuery.sort = '+id'
192+
} else {
193+
this.listQuery.sort = '-id'
194+
}
195+
this.handleFilter()
196+
},
197+
resetTemp() {
198+
this.temp = {
199+
resource: this.$route.query.resource || '',
200+
resourceId: this.$route.query.resourceId || '',
201+
userId: ''
202+
}
203+
},
204+
handleCreate() {
205+
this.resetTemp()
206+
this.dialogStatus = 'create'
207+
this.dialogFormVisible = true
208+
this.dialogFormConfirmDisabled = false
209+
this.$nextTick(() => {
210+
this.$refs['dataForm'].clearValidate()
211+
})
212+
},
213+
createData() {
214+
this.$refs['dataForm'].validate((valid) => {
215+
if (valid) {
216+
this.dialogFormConfirmDisabled = true
217+
218+
createRecord('/resourceAuthority/', this.temp).then(response => {
219+
this.list.unshift(response.data)
220+
this.dialogFormVisible = false
221+
this.dialogFormConfirmDisabled = false
222+
this.$notify({
223+
title: 'Success',
224+
message: 'Created Successfully',
225+
type: 'success',
226+
duration: 2000
227+
})
228+
}).catch(err => {
229+
console.log(err)
230+
this.dialogFormConfirmDisabled = false
231+
})
232+
}
233+
})
234+
},
235+
handleDelete(row) {
236+
this.$confirm('Confirm to remove the record?', 'Warning', {
237+
confirmButtonText: 'Confirm',
238+
cancelButtonText: 'Cancel',
239+
type: 'warning'
240+
}).then(async() => {
241+
deleteRecord('/resourceAuthority/?id=' + row.id).then(() => {
242+
this.dialogFormVisible = false
243+
for (const v of this.list) {
244+
if (v.id === row.id) {
245+
const index = this.list.indexOf(v)
246+
this.list.splice(index, 1)
247+
break
248+
}
249+
}
250+
this.$notify({
251+
title: 'Success',
252+
message: 'Delete Successfully',
253+
type: 'success',
254+
duration: 2000
255+
})
256+
})
257+
})
258+
},
259+
handleDownload() {
260+
this.downloadLoading = true
261+
import('@/vendor/Export2Excel').then(excel => {
262+
const tHeader = ['Service Id', 'User Id']
263+
const filterVal = ['serviceId', 'userId']
264+
const data = this.formatJson(filterVal, this.list)
265+
excel.export_json_to_excel({
266+
header: tHeader,
267+
data,
268+
filename: 'gray-service-list'
269+
})
270+
this.downloadLoading = false
271+
})
272+
},
273+
formatJson(filterVal, jsonData) {
274+
return jsonData.map(v => filterVal.map(j => {
275+
if (j === 'timestamp') {
276+
return parseTime(v[j])
277+
} else {
278+
return v[j]
279+
}
280+
}))
281+
}
282+
}
283+
}
284+
</script>

0 commit comments

Comments
 (0)