Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
严立
/
framework-flow
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a1e3e972
authored
Feb 28, 2024
by
黄燕娟
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix:文件上传
parent
a2415598
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
123 deletions
.env.test
src/api/request.js
src/api/sys.js
src/components/common/Editor.vue
src/views/common/form/components/FileUpload.vue
src/views/common/form/components/ImageUpload.vue
.env.test
View file @
a1e3e972
# 开发环境配置
# 开发环境配置
VUE_APP_MODE
=
'test'
VUE_APP_MODE
=
'test'
VUE_APP_BASE_API
=
'/api'
VUE_APP_BASE_API
=
'
http://sz-tianma.meiqicloud.com
/api'
VITE_AXIOS_API_PRIMARY
=
'http://rapidplatform.meiqicloud.com/api'
VITE_AXIOS_API_PRIMARY
=
'http://rapidplatform.meiqicloud.com/api'
VUE_APP_SERVER_URL
=
'http://sz-tianma.meiqicloud.com/api'
VUE_APP_SERVER_URL
=
'http://sz-tianma.meiqicloud.com/api'
src/api/request.js
View file @
a1e3e972
...
@@ -46,7 +46,7 @@ axios.interceptors.response.use(
...
@@ -46,7 +46,7 @@ axios.interceptors.response.use(
(
response
)
=>
{
(
response
)
=>
{
console
.
log
(
'response'
,
response
)
console
.
log
(
'response'
,
response
)
let
{
code
}
=
response
.
data
;
let
{
code
}
=
response
.
data
;
if
(
code
===
501
)
{
if
(
code
===
113
)
{
window
.
parent
.
postMessage
(
window
.
parent
.
postMessage
(
{
text
:
"子页面发消息给父页面"
,
type
:
"token-past-due"
},
{
text
:
"子页面发消息给父页面"
,
type
:
"token-past-due"
},
"*"
"*"
...
@@ -61,9 +61,9 @@ axios.interceptors.response.use(
...
@@ -61,9 +61,9 @@ axios.interceptors.response.use(
(
error
)
=>
{
(
error
)
=>
{
console
.
log
(
'error'
,
error
)
console
.
log
(
'error'
,
error
)
if
(
!
error
.
response
)
return
Promise
.
reject
(
error
);
if
(
!
error
.
response
)
return
Promise
.
reject
(
error
);
const
{
code
,
data
,
config
}
=
error
.
response
;
const
{
status
,
data
,
config
}
=
error
.
response
;
switch
(
code
)
{
switch
(
status
)
{
// 需要重新登录
// 需要重新登录
case
401
:
{
case
401
:
{
break
;
break
;
...
...
src/api/sys.js
View file @
a1e3e972
...
@@ -27,7 +27,7 @@ export function userGroupPage(params) {
...
@@ -27,7 +27,7 @@ export function userGroupPage(params) {
// 文件上传
// 文件上传
export
function
sysUpload
(
params
)
{
export
function
sysUpload
(
params
)
{
return
request
({
return
request
({
url
:
`/a/sys/
upload
`
,
url
:
`/a/sys/
file/uploadFile
`
,
method
:
'post'
,
method
:
'post'
,
data
:
params
data
:
params
})
})
...
...
src/components/common/Editor.vue
View file @
a1e3e972
...
@@ -85,20 +85,15 @@ export default {
...
@@ -85,20 +85,15 @@ export default {
let
formData
=
new
FormData
();
let
formData
=
new
FormData
();
formData
.
append
(
"file"
,
blobInfo
.
blob
(),
blobInfo
.
filename
());
formData
.
append
(
"file"
,
blobInfo
.
blob
(),
blobInfo
.
filename
());
formData
.
append
(
"isImg"
,
true
);
formData
.
append
(
"isImg"
,
true
);
axios
.
post
(
this
.
uploadUrl
,
formData
,
{
sysUpload
(
formData
)
"Content-type"
:
"multipart/form-data"
,
.
then
((
res
)
=>
{
})
.
then
(
(
res
)
=>
{
this
.
$message
.
success
(
"上传成功"
);
this
.
$message
.
success
(
"上传成功"
);
success
(
this
.
$getRes
(
res
.
data
.
url
));
success
(
this
.
$getRes
(
res
.
data
.
fullPath
));
},
})
(
err
)
=>
{
.
catch
(()
=>
{
this
.
$message
.
error
(
"上传失败"
);
Toast
.
fail
(
"上传失败"
);
console
.
log
(
err
);
});
}
);
},
},
setup
:
(
editor
)
=>
{
setup
:
(
editor
)
=>
{
editor
.
on
(
"init"
,
(
e
)
=>
{
editor
.
on
(
"init"
,
(
e
)
=>
{
...
@@ -112,22 +107,6 @@ export default {
...
@@ -112,22 +107,6 @@ export default {
};
};
},
},
computed
:
{
computed
:
{
uploadUrl
()
{
let
mode
=
sessionStorage
.
getItem
(
"mode"
);
if
(
process
.
env
.
VUE_APP_MODE
===
"development"
)
{
if
(
mode
!==
"PC"
)
{
return
"/a/wflow/res"
;
}
else
{
return
process
.
env
.
VUE_APP_BASE_API
+
"/a/wflow/res"
;
}
}
else
{
if
(
mode
!==
"PC"
)
{
return
"/a/wflow/res"
;
}
else
{
return
process
.
env
.
VUE_APP_SERVER_URL
+
"/a/wflow/res"
;
}
}
},
_value
:
{
_value
:
{
get
()
{
get
()
{
return
this
.
value
;
return
this
.
value
;
...
...
src/views/common/form/components/FileUpload.vue
View file @
a1e3e972
...
@@ -13,7 +13,8 @@
...
@@ -13,7 +13,8 @@
<div
v-else-if=
"mode === 'PC' && !readonly"
v-loading=
"loading"
>
<div
v-else-if=
"mode === 'PC' && !readonly"
v-loading=
"loading"
>
<el-upload
<el-upload
:file-list=
"fileList"
:file-list=
"fileList"
:action=
"uploadUrl"
action=
""
:http-request=
"uploadFile"
:limit=
"maxNumber"
:limit=
"maxNumber"
with-credentials
with-credentials
:multiple=
"maxNumber > 1"
:multiple=
"maxNumber > 1"
...
@@ -100,7 +101,7 @@
...
@@ -100,7 +101,7 @@
import
componentMinxins
from
"../ComponentMinxins"
;
import
componentMinxins
from
"../ComponentMinxins"
;
import
{
Uploader
,
Toast
}
from
"vant"
;
import
{
Uploader
,
Toast
}
from
"vant"
;
import
axios
from
"axios"
;
import
axios
from
"axios"
;
import
{
CONDITION_PROPS
}
from
"../../../admin/layout/process/DefaultNodeProp
s"
;
import
{
sysUpload
}
from
"@/api/sys.j
s"
;
export
default
{
export
default
{
mixins
:
[
componentMinxins
],
mixins
:
[
componentMinxins
],
name
:
"FileUpload"
,
name
:
"FileUpload"
,
...
@@ -132,22 +133,6 @@ export default {
...
@@ -132,22 +133,6 @@ export default {
},
},
},
},
computed
:
{
computed
:
{
uploadUrl
()
{
let
mode
=
sessionStorage
.
getItem
(
"mode"
);
if
(
process
.
env
.
VUE_APP_MODE
===
"development"
)
{
if
(
mode
!==
"PC"
)
{
return
"/a/wflow/res"
;
}
else
{
return
process
.
env
.
VUE_APP_BASE_API
+
"/a/wflow/res"
;
}
}
else
{
if
(
mode
!==
"PC"
)
{
return
"/a/wflow/res"
;
}
else
{
return
process
.
env
.
VUE_APP_SERVER_URL
+
"/a/wflow/res"
;
}
}
},
sizeTip
()
{
sizeTip
()
{
if
(
this
.
fileTypes
.
length
>
0
)
{
if
(
this
.
fileTypes
.
length
>
0
)
{
return
` | 只允许上传[
${
String
(
this
.
fileTypes
).
replaceAll
(
return
` | 只允许上传[
${
String
(
this
.
fileTypes
).
replaceAll
(
...
@@ -189,7 +174,6 @@ export default {
...
@@ -189,7 +174,6 @@ export default {
uploadParams
:
{
isImg
:
false
},
uploadParams
:
{
isImg
:
false
},
headers
:
{
headers
:
{
token
:
localStorage
.
getItem
(
"token"
),
token
:
localStorage
.
getItem
(
"token"
),
factoryId
:
localStorage
.
getItem
(
"factoryId"
),
},
},
};
};
},
},
...
@@ -225,13 +209,7 @@ export default {
...
@@ -225,13 +209,7 @@ export default {
return
size
+
"B"
;
return
size
+
"B"
;
}
}
},
},
removeFile
(
fileId
)
{
axios
.
delete
(
`
${
process
.
env
.
VUE_APP_BASE_API
}
/a/wflow/res/
${
fileId
}
`
)
.
then
((
rsp
)
=>
{
this
.
$message
.
success
(
"移除文件成功"
);
});
},
uploadSuccess
(
response
,
file
,
fileList
)
{
uploadSuccess
(
response
,
file
,
fileList
)
{
this
.
loading
=
false
;
this
.
loading
=
false
;
console
.
log
(
response
,
this
.
_value
);
console
.
log
(
response
,
this
.
_value
);
...
@@ -261,27 +239,28 @@ export default {
...
@@ -261,27 +239,28 @@ export default {
this
.
uploadFile
(
file
);
this
.
uploadFile
(
file
);
}
}
},
},
uploadFile
(
file
)
{
uploadFile
(
params
)
{
//上传文件
//上传文件
const
formData
=
new
FormData
();
const
formData
=
new
FormData
();
formData
.
append
(
"file"
,
file
.
file
);
formData
.
append
(
"file"
,
params
.
file
);
formData
.
append
(
"isImg"
,
false
);
formData
.
append
(
"isImg"
,
false
);
Toast
.
loading
({
message
:
"上传中..."
,
forbidClick
:
true
});
axios
sysUpload
(
formData
)
.
post
(
this
.
uploadUrl
,
formData
,
{
.
then
((
res
)
=>
{
"Content-type"
:
"multipart/form-data"
,
this
.
_value
.
push
({
})
...
res
.
data
,
.
then
(
url
:
res
.
data
.
fullPath
,
(
res
)
=>
{
name
:
res
.
data
.
originalName
,
this
.
_value
.
push
(
res
.
data
);
});
console
.
log
(
7886
,
res
.
data
);
this
.
$emit
(
"input"
,
this
.
_value
);
this
.
$emit
(
"input"
,
this
.
_value
);
Toast
.
success
(
"上传成功"
);
Toast
.
success
(
"上传成功"
);
},
this
.
loading
=
false
;
(
err
)
=>
{
})
.
catch
(()
=>
{
Toast
.
fail
(
"上传失败"
);
Toast
.
fail
(
"上传失败"
);
console
.
log
(
err
);
this
.
loading
=
false
;
}
});
);
},
},
onOversize
(
file
)
{
onOversize
(
file
)
{
Toast
.
fail
(
"文件过大"
);
Toast
.
fail
(
"文件过大"
);
...
@@ -289,7 +268,6 @@ export default {
...
@@ -289,7 +268,6 @@ export default {
handleRemove
(
file
,
fileList
)
{
handleRemove
(
file
,
fileList
)
{
let
i
=
this
.
_value
.
findIndex
((
v
)
=>
v
.
name
===
file
.
name
);
let
i
=
this
.
_value
.
findIndex
((
v
)
=>
v
.
name
===
file
.
name
);
if
(
i
>
-
1
)
{
if
(
i
>
-
1
)
{
//this.removeFile(this._value[i].id)
this
.
_value
.
splice
(
i
,
1
);
this
.
_value
.
splice
(
i
,
1
);
this
.
$emit
(
"input"
,
this
.
_value
);
this
.
$emit
(
"input"
,
this
.
_value
);
console
.
log
(
"删除文件"
,
file
);
console
.
log
(
"删除文件"
,
file
);
...
...
src/views/common/form/components/ImageUpload.vue
View file @
a1e3e972
...
@@ -9,10 +9,11 @@
...
@@ -9,10 +9,11 @@
<div
v-else-if=
"mode === 'PC' && !readonly"
>
<div
v-else-if=
"mode === 'PC' && !readonly"
>
<el-upload
<el-upload
:file-list=
"fileList"
:file-list=
"fileList"
:action=
"uploadUrl
"
action=
"
"
:limit=
"maxNumber"
:limit=
"maxNumber"
with-credentials
with-credentials
:multiple=
"maxNumber > 1"
:multiple=
"maxNumber > 1"
:http-request=
"uploadFile"
:headers=
"headers"
:headers=
"headers"
:data=
"uploadParams"
:data=
"uploadParams"
:on-success=
"uploadSuccess"
:on-success=
"uploadSuccess"
...
@@ -24,7 +25,6 @@
...
@@ -24,7 +25,6 @@
auto-upload
auto-upload
:before-upload=
"beforeUpload"
:before-upload=
"beforeUpload"
>
>
<!-- :http-request="uploadImg" -->
<i
slot=
"default"
class=
"el-icon-plus"
></i>
<i
slot=
"default"
class=
"el-icon-plus"
></i>
<div
slot=
"tip"
class=
"el-upload__tip"
>
<div
slot=
"tip"
class=
"el-upload__tip"
>
{{
placeholder
}}
{{
sizeTip
}}
{{
placeholder
}}
{{
sizeTip
}}
...
@@ -66,7 +66,7 @@ import { Uploader, Toast } from "vant";
...
@@ -66,7 +66,7 @@ import { Uploader, Toast } from "vant";
import
componentMinxins
from
"../ComponentMinxins"
;
import
componentMinxins
from
"../ComponentMinxins"
;
import
axios
from
"@/api/request"
;
import
axios
from
"@/api/request"
;
import
{
deepClone
}
from
"@/utils/common.js"
;
import
{
deepClone
}
from
"@/utils/common.js"
;
import
{
sysUpload
}
from
"@/api/sys.js"
;
export
default
{
export
default
{
mixins
:
[
componentMinxins
],
mixins
:
[
componentMinxins
],
name
:
"ImageUpload"
,
name
:
"ImageUpload"
,
...
@@ -96,22 +96,6 @@ export default {
...
@@ -96,22 +96,6 @@ export default {
},
},
},
},
computed
:
{
computed
:
{
uploadUrl
()
{
let
mode
=
sessionStorage
.
getItem
(
"mode"
);
if
(
process
.
env
.
VUE_APP_MODE
===
"development"
)
{
if
(
mode
!==
"PC"
)
{
return
"/a/wflow/res"
;
}
else
{
return
process
.
env
.
VUE_APP_BASE_API
+
"/a/wflow/res"
;
}
}
else
{
if
(
mode
!==
"PC"
)
{
return
"/a/wflow/res"
;
}
else
{
return
process
.
env
.
VUE_APP_SERVER_URL
+
"/a/wflow/res"
;
}
}
},
sizeTip
()
{
sizeTip
()
{
return
this
.
maxSize
>
0
?
`| 每张图不超过
${
this
.
maxSize
}
MB`
:
""
;
return
this
.
maxSize
>
0
?
`| 每张图不超过
${
this
.
maxSize
}
MB`
:
""
;
},
},
...
@@ -169,24 +153,16 @@ export default {
...
@@ -169,24 +153,16 @@ export default {
}
}
return
false
;
return
false
;
},
},
removeFile
(
fileId
)
{
axios
.
delete
(
`
${
process
.
env
.
VUE_APP_BASE_API
}
/a/wflow/res/
${
fileId
}
`
)
.
then
((
rsp
)
=>
{
this
.
$message
.
success
(
"移除文件成功"
);
});
},
uploadSuccess
(
response
,
file
,
fileList
)
{
uploadSuccess
(
response
,
file
,
fileList
)
{
console
.
log
(
4444
,
response
);
console
.
log
(
"uploadSuccess"
,
response
);
this
.
loading
=
false
;
this
.
loading
=
false
;
this
.
catchList
.
push
(
response
);
this
.
catchList
.
push
(
{
...
response
.
data
,
url
:
response
.
data
.
fullPath
}
);
let
ft
=
fileList
.
filter
((
f
)
=>
f
.
size
!==
undefined
);
let
ft
=
fileList
.
filter
((
f
)
=>
f
.
size
!==
undefined
);
if
(
this
.
catchList
.
length
===
ft
.
length
)
{
if
(
this
.
catchList
.
length
===
ft
.
length
)
{
this
.
_value
.
push
(...
this
.
catchList
);
this
.
_value
.
push
(...
this
.
catchList
);
this
.
$emit
(
"input"
,
this
.
_value
);
this
.
$emit
(
"input"
,
this
.
_value
);
}
}
this
.
$message
.
success
(
response
.
name
+
"
上传成功"
);
this
.
$message
.
success
(
"图片
上传成功"
);
},
},
uploadFail
(
err
)
{
uploadFail
(
err
)
{
this
.
loading
=
false
;
this
.
loading
=
false
;
...
@@ -201,28 +177,25 @@ export default {
...
@@ -201,28 +177,25 @@ export default {
this
.
uploadFile
(
file
);
this
.
uploadFile
(
file
);
}
}
},
},
// uploadImg(params) {},
uploadFile
(
file
)
{
uploadFile
(
params
)
{
//上传文件
//上传文件
const
formData
=
new
FormData
();
const
formData
=
new
FormData
();
formData
.
append
(
"file"
,
file
.
file
);
formData
.
append
(
"file"
,
params
.
file
);
formData
.
append
(
"isImg"
,
true
);
formData
.
append
(
"isImg"
,
true
);
console
.
log
(
5555
,
this
.
uploadUrl
);
sysUpload
(
formData
)
axios
.
then
((
res
)
=>
{
.
post
(
this
.
uploadUrl
,
formData
,
{
this
.
_value
.
push
({
"Content-type"
:
"multipart/form-data"
,
...
res
.
data
,
})
url
:
res
.
data
.
fullPath
,
.
then
(
name
:
res
.
data
.
originalName
,
(
res
)
=>
{
});
this
.
_value
.
push
(
res
.
data
);
this
.
$emit
(
"input"
,
this
.
_value
);
this
.
$emit
(
"input"
,
this
.
_value
);
Toast
.
success
(
"上传成功"
);
Toast
.
success
(
"上传成功"
);
},
})
(
err
)
=>
{
.
catch
((
)
=>
{
Toast
.
fail
(
"上传失败"
);
Toast
.
fail
(
"上传失败"
);
console
.
log
(
err
);
});
}
);
},
},
overLimit
()
{
overLimit
()
{
if
(
this
.
mode
===
"PC"
)
{
if
(
this
.
mode
===
"PC"
)
{
...
@@ -237,7 +210,6 @@ export default {
...
@@ -237,7 +210,6 @@ export default {
handleRemove
(
file
,
fileList
)
{
handleRemove
(
file
,
fileList
)
{
let
i
=
this
.
_value
.
findIndex
((
v
)
=>
v
.
name
===
file
.
name
);
let
i
=
this
.
_value
.
findIndex
((
v
)
=>
v
.
name
===
file
.
name
);
if
(
i
>
-
1
)
{
if
(
i
>
-
1
)
{
//this.removeFile(this._value[i].id)
this
.
_value
.
splice
(
i
,
1
);
this
.
_value
.
splice
(
i
,
1
);
this
.
$emit
(
"input"
,
this
.
_value
);
this
.
$emit
(
"input"
,
this
.
_value
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment