Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas_plus
/
dj-car-life-system
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit aa331854
authored
Mar 24, 2026
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix 上传文件改造
1 parent
5e04e419
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
165 additions
and
138 deletions
src/components/d2-file-import-dialog/index.vue
src/components/index.js
src/views/goods/productManage/list.vue
src/components/d2-file-import-dialog/index.vue
0 → 100644
View file @
aa33185
<!-- 文件导入弹框通用组件 -->
<
template
>
<d2-dialog
:is-visible=
"isVisible"
:title=
"title"
@
closeDialog=
"handleClose"
@
confirmDialog=
"handleConfirm"
>
<el-form
ref=
"fileFormRef"
label-width=
"120px"
:model=
"form"
:rules=
"rules"
>
<el-form-item
label=
"导入文件:"
prop=
"fileName"
>
<el-col
:span=
"16"
>
<el-input
v-model=
"form.fileName"
readonly
/>
</el-col>
<el-col
class=
"m-l-md"
:span=
"4"
>
<el-button
class=
"import-btn"
>
导入文件
<input
ref=
"fileInput"
:accept=
"accept"
class=
"import-input"
type=
"file"
@
change=
"onFileChange"
@
click=
"$event.target.value = null"
>
<el-link
class=
"import-template"
icon=
"el-icon-link"
type=
"primary"
@
click=
"$emit('downloadTemplate')"
>
{{
templateName
}}
</el-link>
</el-button>
</el-col>
</el-form-item>
</el-form>
</d2-dialog>
</
template
>
<
script
>
export
default
{
name
:
"D2FileImportDialog"
,
props
:
{
isVisible
:
{
type
:
Boolean
,
default
:
false
,
},
title
:
{
type
:
String
,
default
:
"批量导入"
,
},
accept
:
{
type
:
String
,
default
:
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
,
},
maxSize
:
{
type
:
Number
,
default
:
9
,
},
templateName
:
{
type
:
String
,
default
:
"模版下载"
,
},
},
data
()
{
return
{
form
:
{
fileName
:
""
},
fileData
:
null
,
rules
:
{
fileName
:
[{
required
:
true
,
message
:
"请上传文件"
,
trigger
:
"change"
}],
},
};
},
watch
:
{
isVisible
(
val
)
{
if
(
!
val
)
{
this
.
resetForm
();
}
},
},
methods
:
{
resetForm
()
{
this
.
$refs
.
fileFormRef
&&
this
.
$refs
.
fileFormRef
.
resetFields
();
this
.
fileData
=
null
;
if
(
this
.
$refs
.
fileInput
)
{
this
.
$refs
.
fileInput
.
value
=
""
;
}
},
handleClose
()
{
this
.
resetForm
();
this
.
$emit
(
"closeDialog"
);
},
handleConfirm
()
{
this
.
$refs
.
fileFormRef
.
validate
((
valid
)
=>
{
if
(
valid
&&
this
.
fileData
)
{
this
.
$emit
(
"confirmDialog"
,
{
fileName
:
this
.
form
.
fileName
,
fileData
:
this
.
fileData
,
});
}
});
},
onFileChange
(
e
)
{
if
(
!
e
.
target
.
files
||
!
e
.
target
.
files
[
0
])
return
;
const
file
=
e
.
target
.
files
[
0
];
const
size
=
file
.
size
/
1024
/
1024
;
e
.
target
.
value
=
""
;
if
(
size
<
this
.
maxSize
)
{
this
.
form
.
fileName
=
file
.
name
;
const
reader
=
new
FileReader
();
reader
.
readAsDataURL
(
file
);
reader
.
onload
=
(
event
)
=>
{
const
imgFile
=
event
.
target
.
result
;
const
arrBase64
=
imgFile
.
split
(
","
);
const
ext
=
file
.
name
.
split
(
"."
).
pop
();
this
.
fileData
=
ext
+
"@"
+
arrBase64
[
1
];
};
}
else
{
this
.
notice
.
errorTips
(
`上传文件不可超过
${
this
.
maxSize
}
M`
);
}
},
},
};
</
script
>
<
style
scoped
>
.m-l-md
{
margin-left
:
20px
;
}
.import-btn
{
position
:
relative
;
}
.import-input
{
opacity
:
0
;
position
:
absolute
;
right
:
0
;
top
:
0
;
width
:
98px
;
height
:
36px
;
cursor
:
pointer
;
font-size
:
0
;
}
.import-template
{
position
:
absolute
;
height
:
20px
;
top
:
50px
;
left
:
0
;
}
</
style
>
src/components/index.js
View file @
aa33185
...
@@ -19,6 +19,7 @@ Vue.component("D2IconSvg", () => import("./d2-icon-svg/index.vue"))
...
@@ -19,6 +19,7 @@ Vue.component("D2IconSvg", () => import("./d2-icon-svg/index.vue"))
Vue
.
component
(
"D2TableHeader"
,
()
=>
import
(
"./d2-table-header/index.vue"
))
Vue
.
component
(
"D2TableHeader"
,
()
=>
import
(
"./d2-table-header/index.vue"
))
Vue
.
component
(
"D2Table"
,
()
=>
import
(
"./d2-table/index.vue"
))
Vue
.
component
(
"D2Table"
,
()
=>
import
(
"./d2-table/index.vue"
))
Vue
.
component
(
"D2Dialog"
,
()
=>
import
(
"./d2-dialog/index.vue"
))
Vue
.
component
(
"D2Dialog"
,
()
=>
import
(
"./d2-dialog/index.vue"
))
Vue
.
component
(
"D2FileImportDialog"
,
()
=>
import
(
"./d2-file-import-dialog/index.vue"
))
Vue
.
component
(
"D2Form"
,
()
=>
import
(
"./d2-form/index.vue"
))
Vue
.
component
(
"D2Form"
,
()
=>
import
(
"./d2-form/index.vue"
))
Vue
.
component
(
"D2Search"
,
()
=>
import
(
"./d2-search/index.vue"
))
Vue
.
component
(
"D2Search"
,
()
=>
import
(
"./d2-search/index.vue"
))
Vue
.
component
(
"RelateStoreDialog"
,
()
=>
Vue
.
component
(
"RelateStoreDialog"
,
()
=>
...
...
src/views/goods/productManage/list.vue
View file @
aa33185
...
@@ -92,79 +92,19 @@
...
@@ -92,79 +92,19 @@
:position-type-list=
"positionTypeList"
:position-type-list=
"positionTypeList"
@
handleDrawerClose=
"handleSkuDrawerClose"
/>
@
handleDrawerClose=
"handleSkuDrawerClose"
/>
<!-- 轻改SKU批量导入 -->
<!-- 轻改SKU批量导入 -->
<d2-dialog
:is-visible=
"fileVisible"
<d2-file-import-dialog
:is-visible=
"fileVisible"
template-name=
"轻改模版下载"
title=
"批量导入轻改SKU"
title=
"批量导入轻改SKU"
@
closeDialog=
"handleBatchImport"
@
closeDialog=
"handleBatchImport"
@
confirmDialog=
"handleConfirmImport"
>
@
confirmDialog=
"handleConfirmImport"
<slot>
@
downloadTemplate=
"exportTemplate('qinggai')"
/>
<el-form
ref=
"fileRuleForm"
label-width=
"120px"
:model=
"fileForm"
:rules=
"fileRules"
>
<el-form-item
label=
"导入文件:"
prop=
"fileName"
>
<el-col
:span=
"16"
>
<el-input
v-model=
"fileForm.fileName"
readonly
/>
</el-col>
<el-col
class=
"m-l-md"
:span=
"4"
>
<el-button
class=
"import-btn"
>
导入文件
<input
id=
"fileUploadQinggai"
accept=
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
class=
"import-input"
type=
"file"
@
change=
"importFile($event, 'qinggai')"
>
<el-link
class=
"import-template"
icon=
"el-icon-link"
type=
"primary"
@
click=
"exportTemplate('qinggai')"
>
轻改模版下载
</el-link>
</el-button>
</el-col>
</el-form-item>
</el-form>
</slot>
</d2-dialog>
<!-- 延保SKU批量导入 -->
<!-- 延保SKU批量导入 -->
<d2-dialog
:is-visible=
"fileVisibleExtension"
<d2-file-import-dialog
:is-visible=
"fileVisibleExtension"
template-name=
"延保模版下载"
title=
"批量导入延保SKU"
title=
"批量导入延保SKU"
@
closeDialog=
"handleBatchImportExtension"
@
closeDialog=
"handleBatchImportExtension"
@
confirmDialog=
"handleConfirmImportExtension"
>
@
confirmDialog=
"handleConfirmImportExtension"
<slot>
@
downloadTemplate=
"exportTemplate('yanbao')"
/>
<el-form
ref=
"fileRuleFormExtension"
label-width=
"120px"
:model=
"fileFormExtension"
:rules=
"fileRules"
>
<el-form-item
label=
"导入文件:"
prop=
"fileName"
>
<el-col
:span=
"16"
>
<el-input
v-model=
"fileFormExtension.fileName"
readonly
/>
</el-col>
<el-col
class=
"m-l-md"
:span=
"4"
>
<el-button
class=
"import-btn"
>
导入文件
<input
id=
"fileUploadYanbao"
accept=
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
class=
"import-input"
type=
"file"
@
change=
"importFile($event, 'yanbao')"
>
<el-link
class=
"import-template"
icon=
"el-icon-link"
type=
"primary"
@
click=
"exportTemplate('yanbao')"
>
延保模版下载
</el-link>
</el-button>
</el-col>
</el-form-item>
</el-form>
</slot>
</d2-dialog>
</d2-container>
</d2-container>
</template>
</template>
...
@@ -446,15 +386,8 @@ export default {
...
@@ -446,15 +386,8 @@ export default {
},
},
selfBuildGoodsType
:
baseConfig
.
selfBuildGoodsType
||
""
,
// 服务商自建类目值
selfBuildGoodsType
:
baseConfig
.
selfBuildGoodsType
||
""
,
// 服务商自建类目值
positionTypeList
:
[],
// 太阳膜类商品部位
positionTypeList
:
[],
// 太阳膜类商品部位
fileRules
:
{
fileName
:
[{
required
:
true
,
message
:
"请上传文件"
,
trigger
:
"change"
}],
},
fileForm
:
{},
fileVisible
:
false
,
fileVisible
:
false
,
fileInfo
:
null
,
fileFormExtension
:
{},
fileVisibleExtension
:
false
,
fileVisibleExtension
:
false
,
fileInfoExtension
:
null
,
// 新 SPU 接口不返回 upgradeGoodsList,此时所有行均为 SPU 级
// 新 SPU 接口不返回 upgradeGoodsList,此时所有行均为 SPU 级
spuOnlyMode
:
false
,
spuOnlyMode
:
false
,
commodityDetailInfoSkuId
:
""
,
// 商品详情SKU ID
commodityDetailInfoSkuId
:
""
,
// 商品详情SKU ID
...
@@ -790,44 +723,15 @@ export default {
...
@@ -790,44 +723,15 @@ export default {
},
},
handleBatchImport
()
{
handleBatchImport
()
{
this
.
fileVisible
=
!
this
.
fileVisible
;
this
.
fileVisible
=
!
this
.
fileVisible
;
this
.
$refs
.
fileRuleForm
&&
this
.
$refs
.
fileRuleForm
.
resetFields
();
this
.
fileInfo
=
null
;
},
},
handleBatchImportExtension
()
{
handleBatchImportExtension
()
{
this
.
fileVisibleExtension
=
!
this
.
fileVisibleExtension
;
this
.
fileVisibleExtension
=
!
this
.
fileVisibleExtension
;
this
.
$refs
.
fileRuleFormExtension
&&
this
.
$refs
.
fileRuleFormExtension
.
resetFields
();
this
.
fileInfoExtension
=
null
;
},
// 上传文件,转码为base64;type 为 qinggai 或 yanbao
importFile
(
e
,
type
)
{
if
(
!
e
.
target
.
files
||
!
e
.
target
.
files
[
0
])
return
;
const
size
=
e
.
target
.
files
[
0
].
size
/
1024
/
1024
;
const
formKey
=
type
===
"qinggai"
?
"fileForm"
:
"fileFormExtension"
;
const
fileInfoKey
=
type
===
"qinggai"
?
"fileInfo"
:
"fileInfoExtension"
;
const
inputId
=
type
===
"qinggai"
?
"fileUploadQinggai"
:
"fileUploadYanbao"
;
if
(
size
<
9
)
{
this
.
$set
(
this
[
formKey
],
"fileName"
,
e
.
target
.
files
[
0
].
name
);
const
reader
=
new
FileReader
();
reader
.
readAsDataURL
(
e
.
target
.
files
[
0
]);
reader
.
onload
=
(
event
)
=>
{
const
imgFile
=
event
.
target
.
result
;
const
arrBase64
=
imgFile
.
split
(
","
);
this
[
fileInfoKey
]
=
e
.
target
.
files
[
0
].
name
.
split
(
"."
)[
e
.
target
.
files
[
0
].
name
.
split
(
"."
)?.
length
-
1
]
+
"@"
+
arrBase64
[
1
];
document
.
getElementById
(
inputId
).
value
=
""
;
};
}
else
{
this
.
notice
.
errorTips
(
"上传文件不可超过9M"
);
document
.
getElementById
(
inputId
).
value
=
""
;
}
},
},
handleConfirmImport
()
{
handleConfirmImport
({
fileName
,
fileData
})
{
this
.
$refs
.
fileRuleForm
.
validate
((
valid
)
=>
{
qinggaiImport
({
file
:
fileData
}).
then
((
res
)
=>
{
if
(
valid
)
{
qinggaiImport
({
file
:
this
.
fileInfo
}).
then
((
res
)
=>
{
if
(
res
)
{
if
(
res
)
{
const
list
=
[...
this
.
updateList
,
{
const
list
=
[...
this
.
updateList
,
{
name
:
this
.
fileForm
.
fileName
,
name
:
fileName
,
ifSuccess
:
false
,
ifSuccess
:
false
,
uuid
:
res
,
uuid
:
res
,
type
:
"upload"
,
type
:
"upload"
,
...
@@ -837,16 +741,12 @@ export default {
...
@@ -837,16 +741,12 @@ export default {
this
.
handleBatchImport
();
this
.
handleBatchImport
();
}
}
});
});
}
});
},
},
handleConfirmImportExtension
()
{
handleConfirmImportExtension
({
fileName
,
fileData
})
{
this
.
$refs
.
fileRuleFormExtension
.
validate
((
valid
)
=>
{
yanbaoImport
({
file
:
fileData
}).
then
((
res
)
=>
{
if
(
valid
)
{
yanbaoImport
({
file
:
this
.
fileInfoExtension
}).
then
((
res
)
=>
{
if
(
res
)
{
if
(
res
)
{
const
list
=
[...
this
.
updateList
,
{
const
list
=
[...
this
.
updateList
,
{
name
:
this
.
fileFormExtension
.
fileName
,
name
:
fileName
,
ifSuccess
:
false
,
ifSuccess
:
false
,
uuid
:
res
,
uuid
:
res
,
type
:
"upload"
,
type
:
"upload"
,
...
@@ -856,8 +756,6 @@ export default {
...
@@ -856,8 +756,6 @@ export default {
this
.
handleBatchImportExtension
();
this
.
handleBatchImportExtension
();
}
}
});
});
}
});
},
},
handleReset
()
{
handleReset
()
{
this
.
searchForm
=
this
.
$options
.
data
.
call
(
this
).
searchForm
;
this
.
searchForm
=
this
.
$options
.
data
.
call
(
this
).
searchForm
;
...
@@ -996,26 +894,4 @@ export default {
...
@@ -996,26 +894,4 @@ export default {
.product-manage
p
{
.product-manage
p
{
margin
:
0
;
margin
:
0
;
}
}
.product-manage
.m-l-md
{
margin-left
:
20px
;
}
.product-manage
.import-btn
{
position
:
relative
;
}
.product-manage
.import-input
{
opacity
:
0
;
position
:
absolute
;
right
:
0
;
top
:
0
;
width
:
98px
;
height
:
36px
;
cursor
:
pointer
;
font-size
:
0
;
}
.product-manage
.import-template
{
position
:
absolute
;
height
:
20px
;
top
:
50px
;
left
:
0
;
}
</
style
>
</
style
>
Write
Preview
Markdown
is supported
Attach a file
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 post a comment