2023-09-06 18:06:52 +08:00
|
|
|
<template>
|
2025-04-26 17:37:09 +08:00
|
|
|
<div>
|
2023-09-13 23:57:28 +08:00
|
|
|
<el-dialog
|
|
|
|
|
destroy-on-close
|
|
|
|
|
:before-close="handleClose"
|
|
|
|
|
:title="title || path"
|
|
|
|
|
v-model="dialogVisible"
|
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
|
top="5vh"
|
|
|
|
|
width="65%"
|
|
|
|
|
>
|
2025-04-26 17:37:09 +08:00
|
|
|
<div v-loading="loadingContent">
|
|
|
|
|
<monaco-editor :can-change-mode="true" v-model="fileContent" :language="fileType" />
|
2023-09-06 18:06:52 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<template #footer>
|
2025-04-26 17:37:09 +08:00
|
|
|
<el-button @click="handleClose">{{ $t('common.cancel') }}</el-button>
|
|
|
|
|
<el-button v-auth="'machine:file:write'" type="primary" @click="updateContent">{{ $t('common.save') }}</el-button>
|
2023-09-06 18:06:52 +08:00
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2025-04-26 17:37:09 +08:00
|
|
|
import { computed, reactive, toRefs, watch } from 'vue';
|
2023-09-06 18:06:52 +08:00
|
|
|
import { machineApi } from '../api';
|
|
|
|
|
import MonacoEditor from '@/components/monaco/MonacoEditor.vue';
|
2024-11-20 22:43:53 +08:00
|
|
|
import { useI18nSaveSuccessMsg } from '@/hooks/useI18n';
|
2023-09-06 18:06:52 +08:00
|
|
|
|
|
|
|
|
const props = defineProps({
|
2024-04-06 04:03:38 +00:00
|
|
|
protocol: { type: Number, default: 1 },
|
2023-09-07 16:33:53 +08:00
|
|
|
title: { type: String, default: '' },
|
2023-09-06 18:06:52 +08:00
|
|
|
machineId: { type: Number },
|
2024-04-09 12:55:51 +08:00
|
|
|
authCertName: { type: String },
|
2023-09-06 18:06:52 +08:00
|
|
|
fileId: { type: Number, default: 0 },
|
|
|
|
|
path: { type: String, default: '' },
|
|
|
|
|
});
|
|
|
|
|
|
2025-04-26 17:37:09 +08:00
|
|
|
const dialogVisible = defineModel<boolean>('visible', { default: false });
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['cancel', 'update:machineId']);
|
2023-09-06 18:06:52 +08:00
|
|
|
|
|
|
|
|
const updateFileContent = machineApi.updateFileContent;
|
|
|
|
|
|
|
|
|
|
const state = reactive({
|
2025-04-26 17:37:09 +08:00
|
|
|
loadingContent: false,
|
2023-09-06 18:06:52 +08:00
|
|
|
content: '',
|
|
|
|
|
fileType: '',
|
|
|
|
|
});
|
|
|
|
|
|
2025-04-26 17:37:09 +08:00
|
|
|
const { fileType } = toRefs(state);
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
isFetching: loadingContent,
|
|
|
|
|
execute: getFileContentExec,
|
|
|
|
|
data: fileContent,
|
|
|
|
|
} = machineApi.fileContent.useApi(
|
|
|
|
|
computed(() => {
|
|
|
|
|
return {
|
|
|
|
|
fileId: props.fileId,
|
|
|
|
|
path: props.path,
|
|
|
|
|
machineId: props.machineId,
|
|
|
|
|
authCertName: props.authCertName,
|
|
|
|
|
protocol: props.protocol,
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
);
|
2023-09-06 18:06:52 +08:00
|
|
|
|
|
|
|
|
watch(props, async (newValue) => {
|
2025-04-26 17:37:09 +08:00
|
|
|
if (dialogVisible.value) {
|
2023-09-06 18:06:52 +08:00
|
|
|
await getFileContent();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const getFileContent = async () => {
|
2025-04-26 17:37:09 +08:00
|
|
|
fileContent.value = '';
|
|
|
|
|
state.fileType = getFileType(props.path);
|
|
|
|
|
await getFileContentExec();
|
2023-09-06 18:06:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleClose = () => {
|
2025-04-26 17:37:09 +08:00
|
|
|
dialogVisible.value = false;
|
2023-09-06 18:06:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const updateContent = async () => {
|
|
|
|
|
await updateFileContent.request({
|
|
|
|
|
content: state.content,
|
|
|
|
|
id: props.fileId,
|
|
|
|
|
path: props.path,
|
|
|
|
|
machineId: props.machineId,
|
2024-04-09 12:55:51 +08:00
|
|
|
authCertName: props.authCertName,
|
2024-04-06 04:03:38 +00:00
|
|
|
protocol: props.protocol,
|
2023-09-06 18:06:52 +08:00
|
|
|
});
|
2024-11-20 22:43:53 +08:00
|
|
|
useI18nSaveSuccessMsg();
|
2023-09-06 18:06:52 +08:00
|
|
|
handleClose();
|
|
|
|
|
state.content = '';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getFileType = (path: string) => {
|
|
|
|
|
if (path.endsWith('.sh')) {
|
|
|
|
|
return 'shell';
|
|
|
|
|
}
|
|
|
|
|
if (path.endsWith('js')) {
|
|
|
|
|
return 'javascript';
|
|
|
|
|
}
|
|
|
|
|
if (path.endsWith('json')) {
|
|
|
|
|
return 'json';
|
|
|
|
|
}
|
|
|
|
|
if (path.endsWith('Dockerfile')) {
|
|
|
|
|
return 'dockerfile';
|
|
|
|
|
}
|
|
|
|
|
if (path.endsWith('nginx.conf')) {
|
|
|
|
|
return 'shell';
|
|
|
|
|
}
|
|
|
|
|
if (path.endsWith('sql')) {
|
|
|
|
|
return 'sql';
|
|
|
|
|
}
|
|
|
|
|
if (path.endsWith('yaml') || path.endsWith('yml')) {
|
|
|
|
|
return 'yaml';
|
|
|
|
|
}
|
|
|
|
|
if (path.endsWith('xml') || path.endsWith('html')) {
|
|
|
|
|
return 'html';
|
|
|
|
|
}
|
2023-12-11 01:00:09 +08:00
|
|
|
if (path.endsWith('py')) {
|
|
|
|
|
return 'python';
|
|
|
|
|
}
|
2023-09-06 18:06:52 +08:00
|
|
|
return 'text';
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss"></style>
|