setting.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import { GET,POST } from "@/utils/http";
  2. import client from "@/stores/modules/client";
  3. import icpList from '@/utils/ipc'
  4. import tokenInfo from '@/stores/modules/token';
  5. //获取配置
  6. export async function getAllUserConfigs(data){
  7. return GET('/api/ai_image/camera_machine/get_all_user_configs',data)
  8. }
  9. //更新配置
  10. export async function setAllUserConfigs(data){
  11. const result = await POST('/api/ai_image/camera_machine/update_all_user_configs',data);
  12. // 同步到Python
  13. try {
  14. const clientStore = client();
  15. const tokenInfoStore = tokenInfo();
  16. const token = tokenInfoStore.getToken;
  17. await clientStore.ipc.invoke(icpList.setting.syncSysConfigs, {
  18. token: token || ''
  19. });
  20. } catch (error) {
  21. console.error('同步系统配置到Python失败:', error);
  22. // 同步失败不影响主流程
  23. }
  24. return result;
  25. }
  26. //获取左右脚配置
  27. export async function getTopTabs(data){
  28. return GET('/api/ai_image/camera_machine/get_top_tabs',data)
  29. }
  30. //获取配置下的动作列表
  31. export async function getDeviceConfigs(data){
  32. return GET('/api/ai_image/camera_machine/get_device_configs',data)
  33. }
  34. //点击切换执行配置
  35. export async function setLeftRightConfig(data){
  36. const result = await POST('/api/ai_image/camera_machine/update_left_right_config',data);
  37. // 同步到Python
  38. try {
  39. const clientStore = client();
  40. const tokenInfoStore = tokenInfo();
  41. const token = tokenInfoStore.getToken;
  42. await clientStore.ipc.invoke(icpList.setting.syncActions, {
  43. token: token || '',
  44. action: 'update',
  45. data: data
  46. });
  47. } catch (error) {
  48. console.error('同步左右脚配置到Python失败:', error);
  49. // 同步失败不影响主流程
  50. }
  51. return result;
  52. }
  53. //重置配置
  54. export async function restConfig(data){
  55. const result = await POST('/api/ai_image/camera_machine/reset_config',data);
  56. // 同步到Python
  57. try {
  58. const clientStore = client();
  59. const tokenInfoStore = tokenInfo();
  60. const token = tokenInfoStore.getToken;
  61. await clientStore.ipc.invoke(icpList.setting.syncActions, {
  62. token: token || '',
  63. action: 'reset',
  64. tab_id: data.tab_id
  65. });
  66. } catch (error) {
  67. console.error('同步重置配置到Python失败:', error);
  68. // 同步失败不影响主流程
  69. }
  70. return result;
  71. }
  72. //更新顶部TOP
  73. export async function setTabName(data){
  74. const result = await POST('/api/ai_image/camera_machine/update_tab_name',data);
  75. // 同步到Python
  76. try {
  77. const clientStore = client();
  78. const tokenInfoStore = tokenInfo();
  79. const token = tokenInfoStore.getToken;
  80. await clientStore.ipc.invoke(icpList.setting.syncActions, {
  81. token: token || '',
  82. action: 'rename',
  83. id: data.id,
  84. mode_name: data.mode_name
  85. });
  86. } catch (error) {
  87. console.error('同步重命名配置到Python失败:', error);
  88. // 同步失败不影响主流程
  89. }
  90. return result;
  91. }
  92. //删除可执行命令
  93. export async function delDviceConfig(data){
  94. const result = await POST('/api/ai_image/camera_machine/remove_device_config',data);
  95. // 同步到Python
  96. try {
  97. const clientStore = client();
  98. const tokenInfoStore = tokenInfo();
  99. const token = tokenInfoStore.getToken;
  100. await clientStore.ipc.invoke(icpList.setting.syncActions, {
  101. token: token || '',
  102. action: 'delete',
  103. id: data.id
  104. });
  105. } catch (error) {
  106. console.error('同步删除配置到Python失败:', error);
  107. // 同步失败不影响主流程
  108. }
  109. return result;
  110. }
  111. //获取设备配置详情
  112. export async function getDeviceConfigDetail(data){
  113. return GET('/api/ai_image/camera_machine/device_config_detail',data)
  114. }
  115. //根据条件查询可执行程序-单条
  116. export async function getDeviceConfigDetailQuery(data){
  117. return GET('/api/ai_image/camera_machine/device_config_detail_query',data)
  118. }
  119. //创建或者保存动作
  120. export async function saveDeviceConfig(data){
  121. const result = await POST('/api/ai_image/camera_machine/save_device_config',data);
  122. // 同步到Python
  123. try {
  124. const clientStore = client();
  125. const tokenInfoStore = tokenInfo();
  126. const token = tokenInfoStore.getToken;
  127. await clientStore.ipc.invoke(icpList.setting.syncActions, {
  128. token: token || '',
  129. action: 'save',
  130. data: data
  131. });
  132. } catch (error) {
  133. console.error('同步保存配置到Python失败:', error);
  134. // 同步失败不影响主流程
  135. }
  136. return result;
  137. }
  138. // 登录后同步数据
  139. export async function syncAfterLogin(token: string) {
  140. try {
  141. const clientStore = client();
  142. // 同步系统配置
  143. await clientStore.ipc.invoke(icpList.setting.syncSysConfigs, {
  144. token: token
  145. });
  146. // 同步动作配置
  147. await clientStore.ipc.invoke(icpList.setting.syncActions, {
  148. token: token,
  149. action: 'sync_all'
  150. });
  151. console.log('登录后数据同步成功');
  152. } catch (error) {
  153. console.error('登录后数据同步失败:', error);
  154. // 同步失败不影响登录流程
  155. }
  156. }