index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <div class="remote-control_main-container">
  3. <div class="te-c" style="color: #8C92A7">遥控器模拟器</div>
  4. <el-row align="middle" class="mar-top-20">
  5. <el-col :span="3"></el-col>
  6. <el-col :span="6"><div class="button up" title="单击鼠标右键可切换配置" @click="runLeft" >左脚</div></el-col>
  7. <el-col :span="6"><div class="button up" @click="run_take_picture">拍照</div></el-col>
  8. <el-col :span="6"><div class="button up" title="单击鼠标右键可切换配置" @click="runRight">右脚</div></el-col>
  9. <el-col :span="3"></el-col>
  10. </el-row>
  11. <!-- 左脚配置、拍照配置、右脚配置按钮行 -->
  12. <el-row align="middle">
  13. <el-col :span="3"></el-col>
  14. <el-col :span="6"><div class="button up" :class="{ disabled: canStop }" @click="handleLeftRightClick($event, 'left')"><span style="font-size: 12px;">左脚配置</span></div></el-col>
  15. <!-- ========== 新增:拍照配置按钮 ========== -->
  16. <el-col :span="6">
  17. <div class="button up photo-config-btn" :class="{ disabled: canStop, active: showPhotoMenu }" @click="handlePhotoConfigClick">
  18. <span style="font-size: 12px;">拍照配置</span>
  19. </div>
  20. </el-col>
  21. <el-col :span="6"><div class="button up" :class="{ disabled: canStop }" @click="handleLeftRightClick($event, 'right')"><span style="font-size: 12px;">右脚配置</span></div></el-col>
  22. <el-col :span="3"></el-col>
  23. </el-row>
  24. <el-row align="middle">
  25. <el-col :span="3"></el-col>
  26. <el-col :span="6">
  27. <div class="button up" @click="switchLED(1)" v-log="{ describe: { action: 'LED开启' } }">LED开</div>
  28. </el-col>
  29. <el-col :span="6">
  30. <div class="button up" :class="{ disabled: !canStop }" @click="oneClickStop" v-log="{ describe: { action: '一键停止拍摄' } }">停止</div>
  31. </el-col>
  32. <el-col :span="6">
  33. <div class="button up" @click="switchLED(0)" v-log="{ describe: { action: 'LED关闭' } }">LED关</div>
  34. </el-col>
  35. <el-col :span="3"></el-col>
  36. </el-row>
  37. <!-- 左脚配置菜单 -->
  38. <div v-if="showLeftMenu" class="context-menu" :style="{ left: menuPosition.x + 'px', top: menuPosition.y + 'px' }" @click.stop>
  39. <div class="menu-title">左脚配置</div>
  40. <div class="menu-items">
  41. <div
  42. v-for="tab in leftTabs"
  43. :key="tab.id"
  44. class="menu-item"
  45. :class="{ active: leftConfigId === tab.id }"
  46. @click="selectConfig('left', tab.id)"
  47. >
  48. {{ leftConfigId === tab.id ? '✓ ' : '' }}{{ tab.mode_name }}
  49. </div>
  50. </div>
  51. </div>
  52. <!-- 右脚配置菜单 -->
  53. <div v-if="showRightMenu" class="context-menu" :style="{ left: menuPosition.x + 'px', top: menuPosition.y + 'px' }" @click.stop>
  54. <div class="menu-title">右脚配置</div>
  55. <div class="menu-items">
  56. <div
  57. v-for="tab in rightTabs"
  58. :key="tab.id"
  59. class="menu-item"
  60. :class="{ active: rightConfigId === tab.id }"
  61. @click="selectConfig('right', tab.id)"
  62. >
  63. {{ rightConfigId === tab.id ? '✓ ' : '' }}{{ tab.mode_name }}
  64. </div>
  65. </div>
  66. </div>
  67. <!-- ========== 新增:拍照配置菜单 ========== -->
  68. <div v-if="showPhotoMenu" class="context-menu photo-menu" :style="{ left: menuPosition.x + 'px', top: menuPosition.y + 'px' }" @click.stop>
  69. <div class="menu-title">拍照配置</div>
  70. <div class="menu-items">
  71. <div
  72. v-for="point in pointList"
  73. :key="point.key"
  74. class="menu-item photo-point-item"
  75. :class="{ active: selectedPoint === point.key }"
  76. @click="selectPhotoPoint(point.key)"
  77. >
  78. <span class="point-name">{{ selectedPoint === point.key ? '✓ ' : '' }}点位 {{ point.key }}</span>
  79. <el-tag :type="point.connected ? 'success' : 'danger'" size="small">
  80. {{ point.connected ? '已连接' : '未连接' }}
  81. </el-tag>
  82. </div>
  83. </div>
  84. </div>
  85. <!-- 点击其他地方关闭菜单 -->
  86. <div v-if="showLeftMenu || showRightMenu || showPhotoMenu" class="menu-overlay" @click="closeMenus"></div>
  87. </div>
  88. </template>
  89. <script setup lang="ts">
  90. import { defineEmits, defineProps, ref, onMounted } from 'vue'
  91. import socket from "@/stores/modules/socket";
  92. import { getTopTabs, setLeftRightConfig, getAllUserConfigs } from '@/apis/setting';
  93. import { ElMessage } from 'element-plus';
  94. import client from "@/stores/modules/client";
  95. import icpList from '@/utils/ipc';
  96. // 初始化 WebSocket 状态管理
  97. const socketStore = socket()
  98. const clientStore = client()
  99. const props = defineProps<{
  100. canStop: boolean
  101. }>()
  102. const emit = defineEmits(['onRemoteControl'])
  103. // ========== 新增:点位配置 ==========
  104. const STORAGE_KEY = 'photo_point_name'
  105. const selectedPoint = ref('A')
  106. // 相机列表和点位列表
  107. const cameraList = ref<any[]>([])
  108. const pointList = ref<{ key: string; connected: boolean; cameraName: string }[]>([])
  109. // 初始化从 localStorage 读取配置
  110. onMounted(() => {
  111. const savedPoint = localStorage.getItem(STORAGE_KEY)
  112. if (savedPoint && ['A', 'B', 'C'].includes(savedPoint)) {
  113. selectedPoint.value = savedPoint
  114. }
  115. // 获取相机列表
  116. fetchCameraList()
  117. })
  118. // 获取相机列表并更新点位连接状态
  119. const fetchCameraList = () => {
  120. clientStore.ipc.invoke(icpList.camera.getCameraList).then(result => {
  121. if (result && result.CameraLists && Array.isArray(result.CameraLists)) {
  122. cameraList.value = result.CameraLists
  123. updatePointConnectionStatus()
  124. }
  125. }).catch(err => {
  126. console.error('获取相机列表失败:', err)
  127. })
  128. }
  129. // 更新点位连接状态(仅显示已绑定相机的点位)
  130. const updatePointConnectionStatus = async () => {
  131. let isoConfig: any = {}
  132. try {
  133. const result = await getAllUserConfigs({})
  134. if (result.code == 0 && result.data?.configs?.camera_configs?.iso_config) {
  135. isoConfig = result.data.configs.camera_configs.iso_config
  136. }
  137. } catch (err) {
  138. console.error('获取点位配置失败:', err)
  139. }
  140. // 只保留已绑定相机的点位
  141. const validPoints = Object.keys(isoConfig).filter(key => {
  142. const config = isoConfig[key]
  143. return config && config.CameraKey && config.CameraKey !== ''
  144. })
  145. if (validPoints.length === 0) {
  146. validPoints.push('A')
  147. }
  148. pointList.value = validPoints.map(key => {
  149. const cameraKey = isoConfig[key]?.CameraKey || ''
  150. let connected = false
  151. let cameraName = ''
  152. if (cameraKey) {
  153. const camera = cameraList.value.find(c => c.CameraKey === cameraKey)
  154. if (camera) {
  155. connected = camera.CameraStatus === true
  156. cameraName = camera.CameraName
  157. }
  158. }
  159. return { key, connected, cameraName }
  160. })
  161. // 验证当前选中的点位是否有效
  162. if (!pointList.value.some(p => p.key === selectedPoint.value)) {
  163. selectedPoint.value = pointList.value[0]?.key || 'A'
  164. }
  165. }
  166. // 暴露点位给父组件
  167. defineExpose({
  168. getSelectedPoint: () => selectedPoint.value
  169. })
  170. // ========== 配置切换相关 ==========
  171. const leftConfigId = ref(0)
  172. const rightConfigId = ref(0)
  173. const leftTabs = ref([]) // 左脚配置选项
  174. const rightTabs = ref([]) // 右脚配置选项
  175. const showLeftMenu = ref(false) // 显示左脚菜单
  176. const showRightMenu = ref(false) // 显示右脚菜单
  177. const showPhotoMenu = ref(false) // 显示拍照配置菜单
  178. const menuPosition = ref({ x: 0, y: 0 }) // 菜单位置
  179. const runLeft = async () => {
  180. emit('onRemoteControl','left')
  181. }
  182. const runRight = async () => {
  183. emit('onRemoteControl','right')
  184. }
  185. const run_take_picture = () => {
  186. emit('onRemoteControl','take_picture')
  187. }
  188. //LED
  189. const switchLED = async (value) => {
  190. socketStore.sendMessage({
  191. type: 'control_mcu',
  192. data: {
  193. device_name: "laser_position",
  194. value,
  195. }
  196. });
  197. }
  198. // 一键停止
  199. const oneClickStop = () => {
  200. if (!props.canStop) {
  201. return
  202. }
  203. socketStore.sendMessage({
  204. type: 'stop_action',
  205. })
  206. }
  207. // 右击左脚按钮
  208. const handleLeftRightClick = (event, type) => {
  209. if(props.canStop){
  210. return
  211. }
  212. event.preventDefault()
  213. menuPosition.value = { x: event.clientX, y: event.clientY }
  214. if (type === 'left') {
  215. showLeftMenu.value = true
  216. showRightMenu.value = false
  217. loadLeftConfig()
  218. } else {
  219. showRightMenu.value = true
  220. showLeftMenu.value = false
  221. loadRightConfig()
  222. }
  223. }
  224. // 加载左脚配置
  225. const loadLeftConfig = async () => {
  226. try {
  227. const result = await getTopTabs({ type: 0 })
  228. if (result.code === 0) {
  229. leftConfigId.value = result.data.select_configs.left
  230. leftTabs.value = result.data.tabs
  231. }
  232. } catch (error) {
  233. console.error('加载左脚配置失败:', error)
  234. }
  235. }
  236. // 加载右脚配置
  237. const loadRightConfig = async () => {
  238. try {
  239. const result = await getTopTabs({ type: 1 })
  240. if (result.code === 0) {
  241. rightConfigId.value = result.data.select_configs.right
  242. rightTabs.value = result.data.tabs
  243. }
  244. } catch (error) {
  245. console.error('加载右脚配置失败:', error)
  246. }
  247. }
  248. // 选择配置
  249. const selectConfig = async (type, configId) => {
  250. try {
  251. if(props.canStop){
  252. ElMessage.error('正在拍摄中,请稍候')
  253. return
  254. }
  255. const result = await setLeftRightConfig({
  256. type: type,
  257. id: configId
  258. })
  259. if (result.code === 0) {
  260. if (type === 'left') {
  261. leftConfigId.value = configId
  262. showLeftMenu.value = false
  263. } else {
  264. rightConfigId.value = configId
  265. showRightMenu.value = false
  266. }
  267. ElMessage.success('配置切换成功')
  268. }
  269. } catch (error) {
  270. console.error('切换配置失败:', error)
  271. ElMessage.error('配置切换失败')
  272. }
  273. }
  274. // 关闭菜单
  275. const closeMenus = () => {
  276. showLeftMenu.value = false
  277. showRightMenu.value = false
  278. showPhotoMenu.value = false
  279. }
  280. // ========== 新增:拍照配置菜单相关 ==========
  281. // 点击拍照配置按钮
  282. const handlePhotoConfigClick = (event: MouseEvent) => {
  283. if(props.canStop){
  284. return
  285. }
  286. event.preventDefault()
  287. menuPosition.value = { x: event.clientX, y: event.clientY }
  288. // 关闭其他菜单
  289. showLeftMenu.value = false
  290. showRightMenu.value = false
  291. // 获取最新的相机列表
  292. fetchCameraList()
  293. showPhotoMenu.value = true
  294. }
  295. // 选择拍照点位
  296. const selectPhotoPoint = (pointKey: string) => {
  297. selectedPoint.value = pointKey
  298. localStorage.setItem(STORAGE_KEY, pointKey)
  299. showPhotoMenu.value = false
  300. ElMessage.success(`已切换到点位 ${pointKey}`)
  301. }
  302. </script>
  303. <style scoped lang="scss">
  304. .remote-control_main-container {
  305. background: #EAECED;
  306. height: 450px;
  307. width: 300px;
  308. margin: 0 auto;
  309. margin-top: 10px;
  310. padding-top: 30px;
  311. background: url(@/assets/images/Photography/yk.png) 0px 0px no-repeat;
  312. background-size: 300px 450px;
  313. }
  314. .button {
  315. width: 60px;
  316. height: 60px;
  317. background: #fff;
  318. border-radius: 60px;
  319. line-height: 60px;
  320. color: #474747;
  321. margin: 0 auto;
  322. box-shadow: 0 2px 8px 0 rgba(0,0,0,0.2);
  323. background: url(@/assets/images/Photography/hui.png) 0px 0px no-repeat;
  324. background-size: 60px 60px;
  325. }
  326. .el-row {
  327. min-height: 100px;
  328. }
  329. .button:hover {
  330. background: url(@/assets/images/Photography/lan.png) 0px 0px no-repeat;
  331. background-size: 60px 60px;
  332. cursor: pointer;
  333. }
  334. .button.stop {
  335. background: #ff4c00;
  336. color: white;
  337. border-radius: 10px;
  338. width: 120px;
  339. height: 40px;
  340. line-height: 40px;
  341. font-size: 14px;
  342. margin: 0 auto;
  343. }
  344. .button.stop:hover {
  345. background: #e64500;
  346. }
  347. .button.disabled {
  348. opacity: 0.5;
  349. cursor: not-allowed;
  350. pointer-events: none;
  351. }
  352. .context-menu {
  353. position: fixed;
  354. background: white;
  355. border: 1px solid #e4e7ed;
  356. border-radius: 4px;
  357. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  358. z-index: 2000;
  359. min-width: 120px;
  360. max-width: 200px;
  361. }
  362. .menu-title {
  363. padding: 8px 12px;
  364. font-size: 12px;
  365. font-weight: 600;
  366. color: #606266;
  367. border-bottom: 1px solid #ebeef5;
  368. background-color: #f5f7fa;
  369. }
  370. .menu-items {
  371. max-height: 150px;
  372. overflow: auto;
  373. }
  374. .menu-item {
  375. padding: 8px 12px;
  376. font-size: 14px;
  377. color: #606266;
  378. cursor: pointer;
  379. transition: background-color 0.2s;
  380. &:hover {
  381. background-color: #f5f7fa;
  382. }
  383. &.active {
  384. color: #2957FF;
  385. font-weight: 600;
  386. }
  387. }
  388. .menu-overlay {
  389. position: fixed;
  390. top: 0;
  391. left: 0;
  392. right: 0;
  393. bottom: 0;
  394. z-index: 1999;
  395. }
  396. /* 新增:拍照配置样式 */
  397. .photo-config-btn.active {
  398. background: url(@/assets/images/Photography/lan.png) 0px 0px no-repeat !important;
  399. background-size: 60px 60px !important;
  400. }
  401. .photo-menu {
  402. min-width: 180px;
  403. }
  404. .photo-point-item {
  405. display: flex;
  406. align-items: center;
  407. justify-content: space-between;
  408. gap: 12px;
  409. }
  410. .photo-point-item .point-name {
  411. flex-shrink: 0;
  412. }
  413. </style>