2023-09-06 18:06:52 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="file-manage">
|
2023-09-07 16:33:53 +08:00
|
|
|
<el-dialog v-if="dialogVisible" :title="title" v-model="dialogVisible" :show-close="true" :before-close="handleClose" width="50%">
|
2023-09-06 18:06:52 +08:00
|
|
|
<el-table :data="fileTable" stripe style="width: 100%" v-loading="loading">
|
2024-11-20 22:43:53 +08:00
|
|
|
<el-table-column prop="name" :label="$t('common.name')" min-width="100px">
|
2023-09-06 18:06:52 +08:00
|
|
|
<template #header>
|
|
|
|
|
<el-button class="ml0" type="primary" circle size="small" icon="Plus" @click="add()"> </el-button>
|
2025-04-18 22:07:37 +08:00
|
|
|
<span class="ml-2">{{ $t('common.name') }}</span>
|
2023-09-06 18:06:52 +08:00
|
|
|
</template>
|
|
|
|
|
<template #default="scope">
|
|
|
|
|
<el-input v-model="scope.row.name" :disabled="scope.row.id != null" clearable> </el-input>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2024-11-20 22:43:53 +08:00
|
|
|
<el-table-column prop="name" :label="$t('common.type')" width="130px">
|
2023-09-06 18:06:52 +08:00
|
|
|
<template #default="scope">
|
2024-11-20 22:43:53 +08:00
|
|
|
<EnumSelect :enums="FileTypeEnum" :disabled="scope.row.id != null" v-model="scope.row.type" />
|
2023-09-06 18:06:52 +08:00
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2024-11-20 22:43:53 +08:00
|
|
|
<el-table-column prop="path" :label="$t('common.path')" min-width="180" show-overflow-tooltip>
|
2023-09-06 18:06:52 +08:00
|
|
|
<template #default="scope">
|
|
|
|
|
<el-input v-model="scope.row.path" :disabled="scope.row.id != null" clearable> </el-input>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2024-11-20 22:43:53 +08:00
|
|
|
<el-table-column :label="$t('common.operation')" min-width="130">
|
2023-09-06 18:06:52 +08:00
|
|
|
<template #default="scope">
|
|
|
|
|
<el-button v-if="scope.row.id == null" @click="addFiles(scope.row)" type="success" icon="success-filled" plain></el-button>
|
|
|
|
|
<el-button v-if="scope.row.id != null" @click="getConf(scope.row)" type="primary" icon="tickets" plain></el-button>
|
|
|
|
|
<el-button v-auth="'machine:file:del'" type="danger" @click="deleteRow(scope.$index, scope.row)" icon="delete" plain></el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
<el-row style="margin-top: 10px" type="flex" justify="end">
|
|
|
|
|
<el-pagination
|
|
|
|
|
style="text-align: center"
|
|
|
|
|
:total="total"
|
|
|
|
|
layout="prev, pager, next, total, jumper"
|
|
|
|
|
v-model:current-page="query.pageNum"
|
|
|
|
|
:page-size="query.pageSize"
|
|
|
|
|
@current-change="handlePageChange"
|
|
|
|
|
>
|
|
|
|
|
</el-pagination>
|
|
|
|
|
</el-row>
|
|
|
|
|
|
2023-09-07 16:33:53 +08:00
|
|
|
<el-dialog destroy-on-close :title="fileDialog.title" v-model="fileDialog.visible" :close-on-click-modal="false" width="70%">
|
2024-04-09 12:55:51 +08:00
|
|
|
<machine-file
|
|
|
|
|
:title="fileDialog.title"
|
|
|
|
|
:machine-id="machineId"
|
|
|
|
|
:auth-cert-name="props.authCertName"
|
|
|
|
|
:file-id="fileDialog.fileId"
|
|
|
|
|
:path="fileDialog.path"
|
|
|
|
|
:protocol="protocol"
|
|
|
|
|
/>
|
2023-09-07 16:33:53 +08:00
|
|
|
</el-dialog>
|
|
|
|
|
|
|
|
|
|
<machine-file-content
|
|
|
|
|
:title="fileContent.title"
|
|
|
|
|
v-model:visible="fileContent.contentVisible"
|
|
|
|
|
:machine-id="machineId"
|
2024-04-09 12:55:51 +08:00
|
|
|
:auth-cert-name="props.authCertName"
|
2023-09-07 16:33:53 +08:00
|
|
|
:file-id="fileContent.fileId"
|
|
|
|
|
:path="fileContent.path"
|
|
|
|
|
/>
|
2023-09-06 18:06:52 +08:00
|
|
|
</el-dialog>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-04-06 04:03:38 +00:00
|
|
|
import { reactive, toRefs, watch } from 'vue';
|
2023-09-06 18:06:52 +08:00
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
|
|
|
|
import { machineApi } from '../api';
|
|
|
|
|
import { FileTypeEnum } from '../enums';
|
|
|
|
|
import MachineFile from './MachineFile.vue';
|
|
|
|
|
import MachineFileContent from './MachineFileContent.vue';
|
2024-11-20 22:43:53 +08:00
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
|
import EnumSelect from '@/components/enumselect/EnumSelect.vue';
|
|
|
|
|
import { useI18nDeleteConfirm, useI18nSaveSuccessMsg } from '@/hooks/useI18n';
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n();
|
2023-09-06 18:06:52 +08:00
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
visible: { type: Boolean },
|
2024-04-06 04:03:38 +00:00
|
|
|
protocol: { type: Number, default: 1 },
|
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
|
|
|
title: { type: String },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['update:visible', 'cancel', 'update:machineId']);
|
|
|
|
|
|
|
|
|
|
const addFile = machineApi.addConf;
|
|
|
|
|
const delFile = machineApi.delConf;
|
|
|
|
|
const files = machineApi.files;
|
|
|
|
|
|
|
|
|
|
const state = reactive({
|
|
|
|
|
dialogVisible: false,
|
|
|
|
|
query: {
|
|
|
|
|
id: 0,
|
|
|
|
|
pageNum: 1,
|
|
|
|
|
pageSize: 8,
|
|
|
|
|
},
|
|
|
|
|
loading: false,
|
|
|
|
|
form: {
|
|
|
|
|
id: null,
|
|
|
|
|
type: null,
|
|
|
|
|
name: '',
|
|
|
|
|
remark: '',
|
|
|
|
|
},
|
|
|
|
|
total: 0,
|
|
|
|
|
fileTable: [] as any,
|
|
|
|
|
fileDialog: {
|
|
|
|
|
visible: false,
|
2024-04-06 04:03:38 +00:00
|
|
|
protocol: 1,
|
2023-09-06 18:06:52 +08:00
|
|
|
title: '',
|
|
|
|
|
fileId: 0,
|
|
|
|
|
path: '',
|
|
|
|
|
},
|
|
|
|
|
fileContent: {
|
2023-09-07 16:33:53 +08:00
|
|
|
title: '',
|
2023-09-06 18:06:52 +08:00
|
|
|
fileId: 0,
|
|
|
|
|
contentVisible: false,
|
|
|
|
|
path: '',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const { dialogVisible, loading, query, total, fileTable, fileDialog, fileContent } = toRefs(state);
|
|
|
|
|
|
|
|
|
|
watch(props, async (newValue) => {
|
|
|
|
|
state.dialogVisible = newValue.visible;
|
|
|
|
|
if (newValue.machineId && newValue.visible) {
|
|
|
|
|
await getFiles();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const getFiles = async () => {
|
|
|
|
|
try {
|
|
|
|
|
state.loading = true;
|
|
|
|
|
state.query.id = props.machineId as any;
|
|
|
|
|
const res = await files.request(state.query);
|
|
|
|
|
state.fileTable = res.list || [];
|
|
|
|
|
state.total = res.total;
|
|
|
|
|
} finally {
|
|
|
|
|
state.loading = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handlePageChange = (curPage: number) => {
|
|
|
|
|
state.query.pageNum = curPage;
|
|
|
|
|
getFiles();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const add = () => {
|
|
|
|
|
// 往数组头部添加元素
|
|
|
|
|
state.fileTable = [{}].concat(state.fileTable);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const addFiles = async (row: any) => {
|
|
|
|
|
row.machineId = props.machineId;
|
|
|
|
|
await addFile.request(row);
|
2024-11-20 22:43:53 +08:00
|
|
|
useI18nSaveSuccessMsg();
|
2023-09-06 18:06:52 +08:00
|
|
|
getFiles();
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-20 22:43:53 +08:00
|
|
|
const deleteRow = async (idx: any, row: any) => {
|
2023-09-06 18:06:52 +08:00
|
|
|
if (row.id) {
|
2024-11-20 22:43:53 +08:00
|
|
|
await useI18nDeleteConfirm(row.name);
|
|
|
|
|
// 删除配置文件
|
|
|
|
|
await delFile.request({
|
|
|
|
|
machineId: props.machineId,
|
|
|
|
|
id: row.id,
|
2023-09-06 18:06:52 +08:00
|
|
|
});
|
2024-11-20 22:43:53 +08:00
|
|
|
getFiles();
|
2023-09-06 18:06:52 +08:00
|
|
|
} else {
|
|
|
|
|
state.fileTable.splice(idx, 1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getConf = async (row: any) => {
|
|
|
|
|
if (row.type == 1) {
|
|
|
|
|
state.fileDialog.fileId = row.id;
|
|
|
|
|
state.fileDialog.title = row.name;
|
|
|
|
|
state.fileDialog.path = row.path;
|
2023-09-07 16:33:53 +08:00
|
|
|
state.fileDialog.title = `${props.title} => ${row.path}`;
|
2023-09-06 18:06:52 +08:00
|
|
|
state.fileDialog.visible = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-09-07 16:33:53 +08:00
|
|
|
|
2023-09-06 18:06:52 +08:00
|
|
|
showFileContent(row.id, row.path);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const showFileContent = async (fileId: number, path: string) => {
|
|
|
|
|
state.fileContent.fileId = fileId;
|
|
|
|
|
state.fileContent.path = path;
|
2023-09-07 16:33:53 +08:00
|
|
|
state.fileContent.title = `${props.title} => ${path}`;
|
2023-09-06 18:06:52 +08:00
|
|
|
state.fileContent.contentVisible = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 关闭取消按钮触发的事件
|
|
|
|
|
*/
|
|
|
|
|
const handleClose = () => {
|
|
|
|
|
emit('update:visible', false);
|
|
|
|
|
emit('update:machineId', null);
|
|
|
|
|
emit('cancel');
|
|
|
|
|
state.fileTable = [];
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
.machine-file-upload-exec {
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
position: relative;
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
}
|
|
|
|
|
.inline-block {
|
|
|
|
|
display: inline-block;
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
}
|
|
|
|
|
.margin-change {
|
|
|
|
|
display: inline-block;
|
|
|
|
|
margin-left: 10px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|