perf: 优化playbook 翻译文本

This commit is contained in:
Aaron3S
2023-02-02 11:36:23 +08:00
committed by Jiangjie.Bai
parent 5a27662f47
commit 171ee84c1b
3 changed files with 102 additions and 22 deletions

View File

@@ -812,6 +812,18 @@
"Weekly": "按周" "Weekly": "按周"
}, },
"ops": { "ops": {
"Confirm": "确认",
"Cancel": "确认",
"DeleteFile": "删除文件",
"DeleteConfirmMessage": "删除后无法恢复,是否继续?",
"CloseConfirm": "确认关闭",
"CloseConfirmMessage": "文件发生变化,是否保存?",
"SaveSuccess": "保存成功",
"DeleteSuccess": "删除成功",
"NewFile": "新建文件",
"NewDirectory": "新建目录",
"Rename": "重命名",
"Delete": "删除",
"SelectCreateMethod": "选择创建方式", "SelectCreateMethod": "选择创建方式",
"Workspace": "工作空间", "Workspace": "工作空间",
"UploadPlaybook": "上传 Playbook", "UploadPlaybook": "上传 Playbook",

View File

@@ -0,0 +1,57 @@
<template>
<Dialog
v-if="iVisible"
title="新建文件"
:visible.sync="iVisible"
width="20%"
top="1vh"
:show-cancel="true"
:show-confirm="true"
@confirm="onConfirm"
>
<el-form>
<el-form-item label="名称">
<el-input v-model="name" />
</el-form-item>
</el-form>
</Dialog>
</template>
<script>
import Dialog from '@/components/Dialog'
export default {
components: {
Dialog
},
props: {
visible: {
type: Boolean,
default: false
}
},
data() {
return {
name: ''
}
},
computed: {
iVisible: {
set(val) {
this.$emit('update:visible', val)
},
get() {
return this.visible
}
}
},
mounted() {},
methods: {
onConfirm() {
this.$emit('confirm', this.name)
this.iVisible = false
}
}
}
</script>

View File

@@ -1,18 +1,19 @@
<template> <template>
<div> <div>
<NewNodeDialog v-if="createDialogVisible" :visible.sync="createDialogVisible" @confirm="doCreate" />
<TreeTable ref="TreeTable" :tree-setting="treeSetting"> <TreeTable ref="TreeTable" :tree-setting="treeSetting">
<template slot="rMenu"> <template slot="rMenu">
<li id="m_create_file" class="rmenu" tabindex="-1" @click="onCreate('file')"> <li id="m_create_file" class="rmenu" tabindex="-1" @click="onCreate('file')">
创建文件 {{ $tc('ops.NewFile') }}
</li> </li>
<li id="m_create_directory" class="rmenu" tabindex="-1" @click="onCreate('directory')"> <li id="m_create_directory" class="rmenu" tabindex="-1" @click="onCreate('directory')">
创建文件夹 {{ $tc('ops.NewDirectory') }}
</li> </li>
<li id="m_rename" class="rmenu" tabindex="-1" @click="onRename"> <li id="m_rename" class="rmenu" tabindex="-1" @click="onRename">
重命名 {{ $tc('ops.Rename') }}
</li> </li>
<li id="m_delete" class="rmenu" tabindex="-1" @click="onDelete"> <li id="m_delete" class="rmenu" tabindex="-1" @click="onDelete">
删除 {{ $tc('ops.Delete') }}
</li> </li>
</template> </template>
<template slot="table"> <template slot="table">
@@ -43,10 +44,12 @@
import { TreeTable } from '@/components' import { TreeTable } from '@/components'
import CodeEditor from '@/components/FormFields/CodeEditor' import CodeEditor from '@/components/FormFields/CodeEditor'
import item from '@/layout/components/NavLeft/Item' import item from '@/layout/components/NavLeft/Item'
import NewNodeDialog from '@/views/ops/Template/Playbook/PlaybookDetail/Editor/NewNodeDialog.vue'
export default { export default {
name: 'CommandExecution', name: 'CommandExecution',
components: { components: {
NewNodeDialog,
TreeTable, TreeTable,
CodeEditor CodeEditor
}, },
@@ -58,6 +61,9 @@ export default {
}, },
data() { data() {
return { return {
newNode: {},
createDialogVisible: false,
createType: 'directory',
parentId: '', parentId: '',
closing: false, closing: false,
DataZTree: 0, DataZTree: 0,
@@ -92,7 +98,7 @@ export default {
}, },
treeSetting: { treeSetting: {
async: false, async: false,
treeUrl: `/api/v1/ops/playbook/${this.object.id}/file`, treeUrl: `/api/v1/ops/playbook/${this.object.id}/file/`,
showRefresh: true, showRefresh: true,
showMenu: true, showMenu: true,
showDelete: false, showDelete: false,
@@ -102,6 +108,7 @@ export default {
customTreeHeader: false, customTreeHeader: false,
callback: { callback: {
onSelected: function(event, treeNode) { onSelected: function(event, treeNode) {
console.log(treeNode)
if (!treeNode.isParent) { if (!treeNode.isParent) {
this.onOpenEditor(treeNode) this.onOpenEditor(treeNode)
} }
@@ -155,6 +162,9 @@ export default {
this.onOpenEditor({ id: 'main.yml', name: 'main.yml' }) this.onOpenEditor({ id: 'main.yml', name: 'main.yml' })
}, },
methods: { methods: {
refreshEditor(id, name) {
this.openedEditor[id].name = name
},
onReset() { onReset() {
const editor = this.activeEditor const editor = this.activeEditor
editor.value = editor.originValue editor.value = editor.originValue
@@ -167,27 +177,27 @@ export default {
if (this.closing) { if (this.closing) {
this.remoteTab(editor.key) this.remoteTab(editor.key)
} }
this.$message.success('保存成功!') this.$message.success(this.$tc('ops.SaveSuccess'))
}) })
}, },
onCreate(type) { onCreate(type) {
this.dataztree.hideRMenu() this.dataztree.hideRMenu()
this.createDialogVisible = true
this.createType = type
},
doCreate(name) {
const parentNode = this.zTree.getSelectedNodes()[0] const parentNode = this.zTree.getSelectedNodes()[0]
if (!parentNode) { if (!parentNode) {
return return
} }
const parentId = parentNode.isParent ? parentNode.id : parentNode.pId const parentId = parentNode.isParent ? parentNode.id : parentNode.pId
this.zTree.expandNode(parentNode, true, false, true, false)
const req = { const req = {
key: parentId, key: parentId,
is_directory: type === 'directory' is_directory: this.createType === 'directory',
name: name
} }
this.$axios.post(`/api/v1/ops/playbook/${this.object.id}/file/`, req).then(data => { this.$axios.post(`/api/v1/ops/playbook/${this.object.id}/file/`, req).then(data => {
const newNode = data this.refreshTree()
this.zTree.addNodes(parentNode, newNode)
const node = this.zTree.getNodeByParam('id', newNode.id, parentNode)
this.zTree.editName(node)
}) })
}, },
onDelete() { onDelete() {
@@ -196,19 +206,19 @@ export default {
if (!node) { if (!node) {
return return
} }
this.$confirm('删除操作无法恢复是否继续?', '确认保存', { this.$confirm(this.$tc('ops.DeleteConfirmMessage'), this.$tc('DeleteFile'), {
confirmButtonText: '确定', confirmButtonText: this.$tc('ops.Confirm'),
cancelButtonText: '取消', cancelButtonText: this.$tc('ops.Cancel'),
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.$axios.delete(`/api/v1/ops/playbook/${this.object.id}/file/?key=${node.id}`).then(() => { this.$axios.delete(`/api/v1/ops/playbook/${this.object.id}/file/?key=${node.id}`).then(() => {
if (!node.isParent) { if (!node.isParent) {
this.remoteTab(node.id) this.remoteTab(node.id)
} }
this.zTree.removeNode(node) this.refreshTree()
this.$message({ this.$message({
type: 'success', type: 'success',
message: '删除成功!' message: this.$tc('ops.DeleteSuccess')
}) })
}) })
}) })
@@ -225,19 +235,20 @@ export default {
this.$set(this.openedEditor, node.id, this.$set(this.openedEditor, node.id,
{ key: node.id, name: node.name, originValue: '', value: '' }) { key: node.id, name: node.name, originValue: '', value: '' })
this.activeEditorId = node.id this.activeEditorId = node.id
this.getFileContent(node.id)
}, },
onCloseEditor(key) { onCloseEditor(key) {
const editor = this.openedEditor[key] const editor = this.openedEditor[key]
let text = '' let text = ''
if (this.hasChange(editor)) { if (this.hasChange(editor)) {
text = '文件发生变化是否保存?' text = this.$tc('ops.CloseConfirmMessage')
} else { } else {
this.remoteTab(key) this.remoteTab(key)
return return
} }
this.$confirm(text, '确认关闭', { this.$confirm(text, this.$tc('ops.CloseConfirm'), {
confirmButtonText: '确定', confirmButtonText: this.$tc('ops.Confirm'),
cancelButtonText: '取消', cancelButtonText: this.$tc('ops.Cancel'),
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.closing = true this.closing = true