|
18 | 18 | v-for="item in targets"
|
19 | 19 | :key="item._id"
|
20 | 20 | :label="item.label"
|
21 |
| - :value="item" |
| 21 | + :value="item._id" |
22 | 22 | />
|
23 | 23 | </el-select>
|
24 | 24 | </el-form-item>
|
|
32 | 32 | {{ func.name }} - {{ func.label }}
|
33 | 33 | </el-tag>
|
34 | 34 | </el-form-item>
|
| 35 | + <el-form-item v-if="triggers && triggers.length" label="部署触发器" size="normal"> |
| 36 | + <el-tag v-for="tri in triggers" :key="tri._id" type="default" size="mini" style="margin-right: 10px;"> |
| 37 | + {{ tri.name }} - {{ tri.event }} |
| 38 | + </el-tag> |
| 39 | + </el-form-item> |
35 | 40 | <el-form-item label="部署说明" prop="comment">
|
36 | 41 | <el-input
|
37 | 42 | v-model="form.comment"
|
@@ -82,30 +87,79 @@ export default {
|
82 | 87 | form: this.defaultForm(),
|
83 | 88 | // 部署目标
|
84 | 89 | targets: [],
|
85 |
| - formRules |
| 90 | + formRules, |
| 91 | + internal_functions: [], |
| 92 | + triggers: [] |
86 | 93 | }
|
87 | 94 | },
|
88 | 95 | computed: {
|
89 | 96 | visible() {
|
90 | 97 | return this.value
|
| 98 | + }, |
| 99 | + selected_target() { |
| 100 | + if (!this.form.target) { |
| 101 | + return null |
| 102 | + } |
| 103 | + const [found] = this.targets.filter(it => it._id === this.form.target) |
| 104 | + return found |
| 105 | + } |
| 106 | + }, |
| 107 | + watch: { |
| 108 | + functions() { |
| 109 | + if (this.functions) { |
| 110 | + this.internal_functions = [...this.functions] |
| 111 | + this.loadTriggers() |
| 112 | + } |
91 | 113 | }
|
92 | 114 | },
|
93 | 115 | async mounted() {
|
94 |
| - const r = await db.collection('deploy_targets').get() |
95 |
| - if (!r.ok) throw new Error('get targets failed') |
96 |
| -
|
97 |
| - this.targets = r.data |
| 116 | + this.load() |
| 117 | + }, |
| 118 | + activated() { |
| 119 | + this.load() |
98 | 120 | },
|
99 | 121 | methods: {
|
| 122 | + async load() { |
| 123 | + const r = await db.collection('deploy_targets').get() |
| 124 | + if (!r.ok) throw new Error('get targets failed') |
| 125 | +
|
| 126 | + this.targets = r.data |
| 127 | + }, |
| 128 | + async loadTriggers() { |
| 129 | + this.triggers = [] |
| 130 | + if (!this.internal_functions?.length) { |
| 131 | + return |
| 132 | + } |
| 133 | + const func_ids = this.internal_functions.map(func => func._id) |
| 134 | + const r = await db.collection('__triggers') |
| 135 | + .where({ |
| 136 | + func_id: db.command.in(func_ids) |
| 137 | + }) |
| 138 | + .get() |
| 139 | +
|
| 140 | + if (r.ok) { |
| 141 | + this.triggers = r.data |
| 142 | + } |
| 143 | + }, |
100 | 144 | deploy() {
|
| 145 | + if (!this.functions?.length && !this.policies?.length) { |
| 146 | + this.$message.error('无可部署内容') |
| 147 | + return |
| 148 | + } |
| 149 | +
|
| 150 | + if (!this.selected_target) { |
| 151 | + this.$message.error('无推送目标选中') |
| 152 | + } |
| 153 | +
|
101 | 154 | this.$refs['dataForm'].validate(async(valid) => {
|
102 | 155 | if (!valid) { return }
|
103 | 156 | const data = {
|
104 | 157 | policies: this.policies,
|
105 | 158 | functions: this.functions,
|
| 159 | + triggers: this.triggers, |
106 | 160 | comment: this.form.comment
|
107 | 161 | }
|
108 |
| - const target = this.form.target |
| 162 | + const target = this.selected_target |
109 | 163 | const r = await deploy2remote(target.url, target.token, data)
|
110 | 164 | if (r.code === 0) {
|
111 | 165 | this.$message.success('操作成功!')
|
|
0 commit comments