feat(权限): 新增 v-permission 按钮级权限指令并移除前端权限别名
This commit is contained in:
@@ -5,13 +5,10 @@ import type { TemplateVersionAction } from '@/api/management/documents'
|
||||
|
||||
import type { DocumentTemplate } from '../types'
|
||||
import { readStatusLabel, readStatusTone } from '../mock'
|
||||
import { DOC_TEMPLATE_PERMISSIONS, workflowPermission } from '../permissions'
|
||||
|
||||
const props = defineProps<{
|
||||
template: DocumentTemplate
|
||||
canEdit: boolean
|
||||
canInitiate: boolean
|
||||
canWorkflow: (action: TemplateVersionAction) => boolean
|
||||
canRemove: boolean
|
||||
/** 演示模式下「删除」是真删;真实模式下语义是下架(模板无 DELETE 接口,走归档) */
|
||||
isMock: boolean
|
||||
}>()
|
||||
@@ -31,16 +28,10 @@ const statusLabel = computed(() => readStatusLabel(props.template))
|
||||
const statusTone = computed(() => readStatusTone(props.template))
|
||||
|
||||
/** 只有已发布 / 待复审的模板可以发起签署;草稿与已归档不可用 */
|
||||
const canInitiateTemplate = computed(
|
||||
() => props.canInitiate && Boolean(props.template.currentVersionId || props.isMock),
|
||||
)
|
||||
const hasInitiableVersion = computed(() => Boolean(props.template.currentVersionId || props.isMock))
|
||||
|
||||
const initiateTitle = computed(() =>
|
||||
canInitiateTemplate.value
|
||||
? '用此模板发起签署'
|
||||
: props.canInitiate
|
||||
? '仅已发布或待复审的模板可发起签署'
|
||||
: '当前账号没有发起签署任务的权限',
|
||||
hasInitiableVersion.value ? '用此模板发起签署' : '仅已发布或待复审的模板可发起签署',
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -78,7 +69,7 @@ const primaryAction = computed<{ key: TemplateVersionAction; label: string } | n
|
||||
*/
|
||||
const secondaryActions = computed<{ key: TemplateVersionAction; label: string; title: string }[]>(
|
||||
() => {
|
||||
if (props.template.backendStatus === 'PENDING_REVIEW' && props.canWorkflow('reject')) {
|
||||
if (props.template.backendStatus === 'PENDING_REVIEW') {
|
||||
return [
|
||||
{
|
||||
key: 'reject',
|
||||
@@ -94,7 +85,7 @@ const secondaryActions = computed<{ key: TemplateVersionAction; label: string; t
|
||||
|
||||
/**
|
||||
* 本次交付暂不包含「版本历史」与「删除 / 下架」入口,先隐藏对应按钮。
|
||||
* 相关 emit、页面处理函数与接口调用保持原样,需要时把开关改回 true 即可恢复。
|
||||
* 权限码已按 doc:template:hist / doc:template:stop 接好,需要恢复时把开关改回 true 即可。
|
||||
*/
|
||||
const showVersionAction = false
|
||||
const showRemoveAction = false
|
||||
@@ -124,11 +115,17 @@ const removeTitle = computed(() => (props.isMock ? '删除此文书' : '下架
|
||||
</span>
|
||||
<div class="template-actions">
|
||||
<button type="button" class="card-button" @click="emit('preview', template)">预览</button>
|
||||
<button v-if="canEdit" type="button" class="card-button" @click="emit('edit', template)">
|
||||
<button
|
||||
v-permission="DOC_TEMPLATE_PERMISSIONS.edit"
|
||||
type="button"
|
||||
class="card-button"
|
||||
@click="emit('edit', template)"
|
||||
>
|
||||
编辑
|
||||
</button>
|
||||
<button
|
||||
v-if="showVersionAction && canInitiate"
|
||||
v-if="showVersionAction"
|
||||
v-permission="DOC_TEMPLATE_PERMISSIONS.history"
|
||||
type="button"
|
||||
class="card-button"
|
||||
title="查看该文书的版本历史"
|
||||
@@ -137,7 +134,8 @@ const removeTitle = computed(() => (props.isMock ? '删除此文书' : '下架
|
||||
版本
|
||||
</button>
|
||||
<button
|
||||
v-if="canInitiateTemplate"
|
||||
v-if="hasInitiableVersion"
|
||||
v-permission="DOC_TEMPLATE_PERMISSIONS.initiate"
|
||||
type="button"
|
||||
class="card-button primary"
|
||||
:title="initiateTitle"
|
||||
@@ -147,7 +145,8 @@ const removeTitle = computed(() => (props.isMock ? '删除此文书' : '下架
|
||||
</button>
|
||||
<!-- 还不能签署时,把「当前该做的下一步」放在同一位置,避免按钮越堆越多 -->
|
||||
<button
|
||||
v-if="primaryAction && canWorkflow(primaryAction.key)"
|
||||
v-if="primaryAction"
|
||||
v-permission="workflowPermission(primaryAction.key)"
|
||||
type="button"
|
||||
class="card-button primary"
|
||||
:title="`${primaryAction.label}后才能发起签署`"
|
||||
@@ -158,6 +157,7 @@ const removeTitle = computed(() => (props.isMock ? '删除此文书' : '下架
|
||||
<button
|
||||
v-for="action in secondaryActions"
|
||||
:key="action.key"
|
||||
v-permission="workflowPermission(action.key)"
|
||||
type="button"
|
||||
class="card-button"
|
||||
:title="action.title"
|
||||
@@ -166,7 +166,8 @@ const removeTitle = computed(() => (props.isMock ? '删除此文书' : '下架
|
||||
{{ action.label }}
|
||||
</button>
|
||||
<button
|
||||
v-if="showRemoveAction && canRemove"
|
||||
v-if="showRemoveAction"
|
||||
v-permission="DOC_TEMPLATE_PERMISSIONS.stop"
|
||||
type="button"
|
||||
class="card-button danger"
|
||||
:title="removeTitle"
|
||||
|
||||
Reference in New Issue
Block a user