当前位置:首页 > VUE

vue实现审核功能

2026-01-11 23:12:44VUE

实现审核功能的基本思路

审核功能通常涉及状态管理、权限控制和操作记录。Vue中可以通过组件化设计、状态管理库(如Vuex或Pinia)和后端API配合实现。

审核状态管理

使用Vuex或Pinia存储审核状态数据。定义审核状态枚举和对应操作:

// Pinia示例
import { defineStore } from 'pinia'

export const useAuditStore = defineStore('audit', {
  state: () => ({
    items: [], // 待审核条目
    statusOptions: [
      { value: 0, label: '待审核' },
      { value: 1, label: '已通过' },
      { value: 2, label: '已拒绝' }
    ]
  }),
  actions: {
    async fetchItems() {
      const res = await api.getPendingItems()
      this.items = res.data
    },
    async approveItem(id) {
      await api.approveItem(id)
      await this.fetchItems()
    }
  }
})

审核操作组件

创建可复用的审核操作组件,包含通过/拒绝按钮和备注输入:

vue实现审核功能

<template>
  <div class="audit-actions">
    <el-button type="success" @click="handleApprove">通过</el-button>
    <el-button type="danger" @click="handleReject">拒绝</el-button>
    <el-input v-model="remark" placeholder="审核备注"></el-input>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useAuditStore } from '@/stores/audit'

const props = defineProps(['itemId'])
const remark = ref('')
const auditStore = useAuditStore()

const handleApprove = () => {
  auditStore.approveItem(props.itemId, remark.value)
}

const handleReject = () => {
  auditStore.rejectItem(props.itemId, remark.value)
}
</script>

审核列表展示

使用表格展示待审核内容,集成审核操作组件:

<template>
  <el-table :data="auditStore.items">
    <el-table-column prop="content" label="内容"></el-table-column>
    <el-table-column prop="status" label="状态">
      <template #default="{row}">
        {{ getStatusText(row.status) }}
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template #default="{row}">
        <AuditActions :item-id="row.id" />
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import { useAuditStore } from '@/stores/audit'
import AuditActions from './AuditActions.vue'

const auditStore = useAuditStore()
auditStore.fetchItems()

const getStatusText = (status) => {
  return auditStore.statusOptions.find(o => o.value === status)?.label || ''
}
</script>

权限控制

通过路由守卫和组件权限指令控制审核功能访问:

vue实现审核功能

// 路由守卫
router.beforeEach((to) => {
  if (to.meta.requiresAudit && !userStore.hasAuditPermission) {
    return '/403'
  }
})

// 自定义指令
app.directive('audit', {
  mounted(el, binding) {
    if (!userStore.hasAuditPermission) {
      el.parentNode.removeChild(el)
    }
  }
})

审核日志记录

创建独立的审核日志组件,显示历史记录:

<template>
  <el-timeline>
    <el-timeline-item 
      v-for="log in logs"
      :key="log.id"
      :timestamp="log.time"
      placement="top"
    >
      {{ log.operator }} {{ log.action }}了内容:{{ log.content }}
      <p v-if="log.remark">备注:{{ log.remark }}</p>
    </el-timeline-item>
  </el-timeline>
</template>

<script setup>
import { ref } from 'vue'
import { getAuditLogs } from '@/api/audit'

const logs = ref([])
getAuditLogs().then(res => {
  logs.value = res.data
})
</script>

后端API集成

典型审核API接口设计示例:

// 获取待审核列表
export const getPendingItems = () => axios.get('/audit/pending')

// 审核通过
export const approveItem = (id, remark) => 
  axios.post(`/audit/${id}/approve`, { remark })

// 审核拒绝
export const rejectItem = (id, remark) => 
  axios.post(`/audit/${id}/reject`, { remark })

// 获取审核日志
export const getAuditLogs = (params) => 
  axios.get('/audit/logs', { params })

标签: 功能vue
分享给朋友:

相关文章

vue slot实现

vue slot实现

vue slot 的实现方法 在 Vue 中,slot 是一种内容分发机制,允许父组件向子组件传递模板内容。以下是几种常见的 slot 实现方式: 默认 slot 默认 slot 是最基础的 slo…

vue实现文字

vue实现文字

Vue 中实现文字显示的方法 在 Vue 中实现文字显示可以通过多种方式,包括插值表达式、指令、组件等。以下是几种常见的实现方法: 插值表达式 使用双大括号 {{ }} 进行文本插值,这是 Vue…

vue实现颜色

vue实现颜色

Vue 实现颜色的方法 在 Vue 中实现颜色管理可以通过多种方式,以下是一些常见的方法: 使用 CSS 变量动态绑定颜色 在 Vue 组件的样式中定义 CSS 变量,并通过 Vue 的数据绑定动态…

vue拖动实现

vue拖动实现

实现 Vue 拖动功能的方法 使用 HTML5 拖放 API 在 Vue 中可以利用 HTML5 的原生拖放 API 实现拖动功能。通过 draggable 属性标记可拖动元素,结合 @dragsta…

vue实现 页面

vue实现 页面

Vue 实现页面的核心方法 创建 Vue 项目 使用 Vue CLI 或 Vite 快速初始化项目。Vue CLI 是官方脚手架工具,适合传统项目;Vite 提供更快的现代构建体验。 npm cre…

vue 水印 实现

vue 水印 实现

Vue 水印实现方法 使用 canvas 动态生成水印 在 Vue 组件中通过 canvas 绘制水印,并将其作为背景图片插入到目标元素中。这种方法灵活性高,支持动态调整水印内容、角度和透明度。 &…