@jr-public/jr-upload-ui 1.0.1 → 1.0.3
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.
- package/package.json +3 -3
- package/packages/vue2/src/JrUploadModal.vue +102 -0
- package/packages/vue3/src/JrUploadModalVUE3.vue +107 -0
- package/vue2/index.js +1 -1
- package/vue3/index.js +1 -1
- package/.idea/compiler.xml +0 -6
- package/.idea/jr-upload-ui.iml +0 -9
- package/.idea/misc.xml +0 -9
- package/.idea/modules.xml +0 -8
- package/jr-public-jr-upload-ui-1.0.0.tgz +0 -0
- package/jr-public-jr-upload-ui-1.0.1.tgz +0 -0
- package/npm_recovery_codes.txt +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
{
|
|
2
2
|
"name": "@jr-public/jr-upload-ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "JR upload modal components for Vue2 and Vue3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -38,4 +38,4 @@
|
|
|
38
38
|
"rollup-plugin-terser": "^7.0.2",
|
|
39
39
|
"rollup-plugin-vue": "^6.0.0-beta.10"
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|
|
@@ -163,6 +163,14 @@
|
|
|
163
163
|
</div>
|
|
164
164
|
<div class="file-side-panel">
|
|
165
165
|
<div class="file-actions">
|
|
166
|
+
<button
|
|
167
|
+
v-if="isPreviewableFile(file.name)"
|
|
168
|
+
@click="showPreview(file)"
|
|
169
|
+
class="file-action preview-btn"
|
|
170
|
+
title="预览"
|
|
171
|
+
>
|
|
172
|
+
预览
|
|
173
|
+
</button>
|
|
166
174
|
<button
|
|
167
175
|
v-if="file.status !== 'uploading' && file.status !== 'success'"
|
|
168
176
|
@click="removeFile(file)"
|
|
@@ -1609,6 +1617,89 @@ export default {
|
|
|
1609
1617
|
},
|
|
1610
1618
|
|
|
1611
1619
|
// 工具方法
|
|
1620
|
+
|
|
1621
|
+
// 判断是否为可预览文件(图片和PDF)
|
|
1622
|
+
isPreviewableFile(fileName) {
|
|
1623
|
+
if (!fileName) return false
|
|
1624
|
+
const extension = fileName.split('.').pop().toLowerCase()
|
|
1625
|
+
return /^(jpg|jpeg|png|gif|bmp|webp|svg|pdf)$/i.test(extension)
|
|
1626
|
+
},
|
|
1627
|
+
|
|
1628
|
+
// 判断是否为图片文件
|
|
1629
|
+
isImageFile(fileName) {
|
|
1630
|
+
if (!fileName) return false
|
|
1631
|
+
const extension = fileName.split('.').pop().toLowerCase()
|
|
1632
|
+
return /^(jpg|jpeg|png|gif|bmp|webp|svg)$/i.test(extension)
|
|
1633
|
+
},
|
|
1634
|
+
|
|
1635
|
+
// 判断是否为PDF文件
|
|
1636
|
+
isPdfFile(fileName) {
|
|
1637
|
+
if (!fileName) return false
|
|
1638
|
+
const extension = fileName.split('.').pop().toLowerCase()
|
|
1639
|
+
return /^pdf$/i.test(extension)
|
|
1640
|
+
},
|
|
1641
|
+
|
|
1642
|
+
// 预览文件 - 在新标签页中打开
|
|
1643
|
+
showPreview(fileObj) {
|
|
1644
|
+
try {
|
|
1645
|
+
const fileName = fileObj.file ? fileObj.file.name : fileObj.name
|
|
1646
|
+
const fileSize = fileObj.file ? fileObj.file.size : fileObj.size
|
|
1647
|
+
const fileBlob = fileObj.file || fileObj
|
|
1648
|
+
|
|
1649
|
+
if (!this.isPreviewableFile(fileName)) {
|
|
1650
|
+
console.log('不支持预览此文件类型')
|
|
1651
|
+
return
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
// 创建Blob URL
|
|
1655
|
+
const blobUrl = URL.createObjectURL(fileBlob)
|
|
1656
|
+
const fileType = this.isImageFile(fileName) ? 'image' : 'pdf'
|
|
1657
|
+
|
|
1658
|
+
// 在新标签页中打开预览
|
|
1659
|
+
this.openPreviewInNewTab(blobUrl, fileName, fileType, fileSize)
|
|
1660
|
+
} catch (error) {
|
|
1661
|
+
console.error('预览出错:', error)
|
|
1662
|
+
this.showError('预览失败:' + error.message)
|
|
1663
|
+
}
|
|
1664
|
+
},
|
|
1665
|
+
|
|
1666
|
+
// 在新标签页中打开预览
|
|
1667
|
+
openPreviewInNewTab(fileSrc, fileName, fileType, fileSize) {
|
|
1668
|
+
const fileSizeInfo = fileSize ? ' (' + this.formatFileSize(fileSize) + ')' : ''
|
|
1669
|
+
|
|
1670
|
+
const previewWindow = window.open('', '_blank')
|
|
1671
|
+
if (!previewWindow) {
|
|
1672
|
+
this.showError('无法打开新标签页,请检查浏览器是否阻止了弹出窗口')
|
|
1673
|
+
return
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
let contentHtml = ''
|
|
1677
|
+
if (fileType === 'image') {
|
|
1678
|
+
contentHtml = '<div class="content"><img src="' + fileSrc + '" alt="' + fileName + '" /></div>'
|
|
1679
|
+
} else if (fileType === 'pdf') {
|
|
1680
|
+
contentHtml = '<div class="content"><iframe src="' + fileSrc + '" title="' + fileName + '"></iframe></div>'
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
const previewHtml = '<!DOCTYPE html><html><head><meta charset="UTF-8">' +
|
|
1684
|
+
'<meta name="viewport" content="width=device-width, initial-scale=1.0">' +
|
|
1685
|
+
'<title>' + fileName + fileSizeInfo + ' - 预览</title>' +
|
|
1686
|
+
'<style>' +
|
|
1687
|
+
'body{margin:0;padding:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC",sans-serif;background-color:#f5f5f5;display:flex;flex-direction:column;height:100vh;}' +
|
|
1688
|
+
'.header{background-color:#fff;border-bottom:1px solid #e0e0e0;padding:15px 20px;box-shadow:0 2px 4px rgba(0,0,0,0.1);}' +
|
|
1689
|
+
'.header h1{margin:0;font-size:18px;color:#333;font-weight:500;}' +
|
|
1690
|
+
'.file-size{color:#999;font-size:14px;margin-left:10px;}' +
|
|
1691
|
+
'.content{flex:1;display:flex;align-items:center;justify-content:center;padding:20px;overflow:auto;}' +
|
|
1692
|
+
'.content img{max-width:100%;max-height:100%;object-fit:contain;box-shadow:0 4px 8px rgba(0,0,0,0.1);}' +
|
|
1693
|
+
'.content iframe{width:100%;height:100%;border:none;background-color:#fff;box-shadow:0 4px 8px rgba(0,0,0,0.1);}' +
|
|
1694
|
+
'</style></head><body>' +
|
|
1695
|
+
'<div class="header"><h1>' + fileName + '<span class="file-size">' + fileSizeInfo + '</span></h1></div>' +
|
|
1696
|
+
contentHtml +
|
|
1697
|
+
'</body></html>'
|
|
1698
|
+
|
|
1699
|
+
previewWindow.document.write(previewHtml)
|
|
1700
|
+
previewWindow.document.close()
|
|
1701
|
+
},
|
|
1702
|
+
|
|
1612
1703
|
formatFileSize(bytes) {
|
|
1613
1704
|
if (bytes === 0) return '0 B'
|
|
1614
1705
|
const k = 1024
|
|
@@ -2975,6 +3066,17 @@ export default {
|
|
|
2975
3066
|
color: #6b7280;
|
|
2976
3067
|
}
|
|
2977
3068
|
|
|
3069
|
+
.preview-btn {
|
|
3070
|
+
color: #3b82f6;
|
|
3071
|
+
border-color: rgba(59, 130, 246, 0.3);
|
|
3072
|
+
}
|
|
3073
|
+
|
|
3074
|
+
.preview-btn:hover {
|
|
3075
|
+
background: rgba(59, 130, 246, 0.1);
|
|
3076
|
+
border-color: rgba(59, 130, 246, 0.5);
|
|
3077
|
+
color: #2563eb;
|
|
3078
|
+
}
|
|
3079
|
+
|
|
2978
3080
|
.remove-btn {
|
|
2979
3081
|
color: #ef4444;
|
|
2980
3082
|
border-color: rgba(239, 68, 68, 0.3);
|
|
@@ -163,6 +163,14 @@
|
|
|
163
163
|
</div>
|
|
164
164
|
<div class="file-side-panel">
|
|
165
165
|
<div class="file-actions">
|
|
166
|
+
<button
|
|
167
|
+
v-if="isPreviewableFile(file.name)"
|
|
168
|
+
@click="showPreview(file)"
|
|
169
|
+
class="file-action preview-btn"
|
|
170
|
+
title="预览"
|
|
171
|
+
>
|
|
172
|
+
预览
|
|
173
|
+
</button>
|
|
166
174
|
<button
|
|
167
175
|
v-if="file.status !== 'uploading' && file.status !== 'success'"
|
|
168
176
|
@click="removeFile(file)"
|
|
@@ -1632,6 +1640,89 @@ export default {
|
|
|
1632
1640
|
}
|
|
1633
1641
|
|
|
1634
1642
|
// 工具方法
|
|
1643
|
+
|
|
1644
|
+
// 判断是否为可预览文件(图片和PDF)
|
|
1645
|
+
const isPreviewableFile = (fileName) => {
|
|
1646
|
+
if (!fileName) return false
|
|
1647
|
+
const extension = fileName.split('.').pop().toLowerCase()
|
|
1648
|
+
return /^(jpg|jpeg|png|gif|bmp|webp|svg|pdf)$/i.test(extension)
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
// 判断是否为图片文件
|
|
1652
|
+
const isImageFile = (fileName) => {
|
|
1653
|
+
if (!fileName) return false
|
|
1654
|
+
const extension = fileName.split('.').pop().toLowerCase()
|
|
1655
|
+
return /^(jpg|jpeg|png|gif|bmp|webp|svg)$/i.test(extension)
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
// 判断是否为PDF文件
|
|
1659
|
+
const isPdfFile = (fileName) => {
|
|
1660
|
+
if (!fileName) return false
|
|
1661
|
+
const extension = fileName.split('.').pop().toLowerCase()
|
|
1662
|
+
return /^pdf$/i.test(extension)
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
// 预览文件 - 在新标签页中打开
|
|
1666
|
+
const showPreview = (fileObj) => {
|
|
1667
|
+
try {
|
|
1668
|
+
const fileName = fileObj.file ? fileObj.file.name : fileObj.name
|
|
1669
|
+
const fileSize = fileObj.file ? fileObj.file.size : fileObj.size
|
|
1670
|
+
const fileBlob = fileObj.file || fileObj
|
|
1671
|
+
|
|
1672
|
+
if (!isPreviewableFile(fileName)) {
|
|
1673
|
+
console.log('不支持预览此文件类型')
|
|
1674
|
+
return
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
// 创建Blob URL
|
|
1678
|
+
const blobUrl = URL.createObjectURL(fileBlob)
|
|
1679
|
+
const fileType = isImageFile(fileName) ? 'image' : 'pdf'
|
|
1680
|
+
|
|
1681
|
+
// 在新标签页中打开预览
|
|
1682
|
+
openPreviewInNewTab(blobUrl, fileName, fileType, fileSize)
|
|
1683
|
+
} catch (error) {
|
|
1684
|
+
console.error('预览出错:', error)
|
|
1685
|
+
showError('预览失败:' + error.message)
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
// 在新标签页中打开预览
|
|
1690
|
+
const openPreviewInNewTab = (fileSrc, fileName, fileType, fileSize) => {
|
|
1691
|
+
const fileSizeInfo = fileSize ? ' (' + formatFileSize(fileSize) + ')' : ''
|
|
1692
|
+
|
|
1693
|
+
const previewWindow = window.open('', '_blank')
|
|
1694
|
+
if (!previewWindow) {
|
|
1695
|
+
showError('无法打开新标签页,请检查浏览器是否阻止了弹出窗口')
|
|
1696
|
+
return
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
let contentHtml = ''
|
|
1700
|
+
if (fileType === 'image') {
|
|
1701
|
+
contentHtml = '<div class="content"><img src="' + fileSrc + '" alt="' + fileName + '" /></div>'
|
|
1702
|
+
} else if (fileType === 'pdf') {
|
|
1703
|
+
contentHtml = '<div class="content"><iframe src="' + fileSrc + '" title="' + fileName + '"></iframe></div>'
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
const previewHtml = '<!DOCTYPE html><html><head><meta charset="UTF-8">' +
|
|
1707
|
+
'<meta name="viewport" content="width=device-width, initial-scale=1.0">' +
|
|
1708
|
+
'<title>' + fileName + fileSizeInfo + ' - 预览</title>' +
|
|
1709
|
+
'<style>' +
|
|
1710
|
+
'body{margin:0;padding:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC",sans-serif;background-color:#f5f5f5;display:flex;flex-direction:column;height:100vh;}' +
|
|
1711
|
+
'.header{background-color:#fff;border-bottom:1px solid #e0e0e0;padding:15px 20px;box-shadow:0 2px 4px rgba(0,0,0,0.1);}' +
|
|
1712
|
+
'.header h1{margin:0;font-size:18px;color:#333;font-weight:500;}' +
|
|
1713
|
+
'.file-size{color:#999;font-size:14px;margin-left:10px;}' +
|
|
1714
|
+
'.content{flex:1;display:flex;align-items:center;justify-content:center;padding:20px;overflow:auto;}' +
|
|
1715
|
+
'.content img{max-width:100%;max-height:100%;object-fit:contain;box-shadow:0 4px 8px rgba(0,0,0,0.1);}' +
|
|
1716
|
+
'.content iframe{width:100%;height:100%;border:none;background-color:#fff;box-shadow:0 4px 8px rgba(0,0,0,0.1);}' +
|
|
1717
|
+
'</style></head><body>' +
|
|
1718
|
+
'<div class="header"><h1>' + fileName + '<span class="file-size">' + fileSizeInfo + '</span></h1></div>' +
|
|
1719
|
+
contentHtml +
|
|
1720
|
+
'</body></html>'
|
|
1721
|
+
|
|
1722
|
+
previewWindow.document.write(previewHtml)
|
|
1723
|
+
previewWindow.document.close()
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1635
1726
|
const formatFileSize = (bytes) => {
|
|
1636
1727
|
if (bytes === 0) return '0 B'
|
|
1637
1728
|
const k = 1024
|
|
@@ -2307,6 +2398,11 @@ export default {
|
|
|
2307
2398
|
|
|
2308
2399
|
// 工具方法
|
|
2309
2400
|
formatFileSize,
|
|
2401
|
+
isPreviewableFile,
|
|
2402
|
+
isImageFile,
|
|
2403
|
+
isPdfFile,
|
|
2404
|
+
showPreview,
|
|
2405
|
+
openPreviewInNewTab,
|
|
2310
2406
|
generateFileId,
|
|
2311
2407
|
generateUUID32,
|
|
2312
2408
|
truncateFileName,
|
|
@@ -3081,6 +3177,17 @@ export default {
|
|
|
3081
3177
|
color: #6b7280;
|
|
3082
3178
|
}
|
|
3083
3179
|
|
|
3180
|
+
.preview-btn {
|
|
3181
|
+
color: #3b82f6;
|
|
3182
|
+
border-color: rgba(59, 130, 246, 0.3);
|
|
3183
|
+
}
|
|
3184
|
+
|
|
3185
|
+
.preview-btn:hover {
|
|
3186
|
+
background: rgba(59, 130, 246, 0.1);
|
|
3187
|
+
border-color: rgba(59, 130, 246, 0.5);
|
|
3188
|
+
color: #2563eb;
|
|
3189
|
+
}
|
|
3190
|
+
|
|
3084
3191
|
.remove-btn {
|
|
3085
3192
|
color: #ef4444;
|
|
3086
3193
|
border-color: rgba(239, 68, 68, 0.3);
|
package/vue2/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// vue2 入口文件 - 转发到实际的源文件
|
|
2
|
-
export { default, JrUploadModal } from '../packages/vue2/src/index.js'
|
|
2
|
+
export { default, JrUploadModal } from '../packages/vue2/src/index.js'
|
package/vue3/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// vue3 入口文件 - 转发到实际的源文件
|
|
2
|
-
export { default, JrUploadModalVue3 } from '../packages/vue3/src/index.js'
|
|
2
|
+
export { default, JrUploadModalVue3 } from '../packages/vue3/src/index.js'
|
package/.idea/compiler.xml
DELETED
package/.idea/jr-upload-ui.iml
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="JAVA_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
-
<exclude-output />
|
|
5
|
-
<content url="file://$MODULE_DIR$" />
|
|
6
|
-
<orderEntry type="inheritedJdk" />
|
|
7
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
-
</component>
|
|
9
|
-
</module>
|
package/.idea/misc.xml
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="MavenRunner">
|
|
4
|
-
<option name="jreName" value="#JAVA_HOME" />
|
|
5
|
-
</component>
|
|
6
|
-
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
|
7
|
-
<output url="file://$PROJECT_DIR$/out" />
|
|
8
|
-
</component>
|
|
9
|
-
</project>
|
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/jr-upload-ui.iml" filepath="$PROJECT_DIR$/.idea/jr-upload-ui.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
|
Binary file
|
|
Binary file
|
package/npm_recovery_codes.txt
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
dbcb2352b88e15524c58f1fc0aacb55b59b2a5e8994b8cdc847dd0b3b804ab20
|
|
2
|
-
9b8508ef4990d7fdc819130527015225eb56c769802334ad2cb2cffc96ff11da
|
|
3
|
-
9b8acfc4288bd7e5056446381b6700c7d0ec8fea7a51b38625a36e87d1c35192
|
|
4
|
-
05c6788ac82f44baea84bbca9369ba2ffc252aa24a24b8bc56a51d128e29e401
|
|
5
|
-
a12b6bc5fc379ccfe51f9d1fe2becff6c6fd5d29d9920def9bb05f3e05e37868
|