Explorar el Código

feat: 产品-数据解析的调试,改为远程调试

yanglzh hace 1 año
padre
commit
3d2535551d

+ 2 - 0
src/api/device/index.ts

@@ -8,6 +8,8 @@ export default {
     },
   },
   product: {
+    // 脚本测试执行
+    scriptRun: (data: object) => post('/product/script/run', data),
     // 设备属性设置
     propertySet: (data: object) => post('/product/property/set', data),
     // 获取设备接入信息

+ 5 - 2
src/components/codeEditor/index.vue

@@ -66,7 +66,7 @@ let props = defineProps({
   onchange: {
     type: Object as any,
     required: false,
-    default: () => {},
+    default: () => { },
   },
   cursorBlinkRate: {
     type: Number,
@@ -77,7 +77,7 @@ let props = defineProps({
 
 const editor = ref();
 
-let coder;
+let coder: any;
 
 nextTick(() => {
   coder = _CodeMirror.fromTextArea(editor.value, {
@@ -85,8 +85,11 @@ nextTick(() => {
     // 缩进格式
     tabSize: 2,
     // 显示行号
+    autofocus: true,
     lineNumbers: true,
     lineWrapping: true,
+    showCursorWhenSelecting: true,
+    cursorBlinkRate: 530,
     theme: "ayu-mirage",
     matchTags: { bothTags: true },
     foldGutter: true,

+ 28 - 13
src/views/iot/device/product/component/dataParse.vue

@@ -11,7 +11,7 @@
 		</div>
 	</div>
 	<el-button type="primary" style="margin-top:20px" v-auth="'save'" @click="saveCode">保存脚本</el-button>
-	<el-button type="primary" style="margin-top:20px" v-auth="'debug'" @click="mock">调试</el-button>
+	<el-button type="primary" style="margin-top:20px" v-auth="'debug'" :loading="runing" @click="mock">调试</el-button>
 </template>
 
 <script lang="ts" setup>
@@ -54,6 +54,7 @@ const inputData = ref('')
 const outputData = ref('')
 const content = ref('')
 const functionName = ref('parse')
+const runing = ref(false)
 const mirrorRef = ref()
 
 onMounted(() => {
@@ -103,7 +104,7 @@ function validate() {
 
 async function mock() {
 	outputData.value = ''
-	
+
 	await validate()
 
 	if (!inputData.value) return ElMessage.error('请输入参数')
@@ -114,18 +115,31 @@ async function mock() {
 		return ElMessage.error('请先输入可执行脚本')
 	}
 
+	// 远程调试
+	runing.value = true
+	api.product.scriptRun({
+		functionName: functionName.value,
+		scriptInfo: funStr,
+		jsonData: inputData.value,
+	}).then((res: any) => {
+		// outputData.value = typeof res.data === 'object' ? JSON.stringify(res.data, null, 2) : res.data
+		outputData.value = res.data
+	}).finally(() => {
+		runing.value = false
+	})
 
-	const worker = new Worker('./worker.js');
-	// 向 Worker 发送消息
-	worker.postMessage({ type: 'runFunction', functionString: funStr, functionName: functionName.value, params: inputData.value });
-	// 监听 Worker 返回的消息
-	worker.addEventListener('message', ({ data }) => {
-		worker.terminate()
-		if (data.isOk) {
-			return outputData.value = typeof data.data === 'object' ? JSON.stringify(data.data, null, 2) : data.data
-		}
-		ElMessage.error(data.message)
-	});
+	// 本地调试
+	// const worker = new Worker('./worker.js');
+	// // 向 Worker 发送消息
+	// worker.postMessage({ type: 'runFunction', functionString: funStr, functionName: functionName.value, params: inputData.value });
+	// // 监听 Worker 返回的消息
+	// worker.addEventListener('message', ({ data }) => {
+	// 	worker.terminate()
+	// 	if (data.isOk) {
+	// 		return outputData.value = typeof data.data === 'object' ? JSON.stringify(data.data, null, 2) : data.data
+	// 	}
+	// 	ElMessage.error(data.message)
+	// });
 }
 </script>
 
@@ -137,6 +151,7 @@ async function mock() {
 .input,
 .output {
 	margin-top: 14px;
+
 	:deep(.el-textarea__inner) {
 		height: calc(50vh - 200px);
 	}