init
This commit is contained in:
70
src/views/vab/table/components/TableEdit.vue
Normal file
70
src/views/vab/table/components/TableEdit.vue
Normal file
@@ -0,0 +1,70 @@
|
||||
<template>
|
||||
<el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px" @close="close">
|
||||
<el-form ref="form" label-width="80px" :model="form" :rules="rules">
|
||||
<el-form-item label="标题" prop="title">
|
||||
<el-input v-model.trim="form.title" autocomplete="off" />
|
||||
</el-form-item>
|
||||
<el-form-item label="作者" prop="author">
|
||||
<el-input v-model.trim="form.author" autocomplete="off" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="close">取 消</el-button>
|
||||
<el-button type="primary" @click="save">确 定</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { doEdit } from '@/api/table'
|
||||
|
||||
export default {
|
||||
name: 'TableEdit',
|
||||
data() {
|
||||
return {
|
||||
form: {
|
||||
title: '',
|
||||
author: '',
|
||||
},
|
||||
rules: {
|
||||
title: [{ required: true, trigger: 'blur', message: '请输入标题' }],
|
||||
author: [{ required: true, trigger: 'blur', message: '请输入作者' }],
|
||||
},
|
||||
title: '',
|
||||
dialogFormVisible: false,
|
||||
}
|
||||
},
|
||||
created() {},
|
||||
methods: {
|
||||
showEdit(row) {
|
||||
if (!row) {
|
||||
this.title = '添加'
|
||||
} else {
|
||||
this.title = '编辑'
|
||||
this.form = Object.assign({}, row)
|
||||
}
|
||||
this.dialogFormVisible = true
|
||||
},
|
||||
close() {
|
||||
this.$refs['form'].resetFields()
|
||||
this.form = this.$options.data().form
|
||||
this.dialogFormVisible = false
|
||||
this.$emit('fetch-data')
|
||||
},
|
||||
save() {
|
||||
this.$refs['form'].validate(async (valid) => {
|
||||
if (valid) {
|
||||
const { msg } = await doEdit(this.form)
|
||||
this.$baseMessage(msg, 'success')
|
||||
this.$refs['form'].resetFields()
|
||||
this.dialogFormVisible = false
|
||||
this.$emit('fetch-data')
|
||||
this.form = this.$options.data().form
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
220
src/views/vab/table/index.vue
Normal file
220
src/views/vab/table/index.vue
Normal file
@@ -0,0 +1,220 @@
|
||||
<template>
|
||||
<div class="table-container">
|
||||
<vab-query-form>
|
||||
<vab-query-form-left-panel>
|
||||
<el-button icon="el-icon-plus" type="primary" @click="handleAdd">添加</el-button>
|
||||
<el-button icon="el-icon-delete" type="danger" @click="handleDelete">删除</el-button>
|
||||
<el-button type="primary" @click="testMessage">baseMessage</el-button>
|
||||
<el-button type="primary" @click="testALert">baseAlert</el-button>
|
||||
<el-button type="primary" @click="testConfirm">baseConfirm</el-button>
|
||||
<el-button type="primary" @click="testNotify">baseNotify</el-button>
|
||||
</vab-query-form-left-panel>
|
||||
<vab-query-form-right-panel>
|
||||
<el-form ref="form" :inline="true" :model="queryForm" @submit.native.prevent>
|
||||
<el-form-item>
|
||||
<el-input v-model="queryForm.title" placeholder="标题" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button icon="el-icon-search" native-type="submit" type="primary" @click="handleQuery">查询</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</vab-query-form-right-panel>
|
||||
</vab-query-form>
|
||||
|
||||
<el-table
|
||||
ref="tableSort"
|
||||
v-loading="listLoading"
|
||||
:data="list"
|
||||
:element-loading-text="elementLoadingText"
|
||||
:height="height"
|
||||
@selection-change="setSelectRows"
|
||||
@sort-change="tableSortChange"
|
||||
>
|
||||
<el-table-column show-overflow-tooltip type="selection" width="55" />
|
||||
<el-table-column label="序号" show-overflow-tooltip width="95">
|
||||
<template #default="scope">
|
||||
{{ scope.$index + 1 }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="标题" prop="title" show-overflow-tooltip />
|
||||
<el-table-column label="作者" prop="author" show-overflow-tooltip />
|
||||
<el-table-column label="头像" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<el-image v-if="imgShow" :preview-src-list="imageList" :src="row.img" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="点击量" prop="pageViews" show-overflow-tooltip sortable />
|
||||
<el-table-column label="状态" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<el-tooltip class="item" :content="row.status" effect="dark" placement="top-start">
|
||||
<el-tag :type="row.status | statusFilter">
|
||||
{{ row.status }}
|
||||
</el-tag>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="时间" prop="datetime" show-overflow-tooltip width="200" />
|
||||
<el-table-column label="操作" show-overflow-tooltip width="180px">
|
||||
<template #default="{ row }">
|
||||
<el-button type="text" @click="handleEdit(row)">编辑</el-button>
|
||||
<el-button type="text" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
:background="background"
|
||||
:current-page="queryForm.pageNo"
|
||||
:layout="layout"
|
||||
:page-size="queryForm.pageSize"
|
||||
:total="total"
|
||||
@current-change="handleCurrentChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
<table-edit ref="edit" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { doDelete, getList } from '@/api/table'
|
||||
import TableEdit from './components/TableEdit'
|
||||
|
||||
export default {
|
||||
name: 'ComprehensiveTable',
|
||||
components: {
|
||||
TableEdit,
|
||||
},
|
||||
filters: {
|
||||
statusFilter(status) {
|
||||
const statusMap = {
|
||||
published: 'success',
|
||||
draft: 'gray',
|
||||
deleted: 'danger',
|
||||
}
|
||||
return statusMap[status]
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
imgShow: true,
|
||||
list: [],
|
||||
imageList: [],
|
||||
listLoading: true,
|
||||
layout: 'total, sizes, prev, pager, next, jumper',
|
||||
total: 0,
|
||||
background: true,
|
||||
selectRows: '',
|
||||
elementLoadingText: '正在加载...',
|
||||
queryForm: {
|
||||
pageNo: 1,
|
||||
pageSize: 20,
|
||||
title: '',
|
||||
},
|
||||
timeOutID: null,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
height() {
|
||||
return this.$baseTableHeight()
|
||||
},
|
||||
},
|
||||
created() {
|
||||
this.fetchData()
|
||||
},
|
||||
beforeDestroy() {
|
||||
clearTimeout(this.timeOutID)
|
||||
},
|
||||
mounted() {},
|
||||
methods: {
|
||||
tableSortChange() {
|
||||
const imageList = []
|
||||
this.$refs.tableSort.tableData.forEach((item, index) => {
|
||||
imageList.push(item.img)
|
||||
})
|
||||
this.imageList = imageList
|
||||
},
|
||||
setSelectRows(val) {
|
||||
this.selectRows = val
|
||||
},
|
||||
handleAdd() {
|
||||
this.$refs['edit'].showEdit()
|
||||
},
|
||||
handleEdit(row) {
|
||||
this.$refs['edit'].showEdit(row)
|
||||
},
|
||||
handleDelete(row) {
|
||||
if (row.id) {
|
||||
this.$baseConfirm('你确定要删除当前项吗', null, async () => {
|
||||
const { msg } = await doDelete({ ids: row.id })
|
||||
this.$baseMessage(msg, 'success')
|
||||
this.fetchData()
|
||||
})
|
||||
} else {
|
||||
if (this.selectRows.length > 0) {
|
||||
const ids = this.selectRows.map((item) => item.id).join()
|
||||
this.$baseConfirm('你确定要删除选中项吗', null, async () => {
|
||||
const { msg } = await doDelete({ ids: ids })
|
||||
this.$baseMessage(msg, 'success')
|
||||
this.fetchData()
|
||||
})
|
||||
} else {
|
||||
this.$baseMessage('未选中任何行', 'error')
|
||||
return false
|
||||
}
|
||||
}
|
||||
},
|
||||
handleSizeChange(val) {
|
||||
this.queryForm.pageSize = val
|
||||
this.fetchData()
|
||||
},
|
||||
handleCurrentChange(val) {
|
||||
this.queryForm.pageNo = val
|
||||
this.fetchData()
|
||||
},
|
||||
handleQuery() {
|
||||
this.queryForm.pageNo = 1
|
||||
this.fetchData()
|
||||
},
|
||||
async fetchData() {
|
||||
this.listLoading = true
|
||||
const { data, totalCount } = await getList(this.queryForm)
|
||||
this.list = data
|
||||
const imageList = []
|
||||
data.forEach((item, index) => {
|
||||
imageList.push(item.img)
|
||||
})
|
||||
this.imageList = imageList
|
||||
this.total = totalCount
|
||||
this.timeOutID = setTimeout(() => {
|
||||
this.listLoading = false
|
||||
}, 500)
|
||||
},
|
||||
testMessage() {
|
||||
this.$baseMessage('test1', 'success')
|
||||
},
|
||||
testALert() {
|
||||
this.$baseAlert('11')
|
||||
this.$baseAlert('11', '自定义标题', () => {
|
||||
/* 可以写回调; */
|
||||
})
|
||||
this.$baseAlert('11', null, () => {
|
||||
/* 可以写回调; */
|
||||
})
|
||||
},
|
||||
testConfirm() {
|
||||
this.$baseConfirm(
|
||||
'你确定要执行该操作?',
|
||||
null,
|
||||
() => {
|
||||
/* 可以写回调; */
|
||||
},
|
||||
() => {
|
||||
/* 可以写回调; */
|
||||
}
|
||||
)
|
||||
},
|
||||
testNotify() {
|
||||
this.$baseNotify('测试消息提示', 'test', 'success', 'bottom-right')
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user