|
|
@@ -3,48 +3,235 @@
|
|
|
<el-card>
|
|
|
<div slot="header">
|
|
|
<span>活动管理</span>
|
|
|
- <el-button type="primary" size="mini" style="float:right" @click="showCreate = true">创建活动</el-button>
|
|
|
+ <div style="float:right">
|
|
|
+ <el-select
|
|
|
+ v-model="filter.status"
|
|
|
+ placeholder="状态筛选"
|
|
|
+ size="mini"
|
|
|
+ style="margin-right:12px;width:130px"
|
|
|
+ clearable
|
|
|
+ @change="loadActivities"
|
|
|
+ >
|
|
|
+ <el-option label="全部" value="" />
|
|
|
+ <el-option label="草稿" value="draft" />
|
|
|
+ <el-option label="已发布" value="published" />
|
|
|
+ <el-option label="已结束" value="ended" />
|
|
|
+ </el-select>
|
|
|
+ <el-button type="primary" size="mini" @click="openCreate">创建活动</el-button>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
<el-table :data="activities" v-loading="loading" border stripe>
|
|
|
<el-table-column prop="id" label="ID" width="80" />
|
|
|
- <el-table-column prop="title" label="活动标题" />
|
|
|
- <el-table-column prop="status" label="状态" width="100" />
|
|
|
- <el-table-column prop="startTime" label="开始时间" width="180" />
|
|
|
- <el-table-column prop="endTime" label="结束时间" width="180" />
|
|
|
- <el-table-column label="操作" width="150">
|
|
|
+ <el-table-column prop="title" label="活动标题" min-width="160" />
|
|
|
+ <el-table-column prop="dimensionCode" label="维度" width="100" />
|
|
|
+ <el-table-column label="状态" width="100">
|
|
|
<template slot-scope="{ row }">
|
|
|
- <el-button size="mini" @click="editActivity(row)">编辑</el-button>
|
|
|
+ <el-tag :type="statusType(row.status)" size="mini">
|
|
|
+ {{ statusLabel(row.status) }}
|
|
|
+ </el-tag>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="startTime" label="开始时间" width="170" />
|
|
|
+ <el-table-column prop="endTime" label="结束时间" width="170" />
|
|
|
+ <el-table-column label="操作" width="240">
|
|
|
+ <template slot-scope="{ row }">
|
|
|
+ <el-button size="mini" @click="editActivity(row)" :disabled="row.status === 'ended'">编辑</el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="success"
|
|
|
+ @click="handlePublish(row)"
|
|
|
+ v-if="row.status === 'draft'"
|
|
|
+ >发布</el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="warning"
|
|
|
+ @click="handleEnd(row)"
|
|
|
+ v-if="row.status === 'published'"
|
|
|
+ >结束</el-button>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
+ <el-pagination
|
|
|
+ v-if="total > 0"
|
|
|
+ @size-change="handleSizeChange"
|
|
|
+ @current-change="handlePageChange"
|
|
|
+ :current-page="filter.page"
|
|
|
+ :page-sizes="[10, 20, 50]"
|
|
|
+ :page-size="filter.size"
|
|
|
+ layout="total, sizes, prev, pager, next, jumper"
|
|
|
+ :total="total"
|
|
|
+ style="margin-top:16px;text-align:right"
|
|
|
+ />
|
|
|
</el-card>
|
|
|
+
|
|
|
+ <el-dialog
|
|
|
+ :title="editId ? '编辑活动' : '创建活动'"
|
|
|
+ :visible.sync="dialogVisible"
|
|
|
+ width="600px"
|
|
|
+ @closed="resetForm"
|
|
|
+ >
|
|
|
+ <el-form label-width="120px">
|
|
|
+ <el-form-item label="活动标题">
|
|
|
+ <el-input v-model="form.title" placeholder="请输入活动标题" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="活动描述">
|
|
|
+ <el-input v-model="form.description" type="textarea" :rows="3" placeholder="请输入活动描述" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="维度">
|
|
|
+ <el-select v-model="form.dimensionCode" placeholder="请选择维度" style="width:100%">
|
|
|
+ <el-option label="身 (健康)" value="body" />
|
|
|
+ <el-option label="智 (智慧)" value="mind" />
|
|
|
+ <el-option label="行 (行动)" value="action" />
|
|
|
+ <el-option label="富 (财富)" value="wealth" />
|
|
|
+ <el-option label="心 (心灵)" value="heart" />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="开始时间">
|
|
|
+ <el-date-picker v-model="form.startTime" type="datetime" placeholder="选择开始时间" style="width:100%" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="结束时间">
|
|
|
+ <el-date-picker v-model="form.endTime" type="datetime" placeholder="选择结束时间" style="width:100%" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div slot="footer">
|
|
|
+ <el-button @click="dialogVisible = false">取消</el-button>
|
|
|
+ <el-button type="primary" @click="saveActivity" :loading="saving">保存</el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { getActivityList, createActivity, updateActivity, publishActivity, endActivity } from '@/api/activity'
|
|
|
+
|
|
|
+const STATUS_MAP = {
|
|
|
+ draft: { label: '草稿', type: 'info' },
|
|
|
+ published: { label: '已发布', type: 'success' },
|
|
|
+ ended: { label: '已结束', type: 'danger' }
|
|
|
+}
|
|
|
+
|
|
|
export default {
|
|
|
name: 'Activities',
|
|
|
- data() { return { loading: false, activities: [], showCreate: false } },
|
|
|
- created() { this.loadActivities() },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ loading: false,
|
|
|
+ saving: false,
|
|
|
+ activities: [],
|
|
|
+ total: 0,
|
|
|
+ editId: null,
|
|
|
+ dialogVisible: false,
|
|
|
+ filter: {
|
|
|
+ status: '',
|
|
|
+ page: 1,
|
|
|
+ size: 10
|
|
|
+ },
|
|
|
+ form: {
|
|
|
+ title: '',
|
|
|
+ description: '',
|
|
|
+ dimensionCode: '',
|
|
|
+ startTime: null,
|
|
|
+ endTime: null
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.loadActivities()
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ statusType(status) {
|
|
|
+ return (STATUS_MAP[status] && STATUS_MAP[status].type) || 'info'
|
|
|
+ },
|
|
|
+ statusLabel(status) {
|
|
|
+ return (STATUS_MAP[status] && STATUS_MAP[status].label) || status
|
|
|
+ },
|
|
|
async loadActivities() {
|
|
|
this.loading = true
|
|
|
try {
|
|
|
- const baseURL = process.env.VUE_APP_BASE_API || ''
|
|
|
- const token = localStorage.getItem('token')
|
|
|
- const axios = this.$axios || (await import('axios')).default
|
|
|
- const res = await axios.post(baseURL + '/api/activity/list', {}, {
|
|
|
- headers: { Authorization: 'Bearer ' + token }
|
|
|
- })
|
|
|
- this.activities = res.data?.data || []
|
|
|
+ const params = {
|
|
|
+ page: this.filter.page,
|
|
|
+ size: this.filter.size
|
|
|
+ }
|
|
|
+ if (this.filter.status) {
|
|
|
+ params.status = this.filter.status
|
|
|
+ }
|
|
|
+ const res = await getActivityList(params)
|
|
|
+ this.activities = (res.data && res.data.records) || []
|
|
|
+ this.total = (res.data && res.data.total) || 0
|
|
|
} catch (e) {
|
|
|
- this.$message?.error?.('加载活动列表失败')
|
|
|
+ this.$message && this.$message.error && this.$message.error('加载活动列表失败')
|
|
|
} finally {
|
|
|
this.loading = false
|
|
|
}
|
|
|
},
|
|
|
+ handleSizeChange(size) {
|
|
|
+ this.filter.size = size
|
|
|
+ this.filter.page = 1
|
|
|
+ this.loadActivities()
|
|
|
+ },
|
|
|
+ handlePageChange(page) {
|
|
|
+ this.filter.page = page
|
|
|
+ this.loadActivities()
|
|
|
+ },
|
|
|
+ openCreate() {
|
|
|
+ this.editId = null
|
|
|
+ this.resetForm()
|
|
|
+ this.dialogVisible = true
|
|
|
+ },
|
|
|
+ resetForm() {
|
|
|
+ this.form = {
|
|
|
+ title: '',
|
|
|
+ description: '',
|
|
|
+ dimensionCode: '',
|
|
|
+ startTime: null,
|
|
|
+ endTime: null
|
|
|
+ }
|
|
|
+ },
|
|
|
editActivity(row) {
|
|
|
- this.$message.info('活动编辑功能待实现')
|
|
|
+ this.editId = row.id
|
|
|
+ this.form = {
|
|
|
+ title: row.title || '',
|
|
|
+ description: row.description || '',
|
|
|
+ dimensionCode: row.dimensionCode || '',
|
|
|
+ startTime: row.startTime || null,
|
|
|
+ endTime: row.endTime || null
|
|
|
+ }
|
|
|
+ this.dialogVisible = true
|
|
|
+ },
|
|
|
+ async saveActivity() {
|
|
|
+ this.saving = true
|
|
|
+ try {
|
|
|
+ if (this.editId) {
|
|
|
+ await updateActivity({ ...this.form, id: this.editId })
|
|
|
+ this.$message && this.$message.success && this.$message.success('更新成功')
|
|
|
+ } else {
|
|
|
+ await createActivity(this.form)
|
|
|
+ this.$message && this.$message.success && this.$message.success('创建成功')
|
|
|
+ }
|
|
|
+ this.dialogVisible = false
|
|
|
+ this.loadActivities()
|
|
|
+ } catch (e) {
|
|
|
+ this.$message && this.$message.error && this.$message.error('保存失败')
|
|
|
+ } finally {
|
|
|
+ this.saving = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async handlePublish(row) {
|
|
|
+ try {
|
|
|
+ await publishActivity(row.id)
|
|
|
+ this.$message && this.$message.success && this.$message.success('发布成功')
|
|
|
+ this.loadActivities()
|
|
|
+ } catch (e) {
|
|
|
+ this.$message && this.$message.error && this.$message.error('发布失败')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async handleEnd(row) {
|
|
|
+ try {
|
|
|
+ await endActivity(row.id)
|
|
|
+ this.$message && this.$message.success && this.$message.success('活动已结束')
|
|
|
+ this.loadActivities()
|
|
|
+ } catch (e) {
|
|
|
+ this.$message && this.$message.error && this.$message.error('操作失败')
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|