fix: daily page
This commit is contained in:
62
src/api/spring/daily/scene.js
Normal file
62
src/api/spring/daily/scene.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
export function getList(params) {
|
||||||
|
return request({
|
||||||
|
url: '/management/api/spring/greeting-scene/list',
|
||||||
|
method: 'get',
|
||||||
|
params,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doAdd(data) {
|
||||||
|
return request({
|
||||||
|
url: '/management/api/spring/greeting-scene/create',
|
||||||
|
method: 'post',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doEdit(id, data) {
|
||||||
|
return request({
|
||||||
|
url: `/management/api/spring/greeting-scene/update/${id}`,
|
||||||
|
method: 'put',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doDelete(data) {
|
||||||
|
return request({
|
||||||
|
url: '/management/api/spring/greeting-scene/delete',
|
||||||
|
method: 'put',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doMoveUp(id) {
|
||||||
|
return request({
|
||||||
|
url: `/management/api/spring/greeting-scene/moveUp/${id}`,
|
||||||
|
method: 'patch',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doMoveDown(id) {
|
||||||
|
return request({
|
||||||
|
url: `/management/api/spring/greeting-scene/moveDown/${id}`,
|
||||||
|
method: 'patch',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function doMoveToTop(id) {
|
||||||
|
return request({
|
||||||
|
url: `/management/api/spring/greeting-scene/moveToTop/${id}`,
|
||||||
|
method: 'patch',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toggleEnable(id, isEnabled) {
|
||||||
|
return request({
|
||||||
|
url: `/management/api/spring/greeting-scene/enable/${id}`,
|
||||||
|
method: 'patch',
|
||||||
|
data: { isEnabled },
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -55,6 +55,34 @@ export const asyncRoutes = [
|
|||||||
name: 'SpringMini',
|
name: 'SpringMini',
|
||||||
meta: { title: '新春祝福', icon: 'gift', permissions: ['admin'] },
|
meta: { title: '新春祝福', icon: 'gift', permissions: ['admin'] },
|
||||||
children: [
|
children: [
|
||||||
|
{
|
||||||
|
path: 'daily-index',
|
||||||
|
component: EmptyLayout,
|
||||||
|
alwaysShow: true,
|
||||||
|
redirect: 'noRedirect',
|
||||||
|
name: 'DailyIndex',
|
||||||
|
meta: {
|
||||||
|
title: '每日问候',
|
||||||
|
icon: 'clover',
|
||||||
|
permissions: ['admin'],
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: 'daily',
|
||||||
|
name: 'Daily',
|
||||||
|
component: () => import('@/views/spring/daily/index'),
|
||||||
|
meta: { title: '每日问候', icon: 'calendar' },
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: 'scene',
|
||||||
|
name: 'Scene',
|
||||||
|
component: () => import('@/views/spring/daily/scene/index'),
|
||||||
|
meta: { title: '场景配置', icon: 'setting' },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'index',
|
path: 'index',
|
||||||
component: EmptyLayout,
|
component: EmptyLayout,
|
||||||
|
|||||||
9
src/views/spring/daily/index.vue
Normal file
9
src/views/spring/daily/index.vue
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<template>
|
||||||
|
<router-view />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'Daily',
|
||||||
|
}
|
||||||
|
</script>
|
||||||
107
src/views/spring/daily/scene/components/SceneEdit.vue
Normal file
107
src/views/spring/daily/scene/components/SceneEdit.vue
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<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="form.name" autocomplete="off" placeholder="请输入场景名称" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="场景Key" prop="scene">
|
||||||
|
<el-input v-model="form.scene" autocomplete="off" placeholder="请输入场景Key (e.g., vitality)" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="图标" prop="icon">
|
||||||
|
<el-input v-model="form.icon" autocomplete="off" placeholder="请输入图标 (e.g., 😊)" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="默认祝福语ID" prop="greetingId">
|
||||||
|
<el-input v-model="form.greetingId" autocomplete="off" placeholder="请输入默认祝福语ID" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="背景图" prop="imageUrl">
|
||||||
|
<single-upload
|
||||||
|
v-model="form.imageUrl"
|
||||||
|
style="width: 100px; height: 100px"
|
||||||
|
:upload-url="uploadUrl"
|
||||||
|
@upload-success="handleUploadSuccess"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item v-if="!form.id" label="是否启用" prop="isEnabled">
|
||||||
|
<el-switch v-model="form.isEnabled" active-text="启用" :active-value="true" inactive-text="禁用" :inactive-value="false" />
|
||||||
|
</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/daily/scene'
|
||||||
|
import SingleUpload from '@/components/SingleUpload'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'SceneEdit',
|
||||||
|
components: { SingleUpload },
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
form: {
|
||||||
|
name: '',
|
||||||
|
scene: '',
|
||||||
|
icon: '',
|
||||||
|
greetingId: '',
|
||||||
|
imageUrl: '',
|
||||||
|
isEnabled: true,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
name: [{ required: true, trigger: 'blur', message: '请输入场景名称' }],
|
||||||
|
scene: [{ required: true, trigger: 'blur', message: '请输入场景Key' }],
|
||||||
|
isEnabled: [{ required: true, trigger: 'blur', message: '请选择是否启用' }],
|
||||||
|
},
|
||||||
|
title: '',
|
||||||
|
dialogFormVisible: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
uploadUrl() {
|
||||||
|
return `${process.env.VUE_APP_API_BASE_URL}/management/api/common/upload`
|
||||||
|
},
|
||||||
|
},
|
||||||
|
created() {},
|
||||||
|
methods: {
|
||||||
|
handleUploadSuccess(url) {
|
||||||
|
this.form.imageUrl = url
|
||||||
|
},
|
||||||
|
showEdit(row) {
|
||||||
|
if (!row) {
|
||||||
|
this.title = '添加'
|
||||||
|
this.form = {
|
||||||
|
name: '',
|
||||||
|
scene: '',
|
||||||
|
icon: '',
|
||||||
|
greetingId: '',
|
||||||
|
imageUrl: '',
|
||||||
|
isEnabled: true,
|
||||||
|
}
|
||||||
|
} 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) {
|
||||||
|
const { msg } = this.form.id ? await doEdit(this.form.id, this.form) : await doAdd(this.form)
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
this.$emit('fetch-data')
|
||||||
|
this.close()
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
173
src/views/spring/daily/scene/index.vue
Normal file
173
src/views/spring/daily/scene/index.vue
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
<template>
|
||||||
|
<div class="scene-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" @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column show-overflow-tooltip type="selection" width="55" />
|
||||||
|
<el-table-column align="center" label="排序" prop="sort" show-overflow-tooltip width="80" />
|
||||||
|
<el-table-column align="center" label="场景名称" prop="name" show-overflow-tooltip />
|
||||||
|
<el-table-column align="center" label="场景Key" prop="scene" show-overflow-tooltip />
|
||||||
|
<el-table-column align="center" label="图标" prop="icon" show-overflow-tooltip />
|
||||||
|
<el-table-column align="center" label="背景图" width="100">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-image
|
||||||
|
v-if="scope.row.imageUrl"
|
||||||
|
fit="cover"
|
||||||
|
:preview-src-list="[scope.row.imageUrl]"
|
||||||
|
:src="getThumbUrl(scope.row.imageUrl)"
|
||||||
|
style="width: 50px; height: 50px"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column align="center" label="默认祝福语ID" prop="greetingId" show-overflow-tooltip />
|
||||||
|
<el-table-column align="center" label="是否启用" show-overflow-tooltip width="100">
|
||||||
|
<template slot-scope="{ row }">
|
||||||
|
<el-switch :active-value="true" :inactive-value="false" :value="row.isEnabled" @change="handleStatusChange(row, $event)" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column align="center" label="操作" show-overflow-tooltip width="200">
|
||||||
|
<template slot-scope="{ row }">
|
||||||
|
<el-button type="text" @click="handleEdit(row)">编辑</el-button>
|
||||||
|
<el-button type="text" @click="handleMoveUp(row)">上移</el-button>
|
||||||
|
<el-button type="text" @click="handleMoveDown(row)">下移</el-button>
|
||||||
|
<el-button type="text" @click="handleDelete(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"
|
||||||
|
/>
|
||||||
|
<scene-edit ref="edit" @fetch-data="fetchData" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { getList, doDelete, toggleEnable, doMoveUp, doMoveDown } from '@/api/spring/daily/scene'
|
||||||
|
import { getThumbUrl } from '@/utils/blessing'
|
||||||
|
import SceneEdit from './components/SceneEdit'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'Scene',
|
||||||
|
components: { SceneEdit },
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
list: null,
|
||||||
|
listLoading: true,
|
||||||
|
layout: 'total, sizes, prev, pager, next, jumper',
|
||||||
|
total: 0,
|
||||||
|
elementLoadingText: '正在加载...',
|
||||||
|
queryForm: {
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
name: '',
|
||||||
|
},
|
||||||
|
selectRows: '',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getThumbUrl,
|
||||||
|
handleSelectionChange(val) {
|
||||||
|
this.selectRows = val
|
||||||
|
},
|
||||||
|
handleEdit(row) {
|
||||||
|
if (row.id) {
|
||||||
|
this.$refs['edit'].showEdit(row)
|
||||||
|
} else {
|
||||||
|
this.$refs['edit'].showEdit()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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
|
||||||
|
const { data } = await getList(this.queryForm)
|
||||||
|
this.list = data.list
|
||||||
|
this.total = data.totalCount
|
||||||
|
this.listLoading = false
|
||||||
|
},
|
||||||
|
async handleStatusChange(row, newVal) {
|
||||||
|
try {
|
||||||
|
await toggleEnable(row.id, newVal)
|
||||||
|
row.isEnabled = newVal
|
||||||
|
this.$baseMessage(`${newVal ? '启用' : '禁用'}成功`, 'success')
|
||||||
|
} catch (e) {
|
||||||
|
this.$baseMessage(`${newVal ? '启用' : '禁用'}失败`, 'error')
|
||||||
|
this.fetchData()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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)
|
||||||
|
this.$baseConfirm('你确定要删除选中项吗', null, async () => {
|
||||||
|
const { msg } = await doDelete({ ids })
|
||||||
|
this.$baseMessage(msg, 'success')
|
||||||
|
this.fetchData()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.$baseMessage('未选中任何行', 'error')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handleMoveUp(row) {
|
||||||
|
try {
|
||||||
|
await doMoveUp(row.id)
|
||||||
|
this.$baseMessage('上移成功', 'success')
|
||||||
|
this.fetchData()
|
||||||
|
} catch (e) {
|
||||||
|
// error handled by request interceptor usually
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handleMoveDown(row) {
|
||||||
|
try {
|
||||||
|
await doMoveDown(row.id)
|
||||||
|
this.$baseMessage('下移成功', 'success')
|
||||||
|
this.fetchData()
|
||||||
|
} catch (e) {
|
||||||
|
// error handled by request interceptor usually
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user