index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <headerBar
  3. title="拍摄物体镜头矫正"
  4. :menu="[
  5. {
  6. type:'setting'
  7. },
  8. {
  9. type:'remoteControl'
  10. },
  11. ]"
  12. />
  13. <div class="mb-4">
  14. <template v-if="!show">
  15. <div>{{useUserInfoStore.userInfo.account_name}}</div>
  16. <div>{{useUserInfoStore.userInfo.phone}}</div>
  17. </template>
  18. <template v-else>
  19. <img :src="src" width="500px" height="500px"/>
  20. <img :src="preview" width="500px" height="500px"/>
  21. </template>
  22. <!--
  23. <el-button @click="showVideo">实时预览</el-button>
  24. <el-button @click="hideVideo">关闭预览</el-button>
  25. <el-button @click="takePictures">拍照</el-button>
  26. <el-button @click="socketConnect">socket 连接</el-button>
  27. <el-button @click="connect_mcu">发送设备连接检测请求</el-button>
  28. <el-button @click="connect_bluetooth">发送遥控器请求</el-button>
  29. <el-button @click="socketDisconnect">socket 断开</el-button>
  30. <el-button @click="loginError">登录失败</el-button>
  31. <el-button type="primary" @click="loginIn">登录成功</el-button>
  32. <el-button type="success" @click="showLoginDialog">登录</el-button>
  33. <el-button type="info" @click="checkVisible = true">软件检查</el-button>
  34. -->
  35. <el-button type="info" @click="openSeeting">打开设置</el-button>
  36. <el-button type="info" @click="openTplSeeting">打开主图和详情设置</el-button>
  37. <el-button type="info" @click="connect_mcu">链接MCU</el-button>
  38. <el-button type="info" @click="connect_bluetooth">连接蓝牙</el-button>
  39. <el-button @click="socketDisconnect">socket 断开</el-button>
  40. <router-link
  41. class="mar-left-10"
  42. :to="{
  43. name:'PhotographyCheck'
  44. }"
  45. >
  46. <el-button type="warning">拍摄物体</el-button>
  47. </router-link>
  48. <router-link
  49. class="mar-left-10"
  50. :to="{
  51. name:'PhotographyShot'
  52. }"
  53. >
  54. <el-button type="warning">拍摄商品</el-button>
  55. </router-link>
  56. <!-- <hardware-check v-model="checkVisible" @confirm="onCheckComplete"></hardware-check>-->
  57. <Login v-model:dialogVisible="dialogVisible" @login-success="handleLoginSuccess"/>
  58. <el-button
  59. class="mar-left-10"
  60. type="primary" @click="loginIn">登录成功</el-button>
  61. </div>
  62. <div class="mb-4">
  63. <el-input v-model="paramsKey" placeholder="参数名称"></el-input>
  64. <el-input v-model="paramsValue" placeholder="参数值"></el-input>
  65. <el-button @click="setParams">保存</el-button>
  66. </div>
  67. </template>
  68. <script setup lang="ts">
  69. import { ref } from 'vue'
  70. import useUserInfo from "@/stores/modules/user";
  71. import { login, getUserInfo } from '@/apis/user';
  72. import Login from '@/components/login/index.vue';
  73. import HardwareCheck from '@/components/check/index.vue'
  74. import headerBar from '@/components/header-bar/index.vue'
  75. import { getFilePath,getRouterUrl } from '@/utils/appfun'
  76. import {useRouter} from "vue-router";
  77. const Router = useRouter()
  78. const useUserInfoStore = useUserInfo();
  79. const dialogVisible = ref(false);
  80. const checkVisible = ref(false)
  81. import client from "@/stores/modules/client";
  82. import icpList from '@/utils/ipc'
  83. import socket from "@/stores/modules/socket";
  84. const clientStore = client();
  85. function showLoginDialog() {
  86. dialogVisible.value = true;
  87. }
  88. function handleLoginSuccess() {
  89. // 处理登录成功后的逻辑
  90. console.log('登录成功');
  91. }
  92. function onCheckComplete(){
  93. }
  94. async function loginIn() {
  95. console.log('aaa')
  96. const res = await login({
  97. "site":1,
  98. "username":"13777879245",
  99. "password":"753159",
  100. "type":1,
  101. "device":"aigc-photo"
  102. })
  103. const userRes = await getUserInfo({
  104. "site":1,
  105. "token":res.data.token
  106. })
  107. useUserInfoStore.updateUserInfo(userRes.data)
  108. }
  109. async function loginError() {
  110. const res = await login({
  111. "site":1,
  112. "username":"18679381902",
  113. "password":"123456",
  114. "device":"aigc-photo"
  115. })
  116. console.log(res)
  117. }
  118. const show = ref(false)
  119. const imgKey = ref(0)
  120. const src = ref('http://localhost:5513/liveview.jpg')
  121. let interval:any = null
  122. function showVideo(){
  123. if(clientStore.isClient){
  124. clientStore.ipc.removeAllListeners(icpList.camera.PreviewShow);
  125. clientStore.ipc.send(icpList.camera.PreviewShow);
  126. clientStore.ipc.on(icpList.camera.PreviewShow, async (event, result) => {
  127. show.value = true;
  128. src.value = `http://localhost:5513/liveview.jpg?key=${imgKey.value}`
  129. interval = setInterval(()=>{
  130. imgKey.value++;
  131. src.value = `http://localhost:5513/liveview.jpg?key=${imgKey.value}`
  132. },100)
  133. })
  134. }
  135. }
  136. const preview = ref('http://localhost:5513/preview.jpg')
  137. const previewKey = ref(0)
  138. function hideVideo(){
  139. if(clientStore.isClient){
  140. clientStore.ipc.removeAllListeners(icpList.camera.PreviewHide);
  141. clientStore.ipc.send(icpList.camera.PreviewHide);
  142. clientStore.ipc.on(icpList.camera.PreviewHide, async (event, result) => {
  143. show.value = false;
  144. if(interval) clearInterval(interval)
  145. })
  146. }
  147. }
  148. const paramsKey = ref('')
  149. const paramsValue = ref('')
  150. function setParams(){
  151. if(clientStore.isClient){
  152. clientStore.ipc.removeAllListeners(icpList.camera.setParams);
  153. clientStore.ipc.send(icpList.camera.setParams,{
  154. key:paramsKey.value,
  155. value:paramsValue.value
  156. });
  157. }
  158. }
  159. function takePictures(){
  160. if(clientStore.isClient){
  161. clientStore.ipc.removeAllListeners(icpList.camera.takePictures);
  162. clientStore.ipc.send(icpList.camera.takePictures);
  163. clientStore.ipc.on(icpList.camera.takePictures, async (event, result) => {
  164. setTimeout(()=>{
  165. previewKey.value++;
  166. preview.value = `http://localhost:5513/preview.jpg?key=${previewKey.value}`
  167. },1000)
  168. })
  169. }
  170. }
  171. // 初始化 WebSocket 状态管理
  172. const socketStore = socket()
  173. function socketConnect(){
  174. if(clientStore.isClient){
  175. socketStore.connectSocket()
  176. clientStore.ipc.on(icpList.socket.message, async (event, result) => {
  177. console.log(result)
  178. })
  179. }
  180. }
  181. async function connect_mcu(){
  182. if(clientStore.isClient){
  183. await socketStore.connectSocket();
  184. socketStore.sendMessage({
  185. type: 'connect_mcu',
  186. data:"connect_mcu"
  187. })
  188. }
  189. }
  190. async function connect_bluetooth(){
  191. await socketStore.connectSocket();
  192. socketStore.sendMessage({type: 'connect_bluetooth',})
  193. clientStore.ipc.on(icpList.socket.message+'_blue_tooth', (event, result) => {
  194. console.log('4')
  195. console.log(result)
  196. });
  197. }
  198. function socketDisconnect(){
  199. if(clientStore.isClient){
  200. socketStore.disconnectSocket()
  201. }
  202. }
  203. function openSeeting(){
  204. console.log('aaaaa')
  205. clientStore.ipc.removeAllListeners(icpList.utils.openMain);
  206. let params = {
  207. title: '设置',
  208. width: 900,
  209. height: 630,
  210. frame: true,
  211. id:"seeting",
  212. url:"http://localhost:3000/#/setting"
  213. }
  214. clientStore.ipc.send(icpList.utils.openMain,params);
  215. }
  216. function openTplSeeting(){
  217. const { href } = Router.resolve({
  218. name: 'PhotographyDetail',
  219. query:{
  220. goods_art_nos:['ARN1411512'],
  221. }
  222. })
  223. clientStore.ipc.removeAllListeners(icpList.utils.openMain);
  224. let params = {
  225. title: '主图和详情设置',
  226. width: 900,
  227. height: 650,
  228. frame: true,
  229. id:"photographyDetail",
  230. url:getRouterUrl(href)
  231. }
  232. clientStore.ipc.send(icpList.utils.openMain,params);
  233. }
  234. </script>
  235. <style scoped>
  236. </style>