|
@@ -16,7 +16,7 @@ import {
|
|
|
showLoadingToast,
|
|
|
showToast,
|
|
|
} from "vant";
|
|
|
-import state from "/src/state";
|
|
|
+import state, { IPlatform } from "/src/state";
|
|
|
import { api_closeCamera, api_openCamera, api_savePicture } from "/src/helpers/communication";
|
|
|
import store from "store";
|
|
|
import iconInfo from "../image/info.svg";
|
|
@@ -41,14 +41,30 @@ export default defineComponent({
|
|
|
const svg: any = document.getElementById("osmdSvgPage1");
|
|
|
if (svg) {
|
|
|
const _canvas = svg2canvas(svg.outerHTML);
|
|
|
- const base64 = _canvas.toDataURL("image/png", 1);
|
|
|
- const res = await api_savePicture({
|
|
|
- base64,
|
|
|
- });
|
|
|
- if (res?.content?.status === "success") {
|
|
|
- showToast({ message: "保存成功", type: "success" });
|
|
|
+
|
|
|
+ if (state.platform === IPlatform.PC) {
|
|
|
+ let el: any = document.createElement("a");
|
|
|
+ // 设置 href 为图片经过 base64 编码后的字符串,默认为 png 格式
|
|
|
+ el.href = _canvas.toDataURL();
|
|
|
+ el.download = state.examSongName;
|
|
|
+
|
|
|
+ // 创建一个点击事件并对 a 标签进行触发
|
|
|
+ const event = new MouseEvent("click");
|
|
|
+ el.dispatchEvent(event);
|
|
|
+ setTimeout(() => {
|
|
|
+ showToast({ message: "保存成功", type: "success" });
|
|
|
+ el = null
|
|
|
+ }, 300);
|
|
|
} else {
|
|
|
- showToast({ message: "保存失败", type: "fail" });
|
|
|
+ const base64 = _canvas.toDataURL("image/png", 1);
|
|
|
+ const res = await api_savePicture({
|
|
|
+ base64,
|
|
|
+ });
|
|
|
+ if (res?.content?.status === "success") {
|
|
|
+ showToast({ message: "保存成功", type: "success" });
|
|
|
+ } else {
|
|
|
+ showToast({ message: "保存失败", type: "fail" });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}, 500);
|