haiwei-module-admin 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.browserslistrc +2 -0
  2. package/.eslintrc.js +18 -0
  3. package/.prettierrc +6 -0
  4. package/.vscode/settings.json +10 -0
  5. package/babel.config.js +10 -0
  6. package/package.json +9 -17
  7. package/postcss.config.js +5 -0
  8. package/script/npm_install.bat +4 -0
  9. package/script/npm_install.ps1 +3 -0
  10. package/script/npm_publish.bat +4 -0
  11. package/script/npm_publish.ps1 +3 -0
  12. package/script/npm_update.bat +4 -0
  13. package/script/npm_update.ps1 +3 -0
  14. package/src/api/components/file.js +3 -0
  15. package/src/components/enum-checkbox/index.vue +1 -1
  16. package/src/components/enum-radio/index.vue +1 -1
  17. package/src/components/enum-select/index.vue +1 -1
  18. package/src/components/file-preview/index copy.vue +531 -0
  19. package/src/components/file-preview/index.vue +534 -0
  20. package/src/components/index.js +1 -1
  21. package/src/components/login-mode-select/index.vue +1 -1
  22. package/src/components/module-select/index.vue +1 -1
  23. package/src/components/platform-select/index.vue +1 -1
  24. package/src/components/role-select/index.vue +1 -1
  25. package/src/index.js +6 -6
  26. package/src/routes/index.js +1 -1
  27. package/src/views/account/components/save/index.vue +1 -1
  28. package/src/views/account/index/index.vue +1 -1
  29. package/src/views/auditInfo/components/details/index.vue +1 -1
  30. package/src/views/button/permission-bind/index.vue +1 -1
  31. package/src/views/cache/index/index.vue +1 -1
  32. package/src/views/file/components/save/index.vue +106 -0
  33. package/src/views/file/index/index.vue +54 -3
  34. package/src/views/file/index/page.js +8 -0
  35. package/src/views/menu/components/add/index.vue +1 -1
  36. package/src/views/menu/components/edit/index.vue +1 -1
  37. package/src/views/mime/components/save/index.vue +1 -1
  38. package/src/views/mime/index/index.vue +1 -1
  39. package/src/views/module/components/page-list/index.vue +1 -1
  40. package/src/views/module/components/permission-list/index.vue +1 -1
  41. package/src/views/role/components/platform-bind/index.vue +1 -1
  42. package/src/views/role/components/save/index.vue +1 -1
  43. package/src/views/role/index/index.vue +1 -1
  44. package/vue.config.js +118 -0
@@ -0,0 +1,531 @@
1
+ <template>
2
+ <div class="file-preview">
3
+ <!-- 图片预览链接 -->
4
+ <a v-if="isImage" class="preview-link" @click="showPreviewDialog">
5
+ 查看
6
+ </a>
7
+
8
+ <!-- 非图片文件下载 -->
9
+ <nm-file-download v-else :url="downloadUrl" :private="isPrivate" :fileName="fileName" :text="downloadText" :icon="downloadIcon" :size="downloadSize" :type="downloadType" @click="onDownload" />
10
+
11
+ <!-- 图片预览对话框 -->
12
+ <nm-dialog
13
+ v-if="isImage"
14
+ ref="previewDialog"
15
+ :visible.sync="previewVisible"
16
+ :title="previewTitle"
17
+ width="800px"
18
+ height="800px"
19
+ :fullscreen="false"
20
+ :footer="false"
21
+ custom-class="image-preview-dialog"
22
+ @closed="resetState"
23
+ >
24
+ <div class="preview-wrapper">
25
+ <!-- 使用CSS实现图片居中,而不是JS计算 -->
26
+ <div class="preview-container" ref="previewContainer">
27
+ <img
28
+ :src="previewUrl"
29
+ :alt="fileName"
30
+ class="preview-image"
31
+ ref="previewImage"
32
+ @load="handleImageLoad"
33
+ @error="handleImageError"
34
+ :style="imageStyle"
35
+ @mousedown="startDrag"
36
+ @wheel="handleWheel"
37
+ @dblclick="resetImage"
38
+ />
39
+ </div>
40
+
41
+ <!-- 操作按钮栏 -->
42
+ <div class="toolbar">
43
+ <button class="toolbar-btn" @click="zoomIn">
44
+ <span class="icon">+</span>
45
+ <span class="text">放大</span>
46
+ </button>
47
+ <button class="toolbar-btn" @click="zoomOut">
48
+ <span class="icon">-</span>
49
+ <span class="text">缩小</span>
50
+ </button>
51
+ <button class="toolbar-btn" @click="resetImage">
52
+ <span class="icon">⟳</span>
53
+ <span class="text">重置</span>
54
+ </button>
55
+ </div>
56
+ </div>
57
+ </nm-dialog>
58
+ </div>
59
+ </template>
60
+
61
+ <script>
62
+ export default {
63
+ name: 'FilePreview',
64
+ props: {
65
+ fullPath: { type: String, required: true },
66
+ fileName: String,
67
+ isPrivate: { type: Boolean, default: false },
68
+ ext: String,
69
+ downloadText: { type: String, default: '下载' },
70
+ downloadIcon: { type: String, default: 'download' },
71
+ downloadSize: String,
72
+ downloadType: { type: String, default: 'primary' },
73
+ previewTitle: { type: String, default: '图片预览' },
74
+ imageExtensions: {
75
+ type: Array,
76
+ default: () => ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg', 'ico']
77
+ }
78
+ },
79
+
80
+ data() {
81
+ return {
82
+ previewVisible: false,
83
+ previewUrl: '',
84
+ fileInfo: null,
85
+
86
+ // 图片状态
87
+ imageLoading: false,
88
+ imageError: false,
89
+ loadingTimeout: null,
90
+
91
+ // 图片位置和缩放(使用CSS transform,但让CSS处理居中)
92
+ position: { x: 0, y: 0 },
93
+ scale: 1,
94
+ minScale: 0.1,
95
+ maxScale: 5,
96
+
97
+ // 拖拽状态
98
+ isDragging: false,
99
+ startPosition: { x: 0, y: 0 }
100
+ }
101
+ },
102
+
103
+ computed: {
104
+ isImage() {
105
+ // return false;
106
+ const ext = this.ext || (this.fileName || '').split('.').pop() || ''
107
+ return this.imageExtensions.includes(ext.toLowerCase())
108
+ },
109
+
110
+ downloadUrl() {
111
+ console.log('this.fileInfo?.url ', this.fileInfo?.url)
112
+ return this.fileInfo?.url || this.fullPath
113
+ },
114
+
115
+ imageStyle() {
116
+ return {
117
+ transform: `translate(${this.position.x}px, ${this.position.y}px) scale(${this.scale})`,
118
+ cursor: this.isDragging ? 'grabbing' : 'grab'
119
+ }
120
+ }
121
+ },
122
+
123
+ watch: {
124
+ fullPath(val) {
125
+ if (val && this.isImage && !this.isPrivate) {
126
+ this.previewUrl = val
127
+ }
128
+ },
129
+
130
+ previewVisible(val) {
131
+ if (!val) {
132
+ this.resetState()
133
+ }
134
+ }
135
+ },
136
+
137
+ mounted() {
138
+ // 监听全局鼠标事件用于拖拽
139
+ document.addEventListener('mousemove', this.handleDrag)
140
+ document.addEventListener('mouseup', this.stopDrag)
141
+ },
142
+
143
+ beforeDestroy() {
144
+ // 清理事件监听
145
+ document.removeEventListener('mousemove', this.handleDrag)
146
+ document.removeEventListener('mouseup', this.stopDrag)
147
+
148
+ // 清理超时
149
+ if (this.loadingTimeout) {
150
+ clearTimeout(this.loadingTimeout)
151
+ this.loadingTimeout = null
152
+ }
153
+ },
154
+
155
+ methods: {
156
+ getFileExtension() {
157
+ if (this.ext) return this.ext.toLowerCase()
158
+ const name = this.fileName || this.fullPath || ''
159
+ const dotIndex = name.lastIndexOf('.')
160
+ return dotIndex > -1 ? name.slice(dotIndex + 1).toLowerCase() : ''
161
+ },
162
+
163
+ async getFileInfo() {
164
+ if (!this.fullPath) return null
165
+
166
+ try {
167
+ const result = await $api.admin.file.getByFullPath(this.fullPath)
168
+ this.fileInfo = result
169
+
170
+ console.log('result', result)
171
+
172
+ return result
173
+ } catch (error) {
174
+ console.error('获取文件信息失败:', error)
175
+ return null
176
+ }
177
+ },
178
+
179
+ async showPreviewDialog() {
180
+ if (!this.isImage) return
181
+
182
+ this.resetState()
183
+ this.imageLoading = true
184
+ this.previewVisible = true
185
+
186
+ try {
187
+ const fileInfo = await this.getFileInfo()
188
+ if (!fileInfo) {
189
+ this.imageLoading = false
190
+ this.imageError = true
191
+ return
192
+ }
193
+
194
+ await this.setPreviewUrl(fileInfo)
195
+
196
+ // 设置一个立即检查,防止缓存图片不触发load事件
197
+ this.$nextTick(() => {
198
+ setTimeout(() => {
199
+ if (this.imageLoading && this.$refs.previewImage && this.$refs.previewImage.complete) {
200
+ this.handleImageLoad()
201
+ }
202
+ }, 300) // 300ms后检查
203
+ })
204
+
205
+ // 设置超时,防止图片加载事件未触发
206
+ this.loadingTimeout = setTimeout(() => {
207
+ if (this.imageLoading) {
208
+ console.warn('图片加载超时,强制结束加载状态')
209
+ this.imageLoading = false
210
+ // 检查图片是否已经加载完成
211
+ if (this.$refs.previewImage && this.$refs.previewImage.complete) {
212
+ this.handleImageLoad()
213
+ }
214
+ }
215
+ }, 2000) // 2秒超时
216
+ } catch (error) {
217
+ console.error('打开预览对话框失败:', error)
218
+ this.imageLoading = false
219
+ this.imageError = true
220
+ }
221
+ },
222
+
223
+ async setPreviewUrl(fileInfo) {
224
+ let newUrl
225
+ if (this.isPrivate && fileInfo.url) {
226
+ try {
227
+ newUrl = await $api.admin.file.preview(fileInfo.url)
228
+ } catch {
229
+ newUrl = fileInfo.url
230
+ }
231
+ } else {
232
+ newUrl = fileInfo.url || this.fullPath
233
+ }
234
+
235
+ // 先清空URL,强制重新加载(即使URL相同)
236
+ if (this.previewUrl) {
237
+ this.previewUrl = ''
238
+ // 等待一个tick确保DOM更新
239
+ await this.$nextTick()
240
+ }
241
+
242
+ // 设置新的URL
243
+ this.previewUrl = newUrl
244
+
245
+ // 等待DOM更新后检查图片是否已经加载完成
246
+ this.$nextTick(() => {
247
+ // 如果图片元素存在且已经加载完成,直接触发加载完成事件
248
+ if (this.$refs.previewImage && this.$refs.previewImage.complete) {
249
+ // 小延迟确保图片完全渲染
250
+ setTimeout(() => {
251
+ if (this.imageLoading) {
252
+ this.handleImageLoad()
253
+ }
254
+ }, 100)
255
+ }
256
+ })
257
+ },
258
+
259
+ async onDownload() {
260
+ const fileInfo = await this.getFileInfo()
261
+ const url = fileInfo?.url || this.fullPath
262
+ this.$emit('download', url, this.fileName)
263
+ },
264
+
265
+ handleImageLoad() {
266
+ // 清理超时
267
+ if (this.loadingTimeout) {
268
+ clearTimeout(this.loadingTimeout)
269
+ this.loadingTimeout = null
270
+ }
271
+ this.imageLoading = false
272
+ // 图片加载完成后自动居中
273
+ this.resetImage()
274
+ },
275
+
276
+ handleImageError() {
277
+ // 清理超时
278
+ if (this.loadingTimeout) {
279
+ clearTimeout(this.loadingTimeout)
280
+ this.loadingTimeout = null
281
+ }
282
+ this.imageLoading = false
283
+ this.imageError = true
284
+ },
285
+
286
+ // 鼠标滚轮缩放 - 以鼠标为中心点缩放
287
+ handleWheel(event) {
288
+ event.preventDefault()
289
+
290
+ const delta = event.deltaY < 0 ? 0.1 : -0.1
291
+ const newScale = Math.max(this.minScale, Math.min(this.maxScale, this.scale + delta))
292
+
293
+ // 计算缩放中心(相对于图片)
294
+ if (this.$refs.previewContainer) {
295
+ const containerRect = this.$refs.previewContainer.getBoundingClientRect()
296
+ const mouseX = event.clientX - containerRect.left
297
+ const mouseY = event.clientY - containerRect.top
298
+
299
+ // 计算鼠标相对于图片原始坐标系的位置
300
+ // 注意:position.x 和 position.y 是图片相对于容器的平移
301
+ const relativeX = (mouseX - this.position.x) / this.scale
302
+ const relativeY = (mouseY - this.position.y) / this.scale
303
+
304
+ // 更新位置以保持鼠标点不变
305
+ this.position.x = mouseX - relativeX * newScale
306
+ this.position.y = mouseY - relativeY * newScale
307
+ this.scale = newScale
308
+ } else {
309
+ this.scale = newScale
310
+ }
311
+ },
312
+
313
+ // 开始拖拽
314
+ startDrag(event) {
315
+ if (event.button !== 0) return // 只响应左键
316
+ this.isDragging = true
317
+ this.startPosition = {
318
+ x: event.clientX - this.position.x,
319
+ y: event.clientY - this.position.y
320
+ }
321
+ event.preventDefault()
322
+ },
323
+
324
+ // 处理拖拽
325
+ handleDrag(event) {
326
+ if (!this.isDragging) return
327
+
328
+ this.position.x = event.clientX - this.startPosition.x
329
+ this.position.y = event.clientY - this.startPosition.y
330
+ },
331
+
332
+ // 停止拖拽
333
+ stopDrag() {
334
+ this.isDragging = false
335
+ },
336
+
337
+ // 放大
338
+ zoomIn() {
339
+ const newScale = Math.min(this.maxScale, this.scale + 0.2)
340
+ if (newScale !== this.scale) {
341
+ this.centerZoom(newScale)
342
+ }
343
+ },
344
+
345
+ // 缩小
346
+ zoomOut() {
347
+ const newScale = Math.max(this.minScale, this.scale - 0.2)
348
+ if (newScale !== this.scale) {
349
+ this.centerZoom(newScale)
350
+ }
351
+ },
352
+
353
+ // 以当前视图中心点缩放(用于工具栏按钮)
354
+ centerZoom(newScale) {
355
+ if (this.$refs.previewContainer) {
356
+ const containerRect = this.$refs.previewContainer.getBoundingClientRect()
357
+ // 使用容器中心作为缩放中心点
358
+ const centerX = containerRect.width / 2
359
+ const centerY = containerRect.height / 2
360
+
361
+ // 计算中心点相对于图片原始坐标系的位置
362
+ const relativeX = (centerX - this.position.x) / this.scale
363
+ const relativeY = (centerY - this.position.y) / this.scale
364
+
365
+ // 更新位置以保持中心点不变
366
+ this.position.x = centerX - relativeX * newScale
367
+ this.position.y = centerY - relativeY * newScale
368
+ }
369
+ this.scale = newScale
370
+ },
371
+
372
+ // 重置图片位置和大小
373
+ resetImage() {
374
+ this.position = { x: 0, y: 0 }
375
+ this.scale = 1
376
+ },
377
+
378
+ // 重置所有状态
379
+ resetState() {
380
+ // 清理超时
381
+ if (this.loadingTimeout) {
382
+ clearTimeout(this.loadingTimeout)
383
+ this.loadingTimeout = null
384
+ }
385
+ this.position = { x: 0, y: 0 }
386
+ this.scale = 1
387
+ this.imageLoading = false
388
+ this.imageError = false
389
+ this.isDragging = false
390
+ }
391
+ }
392
+ }
393
+ </script>
394
+
395
+ <style lang="scss" scoped>
396
+ .file-preview {
397
+ display: inline-block;
398
+
399
+ .preview-link {
400
+ color: #409eff;
401
+ cursor: pointer;
402
+ text-decoration: none;
403
+ transition: color 0.2s;
404
+
405
+ &:hover {
406
+ color: #66b1ff;
407
+ text-decoration: underline;
408
+ }
409
+ }
410
+ }
411
+
412
+ .preview-wrapper {
413
+ width: 100%;
414
+ height: 750px;
415
+ background: #000;
416
+ position: relative;
417
+ overflow: hidden;
418
+ display: flex;
419
+ align-items: center;
420
+ justify-content: center;
421
+ }
422
+
423
+ .preview-container {
424
+ width: 100%;
425
+ height: 100%;
426
+ display: flex;
427
+ align-items: center;
428
+ justify-content: center;
429
+ position: relative;
430
+ overflow: hidden;
431
+ touch-action: none;
432
+ /* 防止移动端默认行为 */
433
+ }
434
+
435
+ .preview-image {
436
+ max-width: 100%;
437
+ max-height: 100%;
438
+ object-fit: contain;
439
+ /* 关键:保持比例并适应容器 */
440
+ transform-origin: 0 0;
441
+ /* 设置为左上角以匹配我们的数学计算 */
442
+ transition: transform 0.2s ease;
443
+ user-select: none;
444
+ -webkit-user-drag: none;
445
+
446
+ /* 平滑的拖拽和缩放效果 */
447
+ will-change: transform;
448
+ }
449
+
450
+ /* 操作工具栏 */
451
+ .toolbar {
452
+ position: absolute;
453
+ bottom: 20px;
454
+ left: 50%;
455
+ transform: translateX(-50%);
456
+ display: flex;
457
+ gap: 10px;
458
+ background: rgba(0, 0, 0, 0.7);
459
+ padding: 10px;
460
+ border-radius: 4px;
461
+ z-index: 10;
462
+ }
463
+
464
+ .toolbar-btn {
465
+ display: flex;
466
+ align-items: center;
467
+ justify-content: center;
468
+ gap: 5px;
469
+ background: rgba(255, 255, 255, 0.1);
470
+ border: 1px solid rgba(255, 255, 255, 0.2);
471
+ color: white;
472
+ padding: 8px 12px;
473
+ border-radius: 4px;
474
+ cursor: pointer;
475
+ font-size: 12px;
476
+ transition: all 0.2s;
477
+
478
+ &:hover {
479
+ background: rgba(255, 255, 255, 0.2);
480
+ border-color: rgba(255, 255, 255, 0.3);
481
+ }
482
+
483
+ &:active {
484
+ transform: scale(0.95);
485
+ }
486
+
487
+ .icon {
488
+ font-size: 14px;
489
+ font-weight: bold;
490
+ }
491
+
492
+ .text {
493
+ white-space: nowrap;
494
+ }
495
+ }
496
+ </style>
497
+
498
+ <style lang="scss">
499
+ /* 对话框全局样式 */
500
+ .image-preview-dialog {
501
+ .el-dialog {
502
+ background: #000;
503
+ border: 1px solid #333;
504
+ }
505
+
506
+ .el-dialog__header {
507
+ background: #000;
508
+ border-bottom: 1px solid #333;
509
+ padding: 10px 20px;
510
+
511
+ .el-dialog__title {
512
+ color: #fff;
513
+ font-size: 14px;
514
+ }
515
+
516
+ .el-dialog__close {
517
+ color: #fff;
518
+
519
+ &:hover {
520
+ color: #409eff;
521
+ }
522
+ }
523
+ }
524
+
525
+ .el-dialog__body {
526
+ padding: 0 !important;
527
+ background: #000 !important;
528
+ overflow: hidden !important;
529
+ }
530
+ }
531
+ </style>