fix problem
This commit is contained in:
parent
86d72edec5
commit
6198d86e95
|
@ -4,7 +4,7 @@
|
||||||
<el-input v-model="regex" placeholder="请输入正则表达式" clearable class="regex-input" />
|
<el-input v-model="regex" placeholder="请输入正则表达式" clearable class="regex-input" />
|
||||||
<el-input v-model="testString" placeholder="请输入测试字符串" clearable class="test-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="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">
|
<div class="match-diagram">
|
||||||
<h2>匹配示意图</h2>
|
<h2>匹配示意图</h2>
|
||||||
|
@ -39,10 +39,10 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted,computed } from 'vue'
|
||||||
import { ElInput, ElButton } from 'element-plus'
|
import { ElInput, ElButton } from 'element-plus'
|
||||||
// 在你的组件文件中
|
// 在你的组件文件中
|
||||||
|
let vscode: any = null
|
||||||
// 现在你可以在这个文件中使用 window.vizregx 而不会得到 TypeScript 的错误
|
// 现在你可以在这个文件中使用 window.vizregx 而不会得到 TypeScript 的错误
|
||||||
const regex = ref('')
|
const regex = ref('')
|
||||||
const testString = ref('')
|
const testString = ref('')
|
||||||
|
@ -73,6 +73,9 @@ const testRegex = () => {
|
||||||
const isInVscode = () => {
|
const isInVscode = () => {
|
||||||
return typeof window.acquireVsCodeApi !== 'undefined'
|
return typeof window.acquireVsCodeApi !== 'undefined'
|
||||||
}
|
}
|
||||||
|
const shouldDisableSaveButton = computed(() => {
|
||||||
|
return !regex.value || !testString.value
|
||||||
|
})
|
||||||
const saveRegex = () => {
|
const saveRegex = () => {
|
||||||
// show a dialog to ask for a name
|
// show a dialog to ask for a name
|
||||||
if (!dialogVisible.value) {
|
if (!dialogVisible.value) {
|
||||||
|
@ -80,20 +83,21 @@ const saveRegex = () => {
|
||||||
} else {
|
} else {
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
if (isInVscode()) {
|
if (isInVscode()) {
|
||||||
const vscode = window.acquireVsCodeApi()
|
if(!vscode) vscode = window.acquireVsCodeApi()
|
||||||
vscode.postMessage({ type: 'regex', regex: regex.value, testString: testString.value }, '*')
|
vscode.postMessage({ command: 'regex.save', name:regxname.value, regexp: regex.value, teststr: testString.value })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 此时 myDiagram.value 应该已经被设置为对应的 DOM
|
// 此时 myDiagram.value 应该已经被设置为对应的 DOM
|
||||||
if (isInVscode()) {
|
if (isInVscode()) {
|
||||||
window.addEventListener('message', (event) => {
|
window.addEventListener('message', (event) => {
|
||||||
const message = event.data
|
const message = event.data
|
||||||
if (message.type === 'regex') {
|
if (message.command === 'regex.show') {
|
||||||
regex.value = message.regex
|
regex.value = message.regexp
|
||||||
|
|
||||||
testString.value = message.testString
|
testString.value = message.teststr
|
||||||
testRegex()
|
testRegex()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue