This commit is contained in:
ann 2023-02-13 15:53:04 +08:00
parent d098ee6f50
commit 54f263243b
3 changed files with 167 additions and 2 deletions

View File

@ -18,6 +18,14 @@ export function getProfileByIpPath(params) {
})
}
export function postYaml(params) {
return request({
url: edgePreUrl + '/profile/yaml',
method: 'post',
data: params
})
}
export function getEdgeServiceByIp(params) {
return request({
url: edgePreUrl + '/registryCenter',

View File

@ -0,0 +1,156 @@
<template>
<el-dialog v-if="createFormVisible" :close-on-click-modal="false" width="80%" :title="'创建'+typeMap[classification]" :visible.sync="createFormVisible">
<el-steps :active="stepNum" finish-status="success" simple>
<el-step title="选择设备服务" />
<el-step title="选择设备元信息" />
<el-step title="设备信息" />
<el-step title="创建自动事件" />
<el-step title="创建设备通信协议" />
</el-steps>
<basicInfoForm v-show="stepNum===0" ref="basicInfoForm" v-model="metaData" :classification="classification" @checkSuccess="handleCheckSuccess()" />
<containerImage v-if="stepNum===1" v-model="metaData" :classification="classification" />
<mountVolumes v-if="stepNum===2" v-model="metaData" />
<advancedSettings v-if="stepNum===3" v-model="metaData" :classification="classification" />
<advancedSettings v-if="stepNum===4" v-model="metaData" :classification="classification" />
<div slot="footer" class="dialog-footer">
<el-button @click="createFormVisible = false;transformYaml()"> </el-button>
<el-button v-if="stepNum!==0" type="primary" @click="prev">上一步</el-button>
<el-button v-if="stepNum!==4" type="primary" @click="next">下一步</el-button>
<el-button v-else type="primary" @click="createDevice">创建</el-button>
</div>
</el-dialog>
</template>
<script>
// import { createServiceData } from '@/api/container/serviceManagement'
import advancedSettings from './advancedSettings.vue'
import basicInfoForm from './basicInfoForm.vue'
import containerImage from './containerImage.vue'
import mountVolumes from './mountVolumes.vue'
// import fs from 'fs'
import yaml from 'js-yaml'
// import baseYaml from './base.yaml'
export default {
components: { basicInfoForm, containerImage, advancedSettings, mountVolumes },
props: {
value: {
type: Boolean,
default: false
},
classification: {
type: String,
default: ''
},
doSearch: {
type: Function,
default: () => { }
}
},
data() {
return {
typeMap: {
deployments: '部署',
statefulsets: '有状态副本集',
daemonsets: '守护进程集'
},
stepNum: 0,
metaData: {},
baseYaml: `apiVersion: apps/v1
kind: Deployment
metadata:
labels: {}
annotations: {}
spec:
replicas: 1
selector:
matchLabels: {}
template:
metadata: {
labels: {}
}
spec:
containers: []
serviceAccount: default
affinity: {}
initContainers: []
volumes: []
imagePullSecrets: null
securityContext:
runAsNonRoot: false
runAsUser: ''
runAsGroup: ''
seLinuxOptions:
level: ''
role: ''
type: ''
user: ''
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
updateStrategy:
type: RollingUpdate
rollingUpdate:
partition: 0
maxUnavailable: 20%
minReadySeconds: 0
`
}
},
computed: {
createFormVisible: {
get() {
return this.value
},
set(value) {
this.$emit('input', value)
}
}
},
created() {
this.transformYaml()
},
methods: {
createDevice() {
// getWorkloadsIsExist(this.classification, {
// clusterName: this.clusterName,
// namespace: this.metaData.metadata.namespace,
// name: this.metaData.metadata.labels.app
// }).then(res => {
// })
},
transformYaml() {
this.stepNum = 0
this.metaData = JSON.parse(JSON.stringify(yaml.load(this.baseYaml), null, 2))
},
prev() {
this.stepNum--
},
next() {
if (this.stepNum === 0) {
this.$refs.basicInfoForm.submitNameCheck()
} else if (this.stepNum === 1) {
if (this.metaData.spec.template.spec.containers.length === 0) {
this.$message.warning('请至少添加一个容器镜像')
} else {
this.stepNum++
}
} else {
this.stepNum++
}
},
handleCheckSuccess() {
this.stepNum++
}
}
}
</script>
<style lang="scss">
.el-steps{
margin-bottom: 15px;
}
</style>

View File

@ -101,7 +101,7 @@
<script>
import List from '@/components/list'
import { deleteService, getEdgeDataByIpPath, patchDeviceservice, putDeviceservice, getProfileByIpPath, postDeviceservice } from '@/api/edge/edge'
import { deleteService, getEdgeDataByIpPath, patchDeviceservice, putDeviceservice, getProfileByIpPath, postYaml } from '@/api/edge/edge'
export default {
components: {
@ -236,6 +236,7 @@ export default {
editProfile(row) {
getProfileByIpPath({ address: this.$route.query.ip, path: '/api/v2/profile/yaml/name/' + row.name }).then(e => {
this.dialogEditProfileVisible = true
this.add = false
this.code = JSON.stringify(e.data, null, 2)
})
},
@ -245,7 +246,7 @@ export default {
this.dialogEditProfileVisible = true
},
submitProfile() {
this.add ? postDeviceservice({ address: this.$route.query.ip, path: '/api/v2/profile/yaml', postContent: [JSON.parse(this.code)] }).then(e => {
this.add ? postYaml({ address: this.$route.query.ip, profile: JSON.parse(this.code) }).then(e => {
if (e.code === 200) {
this.dialogEditProfileVisible = false
this.$message.success('添加成功')