2026-01-30 09:54:46 +08:00

102 lines
5.6 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
require("../../common/libraries/request.js");
const common_store_useWatermarkStore = require("../../common/store/useWatermarkStore.js");
require("../../common/store/useWeAppAuthStore.js");
require("../../common/store/useWorkStore.js");
const common_libraries_day = require("../../common/libraries/day.js");
const common_libraries_naviHelper = require("../../common/libraries/naviHelper.js");
const common_libraries_upload = require("../../common/libraries/upload.js");
const INDEX_watermark_camera_model = require("./model.js");
const watermark = common_store_useWatermarkStore.useWatermarkStore();
const method = {
handleWatermarkCameraSwitch() {
INDEX_watermark_camera_model.useModel.devicePosition.value = INDEX_watermark_camera_model.useModel.devicePosition.value === "back" ? "front" : "back";
},
takePhoto() {
const ctx = common_vendor.index.createCameraContext();
const systemInfo = common_vendor.index.getSystemInfoSync();
let canvasTop = (systemInfo == null ? void 0 : systemInfo.windowHeight) * (82 / 100);
console.log(systemInfo, "systemInfo");
ctx.takePhoto({
quality: "high",
success: (res) => {
var _a, _b;
common_vendor.index.showLoading({
title: ((_b = (_a = INDEX_watermark_camera_model.useModel) == null ? void 0 : _a.source) == null ? void 0 : _b.value) === "save" ? "正在保存..." : "正在上传...",
mask: true
});
let ctx2 = common_vendor.index.createCanvasContext("watermark_camera");
common_vendor.index.getImageInfo({
src: res == null ? void 0 : res.tempImagePath,
success: (img) => {
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
const { width, height } = img;
console.log(img, "img");
const canvasWidth = 430;
const canvasHeight = height * canvasWidth / width;
INDEX_watermark_camera_model.useModel.time.value = common_libraries_day.showCurrentTime();
ctx2.drawImage((res == null ? void 0 : res.tempImagePath) || "", 0, 0, canvasWidth, canvasHeight);
ctx2.setFillStyle("rgba(0, 0, 0, 0.2)");
ctx2.fillRect(0, canvasTop - 100, canvasWidth, 100);
ctx2.setFillStyle("#ff7105");
ctx2.fillRect(131, canvasTop - 75, 2, 28);
ctx2.fillStyle = "#fff";
ctx2.font = "500 16px Arial";
ctx2.fillText(((_c = (_b2 = (_a2 = INDEX_watermark_camera_model.useModel) == null ? void 0 : _a2.address) == null ? void 0 : _b2.value) == null ? void 0 : _c.address) || "", 15, canvasTop - 17);
ctx2.fillText(((_f = (_e = (_d = INDEX_watermark_camera_model.useModel) == null ? void 0 : _d.userInfo) == null ? void 0 : _e.value) == null ? void 0 : _f.name) || "没有登录", 141, canvasTop - 64);
ctx2.font = "500 12px Arial";
ctx2.fillText(
`${((_g = INDEX_watermark_camera_model.useModel) == null ? void 0 : _g.day.value) || ""} ${((_h = INDEX_watermark_camera_model.useModel) == null ? void 0 : _h.weekDay.value) || ""}`,
141,
canvasTop - 49
);
ctx2.setLineWidth(3);
ctx2.setStrokeStyle("#fff");
ctx2.font = "900 45px Arial";
ctx2.fillText(((_i = INDEX_watermark_camera_model.useModel) == null ? void 0 : _i.time.value) || "", 12, canvasTop - 45);
ctx2.strokeText(((_j = INDEX_watermark_camera_model.useModel) == null ? void 0 : _j.time.value) || "", 12, canvasTop - 45);
ctx2.stroke();
ctx2.draw(false, () => {
common_vendor.index.canvasToTempFilePath({
canvasId: "watermark_camera",
success: (nImg) => {
var _a3, _b3, _c2, _d2, _e2, _f2, _g2, _h2;
console.log(nImg, "nImg");
if (((_b3 = (_a3 = INDEX_watermark_camera_model.useModel) == null ? void 0 : _a3.source) == null ? void 0 : _b3.value) === "current") {
common_libraries_upload.uploadImgWatermark({
path: nImg == null ? void 0 : nImg.tempFilePath,
name: `${((_e2 = (_d2 = (_c2 = INDEX_watermark_camera_model.useModel) == null ? void 0 : _c2.userInfo) == null ? void 0 : _d2.value) == null ? void 0 : _e2.name) || "未登录"}-打卡-${((_f2 = INDEX_watermark_camera_model.useModel) == null ? void 0 : _f2.day.value) || ""}`
}).then((uploadRes) => {
console.log(uploadRes, "uploadRes");
watermark.watermarkInfo.value = uploadRes ? [uploadRes] : [];
common_vendor.index.navigateBack({
delta: 1
});
common_vendor.index.hideLoading();
}).catch((err) => {
console.log(err, "err");
common_vendor.index.hideLoading();
});
}
if (((_h2 = (_g2 = INDEX_watermark_camera_model.useModel) == null ? void 0 : _g2.source) == null ? void 0 : _h2.value) === "save") {
common_vendor.index.saveImageToPhotosAlbum({
filePath: nImg == null ? void 0 : nImg.tempFilePath,
success: function() {
common_libraries_naviHelper.showToast("保存成功");
console.log("save success");
}
});
}
}
});
});
}
});
console.log(res);
}
});
}
};
exports.method = method;