|
|
@@ -12,7 +12,7 @@ import { useUuidStore } from '@/stores/modules/uuid'
|
|
|
import useUserInfo from "@/stores/modules/user";
|
|
|
import configInfo from '@/stores/modules/config';
|
|
|
import tokenInfo from "@/stores/modules/token";
|
|
|
-import { getAllUserConfigs } from '@/apis/setting';
|
|
|
+import { getAllUserConfigs, getTopTabs } from '@/apis/setting';
|
|
|
|
|
|
export default function usePhotography() {
|
|
|
const loading = ref(false)
|
|
|
@@ -40,6 +40,15 @@ export default function usePhotography() {
|
|
|
const searchGoodsArtNo = ref('')
|
|
|
let smartShooterTimeout: ReturnType<typeof setTimeout> | null = null
|
|
|
|
|
|
+ // ==================== 演示模式 ====================
|
|
|
+ const isDemoMode = ref(false) // 是否处于演示模式
|
|
|
+ const demoGoodsArtNo = ref('演示货号1') // 演示货号
|
|
|
+ const demoProgramType = ref('执行左脚程序') // 演示程序类型
|
|
|
+ const demoConfigList = ref<{id: number, mode_name: string}[]>([]) // 演示配置列表
|
|
|
+ const demoSelectedConfigId = ref<number | null>(null) // 选中的演示配置ID
|
|
|
+ const demoDialogVisible = ref(false) // 演示配置对话框
|
|
|
+ // ==================== 演示模式 END ====================
|
|
|
+
|
|
|
// 初始化 WebSocket 状态管理
|
|
|
const socketStore = socket()
|
|
|
const uuidStore = useUuidStore();
|
|
|
@@ -768,6 +777,20 @@ const onRemoteControl = async (type) => {
|
|
|
if (runAction.value.goods_art_no) {
|
|
|
scheduleSegment(runAction.value.goods_art_no)
|
|
|
}
|
|
|
+
|
|
|
+ // 演示模式:拍摄完成后自动删除货号
|
|
|
+ if (isDemoMode.value) {
|
|
|
+ const demoGoodsNo = demoGoodsArtNo.value
|
|
|
+ setTimeout(async () => {
|
|
|
+ try {
|
|
|
+ await del({ goods_art_nos: [demoGoodsNo] })
|
|
|
+ ElMessage.info('演示拍摄完成,货号已自动删除')
|
|
|
+ } catch (e) {
|
|
|
+ console.error('自动删除演示货号失败:', e)
|
|
|
+ }
|
|
|
+ }, 2000)
|
|
|
+ }
|
|
|
+
|
|
|
runLoading.value = false;
|
|
|
runAction.value.goods_art_no = '';
|
|
|
runAction.value.action = '';
|
|
|
@@ -943,6 +966,129 @@ const onRemoteControl = async (type) => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 演示模式:获取配置列表
|
|
|
+ * @param type 0-左脚程序, 1-右脚程序
|
|
|
+ */
|
|
|
+ const fetchDemoConfigList = async (type: number) => {
|
|
|
+ demoConfigList.value = []
|
|
|
+ demoSelectedConfigId.value = null
|
|
|
+
|
|
|
+ const result = await getTopTabs({ type })
|
|
|
+ if (result.code == 0 && result.data?.tabs) {
|
|
|
+ demoConfigList.value = result.data.tabs
|
|
|
+ if (demoConfigList.value.length > 0) {
|
|
|
+ demoSelectedConfigId.value = demoConfigList.value[0].id
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 演示模式:打开配置选择对话框
|
|
|
+ */
|
|
|
+ const openDemoMode = async () => {
|
|
|
+ demoGoodsArtNo.value = '演示货号1'
|
|
|
+ demoProgramType.value = '执行左脚程序'
|
|
|
+ demoSelectedConfigId.value = null
|
|
|
+ demoConfigList.value = []
|
|
|
+
|
|
|
+ // 获取左脚程序配置列表
|
|
|
+ await fetchDemoConfigList(0)
|
|
|
+
|
|
|
+ demoDialogVisible.value = true
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 演示模式:监听程序类型变化,重新获取配置列表
|
|
|
+ */
|
|
|
+ const onDemoProgramTypeChange = async () => {
|
|
|
+ const type = demoProgramType.value === '执行左脚程序' ? 0 : 1
|
|
|
+ await fetchDemoConfigList(type)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 演示模式:开始演示
|
|
|
+ */
|
|
|
+ const startDemoMode = async () => {
|
|
|
+ if (!demoGoodsArtNo.value.trim()) {
|
|
|
+ ElMessage.error('请输入货号')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!demoSelectedConfigId.value) {
|
|
|
+ ElMessage.error('请选择配置')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置演示模式标记
|
|
|
+ isDemoMode.value = true
|
|
|
+ // 设置货号
|
|
|
+ goods_art_no.value = demoGoodsArtNo.value
|
|
|
+ goods_art_no_tpl.value = demoGoodsArtNo.value
|
|
|
+
|
|
|
+ demoDialogVisible.value = false
|
|
|
+
|
|
|
+ // 直接启动拍摄
|
|
|
+ runGoods({
|
|
|
+ action: demoProgramType.value,
|
|
|
+ goods_art_no: demoGoodsArtNo.value
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 演示模式:停止演示
|
|
|
+ * 执行完成后删除货号,然后退出演示模式
|
|
|
+ */
|
|
|
+ const stopDemoMode = async () => {
|
|
|
+ if (!isDemoMode.value) return
|
|
|
+
|
|
|
+ // 停止当前运行
|
|
|
+ if (runLoading.value || takePictureLoading.value) {
|
|
|
+ socketStore.sendMessage({
|
|
|
+ type: 'stop_action',
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 等待拍摄停止,然后删除货号
|
|
|
+ const demoGoodsNo = demoGoodsArtNo.value
|
|
|
+
|
|
|
+ // 延迟等待设备停止
|
|
|
+ setTimeout(async () => {
|
|
|
+ // 重置状态
|
|
|
+ resetStatus()
|
|
|
+
|
|
|
+ // 删除演示货号
|
|
|
+ try {
|
|
|
+ await del({ goods_art_nos: [demoGoodsNo] })
|
|
|
+ } catch (e) {
|
|
|
+ console.error('删除演示货号失败:', e)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 退出演示模式
|
|
|
+ isDemoMode.value = false
|
|
|
+ goods_art_no.value = ''
|
|
|
+ goods_art_no_tpl.value = ''
|
|
|
+ ElMessage.success('已退出演示模式')
|
|
|
+ }, 500)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 演示模式:监听拍摄完成事件
|
|
|
+ * 演示模式下拍摄完成后自动删除货号
|
|
|
+ */
|
|
|
+ const handlePhotoTakeFinishForDemo = (goodsArtNo: string) => {
|
|
|
+ if (isDemoMode.value && goodsArtNo === demoGoodsArtNo.value) {
|
|
|
+ // 延迟删除,等待数据写入完成
|
|
|
+ setTimeout(async () => {
|
|
|
+ try {
|
|
|
+ await del({ goods_art_nos: [demoGoodsArtNo.value] })
|
|
|
+ ElMessage.info('演示拍摄完成,货号已自动删除')
|
|
|
+ } catch (e) {
|
|
|
+ console.error('自动删除演示货号失败:', e)
|
|
|
+ }
|
|
|
+ }, 2000)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 删除所有货号。
|
|
|
*/
|
|
|
const deleteAllGoods = function () {
|
|
|
@@ -993,6 +1139,17 @@ const onRemoteControl = async (type) => {
|
|
|
initEventListeners,
|
|
|
cleanupEventListeners,
|
|
|
resetStatus,
|
|
|
+ // 演示模式
|
|
|
+ isDemoMode,
|
|
|
+ demoGoodsArtNo,
|
|
|
+ demoProgramType,
|
|
|
+ demoConfigList,
|
|
|
+ demoSelectedConfigId,
|
|
|
+ demoDialogVisible,
|
|
|
+ openDemoMode,
|
|
|
+ startDemoMode,
|
|
|
+ stopDemoMode,
|
|
|
+ onDemoProgramTypeChange,
|
|
|
}
|
|
|
}
|
|
|
|