yxh
8 天以前 be27214928a43cacff975265a7c67e2e2461fd0c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<!--
  【本需求·内网分发】打印客户端下载页
 
  背景:医院内网,医生端电脑不允许拷贝文件。运维把 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>