zxl
2025-06-19 c1e567ddda7f65651179a8a73ca849b07b066b14
manager/src/views/activity/index.vue
@@ -34,7 +34,7 @@
              :value="item.value"
              :key="item.id"
            >
              {{ item.value }}
              {{ item.label }}
            </Option>
          </Select>
        </FormItem>
@@ -91,7 +91,7 @@
        <template slot-scope="{ row }" slot="url">
          <div class="media-container">
            <!-- 图片类型 -->
            <template v-if="row.coverType === '图片'">
            <template v-if="row.coverType === 'image'">
              <img
                :src="row.url"
                alt="活动封面"
@@ -100,7 +100,7 @@
              >
            </template>
            <!-- 视频类型 -->
            <template v-else-if="row.coverType === '视频'">
            <template v-else-if="row.coverType === 'video'">
              <video
                :src="row.url"
                class="video-player"
@@ -128,11 +128,16 @@
            <Button
              type="primary"
              size="small"
              @click="changeStatus(row, row.status === '已发布' ? '下架' : '发布')"
              @click="changeStatus(row, row.publish ? '下架' : '发布')"
              :loading="row.statusLoading"
            >
              {{ row.status === '已发布' ? '下架' : '发布' }}
              {{ row.publish  ? '下架' : '发布' }}
            </Button>
            <Button
              type="info"
              size="small"
              @click="detail(row)"
            >详情</Button>
            <Button
              type="info"
              size="small"
@@ -188,7 +193,7 @@
              </FormItem>
            </Col>
            <Col span="12">
              <FormItem label="活动类型" prop="activityType">
              <FormItem label="活动类型" prop="activityType" :label-width="100">
                <Select
                  v-model="activityFrom.activityType"
                  placeholder="请选择活动类型"
@@ -199,7 +204,7 @@
                    :value="item.value"
                    :key="item.id"
                  >
                    {{ item.value }}
                    {{ item.label }}
                  </Option>
                </Select>
              </FormItem>
@@ -226,12 +231,11 @@
                ></DatePicker>
              </FormItem>
            </Col>
            <Col span="24">
              <FormItem label="封面类型" prop="coverType">
            <Col span="12">
              <FormItem label="封面类型" prop="coverType" :labelWidth="100">
                <Select
                  v-model="coverType"
                  placeholder="请选择封面类型"
                  clearable
                  @on-change="handleCoverTypeChange"
                >
                  <Option
@@ -265,15 +269,15 @@
                  accept="image/*,video/*"
                >
                  <Button icon="ios-cloud-upload-outline">上传封面文件</Button>
                  <div class="upload-tip">支持图片或视频文件,最大20MB</div>
                </Upload>
                <div v-if="file" class="upload-file-info">c
                <div v-if="file" class="upload-file-info">
                  已选文件: {{ file.name }}
                  <Button type="text" @click="handleRemove">删除</Button>
                </div>
              </FormItem>
            </Col>
            <!-- 这两个表单项在同一Row内,会显示在同一行 -->
            <Col span="12">
              <FormItem label="人数限制" prop="limitUserNum">
                <InputNumber
@@ -293,18 +297,8 @@
              </FormItem>
            </Col>
            <Col span="24">
              <Form :model="videoDownForm" :rules="videoDownRule" ref="videoDownForm">
<!--                <FormItem label="下架原因:" :labelWidth="100" prop="activityContent">-->
<!--                  <editor ref="editor" @input="getReason" />-->
<!--                </FormItem>-->
              </Form>
              <FormItem label="活动内容" prop="activityContent">
                <Input
                  v-model="activityFrom.activityContent"
                  type="textarea"
                  :rows="4"
                  placeholder="请输入活动详细内容"
                />
              <FormItem label="活动内容:" prop="activityContent">
                <editor ref="editor" @input="getReason" />
              </FormItem>
            </Col>
          </Row>
@@ -347,6 +341,82 @@
        </Row>
      </Modal>
      <Modal
        v-model="infoModelShow"
        :title="modelTitle"
        @on-cancel="infoModelClose"
        width="800"
        :mask-closable="false"
      >
        <div class="detail-container">
          <Row :gutter="16">
            <Col span="12">
              <div class="detail-item">
                <label>活动名称:</label>
                <span>{{ activityInfo.activityName || '-' }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>活动类型:</label>
                <span>{{activityInfo.activityType === 'online' ? '线上':'线下'}}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>报名时间段:</label>
                <span>{{ activityInfo.reportStartTime }} - {{ activityInfo.reportEndTime }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>活动时间段:</label>
                <span>{{ activityInfo.startTime }} - {{ activityInfo.endTime }}</span>
              </div>
            </Col>
            <Col span="24" v-if="coverType === '输入文字封面'">
              <div class="detail-item">
                <label>封面文字:</label>
                <span>{{ activityInfo.cover || '-' }}</span>
              </div>
            </Col>
            <Col span="24" v-if="coverType === '选择文件封面'">
              <div class="detail-item">
                <label>上传封面:</label>
                <span>{{ activityInfo.cover }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>人数限制:</label>
                <span>{{ activityInfo.limitUserNum || '无限制' }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>活动地点:</label>
                <span>{{ activityInfo.activityLocation || '-' }}</span>
              </div>
            </Col>
            <Col span="24">
              <div class="detail-item">
                <label>活动内容:</label>
                <div
                  class="activity-content"
                  v-html="activityInfo.activityContent || '无内容'"
                ></div>
              </div>
            </Col>
          </Row>
        </div>
        <div slot="footer">
          <Button @click="infoModelClose">关闭</Button>
        </div>
      </Modal>
      <!-- 图片预览模态框 -->
      <Modal v-model="previewVisible" title="图片预览" footer-hide>
        <img :src="previewImageUrl" style="width: 100%">
@@ -372,26 +442,7 @@
  components: {Editor},
  data() {
    return {
      videoDownForm :{
        id: '',
        reason: ''
      },
      videoDownRule: {
        reason: [
          {
            require: true,
            message: '请输入活动内容',
            trigger: 'blur',
            validator: (rule, value, callback) => {
              if (value === null || value === '') {
                callback(new Error('请输入活动内容'));
              } else {
                callback();
              }
            }
          }
        ]
      },
      infoModelShow:false,
      loading: false,
      membersLoading: false,
@@ -415,8 +466,8 @@
      // 活动类型选项
      typeSelect: [
        { id: 1, value: '线上' },
        { id: 2, value: '线下' }
        { id: 1, value: 'online',label:'线上' },
        { id: 2, value: 'offline',label:'线下' }
      ],
      // 封面类型选项
@@ -444,7 +495,25 @@
        endTime: '',
        recommend: false,
        limitUserNum: 0,
        activityLocation: ''
        activityLocation: '',
      },
      activityInfo: {
        id: '',
        activityName: '',
        activityType: '',
        reportTime: [],
        time: [],
        activityContent: '',
        cover: '',
        coverType: '',
        status: '',
        reportStartTime: '',
        reportEndTime: '',
        startTime: '',
        endTime: '',
        recommend: false,
        limitUserNum: 0,
        activityLocation: '',
      },
      // 表单验证规则
@@ -466,6 +535,9 @@
        ],
        cover: [
          { required: true, message: '请输入封面内容', trigger: 'blur' }
        ],
        coverType: [
          { required: true, message: '请选择封面类型', trigger: 'blur' }
        ],
        limitUserNum: [
          { required: true, type: 'number', message: '请输入人数限制', trigger: 'blur' },
@@ -497,7 +569,11 @@
          title: '活动类型',
          key: 'activityType',
          width: 100,
          align: 'center'
          align: 'center',
          render: (h, params) => {
            return h('Tag', {
            }, params.row.activityType === 'online' ? '线上' : '线下')
          }
        },
        {
          title: '推荐',
@@ -513,27 +589,37 @@
          }
        },
        {
          title: '状态',
          key: 'status',
          title: '发布',
          key: 'publish',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h('Tag', {
              props: {
                color: params.row.status === '已发布' ? 'blue' : 'orange'
                color: params.row.publish ? 'green' : 'default'
              }
            }, params.row.status)
            }, params.row.publish ? '已发布' : '未发布')
          }
        },
        {
          title: '报名时间段',
          key: 'reportTimeRange',
          width: 300,
          title: '状态',
          key: 'status',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h('div', `开始: ${this.formatDate(params.row.reportStartTime)}`),
              h('div', `结束: ${this.formatDate(params.row.reportEndTime)}`)
            ])
            const status = params.row.status;
            const statusMap = {
              'noStart': { text: '未开始', color: 'default' },
              'report': { text: '报名中', color: 'green' },
              'inProgress':{ text:'进行中',color:'cyan'},
              'end': { text: '已结束', color: 'red' }
            };
            const currentStatus = statusMap[status] || { text: status, color: 'default' };
            return h('Tag', {
              props: {
                color: currentStatus.color
              }
            }, currentStatus.text);
          }
        },
        {
@@ -558,7 +644,16 @@
          title: '封面类型',
          key: 'coverType',
          width: 100,
          align: 'center'
          align: 'center',
          render: (h, params) => {
            const typeMap = {
              text: '文本',
              video: '视频',
              image: '图片'
            };
            const text = typeMap[params.row.coverType] || params.row.coverType;
            return h('span', text);
          }
        },
        {
          title: '人数限制',
@@ -651,10 +746,14 @@
    this.init()
  },
  methods: {
    detail(row){
      this.modelTitle = '活动详情'
      this.infoModelShow = true
      this.activityInfo = row
    },
    // 获取富文本编辑器的内容
    getReason(content) {
      this.videoDownForm.reason = content
      console.log(content)
      this.activityFrom.activityContent = content
    },
    // 初始化数据
    init() {
@@ -674,8 +773,6 @@
            statusLoading: false
          }))
          this.total = res.total
        } else {
          this.$Message.error(res.msg || '获取活动列表失败')
        }
      }).catch(() => {
        this.loading = false
@@ -724,7 +821,7 @@
    openAdd() {
      this.modelTitle = '新增活动'
      this.modelShow = true
      this.coverType = ''
      this.coverType = '输入文字封面'
      this.file = null
      this.$refs.form.resetFields()
      this.activityFrom.id = ''
@@ -736,7 +833,6 @@
      this.modelShow = true
      this.$nextTick(() => {
        this.$refs.form.resetFields()
        // 填充表单数据
        this.activityFrom = {
          id: row.id,
@@ -762,22 +858,29 @@
          limitUserNum: row.limitUserNum,
          activityLocation: row.activityLocation
        }
        this.$refs.editor.setContent(this.activityFrom.activityLocation)
        // 设置封面类型
        this.coverType = row.coverType === '文字' ? '输入文字封面' : '选择文件封面'
        this.coverType = row.coverType === 'text' ? '输入文字封面' : '选择文件封面'
      })
    },
    infoModelClose(){
      this.infoModelShow = false
    },
    // 关闭模态框
    modelClose() {
      this.modelShow = false
      this.file = null
      this.submitLoading = false
      this.handleRemove();
      this.$refs.form.resetFields()
    },
    // 保存或更新活动
    saveOrUpdate() {
      // 设置封面类型
      this.activityFrom.coverType = this.coverType === '输入文字封面' ? '文字' :
        this.file ? this.getFileCategory(this.file.type) :
          this.activityFrom.coverType
      this.$refs.form.validate(valid => {
        if (valid) {
          this.submitLoading = true
@@ -793,11 +896,6 @@
            this.activityFrom.endTime =  this.formatDate(this.activityFrom.time[1], 'YYYY-MM-DD HH:mm:ss')
          }
          // 设置封面类型
          this.activityFrom.coverType = this.coverType === '输入文字封面' ? '文字' :
            this.file ? this.getFileCategory(this.file.type) :
              this.activityFrom.coverType
          const api = this.activityFrom.id ? editActivity : addActivity
          api(this.activityFrom).then(res => {
            this.submitLoading = false
@@ -805,8 +903,6 @@
              this.$Message.success(res.msg)
              this.modelClose()
              this.getActivityList()
            } else {
              this.$Message.error(res.msg || '操作失败')
            }
          }).catch(() => {
            this.submitLoading = false
@@ -825,8 +921,6 @@
            if (res.code === 200) {
              this.$Message.success(res.msg)
              this.getActivityList()
            } else {
              this.$Message.error(res.msg || '删除失败')
            }
          })
        }
@@ -871,8 +965,6 @@
        if (res.code === 200) {
          this.$Message.success(res.msg)
          row.recommend = recommend
        } else {
          this.$Message.error(res.msg || '操作失败')
        }
      }).catch(() => {
        row.recommendLoading = false
@@ -882,18 +974,16 @@
    // 改变活动状态
    changeStatus(row, action) {
      row.statusLoading = true
      const status = action === '发布' ? '已发布' : '已下架'
      const publish = action === '发布'
      activityChangeStatus({
        id: row.id,
        status: status
        publish: publish
      }).then(res => {
        row.statusLoading = false
        if (res.code === 200) {
          this.$Message.success(res.msg)
          row.status = status
        } else {
          this.$Message.error(res.msg || '操作失败')
          row.publish = publish
        }
      }).catch(() => {
        row.statusLoading = false
@@ -917,8 +1007,6 @@
        if (res.code === 200) {
          this.membersList = res.data
          this.memberTotal = res.total
        } else {
          this.$Message.error(res.msg || '获取报名人员失败')
        }
      }).catch(() => {
        this.membersLoading = false
@@ -986,8 +1074,6 @@
        if (res.code === 200) {
          this.activityFrom.cover = res.data.fileKey
          this.$Message.success('上传成功')
        } else {
          this.$Message.error(res.msg || '上传失败')
        }
      }).catch(() => {
        this.submitLoading = false
@@ -996,24 +1082,18 @@
    // 删除文件
    handleRemove() {
      //点击关闭窗口时确保文件已被清除
      if(this.file === null){
        return;
      }
      if (!this.activityFrom.cover) {
        this.file = null
        return
      }
      this.$Modal.confirm({
        title: '确认删除',
        content: '确定要删除已上传的文件吗?',
        onOk: () => {
          delByKey(this.activityFrom.cover).then(res => {
            if (res.code === 200) {
              this.$Message.success(res.msg)
              this.file = null
              this.activityFrom.cover = ''
            } else {
              this.$Message.error(res.msg || '删除失败')
            }
          })
      delByKey(this.activityFrom.cover).then(res => {
        if (res.code === 200) {
          this.file = null
          this.activityFrom.cover = ''
        }
      })
    },
@@ -1027,14 +1107,14 @@
    // 获取文件分类
    getFileCategory(mimeType) {
      const typeMap = {
        'image': '图片',
        'video': '视频',
        'audio': '音频',
        'application': '文档'
        'image': 'image',
        'video': 'video',
        'audio': 'audio',
        'application': 'application'
      }
      const typePrefix = mimeType.split('/')[0]
      return typeMap[typePrefix] || '未知'
      return typeMap[typePrefix] || 'unknown'
    },
    // 格式化日期
@@ -1211,4 +1291,33 @@
    margin-top: 4px;
  }
}
.detail-container {
  padding: 16px;
}
.detail-item {
  margin-bottom: 18px;
  line-height: 1.5;
  label {
    display: inline-block;
    width: 100px;
    color: #666;
    font-weight: bold;
    vertical-align: top;
  }
  span {
    display: inline-block;
    width: calc(100% - 110px);
  }
}
.activity-content {
  border: 1px solid #dcdee2;
  border-radius: 4px;
  padding: 12px;
  min-height: 100px;
  margin-top: 8px;
}
</style>