fix: avatar page
This commit is contained in:
@@ -207,6 +207,12 @@ export const asyncRoutes = [
|
|||||||
component: () => import('@/views/spring/avatar/systemAvatar/index'),
|
component: () => import('@/views/spring/avatar/systemAvatar/index'),
|
||||||
meta: { title: '系统头像' },
|
meta: { title: '系统头像' },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'avatarCategory',
|
||||||
|
name: 'AvatarCategory',
|
||||||
|
component: () => import('@/views/spring/avatar/category/index'),
|
||||||
|
meta: { title: '头像类型' },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'avatarFrame',
|
path: 'avatarFrame',
|
||||||
name: 'AvatarFrame',
|
name: 'AvatarFrame',
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<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="name">
|
||||||
|
<el-input v-model.trim="form.name" autocomplete="off" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="是否启用" prop="isEnabled">
|
||||||
|
<el-switch v-model="form.isEnabled" />
|
||||||
|
</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 { doAdd, doEdit } from '@/api/spring/avatar/category'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'AvatarCategoryEdit',
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
form: {
|
||||||
|
name: '',
|
||||||
|
sort: 1,
|
||||||
|
isEnabled: true,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
name: [{ required: true, trigger: 'blur', message: '请输入分类名称' }],
|
||||||
|
},
|
||||||
|
title: '',
|
||||||
|
dialogFormVisible: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
showEdit(row) {
|
||||||
|
if (!row) {
|
||||||
|
this.title = '添加'
|
||||||
|
this.form = this.$options.data().form
|
||||||
|
} 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
|
||||||
|
},
|
||||||
|
save() {
|
||||||
|
this.$refs['form'].validate(async (valid) => {
|
||||||
|
if (valid) {
|
||||||
|
try {
|
||||||
|
if (this.title === '添加') {
|
||||||
|
const { msg } = await doAdd(this.form)
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
} else {
|
||||||
|
const { msg } = await doEdit(this.form.id, this.form)
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
}
|
||||||
|
this.$refs['form'].resetFields()
|
||||||
|
this.dialogFormVisible = false
|
||||||
|
this.$emit('fetch-data')
|
||||||
|
this.form = this.$options.data().form
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
172
src/views/spring/avatar/category/index.vue
Normal file
172
src/views/spring/avatar/category/index.vue
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
<template>
|
||||||
|
<div class="avatar-category-container">
|
||||||
|
<vab-query-form>
|
||||||
|
<vab-query-form-left-panel :span="12">
|
||||||
|
<el-button icon="el-icon-plus" type="primary" @click="handleEdit">添加</el-button>
|
||||||
|
<el-button icon="el-icon-delete" type="danger" @click="handleDelete">批量删除</el-button>
|
||||||
|
</vab-query-form-left-panel>
|
||||||
|
<vab-query-form-right-panel :span="12">
|
||||||
|
<el-form :inline="true" :model="queryForm" @submit.native.prevent>
|
||||||
|
<el-form-item>
|
||||||
|
<el-input v-model.trim="queryForm.name" clearable placeholder="请输入分类名称" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button icon="el-icon-search" type="primary" @click="queryData">查询</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</vab-query-form-right-panel>
|
||||||
|
</vab-query-form>
|
||||||
|
|
||||||
|
<el-table v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText">
|
||||||
|
<el-table-column align="center" label="分类名称" prop="name" show-overflow-tooltip />
|
||||||
|
<el-table-column align="center" label="排序" prop="sort" sortable width="100" />
|
||||||
|
<el-table-column align="center" label="状态" prop="isEnabled" width="100">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-switch v-model="row.isEnabled" @change="handleStatusChange(row)" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column align="center" label="创建时间" prop="createdAt" width="200">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatTime(row.createdAt) }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column align="center" fixed="right" label="操作" show-overflow-tooltip width="200">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-button type="text" @click="handleEdit(row)">编辑</el-button>
|
||||||
|
<el-button type="text" @click="handleDelete(row)">删除</el-button>
|
||||||
|
<el-button type="text" @click="handleMoveUp(row)">上移</el-button>
|
||||||
|
<el-button type="text" @click="handleMoveDown(row)">下移</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<el-pagination
|
||||||
|
background
|
||||||
|
:current-page="queryForm.pageNo"
|
||||||
|
:layout="layout"
|
||||||
|
:page-size="queryForm.pageSize"
|
||||||
|
:total="total"
|
||||||
|
@current-change="handleCurrentChange"
|
||||||
|
@size-change="handleSizeChange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<edit ref="edit" @fetch-data="fetchData" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { getList, doDelete, toggleEnable, doMoveUp, doMoveDown } from '@/api/spring/avatar/category'
|
||||||
|
import { formatTime } from '@/utils'
|
||||||
|
import Edit from './components/AvatarCategoryEdit'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'AvatarCategory',
|
||||||
|
components: { Edit },
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
list: [],
|
||||||
|
listLoading: true,
|
||||||
|
layout: 'total, sizes, prev, pager, next, jumper',
|
||||||
|
total: 0,
|
||||||
|
selectRows: [],
|
||||||
|
elementLoadingText: '正在加载...',
|
||||||
|
queryForm: {
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
name: '',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
formatTime,
|
||||||
|
setSelectRows(val) {
|
||||||
|
this.selectRows = val
|
||||||
|
},
|
||||||
|
handleEdit(row) {
|
||||||
|
if (row.id) {
|
||||||
|
this.$refs['edit'].showEdit(row)
|
||||||
|
} else {
|
||||||
|
this.$refs['edit'].showEdit()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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.split(',') })
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
this.fetchData()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.$baseMessage('未选中任何行', 'error')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handleStatusChange(row) {
|
||||||
|
try {
|
||||||
|
const { msg } = await toggleEnable(row.id, row.isEnabled)
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
} catch (error) {
|
||||||
|
row.isEnabled = !row.isEnabled
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handleMoveUp(row) {
|
||||||
|
try {
|
||||||
|
await doMoveUp(row.id)
|
||||||
|
this.fetchData()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handleMoveDown(row) {
|
||||||
|
try {
|
||||||
|
await doMoveDown(row.id)
|
||||||
|
this.fetchData()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleSizeChange(val) {
|
||||||
|
this.queryForm.pageSize = val
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
handleCurrentChange(val) {
|
||||||
|
this.queryForm.pageNo = val
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
queryData() {
|
||||||
|
this.queryForm.pageNo = 1
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
async fetchData() {
|
||||||
|
this.listLoading = true
|
||||||
|
try {
|
||||||
|
const { data } = await getList(this.queryForm)
|
||||||
|
this.list = data.list
|
||||||
|
this.total = data.totalCount
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.listLoading = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.avatar-category-container {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user