<!--
|
【本需求·内网分发】打印客户端下载页
|
|
背景:医院内网,医生端电脑不允许拷贝文件。运维把 electron-hiprint 安装包
|
上传到本系统(或直接 scp 到服务器目录),医生用浏览器打开本页即可下载安装。
|
|
入口:
|
· 顶栏「下载」图标(ToolHeader → ClientDownloadTag)
|
· 登录页底部「打印客户端下载」链接
|
|
权限:
|
· 列表/下载:登录即可(下载地址本身免登录,便于浏览器直连/断点续传)
|
· 上传/删除:仅管理员(前端按 super_admin 角色显示,后端接口本身只要求登录)
|
-->
|
<template>
|
<div class="client-file-page">
|
<div class="client-file-page__head">
|
<div class="client-file-page__title">
|
<Icon icon="ep:download" class="mr-6px" />
|
打印客户端下载
|
</div>
|
<div class="client-file-page__desc">
|
安装后 <b>打印小票不再弹出打印对话框</b>(静默打印)。安装时请右键「以管理员身份运行」,
|
安装完成后在客户端设置里关闭「连接中转服务」,并把默认打印机设为
|
<b>得实 DL-210</b>。
|
</div>
|
</div>
|
|
<ContentWrap>
|
<div class="client-file-page__toolbar">
|
<el-button :icon="Refresh" :loading="loading" @click="loadList">刷新</el-button>
|
<el-button
|
v-if="isAdmin"
|
type="primary"
|
:icon="Upload"
|
:loading="uploading"
|
@click="pickFile"
|
>
|
上传安装包
|
</el-button>
|
<span v-if="isAdmin" class="client-file-page__hint">
|
管理员可用:也可让运维直接把安装包放到服务器 <code>ecg.client-file.dir</code> 目录,刷新即显示
|
</span>
|
<input
|
ref="fileInputRef"
|
type="file"
|
class="client-file-page__file-input"
|
@change="onFileChange"
|
/>
|
</div>
|
|
<!-- 上传进度 -->
|
<div v-if="uploading" class="client-file-page__progress">
|
<el-progress :percentage="uploadPercent" :stroke-width="14" text-inside />
|
<span class="client-file-page__progress-text">{{ uploadingName }}({{ uploadPercent }}%)</span>
|
</div>
|
|
<el-table :data="list" v-loading="loading" stripe empty-text="暂无安装包">
|
<el-table-column label="文件名" prop="name" min-width="320" show-overflow-tooltip>
|
<template #default="{ row }">
|
<Icon icon="ep:document" class="mr-4px" />
|
<span class="client-file-page__name">{{ row.name }}</span>
|
<el-tag v-if="isLatest(row)" size="small" type="success" class="ml-6px">最新</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column label="大小" prop="sizeText" width="120" align="center" />
|
<el-table-column label="上传/更新时间" width="180" align="center">
|
<template #default="{ row }">{{ formatTime(row.lastModified) }}</template>
|
</el-table-column>
|
<el-table-column label="操作" width="260" align="center" fixed="right">
|
<template #default="{ row }">
|
<el-button link type="primary" :icon="Download" @click="download(row.name)">
|
下载
|
</el-button>
|
<el-button link type="primary" :icon="Link" @click="copyLink(row.name)">
|
复制链接
|
</el-button>
|
<el-button
|
v-if="isAdmin"
|
link
|
type="danger"
|
:icon="Delete"
|
:loading="deleting === row.name"
|
@click="remove(row.name)"
|
>
|
删除
|
</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</ContentWrap>
|
|
<div class="client-file-page__foot">
|
安装步骤:① 点「下载」→ ② 右键安装包 →「以管理员身份运行」→ ③ 安装完成后托盘出现图标 →
|
④ 客户端设置里关闭「连接中转服务」、默认打印机选 DL-210 → ⑤ 回 ECG 点「打印小票」验证。
|
</div>
|
</div>
|
</template>
|
|
<script setup lang="ts">
|
import { computed, onMounted, ref } from 'vue'
|
import dayjs from 'dayjs'
|
import { Delete, Download, Link, Refresh, Upload } from '@element-plus/icons-vue'
|
import { ClientFileApi, type ClientFileVO } from '@/api/ecg/clientfile'
|
import { useUserStore } from '@/store/modules/user'
|
import { useMessage } from '@/hooks/web/useMessage'
|
import { copyText } from '@/utils/copyText'
|
|
defineOptions({ name: 'EcgClientFile' })
|
|
const message = useMessage()
|
const userStore = useUserStore()
|
|
const list = ref<ClientFileVO[]>([])
|
const loading = ref(false)
|
const deleting = ref<string>('')
|
const fileInputRef = ref<HTMLInputElement>()
|
|
const uploading = ref(false)
|
const uploadingName = ref('')
|
const uploadPercent = ref(0)
|
|
/** 是否管理员(上传/删除按钮可见性) */
|
const isAdmin = computed(() => {
|
const roles = (userStore.getRoles || []) as string[]
|
return roles.includes('super_admin') || roles.includes('admin')
|
})
|
|
/** 最新版本标记:列表按时间倒序,第一条即最新 */
|
const isLatest = (row: ClientFileVO) => {
|
return list.value.length > 0 && list.value[0].name === row.name
|
}
|
|
const formatTime = (ts: number) => (ts ? dayjs(ts).format('YYYY-MM-DD HH:mm') : '-')
|
|
const loadList = async () => {
|
loading.value = true
|
try {
|
const data = await ClientFileApi.getList()
|
list.value = Array.isArray(data) ? data : []
|
} catch (e) {
|
console.error('[client-file] 加载安装包列表失败', e)
|
message.error('加载安装包列表失败')
|
} finally {
|
loading.value = false
|
}
|
}
|
|
/** 下载(免登录直链,浏览器原生下载/支持断点续传) */
|
const download = (name: string) => {
|
const url = ClientFileApi.downloadUrl(name)
|
const a = document.createElement('a')
|
a.href = url
|
a.download = name
|
a.rel = 'noopener'
|
document.body.appendChild(a)
|
a.click()
|
document.body.removeChild(a)
|
}
|
|
/** 复制下载链接(便于发给别的电脑 / 群发) */
|
const copyLink = async (name: string) => {
|
const url = `${window.location.origin}${ClientFileApi.downloadUrl(name)}`
|
const ok = await copyText(url)
|
if (ok) {
|
message.success('下载链接已复制,可直接发给其它电脑')
|
} else {
|
message.warning('当前浏览器不支持自动复制,请手动复制地址栏链接')
|
}
|
}
|
|
// ==================== 上传(管理员) ====================
|
|
const pickFile = () => {
|
fileInputRef.value?.click()
|
}
|
|
const onFileChange = async (e: Event) => {
|
const input = e.target as HTMLInputElement
|
const file = input.files?.[0]
|
// 清空,保证同一个文件能再次选择触发 change
|
input.value = ''
|
if (!file) return
|
|
uploading.value = true
|
uploadingName.value = file.name
|
uploadPercent.value = 0
|
try {
|
await ClientFileApi.upload(file.name, file, (evt) => {
|
if (evt.total) {
|
uploadPercent.value = Math.min(99, Math.round((evt.loaded / evt.total) * 100))
|
}
|
})
|
uploadPercent.value = 100
|
message.success(`上传成功:${file.name}`)
|
await loadList()
|
} catch (err) {
|
console.error('[client-file] 上传失败', err)
|
message.error('上传失败,请确认文件大小未超过限制(默认 500MB)')
|
} finally {
|
uploading.value = false
|
uploadingName.value = ''
|
setTimeout(() => (uploadPercent.value = 0), 1500)
|
}
|
}
|
|
const remove = async (name: string) => {
|
deleting.value = name
|
try {
|
await ClientFileApi.remove(name)
|
message.success(`已删除:${name}`)
|
await loadList()
|
} catch (e) {
|
console.error('[client-file] 删除失败', e)
|
message.error('删除失败')
|
} finally {
|
deleting.value = ''
|
}
|
}
|
|
onMounted(loadList)
|
</script>
|
|
<style scoped lang="scss">
|
.client-file-page {
|
padding: 12px 16px 24px;
|
|
&__head {
|
margin-bottom: 12px;
|
}
|
|
&__title {
|
display: flex;
|
align-items: center;
|
font-size: 18px;
|
font-weight: 700;
|
color: var(--el-text-color-primary);
|
}
|
|
&__desc {
|
margin-top: 6px;
|
font-size: 13px;
|
line-height: 1.6;
|
color: var(--el-text-color-secondary);
|
}
|
|
&__toolbar {
|
display: flex;
|
align-items: center;
|
gap: 10px;
|
margin-bottom: 10px;
|
flex-wrap: wrap;
|
}
|
|
&__hint {
|
font-size: 12px;
|
color: var(--el-text-color-secondary);
|
}
|
|
&__file-input {
|
display: none;
|
}
|
|
&__progress {
|
display: flex;
|
align-items: center;
|
gap: 10px;
|
margin-bottom: 10px;
|
}
|
|
&__progress-text {
|
font-size: 12px;
|
color: var(--el-text-color-secondary);
|
white-space: nowrap;
|
}
|
|
&__name {
|
font-family: Consolas, Monaco, monospace;
|
}
|
|
&__foot {
|
margin-top: 12px;
|
font-size: 12px;
|
line-height: 1.8;
|
color: var(--el-text-color-secondary);
|
}
|
}
|
</style>
|