Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
S
shop-new
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
王天霸
shop-new
Commits
e7c06a70
提交
e7c06a70
authored
1月 20, 2022
作者:
huaxinzhu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
商品详情,多图片上传
上级
4426ca84
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
107 行增加
和
71 行删除
+107
-71
goodsimg2.vue
src/views/system/goods/add/components/goodsimg2.vue
+107
-71
没有找到文件。
src/views/system/goods/add/components/goodsimg2.vue
浏览文件 @
e7c06a70
<
template
>
<
template
>
<div
class=
"goods-img"
>
<div
class=
"goods-img"
>
<div
id=
"wangeditor"
ref=
"editorElem"
>
<div
id=
"wangeditor"
ref=
"editorElem"
></div>
</div>
</div>
</div>
</
template
>
</
template
>
<
script
>
<
script
>
import
E
from
'wangeditor'
import
E
from
"wangeditor"
;
import
{
UploadImg
}
from
'@/api/module/goods'
import
{
UploadImg
}
from
"@/api/module/goods"
;
export
default
{
export
default
{
props
:
{
props
:
{
description
:
{
description
:
{
type
:
String
,
type
:
String
,
required
:
true
required
:
true
,
}
},
},
data
()
{
},
return
{
data
()
{
editor
:
null
return
{
}
allImg
:
[],
},
editor
:
null
,
mounted
()
{
};
let
that
=
this
},
// 富文本编辑器
mounted
()
{
const
editor
=
new
E
(
'#wangeditor'
)
let
that
=
this
;
editor
.
config
.
height
=
500
// 富文本编辑器
editor
.
config
.
uploadImgMaxLength
=
1
const
editor
=
new
E
(
"#wangeditor"
);
editor
.
config
.
customUploadImg
=
function
(
resultFiles
,
insertImgFn
)
{
editor
.
config
.
height
=
500
;
// resultFiles 是 input 中选中的文件列表
editor
.
config
.
uploadImgShowBase64
=
true
;
// insertImgFn 是获取图片 url 后,插入到编辑器的方法
editor
.
config
.
showLinkImg
=
false
;
// editor.config.uploadImgMaxLength = 1
that
.
getBase64
(
resultFiles
[
0
]).
then
((
res
)
=>
{
editor
.
config
.
customUploadImg
=
function
(
files
,
insertImgFn
)
{
let
result
=
res
.
split
(
","
)
// resultFiles 是 input 中选中的文件列表
let
Base64img
=
result
[
1
]
// insertImgFn 是获取图片 url 后,插入到编辑器的方法
// 上传图片,返回结果,将图片插入到编辑器中
that
.
getAllImg
(
files
).
then
((
res
)
=>
{
let
data
=
{
data
:
[]
};
let
imgBase
=
""
;
if
(
res
.
length
>
0
)
{
for
(
let
i
=
0
;
i
<
res
.
length
;
i
++
)
{
imgBase
=
""
;
imgBase
=
res
[
i
].
split
(
","
)[
1
];
if
(
imgBase
)
{
data
.
data
.
push
({
img_data
:
imgBase
});
}
}
// 上传图片,返回结果,将图片插入到编辑器中
UploadImg
(
data
).
then
((
res
)
=>
{
let
data
=
{
"img_data"
:
Base64img
}
UploadImg
(
data
).
then
(
res
=>
{
if
(
res
.
code
==
1
)
{
if
(
res
.
code
==
1
)
{
insertImgFn
(
res
.
data
.
image_url
)
if
(
res
.
code
==
1
&&
Array
.
isArray
(
res
.
data
)
&&
res
.
data
.
length
>
0
)
{
for
(
let
i
=
0
;
i
<
res
.
data
.
length
;
i
++
)
{
if
(
res
.
data
[
i
].
image_url
)
{
insertImgFn
(
res
.
data
[
i
].
image_url
);
}
}
}
}
}
})
})
;
}
)
}
// res.length > 0 end
}
}
);
editor
.
create
()
// });
this
.
editor
=
editor
};
if
(
this
.
description
)
{
editor
.
create
();
this
.
editor
.
txt
.
html
(
this
.
description
)
this
.
editor
=
editor
;
}
},
if
(
this
.
description
)
{
methods
:
{
this
.
editor
.
txt
.
html
(
this
.
description
);
initInfo
()
{
this
.
editor
=
null
},
getBase64
(
file
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
let
reader
=
new
FileReader
();
let
imgResult
=
""
;
reader
.
readAsDataURL
(
file
);
reader
.
onload
=
function
()
{
imgResult
=
reader
.
result
;
};
reader
.
onerror
=
function
(
error
)
{
reject
(
error
);
};
reader
.
onloadend
=
function
()
{
resolve
(
imgResult
);
};
});
},
}
}
}
},
methods
:
{
initInfo
()
{
this
.
editor
=
null
;
},
getBase64
(
file
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
let
reader
=
new
FileReader
();
let
imgResult
=
""
;
reader
.
readAsDataURL
(
file
);
reader
.
onload
=
function
()
{
imgResult
=
reader
.
result
;
};
reader
.
onerror
=
function
(
error
)
{
reject
(
error
);
};
reader
.
onloadend
=
function
()
{
resolve
(
imgResult
);
};
});
},
async
getAllImg
(
files
)
{
let
imgObj
=
{
img_data
:
""
};
let
res
=
[];
let
orgRes
=
""
;
files
.
forEach
((
item
)
=>
{
res
.
push
(
(
async
(
item
)
=>
{
return
await
this
.
getBase64
(
item
);
})(
item
)
);
});
return
await
Promise
.
all
(
res
);
},
},
};
</
script
>
</
script
>
<
style
scoped
>
<
style
scoped
>
.goods-img
{
.goods-img
{
padding
:
20px
;
padding
:
20px
;
}
}
/
deep
/
.w-e-text-container
{
/
deep
/
.w-e-text-container
{
z-index
:
1000
!important
;
z-index
:
1000
!important
;
}
}
/
deep
/
.w-e-toolbar
{
/
deep
/
.w-e-toolbar
{
z-index
:
1001
!important
;
z-index
:
1001
!important
;
}
}
</
style
>
</
style
>
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论