Skip to content

Commit 99a8d0a

Browse files
committed
调整命令执行方式,增加自定义命令
1 parent 3daf2fa commit 99a8d0a

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

server/router/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,18 @@ router.post('/exec', async (ctx) => {
8484
commands.push('nvm use ' + data.nodeVersion)
8585
}
8686
if (typeof data.commandLines === 'string' || Array.isArray(data.commandLines)) {
87+
const result = []
8788
const commandLines = (Array.isArray(data.commandLines) ? data.commandLines : data.commandLines.split('\n'))
8889
commandLines.map(command => {
8990
commands.push(command.replace(/(^\s+|\s+$)/g, ''))
9091
})
91-
const result = []
9292
const promises = commands.map((command, index) => {
9393
return new Promise((resolve, reject) => {
9494
if (!command) resolve()
9595
let content = ''
96-
const child = spawn('cmd.exe', ['/c', command], {
97-
cwd: data.path,
96+
const child = spawn(command, [''], {
97+
shell: true,
98+
env: process.env,
9899
encoding: 'utf8'
99100
})
100101
const item = {
@@ -127,7 +128,7 @@ router.post('/exec', async (ctx) => {
127128
const execPromise = () => Promise.all(promises).then((data) => {
128129
useResponse(ctx, result.slice(data.nodeVersion ? 1 : 0), 200)
129130
}).catch(error => {
130-
useResponse(ctx, {}, 500, error.toString())
131+
useResponse(ctx, [], 500, error.toString())
131132
}).finally(() => {
132133
if (data.uuid) {
133134
commandList[data.uuid] = commandList[data.uuid].filter(item => item !== current)

src/views/market/index.vue

+20-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
<div class="desc fs-12 opa-70">{{ command.description }}</div>
1010
</div>
1111
</template>
12-
<markdownIt :content="command.content">
12+
<el-input v-if="command.editable" v-model="command.content" type="textarea" :rows="3"></el-input>
13+
<markdownIt v-else :content="command.content">
1314
<el-empty class="pt-6 pb-0" description=" " :image-size="40"></el-empty>
1415
</markdownIt>
1516
<template #footer>
1617
<el-button>复制</el-button>
1718
<el-button type="success">使用</el-button>
18-
<el-button type="danger">运行</el-button>
19+
<el-button type="danger" @click="handleExec(command)">运行</el-button>
1920
</template>
2021
</el-card>
2122
</el-col>
@@ -27,9 +28,25 @@ import { ref } from 'vue'
2728
import api from '@/api'
2829
import markdownIt from '@/components/markdown-it'
2930
const commands = ref([])
31+
const handleExec = ({ wait, content }) => {
32+
if (content) {
33+
api.exec({
34+
wait,
35+
commandLines: content.replace(/^\n+|\n+$/g, '')
36+
})
37+
}
38+
}
3039
const initData = () => {
3140
api.market({}).then(res => {
32-
commands.value = res.data
41+
commands.value = [
42+
{
43+
name: '自定义',
44+
description: '自定义命令',
45+
wait: true,
46+
content: '',
47+
editable: true
48+
}
49+
].concat(res.data)
3350
})
3451
}
3552
initData()

vue.config.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
const { defineConfig } = require('@vue/cli-service')
22
module.exports = defineConfig({
33
publicPath: process.env.NODE_ENV === 'development' ? '/' : '/command-manager/',
4-
transpileDependencies: true
4+
transpileDependencies: true,
5+
devServer: {
6+
client: {
7+
overlay: false
8+
}
9+
}
510
})

0 commit comments

Comments
 (0)