fix problem

This commit is contained in:
程广 2025-02-28 14:50:24 +08:00
parent 86d72edec5
commit 6198d86e95
1 changed files with 12 additions and 8 deletions

View File

@ -4,7 +4,7 @@
<el-input v-model="regex" placeholder="请输入正则表达式" clearable class="regex-input" />
<el-input v-model="testString" placeholder="请输入测试字符串" clearable class="test-input" />
<el-button type="primary" @click="testRegex" class="test-button">测试</el-button>
<el-button type="default" @click="saveRegex" class="test-button">保存</el-button>
<el-button type="default" @click="saveRegex" class="test-button" :disabled="shouldDisableSaveButton">保存</el-button>
<!-- 添加匹配示意图 -->
<div class="match-diagram">
<h2>匹配示意图</h2>
@ -39,10 +39,10 @@
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ref, onMounted,computed } from 'vue'
import { ElInput, ElButton } from 'element-plus'
//
let vscode: any = null
// 使 window.vizregx TypeScript
const regex = ref('')
const testString = ref('')
@ -73,6 +73,9 @@ const testRegex = () => {
const isInVscode = () => {
return typeof window.acquireVsCodeApi !== 'undefined'
}
const shouldDisableSaveButton = computed(() => {
return !regex.value || !testString.value
})
const saveRegex = () => {
// show a dialog to ask for a name
if (!dialogVisible.value) {
@ -80,20 +83,21 @@ const saveRegex = () => {
} else {
dialogVisible.value = false
if (isInVscode()) {
const vscode = window.acquireVsCodeApi()
vscode.postMessage({ type: 'regex', regex: regex.value, testString: testString.value }, '*')
if(!vscode) vscode = window.acquireVsCodeApi()
vscode.postMessage({ command: 'regex.save', name:regxname.value, regexp: regex.value, teststr: testString.value })
}
}
}
onMounted(() => {
// myDiagram.value DOM
if (isInVscode()) {
window.addEventListener('message', (event) => {
const message = event.data
if (message.type === 'regex') {
regex.value = message.regex
if (message.command === 'regex.show') {
regex.value = message.regexp
testString.value = message.testString
testString.value = message.teststr
testRegex()
}
})