ApiCloud套壳App下保存图片
通过ClipboardJS 可以对文本进行复制,但是文本需要放入到html input标签的value里面,否则可能复制不成功
<input type="text" id="Content" readonly="readonly" data-clipboard-text value="@Model.Content" />
$(function () {
var copyBtn = new ClipboardJS('.section_content_right');
copyBtn.on("success", function (e) {
layer.msg("复制成功");
});
copyBtn.on("error", function (e) {
//复制失败;
console.log(e.action)
});
})
通过APICloud 加载对应的JS,然后调用对应的图片保存方法,必须在写apiready=function(){},否则,会报错,api not defined
img是图片的线上完整Url
apiready = function () {
};
function Save(img) {
var ipAddress = $("#ipAddress").val();
img = ipAddress + img;
var timestamp = Date.parse(new Date());
var urls = "fs://image/" + timestamp + ".png"
//layer.confirm("保存图片到相册", 'copyAtSheetPage');
layer.confirm('保存图片到相册?', {
btn: ['是', '否'] //按钮
}, function () {
api.download({
url: img,
savePath: urls
}, function (ret, err) {
if (ret) {
if (ret.state == 1) {
api.saveMediaToAlbum({
path: urls
}, function (ret, err) {
if (ret && ret.status) {
layer.msg('保存成功', { time: 3000 }, function () {
layer.closeAll('dialog');
});
} else {
layer.msg('保存失败', { time: 3000 }, function () {
layer.closeAll('dialog');
});
}
});
}
} else {
layer.msg(JSON.stringify(err), { time: 3000 }, function () {
layer.closeAll('dialog');
});
}
});
})
}