Skip to content

Commit

Permalink
调整命令执行方式,增加自定义命令
Browse files Browse the repository at this point in the history
  • Loading branch information
kscript committed Aug 30, 2024
1 parent 3daf2fa commit 74b9ebd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
9 changes: 5 additions & 4 deletions server/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,18 @@ router.post('/exec', async (ctx) => {
commands.push('nvm use ' + data.nodeVersion)
}
if (typeof data.commandLines === 'string' || Array.isArray(data.commandLines)) {
const result = []
const commandLines = (Array.isArray(data.commandLines) ? data.commandLines : data.commandLines.split('\n'))
commandLines.map(command => {
commands.push(command.replace(/(^\s+|\s+$)/g, ''))
})
const result = []
const promises = commands.map((command, index) => {
return new Promise((resolve, reject) => {
if (!command) resolve()
let content = ''
const child = spawn('cmd.exe', ['/c', command], {
cwd: data.path,
const child = spawn(command, [''], {
shell: true,
env: process.env,
encoding: 'utf8'
})
const item = {
Expand Down Expand Up @@ -127,7 +128,7 @@ router.post('/exec', async (ctx) => {
const execPromise = () => Promise.all(promises).then((data) => {
useResponse(ctx, result.slice(data.nodeVersion ? 1 : 0), 200)
}).catch(error => {
useResponse(ctx, {}, 500, error.toString())
useResponse(ctx, [], 500, error.toString())
}).finally(() => {
if (data.uuid) {
commandList[data.uuid] = commandList[data.uuid].filter(item => item !== current)
Expand Down
27 changes: 22 additions & 5 deletions src/views/market/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
<div class="desc fs-12 opa-70">{{ command.description }}</div>
</div>
</template>
<markdownIt :content="command.content">
<el-input v-if="command.editable" v-model="command.content" type="textarea" :rows="3"></el-input>
<markdownIt v-else :content="command.content">
<el-empty class="pt-6 pb-0" description=" " :image-size="40"></el-empty>
</markdownIt>
<template #footer>
<el-button>复制</el-button>
<el-button type="success">使用</el-button>
<el-button type="danger">运行</el-button>
<el-button type="danger" @click="handleExec(command)">运行</el-button>
</template>
</el-card>
</el-col>
Expand All @@ -26,11 +27,27 @@
import { ref } from 'vue'
import api from '@/api'
import markdownIt from '@/components/markdown-it'
const commands = ref([])
const commands = ref([
{
name: '自定义',
description: '自定义命令',
wait: true,
content: '',
editable: true
}
])
const handleExec = ({ wait, content }) => {
if (content) {
api.exec({
wait,
commandLines: content.replace(/^\n+|\n+$/g, '')
})
}
}
const initData = () => {
api.market({}).then(res => {
commands.value = res.data
})
commands.value = commands.value.slice(0, 1).concat(res.data)
}).catch(console.log)

Check warning on line 50 in src/views/market/index.vue

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
}
initData()
</script>
Expand Down
7 changes: 6 additions & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
publicPath: process.env.NODE_ENV === 'development' ? '/' : '/command-manager/',
transpileDependencies: true
transpileDependencies: true,
devServer: {
client: {
overlay: false
}
}
})

0 comments on commit 74b9ebd

Please sign in to comment.