diff --git a/pages/6170/callPolice/index.vue b/pages/6170/callPolice/index.vue index 99f4a2e..9bc4a43 100644 --- a/pages/6170/callPolice/index.vue +++ b/pages/6170/callPolice/index.vue @@ -47,448 +47,421 @@ \ No newline at end of file diff --git a/pages/6170/deviceControl/index.vue b/pages/6170/deviceControl/index.vue index 8ed74fe..de4b3ea 100644 --- a/pages/6170/deviceControl/index.vue +++ b/pages/6170/deviceControl/index.vue @@ -271,7 +271,8 @@ \ No newline at end of file diff --git a/utils/function.js b/utils/function.js index 1080018..e73e41f 100644 --- a/utils/function.js +++ b/utils/function.js @@ -2,15 +2,67 @@ * 生成短ID (16位字符) */ export const generateShortId = () => { - const crypto = window.crypto || window.msCrypto; - - if (crypto?.getRandomValues) { - return Array.from(crypto.getRandomValues(new Uint32Array(3))) - .map(n => n.toString(36)) - .join('') - .slice(0, 16); - } - - return Date.now().toString(36) + Math.random().toString(36).substr(2, 8); + const crypto = window.crypto || window.msCrypto; + + if (crypto?.getRandomValues) { + return Array.from(crypto.getRandomValues(new Uint32Array(3))) + .map(n => n.toString(36)) + .join('') + .slice(0, 16); + } + + return Date.now().toString(36) + Math.random().toString(36).substr(2, 8); }; -export default generateShortId; \ No newline at end of file +export default generateShortId; + +// 获取设备实时状态的 +/** + * 获取设备状态(带自动轮询) + * @param {Object} options - 配置对象 + * @param {number} options.functionMode - 功能模式 + * @param {string} options.batchId - 批次ID + * @param {Object} options.sendInfo - 设备信息 + * @param {string} options.sendInfo.typeName - 类型名称 + * @param {string} options.sendInfo.deviceImei - 设备IMEI + * @param {number} [options.interval=500] - 轮询间隔(毫秒) + * @param {Function} apiClient - 接口调用函数 + */ +export async function getdeviceSTatus({ + functionMode, + batchId, + typeName, + deviceImei, + interval +}, apiClient) { + const checkStatus = async () => { + try { + const res = await apiClient({ + functionMode, + batchId, + typeName, + deviceImei + }); + if (res.code !== 200) { + throw new Error(res.msg || '请求失败'); + } + switch (res.data.functionAccess) { + case 'OK': + return res; + case 'ACTIVE': + await new Promise(r => setTimeout(r, interval)); + return checkStatus(); + case 'FAILED': + throw new Error('设备操作失败'); + case 'TIMEOUT': + throw new Error('设备响应超时'); + default: + throw new Error('未知状态'); + } + } catch (error) { + console.error('设备状态轮询错误:', error); + throw error; + } + }; + + return checkStatus(); +} \ No newline at end of file