index.vue 8.0 KB

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