fix: SecurityMiddleware
This commit is contained in:
39
src/api/spring/index/topic.js
Normal file
39
src/api/spring/index/topic.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
export function getList(data) {
|
||||
return request({
|
||||
url: '/management/api/spring/card/special-topic/list',
|
||||
method: 'get',
|
||||
params: data,
|
||||
})
|
||||
}
|
||||
|
||||
export function createTopic(data) {
|
||||
return request({
|
||||
url: '/management/api/spring/card/special-topic/create',
|
||||
method: 'post',
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
export function updateTopic(id, data) {
|
||||
return request({
|
||||
url: `/management/api/spring/card/special-topic/update/${id}`,
|
||||
method: 'put',
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
export function enableTopic(id) {
|
||||
return request({
|
||||
url: `/management/api/spring/card/special-topic/enable/${id}`,
|
||||
method: 'patch',
|
||||
})
|
||||
}
|
||||
|
||||
export function disableTopic(id) {
|
||||
return request({
|
||||
url: `/management/api/spring/card/special-topic/disable/${id}`,
|
||||
method: 'patch',
|
||||
})
|
||||
}
|
||||
@@ -73,6 +73,12 @@ export const asyncRoutes = [
|
||||
component: () => import('@/views/spring/index/recommend/index'),
|
||||
meta: { title: '推介列表', icon: 'list' },
|
||||
},
|
||||
{
|
||||
path: 'topic',
|
||||
name: 'Topic',
|
||||
component: () => import('@/views/spring/index/topic/index'),
|
||||
meta: { title: '贺卡专题', icon: 'list' },
|
||||
},
|
||||
{
|
||||
path: 'tips',
|
||||
name: 'tips',
|
||||
|
||||
105
src/views/spring/index/topic/components/TopicEdit.vue
Normal file
105
src/views/spring/index/topic/components/TopicEdit.vue
Normal file
@@ -0,0 +1,105 @@
|
||||
<template>
|
||||
<el-dialog :title="title" :visible.sync="dialogFormVisible" width="600px" @close="close">
|
||||
<el-form ref="form" label-width="100px" :model="form" :rules="rules">
|
||||
<el-form-item label="场景" prop="scene">
|
||||
<el-select v-model="form.scene" placeholder="请选择场景" style="width: 100%">
|
||||
<el-option label="祝福卡片" value="card_generate" />
|
||||
<el-option label="头像" value="avatar_download" />
|
||||
<el-option label="抽签" value="fortune_draw" />
|
||||
<el-option label="壁纸" value="wallpaper_download" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="场景名称" prop="sceneName">
|
||||
<el-input v-model="form.sceneName" placeholder="请输入场景名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="场景描述" prop="sceneDesc">
|
||||
<el-input v-model="form.sceneDesc" placeholder="请输入场景描述" :rows="3" type="textarea" />
|
||||
</el-form-item>
|
||||
<el-form-item label="场景祝福" prop="sceneBlessing">
|
||||
<el-input v-model="form.sceneBlessing" placeholder="请输入场景祝福" :rows="3" type="textarea" />
|
||||
</el-form-item>
|
||||
<el-form-item label="按钮文本" prop="btnText">
|
||||
<el-input v-model="form.btnText" placeholder="请输入按钮文本" />
|
||||
</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>
|
||||
<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 { createTopic, updateTopic } from '@/api/spring/index/topic'
|
||||
import SingleUpload from '@/components/SingleUpload'
|
||||
|
||||
export default {
|
||||
name: 'TopicEdit',
|
||||
components: { SingleUpload },
|
||||
data() {
|
||||
return {
|
||||
form: {
|
||||
scene: '',
|
||||
sceneName: '',
|
||||
sceneDesc: '',
|
||||
sceneBlessing: '',
|
||||
btnText: '',
|
||||
imageUrl: '',
|
||||
},
|
||||
rules: {
|
||||
scene: [{ required: true, trigger: 'change', message: '请选择场景' }],
|
||||
},
|
||||
title: '',
|
||||
dialogFormVisible: false,
|
||||
id: '',
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
uploadUrl() {
|
||||
return `${process.env.VUE_APP_API_BASE_URL}/management/api/common/upload`
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
handleUploadSuccess(url) {
|
||||
this.form.imageUrl = url
|
||||
},
|
||||
showEdit(row) {
|
||||
if (!row) {
|
||||
this.title = '添加专题'
|
||||
this.id = ''
|
||||
} else {
|
||||
this.title = '编辑专题'
|
||||
this.id = row.id
|
||||
this.form = Object.assign({}, row)
|
||||
}
|
||||
this.dialogFormVisible = true
|
||||
},
|
||||
close() {
|
||||
this.$refs['form'].resetFields()
|
||||
this.form = this.$options.data().form
|
||||
this.id = ''
|
||||
this.dialogFormVisible = false
|
||||
},
|
||||
save() {
|
||||
this.$refs['form'].validate(async (valid) => {
|
||||
if (valid) {
|
||||
const { msg } = this.id ? await updateTopic(this.id, this.form) : await createTopic(this.form)
|
||||
this.$baseMessage(msg, 'success')
|
||||
this.$emit('fetch-data')
|
||||
this.close()
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
139
src/views/spring/index/topic/index.vue
Normal file
139
src/views/spring/index/topic/index.vue
Normal file
@@ -0,0 +1,139 @@
|
||||
<template>
|
||||
<div class="topic-container">
|
||||
<vab-query-form>
|
||||
<vab-query-form-left-panel :span="12">
|
||||
<el-button icon="el-icon-plus" type="primary" @click="handleEdit">添加</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.keyword" 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="ID" prop="id" show-overflow-tooltip width="80" />
|
||||
<el-table-column align="center" label="场景" prop="scene" show-overflow-tooltip />
|
||||
<el-table-column align="center" label="场景名称" prop="sceneName" show-overflow-tooltip />
|
||||
<el-table-column align="center" label="场景描述" prop="sceneDesc" show-overflow-tooltip />
|
||||
<el-table-column align="center" label="场景祝福" prop="sceneBlessing" show-overflow-tooltip />
|
||||
<el-table-column align="center" label="按钮文本" prop="btnText" 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="是否启用" 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="160">
|
||||
<template slot-scope="{ row }">
|
||||
{{ formatTime(row.createdAt) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" label="操作" show-overflow-tooltip width="100">
|
||||
<template slot-scope="{ row }">
|
||||
<el-button type="text" @click="handleEdit(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"
|
||||
/>
|
||||
<topic-edit ref="edit" @fetch-data="fetchData" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getList, enableTopic, disableTopic } from '@/api/spring/index/topic'
|
||||
import { formatTime } from '@/utils'
|
||||
import { getThumbUrl } from '@/utils/blessing'
|
||||
import TopicEdit from './components/TopicEdit'
|
||||
|
||||
export default {
|
||||
name: 'Topic',
|
||||
components: { TopicEdit },
|
||||
data() {
|
||||
return {
|
||||
list: null,
|
||||
listLoading: true,
|
||||
layout: 'total, sizes, prev, pager, next, jumper',
|
||||
total: 0,
|
||||
elementLoadingText: '正在加载...',
|
||||
queryForm: {
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
keyword: '',
|
||||
},
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.fetchData()
|
||||
},
|
||||
methods: {
|
||||
formatTime,
|
||||
getThumbUrl,
|
||||
handleEdit(row) {
|
||||
if (row && 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) {
|
||||
const action = newVal ? enableTopic : disableTopic
|
||||
const text = newVal ? '启用' : '禁用'
|
||||
try {
|
||||
await action(row.id)
|
||||
row.isEnabled = newVal
|
||||
this.$baseMessage(`${text}成功`, 'success')
|
||||
} catch (e) {
|
||||
this.$baseMessage(`${text}失败`, 'error')
|
||||
// Since we use :value, the switch might have visually toggled if we don't force update?
|
||||
// Actually, if we use :value and don't update row.isEnabled, Vue re-renders with old value?
|
||||
// Yes, usually.
|
||||
// But to be sure, we can force refresh or just rely on the fact that row.isEnabled wasn't updated.
|
||||
this.fetchData() // Refresh list to ensure consistent state
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user