1 overview
This article introduces the ability to edit and delete the UI form.
2. Edit the execution of the operation
2.1.com Postable process event to main component
2 ..
2.3
3. POP-OUP component packaging
After clicking on the editor in the table, a popup form field is required to change the data. The POP -Up Box component is packaged below to implement the editing function.
3.1. View Element’s official website for bomb frame components
3.2 Create a dialog – window
- Create a dialog box structure in the user control components.
- Add a form in the POP-UP window
- Form
operateForm: {
name: '',
addr: '',
age: '',
birth: '',
sex: ''
},
operateFormLabel: [
{
model: 'name',
label: 'Имя'
},
{
model: 'age',
label: 'возраст'
},
{
model: 'sex',
label: 'Пол',
type: 'select',
opts: [
{
label: 'мужчина',
value: 1
},
{
label: 'Женский',
value: 0
}
]
},
{
model: 'birth',
label: 'Дата рождения',
type: 'date'
},
{
model: 'addr',
label: 'адрес'
}
],
3.3 The monform component
In the edit form above, the OperAateFormLabel data object model is set to birth, so we need to add a date selector to the CommonForm form component to support its edit date.
- Use the default data picker for the item
- Commonform component date picker control
3.4.
Set form window op -up When the form editor is clicked, other situations will not be displayed
- Does the window display the POP -UP attribute
- Show the op -up window when editing is set up
- Set the Commonform component to display the label
3.5
3.6 Add button popup popup form
Dialog control provided by Element official website. The power button is used as a slot. We just need to reuse this slot.
- Apply to a user control
3.8
- Mandatory cancellation event
- Binding definition event
- Display the content of the output event
- Improved definition of accident
3.9 Form pop-up
3.10.
3.11. Shape delete custom effect
4. Modify the form and delete the code completely
4.1 UserManage Component Complete the code
<template>
<div class="manage">
<el-dialog :title="operateType === 'add' ? 'Новые пользователи' : 'Обновление пользователей'" :visible.sync="isShow">
<common-form :formLabel="operateFormLabel" :form="operateForm"></common-form>
<div slot="footer" class="dialog-footer">
<el-button @click="isShow = false">Отмена</el-button>
<el-button type="primary" @click="confirm">Конечно</el-button>
</div>
</el-dialog>
<div class="manage-header">
<el-button type="primary">+ Новый</el-button>
<common-form inline :formLabel="formLabel" :form="searchForm">
<el-button type="primary">поиск</el-button>
</common-form>
</div>
<common-table :tableData="tableData" :tableLabel="tableLabel" :config="config" @changePage="getList()" @edit="editUser" @del="delUser"></common-table>
</div>
</template>
<script>
import CommonForm from '../../components/CommonForm'
import CommonTable from '../../components/CommonTable'
export default {
components: {
CommonForm,
CommonTable
},
data() {
return {
operateType: 'add',
isShow: false,
tableData: [],
tableLabel: [
{
prop: 'name',
label: 'Имя'
},
{
prop: 'age',
label: 'возраст'
},
{
prop: 'sexLabel',
label: 'Пол'
},
{
prop: 'birth',
label: 'Дата рождения',
width: 200
},
{
prop: 'addr',
label: 'адрес',
width: 520
}
],
config: {
page: 1,
total: 30,
loading: false
},
operateForm: {
name: '',
addr: '',
age: '',
birth: '',
sex: ''
},
operateFormLabel: [
{
model: 'name',
label: 'Имя'
},
{
model: 'age',
label: 'возраст'
},
{
model: 'sex',
label: 'Пол',
type: 'select',
opts: [
{
label: 'мужчина',
value: 1
},
{
label: 'Женский',
value: 0
}
]
},
{
model: 'birth',
label: 'Дата рождения',
type: 'date'
},
{
model: 'addr',
label: 'адрес'
}
],
searchForm: {
keyword: ''
},
formLabel: [
{
model: 'keyword',
label: ''
}
]
}
},
methods: {
getList() {
this.config.loading = true
this.$http
.get('/api/user/getUser', {
params: {
page: this.config.page
}
})
.then(res => {
this.tableData = res.data.list.map(item => {
item.sexLabel = item.sex === 0 ? 'Женский' : 'мужчина'
return item
})
this.config.total = res.data.count
this.config.loading = false
})
},
editUser(row) {
this.operateType = 'edit'
this.isShow = true
this.operateForm = row
console.log(row)
},
delUser(row) {
this.$confirm(«Эта операция навсегда удалит пользователя, будет ли она продолжаться?», 'намекать', {
confirmButtonText: 'Конечно',
cancelButtonText: 'Отмена',
type: 'warning'
})
.then(() => {
let id = row.id
this.$http
.get('/api/user/del', {
params: {
id
}
})
.then(res => {
console.log(res.data)
this.$message({
type: 'success',
message: «Успешно удалил!»
})
this.getList()
})
})
.catch(() => {
this.$message({
type: 'info',
message: 'Удалите удаление'
})
})
console.log(row)
},
confirm() {
if (this.operateType === 'edit') {
this.$http.post('/api/user/edit', this.operateForm).then(res => {
console.log(res.data)
this.isShow = false
this.getList()
})
}
}
},
created() {
this.getList()
}
}
</script>
<style lang="scss" scoped>
@import '@/assets/scss/userManage';
</style>
4.2 Complete code for the tunable component
<template>
<div class="common-table">
<el-table :data="tableData" height="90%" stripe v-loading="config.loading">
<el-table-column label="Серийный номер" width="85">
<template slot-scope="scope">
<span style="margin-left: 10px">{{ (config.page - 1) * 20 + scope.$index + 1 }}</span>
</template>
</el-table-column>
<el-table-column v-for="item in tableLabel" :key="item.prop" :label="item.label" show-overflow-tooltip :width="item.width ? item.width : 125">
<template slot-scope="scope">
<span style="margin-left: 10px">{{ scope.row[item.prop] }}</span>
</template>
</el-table-column>
<el-table-column label="работать">
<template slot-scope="scope">
<el-button size="mini" @click="handleEdit(scope.row)">редактировать</el-button>
<el-button size="mini" type="danger" @click="handleDelete(scope.row)">удалять</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination class="pager" layout="prev, pager, next" :total="config.total" :current-page.sync="config.page" @current-change="changePage">
</el-pagination>
</div>
</template>
<script>
export default {
props: {
tableData: Array,
tableLabel: Array,
config: Object
},
methods: {
handleEdit(row) {
this.$emit('edit', row)
},
handleDelete(row) {
this.$emit('del', row)
},
changePage(page) {
this.$emit('changePage', page)
}
}
}
</script>
<style lang="scss" scoped>
.common-table {
// Установите высоту таблицы, вычтите высоту заголовка страницы
height: calc(100% - 62px);
// Установить цвет фона таблицы
background-color: #fff;
// Установить относительное позиционирование
position: relative;
// Установить стиль страниц
.pager {
position: absolute;
bottom: 0;
right: 20px;
}
}
</style>