-
Notifications
You must be signed in to change notification settings - Fork 166
/
Click1.vue
138 lines (133 loc) · 4.29 KB
/
Click1.vue
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
<template>
<div v-loading="loading">
<p style="color: red;font-size: 12px;">如果是单击模式会在点击后激活列编辑</p>
<div class="click-table1-oper">
<el-button type="success" size="small" @click="insertEvent">新增</el-button>
<el-button type="warning" size="small" @click="submitEvent">保存</el-button>
<el-button type="success" size="small" @click="exportCsvEvent">导出</el-button>
</div>
<elx-editable
ref="elxEditable"
class="click-table1"
border
:data.sync="list"
style="width: 100%">
<elx-editable-column prop="id" label="ID" width="80"></elx-editable-column>
<elx-editable-column prop="name" label="角色" show-overflow-tooltip :edit-render="{name: 'ElInput'}"></elx-editable-column>
<elx-editable-column prop="describe" label="描述" :edit-render="{name: 'ElInput', props: {type: 'textarea', autosize: {minRows: 1, maxRows: 4}}}"></elx-editable-column>
<elx-editable-column prop="updateTime" label="更新时间" width="160" :formatter="formatterDate"></elx-editable-column>
<elx-editable-column prop="createTime" label="创建时间" width="160" :formatter="formatterDate"></elx-editable-column>
<elx-editable-column label="操作" width="160">
<template v-slot="scope">
<el-button size="small" type="danger" @click="removeEvent(scope.row)">删除</el-button>
</template>
</elx-editable-column>
<template v-slot:append>
<div>-- slot append --</div>
</template>
</elx-editable>
</div>
</template>
<script>
import XEUtils from 'xe-utils'
import XEAjax from 'xe-ajax'
import { MessageBox, Message } from 'element-ui'
export default {
data () {
return {
loading: false,
list: []
}
},
created () {
this.findList()
},
methods: {
findList () {
this.loading = true
XEAjax.doGet('/api/role/list').then(({ data }) => {
this.list = data
this.loading = false
}).catch(e => {
this.loading = false
})
},
formatterDate (row, column, cellValue, index) {
return XEUtils.toDateString(cellValue, 'yyyy-MM-dd HH:mm:ss')
},
insertEvent () {
this.$refs.elxEditable.insert({
name: `New ${Date.now()}`,
age: 26,
flag: false
}).then(({ row }) => {
this.$refs.elxEditable.setActiveCell(row, 'name')
})
},
removeEvent (row) {
if (row.id) {
MessageBox.confirm('确定永久删除该数据?', '温馨提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.loading = true
XEAjax.doDelete(`/api/role/delete/${row.id}`).then(({ data }) => {
this.findList()
}).catch(e => {
this.loading = false
})
}).catch(e => e)
} else {
this.$refs.elxEditable.remove(row)
}
},
submitEvent () {
this.$refs.elxEditable.validate(valid => {
if (valid) {
let { insertRecords, updateRecords } = this.$refs.elxEditable.getAllRecords()
if (insertRecords.length || updateRecords.length) {
insertRecords.forEach(item => {
if (XEUtils.isDate(item.date)) {
item.date = item.date.getTime()
}
})
updateRecords.forEach(item => {
if (XEUtils.isDate(item.date)) {
item.date = item.date.getTime()
}
})
this.loading = true
XEAjax.doPost('/api/role/save', { insertRecords, updateRecords }).then(({ data }) => {
Message({
type: 'success',
message: '保存成功!'
})
this.findList()
}).catch(e => {
this.loading = false
})
} else {
Message({
type: 'info',
message: '数据未改动!'
})
}
}
})
},
exportCsvEvent () {
this.$refs.elxEditable.exportCsv()
}
}
}
</script>
<style>
.click-table1-oper {
margin-bottom: 18px;
}
.click-table1.elx-editable .elx-editable-row.new-insert,
.click-table1.elx-editable .elx-editable-row.new-insert:hover>td {
background-color: #f0f9eb;
}
</style>