提交
This commit is contained in:
1 parent
91b8dd1aaa
commit
89fda927a2
119 files changed
+36038
-28744
No files matched your search
@@ -0,0 +1,363 @@
|
||||
<!--
|
||||
覆盖 FormCreate 内置 upload:picture-card 下非图片不再用 <img> 破图,
|
||||
改为文档/视频图标 + 文件名(对齐业务附件卡片语义)。
|
||||
-->
|
||||
<template>
|
||||
<div class="_fc-upload _oa-fc-upload">
|
||||
<el-upload
|
||||
ref="uploadRef"
|
||||
:key="fileCount"
|
||||
v-bind="uploadAttrs"
|
||||
:list-type="resolvedListType"
|
||||
:class="{ '_fc-exceed': isExceed }"
|
||||
:file-list="fileList"
|
||||
:http-request="doHttpRequest"
|
||||
:on-preview="handlePreview"
|
||||
:on-change="handleChange"
|
||||
:on-remove="handleRemove"
|
||||
>
|
||||
<slot>
|
||||
<el-icon v-if="!isTextOrPictureList">
|
||||
<Upload />
|
||||
</el-icon>
|
||||
<el-button v-else type="primary">
|
||||
{{ uploadButtonText }}
|
||||
</el-button>
|
||||
</slot>
|
||||
|
||||
<template v-if="useCustomFileSlot" #file="{ file }">
|
||||
<div class="oa-fc-upload-card" :class="{ 'is-file': !isOaUploadImageFile(file) }">
|
||||
<template v-if="file.status === 'uploading'">
|
||||
<el-progress
|
||||
type="circle"
|
||||
:percentage="Number(file.percentage || 0)"
|
||||
:stroke-width="6"
|
||||
:width="70"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="isOaUploadImageFile(file)">
|
||||
<img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
|
||||
</template>
|
||||
<template v-else-if="isOaUploadVideoFile(file)">
|
||||
<div class="oa-fc-upload-card__icon oa-fc-upload-card__icon--video">
|
||||
<el-icon :size="28"><VideoPlay /></el-icon>
|
||||
</div>
|
||||
<div class="oa-fc-upload-card__name" :title="getOaUploadDisplayName(file)">
|
||||
{{ getOaUploadDisplayName(file) }}
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="oa-fc-upload-card__icon oa-fc-upload-card__icon--doc">
|
||||
<el-icon :size="28"><Document /></el-icon>
|
||||
</div>
|
||||
<div class="oa-fc-upload-card__name" :title="getOaUploadDisplayName(file)">
|
||||
{{ getOaUploadDisplayName(file) }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<label v-if="file.status === 'success'" class="el-upload-list__item-status-label">
|
||||
<el-icon class="el-icon--upload-success el-icon--check"><Check /></el-icon>
|
||||
</label>
|
||||
|
||||
<span v-if="file.status !== 'uploading'" class="el-upload-list__item-actions">
|
||||
<span
|
||||
v-if="isOaUploadImageFile(file)"
|
||||
class="el-upload-list__item-preview"
|
||||
title="预览"
|
||||
@click="handlePreview(file)"
|
||||
>
|
||||
<el-icon><ZoomIn /></el-icon>
|
||||
</span>
|
||||
<span
|
||||
class="el-upload-list__item-preview"
|
||||
title="下载"
|
||||
@click.stop="handleDownload(file)"
|
||||
>
|
||||
<el-icon><Download /></el-icon>
|
||||
</span>
|
||||
<span
|
||||
v-if="!isDisabled"
|
||||
class="el-upload-list__item-delete"
|
||||
title="删除"
|
||||
@click="removeFile(file)"
|
||||
>
|
||||
<el-icon><Delete /></el-icon>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</el-upload>
|
||||
|
||||
<el-dialog
|
||||
v-model="previewVisible"
|
||||
append-to-body
|
||||
:modal="previewMask"
|
||||
:title="modalTitle || '预览'"
|
||||
@close="previewVisible = false"
|
||||
>
|
||||
<img style="width: 100%" :src="previewImage" alt="" />
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue'
|
||||
import type { UploadFile, UploadProps, UploadRequestOptions, UploadUserFile } from 'element-plus'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import {
|
||||
Check,
|
||||
Delete,
|
||||
Document,
|
||||
Download,
|
||||
Upload,
|
||||
VideoPlay,
|
||||
ZoomIn
|
||||
} from '@element-plus/icons-vue'
|
||||
import { attachmentFullUrl } from '@/composables/useAttachmentActions'
|
||||
import { downloadAttachmentFile } from '@/utils/download-attachment'
|
||||
import {
|
||||
getOaUploadDisplayName,
|
||||
isOaUploadImageFile,
|
||||
isOaUploadVideoFile
|
||||
} from '@/utils/oa-upload-file-type'
|
||||
|
||||
function toArray(value: unknown): unknown[] {
|
||||
if (value == null || value === '') return []
|
||||
return Array.isArray(value) ? value : [value]
|
||||
}
|
||||
|
||||
function getFileName(file: string): string {
|
||||
return String(file).split('/').pop() || String(file)
|
||||
}
|
||||
|
||||
function parseFile(file: unknown, i: number): UploadUserFile & { is_string?: boolean } {
|
||||
if (file && typeof file === 'object') {
|
||||
return file as UploadUserFile
|
||||
}
|
||||
const url = String(file || '')
|
||||
return {
|
||||
url,
|
||||
name: getFileName(url),
|
||||
uid: i,
|
||||
status: 'success',
|
||||
is_string: true
|
||||
}
|
||||
}
|
||||
|
||||
function parseUpload(file: UploadUserFile): UploadUserFile & {
|
||||
file?: UploadUserFile
|
||||
value?: UploadUserFile
|
||||
is_string?: boolean
|
||||
} {
|
||||
const withMeta = file as UploadUserFile & { is_string?: boolean }
|
||||
return { ...withMeta, file: withMeta, value: withMeta }
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'fcUpload',
|
||||
inheritAttrs: false,
|
||||
components: { Check, Delete, Document, Download, Upload, VideoPlay, ZoomIn },
|
||||
formCreateParser: {
|
||||
toFormValue(value: unknown) {
|
||||
return toArray(value)
|
||||
},
|
||||
toValue(formValue: unknown[], ctx: { prop?: { props?: { limit?: number } } }) {
|
||||
return ctx.prop?.props?.limit === 1 ? formValue[0] || '' : formValue
|
||||
}
|
||||
},
|
||||
props: {
|
||||
previewMask: { type: [Boolean, Object] as any, default: undefined },
|
||||
onPreview: { type: Function, default: undefined },
|
||||
httpRequest: { type: Function, default: undefined },
|
||||
modalTitle: { type: String, default: '' },
|
||||
listType: { type: String, default: '' },
|
||||
uploadText: { type: String, default: '' },
|
||||
formCreateInject: { type: Object, default: undefined },
|
||||
modelValue: { type: [Array, String, Object] as any, default: undefined }
|
||||
},
|
||||
emits: ['update:modelValue', 'change', 'remove', 'fc.el'],
|
||||
data() {
|
||||
return {
|
||||
previewVisible: false,
|
||||
previewImage: '',
|
||||
fileList: [] as Array<UploadUserFile & { is_string?: boolean; value?: unknown }>
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
resolvedListType(): UploadProps['listType'] {
|
||||
return (this.listType as UploadProps['listType']) || 'picture-card'
|
||||
},
|
||||
isTextOrPictureList(): boolean {
|
||||
return this.resolvedListType === 'text' || this.resolvedListType === 'picture'
|
||||
},
|
||||
useCustomFileSlot(): boolean {
|
||||
return this.resolvedListType === 'picture-card' || this.resolvedListType === 'picture'
|
||||
},
|
||||
fileCount(): number {
|
||||
return toArray(this.modelValue).length
|
||||
},
|
||||
isExceed(): boolean {
|
||||
const limit = Number((this.$attrs as any).limit)
|
||||
if (!limit) return false
|
||||
return limit <= this.fileCount
|
||||
},
|
||||
isDisabled(): boolean {
|
||||
return !!(this.$attrs as any).disabled
|
||||
},
|
||||
uploadButtonText(): string {
|
||||
const t = this.formCreateInject?.t?.('clickToUpload')
|
||||
return t || this.uploadText || '点击上传'
|
||||
},
|
||||
uploadAttrs(): Record<string, unknown> {
|
||||
const attrs = { ...(this.$attrs as Record<string, unknown>) }
|
||||
delete attrs.onPreview
|
||||
delete attrs['on-preview']
|
||||
return attrs
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
modelValue: {
|
||||
immediate: true,
|
||||
handler(n: unknown) {
|
||||
this.fileList = toArray(n).map(parseFile).map(parseUpload)
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
isOaUploadImageFile,
|
||||
isOaUploadVideoFile,
|
||||
getOaUploadDisplayName,
|
||||
handlePreview(file: UploadFile) {
|
||||
if (typeof this.onPreview === 'function') {
|
||||
this.onPreview(file)
|
||||
return
|
||||
}
|
||||
if (this.resolvedListType === 'text' || !isOaUploadImageFile(file)) {
|
||||
if (file?.url) window.open(file.url, '_blank')
|
||||
return
|
||||
}
|
||||
this.previewImage = file.url || ''
|
||||
this.previewVisible = true
|
||||
},
|
||||
async handleDownload(file: UploadFile) {
|
||||
const url = String(file?.url || '').trim()
|
||||
const fileName = getOaUploadDisplayName(file)
|
||||
if (!url) {
|
||||
ElMessage.warning('文件地址无效,无法下载')
|
||||
return
|
||||
}
|
||||
// 尚未落到服务端地址时,用本地 raw 触发下载
|
||||
if (url.startsWith('blob:') && file.raw) {
|
||||
const objectUrl = URL.createObjectURL(file.raw)
|
||||
try {
|
||||
const a = document.createElement('a')
|
||||
a.href = objectUrl
|
||||
a.download = fileName
|
||||
a.rel = 'noopener'
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
} finally {
|
||||
URL.revokeObjectURL(objectUrl)
|
||||
}
|
||||
return
|
||||
}
|
||||
await downloadAttachmentFile(
|
||||
{ fileUrl: url, fileName },
|
||||
{ fullFileUrl: (u) => attachmentFullUrl(u) }
|
||||
)
|
||||
},
|
||||
update(list: Array<UploadUserFile & { is_string?: boolean; value?: unknown; url?: string }>) {
|
||||
const files = list
|
||||
.map((v) => (v.is_string ? v.url : (v.value as any) || v.url))
|
||||
.filter((url) => url !== undefined)
|
||||
this.$emit('update:modelValue', files)
|
||||
},
|
||||
handleChange(file: UploadFile, list: UploadFile[]) {
|
||||
this.$emit('change', file, list)
|
||||
if (file.status === 'success') {
|
||||
this.update(list as any)
|
||||
}
|
||||
},
|
||||
handleRemove(file: UploadFile, list: UploadFile[]) {
|
||||
this.$emit('remove', file, list)
|
||||
this.update(list as any)
|
||||
},
|
||||
removeFile(file: UploadFile) {
|
||||
const upload = this.$refs.uploadRef as { handleRemove?: (f: UploadFile) => void } | undefined
|
||||
upload?.handleRemove?.(file)
|
||||
},
|
||||
doHttpRequest(option: UploadRequestOptions) {
|
||||
if (typeof this.httpRequest === 'function') {
|
||||
return this.httpRequest(option)
|
||||
}
|
||||
const payload: any = option
|
||||
payload.source = 'upload'
|
||||
this.formCreateInject?.api?.fetch?.(payload)
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$emit('fc.el', this.$refs.uploadRef)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.oa-fc-upload-card {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
|
||||
.el-upload-list__item-thumbnail {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
|
||||
&.is-file {
|
||||
padding: 8px 6px;
|
||||
background: #f8fafc;
|
||||
}
|
||||
}
|
||||
|
||||
.oa-fc-upload-card__icon {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
|
||||
&--video {
|
||||
background: #ede9fe;
|
||||
color: #7c3aed;
|
||||
}
|
||||
|
||||
&--doc {
|
||||
background: #e0f2fe;
|
||||
color: #0284c7;
|
||||
}
|
||||
}
|
||||
|
||||
.oa-fc-upload-card__name {
|
||||
margin-top: 6px;
|
||||
width: 100%;
|
||||
padding: 0 2px;
|
||||
font-size: 11px;
|
||||
line-height: 1.3;
|
||||
color: #334155;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
word-break: break-all;
|
||||
}
|
||||
</style>
|
||||
@@ -90,6 +90,8 @@
|
||||
timestamp?: string
|
||||
commentText?: string
|
||||
taskId?: string
|
||||
transferToUserId?: string
|
||||
transferToUserName?: string
|
||||
}
|
||||
|
||||
export type OaProgressChainItem = {
|
||||
@@ -189,7 +191,7 @@
|
||||
if (s === 'approved' || s === 'completed') return 'is-ok'
|
||||
if (s === 'pending' || s === 'running') return 'is-pending'
|
||||
if (s === 'rejected' || s === 'returned' || s === 'cancelled') return 'is-danger'
|
||||
if (s === 'done' || s === 'not_reached') return 'is-mute'
|
||||
if (s === 'done' || s === 'not_reached' || s === 'transferred') return 'is-mute'
|
||||
return ''
|
||||
}
|
||||
|
||||
@@ -201,11 +203,17 @@
|
||||
if (s === 'pending' || s === 'running') return '待处理'
|
||||
if (s === 'done') return '无需处理'
|
||||
if (s === 'not_reached') return '未到达'
|
||||
if (s === 'transferred') return '已转交'
|
||||
return ''
|
||||
}
|
||||
|
||||
function personTitle(p: OaProgressPerson) {
|
||||
const parts = [p.nickName || '', statusText(p.status || ''), p.timestamp || ''].filter(Boolean)
|
||||
const target = (p.transferToUserName || p.transferToUserId || '').trim()
|
||||
const statusLabel =
|
||||
p.status === 'transferred' && target
|
||||
? `转交给${target}`
|
||||
: statusText(p.status || '')
|
||||
const parts = [p.nickName || '', statusLabel, p.timestamp || ''].filter(Boolean)
|
||||
return parts.join(' · ')
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,12 @@ export function listConditionCandidates(schema: unknown): ConditionCandidate[] {
|
||||
if (!CONDITION_ELIGIBLE_TYPES.has(type)) continue
|
||||
const field = String(rule.field || rule.name || '')
|
||||
if (!field) continue
|
||||
const flagged = rule.useInCondition === true || rule.props?.useInCondition === true
|
||||
const flagged =
|
||||
rule.useInCondition === true
|
||||
? true
|
||||
: rule.useInCondition === false
|
||||
? false
|
||||
: rule.props?.useInCondition === true
|
||||
if (!flagged) continue
|
||||
const options = (rule.options || rule.props?.options || [])
|
||||
.map((o: any) =>
|
||||
@@ -115,7 +120,12 @@ export function normalizeSchemaConditionRequired(schema: unknown): {
|
||||
const rules = Array.isArray(plain.rule) ? plain.rule : Array.isArray(plain) ? plain : []
|
||||
const walk = (list: any[]) => {
|
||||
for (const rule of list) {
|
||||
const flagged = rule.useInCondition === true || rule.props?.useInCondition === true
|
||||
const flagged =
|
||||
rule.useInCondition === true
|
||||
? true
|
||||
: rule.useInCondition === false
|
||||
? false
|
||||
: rule.props?.useInCondition === true
|
||||
if (flagged) {
|
||||
rule.useInCondition = true
|
||||
if (rule.props && typeof rule.props === 'object') {
|
||||
@@ -123,6 +133,11 @@ export function normalizeSchemaConditionRequired(schema: unknown): {
|
||||
}
|
||||
rule.$required = true
|
||||
rule.required = true
|
||||
} else if (rule.useInCondition === false || rule.props?.useInCondition === false) {
|
||||
rule.useInCondition = false
|
||||
if (rule.props && typeof rule.props === 'object') {
|
||||
rule.props.useInCondition = false
|
||||
}
|
||||
}
|
||||
const children = rule.children || rule.props?.rule
|
||||
if (Array.isArray(children)) walk(children)
|
||||
|
||||
Reference in new issue
Block a user