123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const _sfc_main = {
- data() {
- return {
- photoSrc: "",
- // 拍摄的照片路径
- isCameraReady: false,
- cameraContext: null
- };
- },
- onReady() {
- this.cameraContext = common_vendor.index.createCameraContext();
- },
- methods: {
- // 处理相机错误
- handleCameraError(e) {
- console.error("相机错误:", e);
- common_vendor.index.showToast({
- title: "相机初始化失败,请检查权限设置",
- icon: "none"
- });
- },
- // 拍照方法
- takePhoto() {
- if (!this.cameraContext) {
- common_vendor.index.showToast({
- title: "相机未就绪",
- icon: "none"
- });
- return;
- }
- common_vendor.index.showLoading({
- title: "拍照中..."
- });
- this.cameraContext.takePhoto({
- quality: "high",
- success: (res) => {
- this.photoSrc = res.tempImagePath;
- common_vendor.index.hideLoading();
- },
- fail: (err) => {
- console.error("拍照失败:", err);
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: "拍照失败,请重试",
- icon: "none"
- });
- }
- });
- },
- // 重新拍照
- retakePhoto() {
- this.photoSrc = "";
- },
- startInterview() {
- if (!this.photoSrc) {
- common_vendor.index.showToast({
- title: "请先完成拍照",
- icon: "none"
- });
- return;
- }
- common_vendor.index.showLoading({
- title: "验证中..."
- });
- setTimeout(() => {
- common_vendor.index.hideLoading();
- common_vendor.index.navigateTo({
- url: "/pages/camera/camera",
- fail: (err) => {
- console.error("页面跳转失败:", err);
- common_vendor.index.showToast({
- title: "页面跳转失败",
- icon: "none"
- });
- }
- });
- }, 1500);
- }
- // 上传照片方法(示例)
- /*
- uploadPhoto() {
- uni.uploadFile({
- url: 'https://your-api-endpoint.com/upload',
- filePath: this.photoSrc,
- name: 'photo',
- success: (res) => {
- const data = JSON.parse(res.data);
- if (data.success) {
- // 验证成功,继续流程
- } else {
- // 验证失败,提示用户
- uni.showToast({
- title: data.message || '验证失败,请重试',
- icon: 'none'
- });
- }
- },
- fail: (err) => {
- console.error('上传失败:', err);
- uni.showToast({
- title: '网络错误,请重试',
- icon: 'none'
- });
- }
- });
- }
- */
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: !$data.photoSrc
- }, !$data.photoSrc ? {
- b: common_vendor.o((...args) => $options.handleCameraError && $options.handleCameraError(...args))
- } : {
- c: $data.photoSrc
- }, {
- d: !$data.photoSrc
- }, !$data.photoSrc ? {
- e: common_vendor.o((...args) => $options.takePhoto && $options.takePhoto(...args))
- } : {
- f: common_vendor.o((...args) => $options.retakePhoto && $options.retakePhoto(...args)),
- g: common_vendor.o((...args) => $options.startInterview && $options.startInterview(...args))
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
- wx.createPage(MiniProgramPage);
|