vue3_example.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * Vue3 调用示例
  3. *
  4. * 架构:Vue3 -> Electron IPC (或 Node.js API) -> child_process -> laser_wrapper.py -> entry.pyd/.so
  5. */
  6. const VUE3_CODE = `
  7. // 在 Vue3 中调用
  8. import { ref } from 'vue';
  9. // 假设通过 Electron IPC 调用
  10. const invokeLaser = async (apiName, dataObj = null) => {
  11. let b64Data = null;
  12. if (dataObj) {
  13. b64Data = btoa(unescape(encodeURIComponent(JSON.stringify(dataObj))));
  14. }
  15. // 调用 electron 暴露的 API
  16. return await window.electronAPI.callPythonAPI(apiName, b64Data);
  17. };
  18. export default {
  19. setup() {
  20. const result = ref(null);
  21. const handleGetPath = async () => {
  22. try {
  23. result.value = await invokeLaser('getpath');
  24. } catch (e) {
  25. console.error(e);
  26. }
  27. };
  28. const handleLoadData = async () => {
  29. const params = [
  30. "path/to/locate.csv",
  31. "path/to/measure.csv",
  32. "5.0", // angle_cone
  33. "2.0" // axial_inclination
  34. ];
  35. try {
  36. result.value = await invokeLaser('loaddata', params);
  37. } catch (e) {
  38. console.error(e);
  39. }
  40. };
  41. return { handleGetPath, handleLoadData, result };
  42. }
  43. }
  44. `;
  45. console.log("Vue3 Example Code generated.");