face-photo.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = {
  4. data() {
  5. return {
  6. photoSrc: "",
  7. // 拍摄的照片路径
  8. isCameraReady: false,
  9. cameraContext: null
  10. };
  11. },
  12. onReady() {
  13. this.cameraContext = common_vendor.index.createCameraContext();
  14. },
  15. methods: {
  16. // 处理相机错误
  17. handleCameraError(e) {
  18. console.error("相机错误:", e);
  19. common_vendor.index.showToast({
  20. title: "相机初始化失败,请检查权限设置",
  21. icon: "none"
  22. });
  23. },
  24. // 拍照方法
  25. takePhoto() {
  26. if (!this.cameraContext) {
  27. common_vendor.index.showToast({
  28. title: "相机未就绪",
  29. icon: "none"
  30. });
  31. return;
  32. }
  33. common_vendor.index.showLoading({
  34. title: "拍照中..."
  35. });
  36. this.cameraContext.takePhoto({
  37. quality: "high",
  38. success: (res) => {
  39. this.photoSrc = res.tempImagePath;
  40. common_vendor.index.hideLoading();
  41. },
  42. fail: (err) => {
  43. console.error("拍照失败:", err);
  44. common_vendor.index.hideLoading();
  45. common_vendor.index.showToast({
  46. title: "拍照失败,请重试",
  47. icon: "none"
  48. });
  49. }
  50. });
  51. },
  52. // 重新拍照
  53. retakePhoto() {
  54. this.photoSrc = "";
  55. },
  56. startInterview() {
  57. if (!this.photoSrc) {
  58. common_vendor.index.showToast({
  59. title: "请先完成拍照",
  60. icon: "none"
  61. });
  62. return;
  63. }
  64. common_vendor.index.showLoading({
  65. title: "验证中..."
  66. });
  67. setTimeout(() => {
  68. common_vendor.index.hideLoading();
  69. common_vendor.index.navigateTo({
  70. url: "/pages/camera/camera",
  71. fail: (err) => {
  72. console.error("页面跳转失败:", err);
  73. common_vendor.index.showToast({
  74. title: "页面跳转失败",
  75. icon: "none"
  76. });
  77. }
  78. });
  79. }, 1500);
  80. }
  81. // 上传照片方法(示例)
  82. /*
  83. uploadPhoto() {
  84. uni.uploadFile({
  85. url: 'https://your-api-endpoint.com/upload',
  86. filePath: this.photoSrc,
  87. name: 'photo',
  88. success: (res) => {
  89. const data = JSON.parse(res.data);
  90. if (data.success) {
  91. // 验证成功,继续流程
  92. } else {
  93. // 验证失败,提示用户
  94. uni.showToast({
  95. title: data.message || '验证失败,请重试',
  96. icon: 'none'
  97. });
  98. }
  99. },
  100. fail: (err) => {
  101. console.error('上传失败:', err);
  102. uni.showToast({
  103. title: '网络错误,请重试',
  104. icon: 'none'
  105. });
  106. }
  107. });
  108. }
  109. */
  110. }
  111. };
  112. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  113. return common_vendor.e({
  114. a: !$data.photoSrc
  115. }, !$data.photoSrc ? {
  116. b: common_vendor.o((...args) => $options.handleCameraError && $options.handleCameraError(...args))
  117. } : {
  118. c: $data.photoSrc
  119. }, {
  120. d: !$data.photoSrc
  121. }, !$data.photoSrc ? {
  122. e: common_vendor.o((...args) => $options.takePhoto && $options.takePhoto(...args))
  123. } : {
  124. f: common_vendor.o((...args) => $options.retakePhoto && $options.retakePhoto(...args)),
  125. g: common_vendor.o((...args) => $options.startInterview && $options.startInterview(...args))
  126. });
  127. }
  128. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  129. wx.createPage(MiniProgramPage);