Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz-Vue-R7-Res
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7前端标准模板
iBiz-Vue-R7-Res
提交
11f1483a
提交
11f1483a
编写于
9月 30, 2025
作者:
Cano1997
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update: 图片控件调整下载方式
上级
90644c18
变更
4
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
225 行增加
和
25 行删除
+225
-25
app-image-preview.vue
src/components/app-image-preview/app-image-preview.vue
+36
-6
app-image-upload.vue
src/components/app-image-upload/app-image-upload.vue
+63
-19
img-util.ts
src/utils/img-util/img-util.ts
+125
-0
index.ts
src/utils/index.ts
+1
-0
未找到文件。
src/components/app-image-preview/app-image-preview.vue
浏览文件 @
11f1483a
...
...
@@ -33,7 +33,7 @@
import
{
Vue
,
Component
,
Prop
,
Watch
,
Provide
}
from
'vue-property-decorator'
;
import
{
Environment
}
from
'@/environments/environment'
;
import
{
Subject
,
Unsubscribable
}
from
'rxjs'
;
import
{
safeRedirect
}
from
'@/utils'
;
import
{
getImgUrl
,
safeRedirect
}
from
'@/utils'
;
@
Component
({})
export
default
class
AppImagePreview
extends
Vue
{
...
...
@@ -64,6 +64,30 @@ export default class AppImagePreview extends Vue {
*/
@
Prop
()
public
value
?:
any
;
/**
* 默认为当前实体名称,有指定则按表单参数
*
* @type {string}
* @memberof AppImageUpload
*/
@
Prop
()
public
folder
!
:
string
;
/**
* 视图上下文
*
* @type {*}
* @memberof AppAutocomplete
*/
@
Prop
()
public
context
!
:
any
;
/**
* 默认为当前实体主键id,有指定则按表单参数
*
* @type {string}
* @memberof AppImageUpload
*/
@
Prop
()
public
ownerid
!
:
string
;
/**
* 数据值变化
*
...
...
@@ -112,17 +136,23 @@ export default class AppImagePreview extends Vue {
* @private
* @memberof AppImagePreview
*/
private
setFiles
(
value
:
any
):
void
{
private
async
setFiles
(
value
:
any
):
Promise
<
void
>
{
let
_files
=
JSON
.
parse
(
value
);
if
(
value
&&
Object
.
prototype
.
toString
.
call
(
_files
)
==
'[object Array]'
)
{
this
.
files
=
_files
;
this
.
files
.
forEach
((
file
:
any
)
=>
{
let
url
=
`
${
this
.
downloadUrl
}
/
${
file
.
id
}
`
;
file
.
url
=
url
;
});
for
(
let
index
=
0
;
index
<
this
.
files
.
length
;
index
++
)
{
const
file
:
any
=
this
.
files
[
index
];
let
url
=
`
${
this
.
downloadUrl
}
/
${
file
.
id
}
/
${
file
.
name
}
`
;
const
base64
=
`
${
file
.
id
}
|
${
this
.
folder
}
|
${
this
.
ownerid
}
|
${
this
.
context
.
srfpersonid
||
this
.
context
.
srfuserid
}
`
;
url
=
`
${
url
}
?key=
${
window
.
btoa
(
base64
)}${
Math
.
floor
(
1000
+
Math
.
random
()
*
9000
,
)}
`
file
.
url
=
await
getImgUrl
(
url
,
file
.
name
)
||
url
;
}
}
else
{
this
.
files
=
[];
}
this
.
$forceUpdate
();
}
/**
...
...
src/components/app-image-upload/app-image-upload.vue
浏览文件 @
11f1483a
...
...
@@ -36,7 +36,7 @@
:class =
"
{'el-upload-disabled':disabled}"
:disabled = "disabled"
:action = "uploadUrl"
:headers
= "{ 'srfappdata': appData }
"
:headers
="myHeaders
"
:show-file-list = "false"
:multiple="multiple"
:accept="accept"
...
...
@@ -65,7 +65,8 @@
import
{
Vue
,
Component
,
Prop
,
Watch
,
Provide
}
from
'vue-property-decorator'
;
import
{
Environment
}
from
'@/environments/environment'
;
import
{
Subject
,
Unsubscribable
}
from
'rxjs'
;
import
{
safeRedirect
}
from
'@/utils'
;
import
{
getImgUrl
,
safeRedirect
}
from
'@/utils'
;
import
EntityService
from
'@/service/entity-service'
;
@
Component
({})
export
default
class
AppImageUpload
extends
Vue
{
...
...
@@ -201,6 +202,22 @@ export default class AppImageUpload extends Vue {
*/
@
Prop
({
default
:
'image/*'
})
public
accept
!
:
string
;
/**
* 实体服务
*
* @type {EntityService}
* @memberof AppFileUpload
*/
@
Prop
()
public
appEntityService
!
:
EntityService
;
/**
* 默认为当前实体主键id,有指定则按表单参数
*
* @type {string}
* @memberof AppImageUpload
*/
@
Prop
()
public
ownerid
!
:
string
;
/**
* 上传文件路径
*
...
...
@@ -254,6 +271,22 @@ export default class AppImageUpload extends Vue {
*/
public
appData
:
any
=
""
;
/**
* 当前登陆人的token
*
* @type {string}
* @memberof DiskFileUpload
*/
public
token
:
string
=
"Bearer "
+
localStorage
.
getItem
(
'token'
);
/**
* 上传文件请求头
*
* @type {*}
* @memberof DiskFileUpload
*/
public
myHeaders
:
any
=
{
Authorization
:
this
.
token
,
srfappdata
:
this
.
appData
};
/**
* 设置files
*
...
...
@@ -269,6 +302,31 @@ export default class AppImageUpload extends Vue {
}
}
private
async
handleImgUrl
()
{
for
(
let
index
=
0
;
index
<
this
.
files
.
length
;
index
++
)
{
const
file
:
any
=
this
.
files
[
index
];
let
url
=
`
${
this
.
downloadUrl
}
/
${
file
.
id
}
/
${
file
.
name
}
`
;
const
entityName
=
this
.
appEntityService
.
APPDENAME
;
const
base64
=
`
${
file
.
id
}
|
${
entityName
}
|
${
this
.
ownerid
}
|
${
this
.
context
.
srfpersonid
||
this
.
context
.
srfuserid
}
`
;
url
=
`
${
url
}
?key=
${
window
.
btoa
(
base64
)}${
Math
.
floor
(
1000
+
Math
.
random
()
*
9000
,
)}
`
if
(
this
.
export_params
.
length
>
0
)
{
if
(
!
url
.
includes
(
'?'
))
{
url
+=
'?'
;
}
this
.
export_params
.
forEach
((
item
:
any
,
i
:
any
)
=>
{
url
+=
`
${
Object
.
keys
(
item
)[
0
]}
=
${
Object
.
values
(
item
)[
0
]}
`
;
if
(
i
<
this
.
export_params
.
length
-
1
){
url
+=
'&'
;
}
})
}
file
.
url
=
await
getImgUrl
(
url
,
file
.
name
)
||
url
;
}
this
.
$forceUpdate
();
}
/**
* 数据处理
*
...
...
@@ -276,10 +334,8 @@ export default class AppImageUpload extends Vue {
* @memberof AppImageUpload
*/
private
dataProcess
():
void
{
let
_url
=
`
${
Environment
.
BaseUrl
}${
Environment
.
UploadFile
}
`
;
let
_url
=
`
${
Environment
.
BaseUrl
}${
Environment
.
UploadFile
}
?ownertype=
${
this
.
name
}
&ownerid=
${
JSON
.
parse
(
this
.
data
).
srfkey
}
`
;
if
(
this
.
upload_params
.
length
>
0
)
{
_url
+=
'?'
;
this
.
upload_params
.
forEach
((
item
:
any
,
i
:
any
)
=>
{
_url
+=
`
${
Object
.
keys
(
item
)[
0
]}
=
${
Object
.
values
(
item
)[
0
]}
`
;
if
(
i
<
this
.
upload_params
.
length
-
1
){
...
...
@@ -291,19 +347,7 @@ export default class AppImageUpload extends Vue {
this
.
uploadUrl
=
_url
;
this
.
files
.
forEach
((
file
:
any
)
=>
{
let
url
=
`
${
this
.
downloadUrl
}
/
${
file
.
id
}
`
;
if
(
this
.
export_params
.
length
>
0
)
{
url
+=
'?'
;
this
.
export_params
.
forEach
((
item
:
any
,
i
:
any
)
=>
{
url
+=
`
${
Object
.
keys
(
item
)[
0
]}
=
${
Object
.
values
(
item
)[
0
]}
`
;
if
(
i
<
this
.
export_params
.
length
-
1
){
url
+=
'&'
;
}
})
}
file
.
url
=
url
;
});
this
.
handleImgUrl
();
}
/**
...
...
src/utils/img-util/img-util.ts
0 → 100644
浏览文件 @
11f1483a
import
axios
from
'axios'
;
import
qs
from
'qs'
;
/**
* @description 计算文件类型
* @export
* @param {string} filetype
* @returns {*} {string}
*/
export
function
calcFilemime
(
filetype
:
string
):
string
{
let
mime
=
'image/png'
;
switch
(
filetype
)
{
case
'.wps'
:
mime
=
'application/kswps'
;
break
;
case
'.doc'
:
mime
=
'application/msword'
;
break
;
case
'.docx'
:
mime
=
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
;
break
;
case
'.txt'
:
mime
=
'text/plain'
;
break
;
case
'.zip'
:
mime
=
'application/zip'
;
break
;
case
'.png'
:
mime
=
'imgage/png'
;
break
;
case
'.gif'
:
mime
=
'image/gif'
;
break
;
case
'.jpeg'
:
mime
=
'image/jpeg'
;
break
;
case
'.jpg'
:
mime
=
'image/jpeg'
;
break
;
case
'.rtf'
:
mime
=
'application/rtf'
;
break
;
case
'.avi'
:
mime
=
'video/x-msvideo'
;
break
;
case
'.gz'
:
mime
=
'application/x-gzip'
;
break
;
case
'.tar'
:
mime
=
'application/x-tar'
;
break
;
}
return
mime
;
}
/**
* @description 获取文件名称
* @export
* @param {*} response
* @returns {*} {string}
*/
export
function
getFileName
(
response
:
any
):
string
{
let
fileName
=
''
;
const
contentDisposition
=
response
.
headers
[
'content-disposition'
];
if
(
!
contentDisposition
)
{
return
fileName
;
}
const
disposition
=
qs
.
parse
(
contentDisposition
,
{
delimiter
:
';'
,
});
if
(
disposition
&&
disposition
.
filename
)
{
fileName
=
disposition
.
filename
as
string
;
}
// 特殊处理返回的文件名带有双引号
if
(
fileName
.
startsWith
(
'"'
)
&&
fileName
.
endsWith
(
'"'
))
{
fileName
=
fileName
.
substring
(
1
,
fileName
.
length
-
1
);
}
return
decodeURIComponent
(
escape
(
fileName
));
}
export
function
blobToBase64
(
blob
:
Blob
):
Promise
<
string
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
reader
=
new
FileReader
();
reader
.
onloadend
=
()
=>
resolve
(
reader
.
result
as
string
);
// 自带 data:application/pdf;base64,...
reader
.
onerror
=
reject
;
reader
.
readAsDataURL
(
blob
);
});
}
/**
* @description 获取图片路径,由于图片鉴权调整,导致所有图片默认显示会出现无权限报错,需转化为base64显示
* @export
* @param {string} downloadUrl
* @returns {*} {Promise<string>}
*/
export
function
getImgUrl
(
downloadUrl
:
string
,
fileName
:
string
):
Promise
<
string
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
url
=
downloadUrl
.
replace
(
/
\/
api/
,
''
);
axios
.
get
(
url
,
{
responseType
:
'blob'
}).
then
((
response
:
any
)
=>
{
if
(
!
response
||
response
.
status
!=
200
)
{
console
.
error
(
`图片下载失败!`
);
reject
();
}
// 请求成功,后台返回的是一个文件流
if
(
response
.
data
)
{
// 获取文件名
const
filename
=
getFileName
(
response
)
||
fileName
;
const
ext
=
'.'
+
filename
.
split
(
'.'
).
pop
();
let
filetype
=
calcFilemime
(
ext
);
// 用blob对象获取文件流
let
blob
=
new
Blob
([
response
.
data
],
{
type
:
filetype
});
// 通过文件流创建下载链接
const
base64
=
blobToBase64
(
blob
);
resolve
(
base64
);
}
else
{
console
.
error
(
`图片下载失败!`
);
reject
();
}
})
.
catch
((
error
:
any
)
=>
{
console
.
error
(
error
);
reject
();
});
});
}
src/utils/index.ts
浏览文件 @
11f1483a
...
...
@@ -13,3 +13,4 @@ export { LoadAppData } from './load-app-data/load-app-data';
export
{
Interceptors
}
from
'./interceptor/interceptor'
;
export
{
StudioActionUtil
}
from
'./studio-action/StudioActionUtil'
;
export
{
safeRedirect
}
from
'./redirect-util/redirect-util'
;
export
{
getImgUrl
}
from
'./img-util/img-util'
;
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录