75 lines
2.7 KiB
JavaScript
75 lines
2.7 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const _sfc_main = {
|
|
__name: "camera",
|
|
setup(__props) {
|
|
let cameraContext;
|
|
const sysInfo = common_vendor.index.getSystemInfoSync();
|
|
common_vendor.onMounted(() => {
|
|
cameraContext = common_vendor.index.createCameraContext();
|
|
});
|
|
function takePhoto() {
|
|
cameraContext.takePhoto({
|
|
quality: "high",
|
|
success: async (res) => {
|
|
const src = res.tempImagePath;
|
|
const screenW = sysInfo.windowWidth;
|
|
const screenH = sysInfo.windowHeight;
|
|
const topMaskH = screenH * 0.25;
|
|
const middleH = screenH * 0.5;
|
|
const cutoutH = middleH * 0.6;
|
|
const cutoutW = cutoutH * 1.586;
|
|
const cutoutX = (screenW - cutoutW) / 2;
|
|
const cutoutY = topMaskH + (middleH - cutoutH) / 2;
|
|
const info = await common_vendor.index.getImageInfo({
|
|
src
|
|
});
|
|
const origW = info.width;
|
|
const origH = info.height;
|
|
const ratioW = origW / screenW;
|
|
const ratioH = origH / screenH;
|
|
const sx = cutoutX * ratioW;
|
|
const sy = cutoutY * ratioH;
|
|
const sWidth = cutoutW * ratioW;
|
|
const sHeight = cutoutH * ratioH;
|
|
const ctx = common_vendor.index.createCanvasContext("cropCanvas", {
|
|
enableScroll: false
|
|
});
|
|
ctx.drawImage(src, sx, sy, sWidth, sHeight, 0, 0, sWidth, sHeight);
|
|
ctx.draw(false, () => {
|
|
common_vendor.index.canvasToTempFilePath({
|
|
canvasId: "cropCanvas",
|
|
x: 0,
|
|
y: 0,
|
|
width: sWidth,
|
|
height: sHeight,
|
|
destWidth: sWidth,
|
|
destHeight: sHeight,
|
|
success: (cropRes) => {
|
|
common_vendor.index.setStorageSync("idcardPhoto", cropRes.tempFilePath);
|
|
common_vendor.index.navigateBack({
|
|
delta: 1
|
|
});
|
|
},
|
|
fail: (err) => {
|
|
common_vendor.index.__f__("error", "at pages/addoldman/camera.vue:103", "Canvas to TempFile Fail:", err);
|
|
}
|
|
});
|
|
});
|
|
},
|
|
fail: (err) => {
|
|
common_vendor.index.__f__("error", "at pages/addoldman/camera.vue:109", "Take Photo Fail:", err);
|
|
}
|
|
});
|
|
}
|
|
return (_ctx, _cache) => {
|
|
return {
|
|
a: common_vendor.o(takePhoto)
|
|
};
|
|
};
|
|
}
|
|
};
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-ac60523e"]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/addoldman/camera.js.map
|