Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
V
vue-form
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
vue-form
Commits
96c12f47
提交
96c12f47
authored
12月 28, 2019
作者:
王鹏飞
浏览文件
操作
浏览文件
下载
差异文件
uypdate
上级
1777f283
a670e096
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
102 行增加
和
41 行删除
+102
-41
file.js
examples/sofia-form/file.js
+3
-0
elemInfo.md
src/components/elem-form/upload-form/elemInfo.md
+7
-10
ajax.js
src/components/elem-form/upload-form/src/ajax.js
+85
-0
uploadForm.vue
src/components/elem-form/upload-form/src/uploadForm.vue
+7
-31
没有找到文件。
examples/sofia-form/file.js
浏览文件 @
96c12f47
...
@@ -29,6 +29,9 @@ export default {
...
@@ -29,6 +29,9 @@ export default {
'file_type'
:
10
,
'file_type'
:
10
,
'project_id'
:
1001
'project_id'
:
1001
},
},
'attrs'
:
{
'multiple'
:
true
},
'html'
:
`
'html'
:
`
<div style="color: #72818c; font-size: 14px;">
<div style="color: #72818c; font-size: 14px;">
<p style="margin: 0;">申请者需要将有效身份证件原件扫描或者拍照后提交。</p>
<p style="margin: 0;">申请者需要将有效身份证件原件扫描或者拍照后提交。</p>
...
...
src/components/elem-form/upload-form/elemInfo.md
浏览文件 @
96c12f47
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
| 字段值 | 说明 | 字段属性 | 默认值 |
| 字段值 | 说明 | 字段属性 | 默认值 |
| ------- | ------------------------- | ------- | ----- |
| ------- | ------------------------- | ------- | ----- |
|
`type`
| 类型:
`String`
; 说明:组件类型名 | 自定义字段 |
`upload-form`
|
|
`type`
| 类型:
`String`
; 说明:组件类型名 | 自定义字段 |
`upload-form`
|
|
`action`
| 类型:
`String`
; 说明:请求接口path | 自定义字段 |
`` |
|
`action`
| 类型:
`String`
; 说明:上传请求接口path | 自定义字段 |
`` |
| `deleteAction` | 类型:`String`; 说明:删除请求接口path | 自定义字段 | ``
|
|
`html`
| 类型:
`String`
; 说明:上传说明,支持html | 自定义字段 |
`` |
|
`html`
| 类型:
`String`
; 说明:上传说明,支持html | 自定义字段 |
`` |
| `label` | 类型:`String`; 说明:组件左侧显示名称 | element-ui el-form-item对应字段 | `''` |
| `label` | 类型:`String`; 说明:组件左侧显示名称 | element-ui el-form-item对应字段 | `''` |
| `label-width` | 类型:`String`; 说明:组件左侧显示名称宽度(加单位),父级设置可以子级继承 | element-ui el-form-item对应字段 | `''` |
| `label-width` | 类型:`String`; 说明:组件左侧显示名称宽度(加单位),父级设置可以子级继承 | element-ui el-form-item对应字段 | `''` |
...
@@ -24,11 +25,13 @@
...
@@ -24,11 +25,13 @@
'required': true,
'required': true,
'disabled': false,
'disabled': false,
'model': 'real_name_cn',
'model': 'real_name_cn',
'model-width'
:
''
,
'placeholder'
:
'请输入姓名'
,
'action': '',
'action': '',
'data': {
'data': {
},
'deleteAction': '',
'deleteData': {
},
},
'html': `
'html': `
<div
style=
"color: #72818c; font-size: 14px;"
>
<div
style=
"color: #72818c; font-size: 14px;"
>
...
@@ -45,13 +48,7 @@
...
@@ -45,13 +48,7 @@
'rules': [
'rules': [
{
{
'required': true,
'required': true,
'message'
:
'请输入姓名'
,
'message': '请上传',
'trigger'
:
'blur'
},
{
'min'
:
3
,
'max'
:
5
,
'message'
:
'长度在 3 到 5 个字符'
,
'trigger': 'blur'
'trigger': 'blur'
}
}
]
]
...
...
src/components/elem-form/upload-form/src/ajax.js
0 → 100755
浏览文件 @
96c12f47
function
getError
(
action
,
option
,
xhr
)
{
let
msg
if
(
xhr
.
response
)
{
msg
=
`
${
xhr
.
response
.
error
||
xhr
.
response
}
`
}
else
if
(
xhr
.
responseText
)
{
msg
=
`
${
xhr
.
responseText
}
`
}
else
{
msg
=
`fail to post
${
action
}
${
xhr
.
status
}
`
}
const
err
=
new
Error
(
msg
)
err
.
status
=
xhr
.
status
err
.
method
=
'post'
err
.
url
=
action
return
err
}
function
getBody
(
xhr
)
{
const
text
=
xhr
.
responseText
||
xhr
.
response
if
(
!
text
)
{
return
text
}
try
{
return
JSON
.
parse
(
text
)
}
catch
(
e
)
{
return
text
}
}
export
default
function
upload
(
option
)
{
if
(
typeof
XMLHttpRequest
===
'undefined'
)
{
return
}
const
xhr
=
new
XMLHttpRequest
()
const
action
=
option
.
action
if
(
xhr
.
upload
)
{
xhr
.
upload
.
onprogress
=
function
progress
(
e
)
{
if
(
e
.
total
>
0
)
{
e
.
percent
=
e
.
loaded
/
e
.
total
*
100
}
option
.
onProgress
(
e
)
}
}
const
formData
=
new
FormData
()
if
(
option
.
data
)
{
Object
.
keys
(
option
.
data
).
forEach
(
key
=>
{
formData
.
append
(
key
,
option
.
data
[
key
])
})
}
formData
.
append
(
option
.
filename
,
option
.
file
,
option
.
file
.
name
)
xhr
.
onerror
=
function
error
(
e
)
{
option
.
onError
(
e
)
}
xhr
.
onload
=
function
onload
()
{
if
(
xhr
.
status
<
200
||
xhr
.
status
>=
300
)
{
return
option
.
onError
(
getError
(
action
,
option
,
xhr
))
}
option
.
onSuccess
(
getBody
(
xhr
))
}
xhr
.
open
(
'post'
,
action
,
true
)
if
(
option
.
withCredentials
&&
'withCredentials'
in
xhr
)
{
xhr
.
withCredentials
=
true
}
const
headers
=
option
.
headers
||
{}
for
(
let
item
in
headers
)
{
if
(
headers
.
hasOwnProperty
(
item
)
&&
headers
[
item
]
!==
null
)
{
xhr
.
setRequestHeader
(
item
,
headers
[
item
])
}
}
xhr
.
send
(
formData
)
return
xhr
}
src/components/elem-form/upload-form/src/uploadForm.vue
浏览文件 @
96c12f47
...
@@ -13,12 +13,13 @@
...
@@ -13,12 +13,13 @@
:action=
"item.action"
:action=
"item.action"
:data=
"item.data"
:data=
"item.data"
:before-upload=
"beforeUploadFile"
:before-upload=
"beforeUploadFile"
:on-success=
"onSuccessFile"
:with-credentials=
"true"
:with-credentials=
"true"
v-bind=
"item.attrs ||
{}">
v-bind=
"item.attrs ||
{}">
<el-button
type=
"primary"
>
点击上传
</el-button>
<el-button
type=
"primary"
>
点击上传
</el-button>
<template
v-if=
"formData[item.model]"
>
<template
v-if=
"formData[item.model]"
>
<!-- 遍历显示文件 -->
<!-- 遍历显示文件 -->
{{
successFileUrl
.
replace
(
/.*
\/([^\/]
*
\.
docx
)
$/gi
,
'$1'
)
}}
</
template
>
</
template
>
</el-upload>
</el-upload>
<div
class=
'info'
style=
"line-height: 1.5;"
v-html=
"item.html"
></div>
<div
class=
'info'
style=
"line-height: 1.5;"
v-html=
"item.html"
></div>
...
@@ -35,6 +36,8 @@
...
@@ -35,6 +36,8 @@
</template>
</template>
<
script
>
<
script
>
// import ajax from './ajax'
export
default
{
export
default
{
name
:
'UploadForm'
,
name
:
'UploadForm'
,
componentName
:
'UploadForm'
,
componentName
:
'UploadForm'
,
...
@@ -54,40 +57,13 @@ export default {
...
@@ -54,40 +57,13 @@ export default {
},
},
data
()
{
data
()
{
return
{
return
{
successFileUrl
:
''
,
filesArr
:
[]
filesArr
:
[],
file
:
{
id
:
'WU_FILE_0'
,
name
:
''
,
type
:
''
,
lastModifiedDate
:
''
,
size
:
''
,
file
:
''
}
}
}
},
},
methods
:
{
methods
:
{
handleChange
(
file
,
filelist
)
{
beforeUploadFile
(
file
)
{},
this
.
file
.
name
=
file
.
raw
.
name
onSuccessFile
(
response
,
file
,
fileList
)
{
this
.
file
.
type
=
file
.
raw
.
type
this
.
file
.
lastModifiedDate
=
file
.
raw
.
lastModifiedDate
this
.
file
.
size
=
file
.
raw
.
size
this
.
file
.
file
=
file
.
raw
},
beforeUploadFile
(
file
)
{
debugger
debugger
},
uploadFile
()
{
// if (!/\.(docx)$/gi.test(this.file.name)) {
// this.$message.error('文件格式不对,请重新上传')
// this.filesArr.pop()
// return
// }
// const loading = this.$loading({ lock: true, text: '', spinner: '', background: 'rgba(255, 255, 255, 0.9)' })
// cAction.chapterAction.uploadFile(this.file).then(data => {
// this.successFileUrl = data.url
// this.filesArr.pop()
// }).catch(e => { this.filesArr.pop(); this.$message.error(e.message) }).finally(() => { loading.close() })
}
}
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论