Skip to content

Commit 68aa451

Browse files
committed
feat: bucket show sencondary url; move replicas dialog to auth page;setInterval with getApplications;
1 parent 86674d5 commit 68aa451

File tree

8 files changed

+134
-84
lines changed

8 files changed

+134
-84
lines changed

packages/app-console/src/api/oss.js

+15
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ export function getBucketUrl(bucket) {
104104
return url
105105
}
106106

107+
/**
108+
* get bucket's secondary url e.g: appid-bucketName.oss.aliyun.com
109+
* @param {*} bucketName
110+
* @param {*} param1
111+
* @returns
112+
*/
113+
export function getBucketSecondaryUrl(bucketName) {
114+
const appid = store.state.app.appid
115+
const endpoint = new URL(store.state.app.oss_external_endpoint)
116+
const { protocol, host } = endpoint
117+
const url = `${protocol}//${appid}-${bucketName}.${host}`
118+
return url
119+
}
120+
121+
107122
/**
108123
* Get file list in a bucket
109124
* @param {string} bucketName

packages/app-console/src/views/replicate/auth.vue

+95-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@
6969
align="center"
7070
>
7171
<template slot-scope="scope">
72+
<el-button
73+
v-if="authType === 'target' && scope.row.status=== 'accepted'"
74+
plain
75+
size="mini"
76+
class="filter-item"
77+
type="primary"
78+
@click="showReplicasForm(scope.row)"
79+
>
80+
部署
81+
</el-button>
7282
<el-button
7383
v-if="authType === 'source' && scope.row.status !== 'accepted'"
7484
size="mini"
@@ -108,13 +118,42 @@
108118
</el-button>
109119
</div>
110120
</el-dialog>
121+
122+
<el-dialog :visible.sync="replicasDialogVisible" title="请求部署">
123+
<el-form
124+
ref="createForm"
125+
:rules="rules"
126+
:model="replicasForm"
127+
label-position="left"
128+
label-width="120px"
129+
style="width: 400px; margin-left:20px;"
130+
>
131+
<el-form-item label="目标 appid" prop="target_appid">
132+
<el-input v-model="replicasForm.target_appid" disabled />
133+
</el-form-item>
134+
<el-form-item label="部署权限" prop="permissions">
135+
<el-checkbox-group v-model="replicasForm.permissions">
136+
<el-checkbox label="function" border>云函数</el-checkbox>
137+
<el-checkbox label="policy" border>访问策略</el-checkbox>
138+
</el-checkbox-group>
139+
</el-form-item>
140+
</el-form>
141+
<div slot="footer" class="dialog-footer">
142+
<el-button @click="replicasDialogVisible = false">
143+
取消
144+
</el-button>
145+
<el-button type="primary" @click="handleCreateRequest">
146+
确定
147+
</el-button>
148+
</div>
149+
</el-dialog>
111150
</div>
112151
</template>
113152

114153
<script>
115154
import store from '@/store'
116155
import dayjs from 'dayjs'
117-
import { getReplicateAuths, createReplicateAuth, acceptReplicateAuth, deleteReplicateAuth } from '../../api/replicate'
156+
import { getReplicateAuths, createReplicateAuth, acceptReplicateAuth, deleteReplicateAuth, createReplicateRequest } from '../../api/replicate'
118157
119158
export default {
120159
data() {
@@ -136,7 +175,12 @@ export default {
136175
},
137176
dialogFormVisible: false,
138177
139-
authType: 'target' // target | source
178+
authType: 'target', // target | source
179+
replicasDialogVisible: false,
180+
replicasForm: {
181+
target_appid: '',
182+
permissions: []
183+
},
140184
}
141185
},
142186
created() {
@@ -155,6 +199,55 @@ export default {
155199
this.tableList = this.list.filter(item => item.target_appid === this.appid)
156200
}
157201
},
202+
showReplicasForm(row) {
203+
this.replicasForm.target_appid = row.target_appid
204+
this.replicasDialogVisible = true
205+
},
206+
async handleCreateRequest() {
207+
this.$refs['createForm'].validate(async(valid) => {
208+
if (!valid) { return }
209+
210+
if (this.replicasForm.permissions.length === 0) {
211+
this.$message.warning('请至少选择一个部署权限')
212+
return
213+
}
214+
215+
const params = {
216+
target_appid: this.replicasForm.target_appid
217+
}
218+
if (this.replicasForm.permissions.includes('function')) {
219+
params.functions = {
220+
type: 'all',
221+
items: []
222+
}
223+
}
224+
if (this.replicasForm.permissions.includes('policy')) {
225+
params.policies = {
226+
type: 'all',
227+
items: []
228+
}
229+
}
230+
231+
const res = await createReplicateRequest(params)
232+
233+
if (res.code) {
234+
this.$notify({
235+
type: 'error',
236+
title: '操作失败',
237+
message: res.message
238+
})
239+
return
240+
}
241+
242+
this.$notify({
243+
type: 'success',
244+
title: '操作成功',
245+
message: '部署成功,等待目标应用接受。'
246+
})
247+
248+
this.replicasDialogVisible = false
249+
})
250+
},
158251
showCreateForm() {
159252
this.dialogFormVisible = true
160253
},

packages/app-console/src/views/replicate/request.vue

+1-72
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
<template>
22
<div class="app-container">
3-
<!-- 数据检索区 -->
4-
<div class="filter-container">
5-
<el-button
6-
plain
7-
size="mini"
8-
class="filter-item"
9-
type="primary"
10-
icon="el-icon-plus"
11-
@click="showCreateForm"
12-
>
13-
创建部署请求
14-
</el-button>
15-
</div>
16-
173
<!-- 数据列表 -->
184
<el-table
195
:data="list"
@@ -89,46 +75,6 @@
8975
:limit.sync="listQuery.limit"
9076
@pagination="getReplicateRequests"
9177
/>
92-
93-
<el-dialog :visible.sync="dialogFormVisible" title="请求部署">
94-
<el-form
95-
ref="createForm"
96-
:rules="rules"
97-
:model="form"
98-
label-position="left"
99-
label-width="120px"
100-
style="width: 400px; margin-left:20px;"
101-
>
102-
<el-form-item label="目标appid" prop="target_appid">
103-
<el-select
104-
v-model="form.target_appid"
105-
filterable
106-
placeholder="请选择"
107-
>
108-
<el-option
109-
v-for="item in targetAppids"
110-
:key="item"
111-
:label="item"
112-
:value="item"
113-
/>
114-
</el-select>
115-
</el-form-item>
116-
<el-form-item label="部署权限" prop="permissions">
117-
<el-checkbox-group v-model="form.permissions">
118-
<el-checkbox label="function" border>云函数</el-checkbox>
119-
<el-checkbox label="policy" border>访问策略</el-checkbox>
120-
</el-checkbox-group>
121-
</el-form-item>
122-
</el-form>
123-
<div slot="footer" class="dialog-footer">
124-
<el-button @click="dialogFormVisible = false">
125-
取消
126-
</el-button>
127-
<el-button type="primary" @click="handleCreateRequest">
128-
确定
129-
</el-button>
130-
</div>
131-
</el-dialog>
13278
</div>
13379
</template>
13480

@@ -140,8 +86,7 @@ import {
14086
getReplicateRequests,
14187
createReplicateRequest,
14288
acceptReplicateRequest,
143-
deleteReplicateRequest,
144-
getReplicateAuths
89+
deleteReplicateRequest
14590
} from '../../api/replicate'
14691
14792
export default {
@@ -169,32 +114,16 @@ export default {
169114
},
170115
dialogFormVisible: false,
171116
requestType: 'target', // target | source
172-
targetAppids: []
173117
}
174118
},
175119
created() {
176120
this.appid = store.state.app.appid
177-
this.getReplicateTargetAppid()
178121
this.getReplicateRequests()
179122
},
180123
methods: {
181-
handleSwitchType({ name }) {
182-
this.requestType = name
183-
this.switchList()
184-
},
185124
showCreateForm() {
186125
this.dialogFormVisible = true
187126
},
188-
async getReplicateTargetAppid() {
189-
const res = await getReplicateAuths()
190-
if (res.code) {
191-
return
192-
}
193-
194-
this.targetAppids = res.data
195-
.filter(item => item.source_appid === this.appid)
196-
.map(item => item.target_appid)
197-
},
198127
async getReplicateRequests() {
199128
this.listLoading = true
200129

packages/app-console/src/views/storage/buckets.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export default {
311311
},
312312
// 获取 bucket 地址
313313
getBucketUrl(bucketName) {
314-
return oss.getBucketUrl(bucketName)
314+
return oss.getBucketSecondaryUrl(bucketName)
315315
},
316316
// 查看详情
317317
async handleShowDetail(row) {

packages/app-console/src/views/storage/components/path-link.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
</template>
1414

1515
<script>
16+
import store from '@/store'
17+
1618
export default {
1719
name: 'PathLink',
1820
props: {
@@ -54,14 +56,15 @@ export default {
5456
* ```
5557
*/
5658
resolvePath() {
59+
const appid = store.state.app.appid
5760
const strs = this.path.split('/')
5861
.filter(str => str !== '')
5962
6063
const arr = strs.map(name => {
6164
return { name, path: '' }
6265
})
6366
64-
arr.unshift({ name: this.bucket, path: '/' })
67+
arr.unshift({ name: `${appid}-${this.bucket}`, path: '/' })
6568
for (let i = 1; i < arr.length; i++) {
6669
const pre = arr[i - 1]
6770
arr[i].path = pre.path + arr[i].name + '/'

packages/app-console/src/views/storage/files.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ export default {
269269
// 拼装文件下载 URL
270270
getFileUrl(file) {
271271
assert(file && file.Key, 'invalid file or filename')
272-
return oss.getAppFileUrl(this.bucket, file.Key, this.bucketDetail.credentials)
272+
const url = oss.getAppFileUrl(this.bucket, file.Key, this.bucketDetail.credentials)
273+
console.log('getFileURl', url)
274+
return url
273275
},
274276
getFileName(file) {
275277
assert(file && file.Key, 'invalid file or filename')

packages/system-client/src/api/application.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export async function stopApplicationInstance(appid) {
117117
*/
118118
export async function restartApplicationInstance(appid) {
119119
const res = await request({
120-
url: `/sys-api/apps/${appid}/instance/stop`,
120+
url: `/sys-api/apps/${appid}/instance/restart`,
121121
method: 'post'
122122
})
123123
return res

packages/system-client/src/views/application/index.vue

+14-6
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,26 @@ export default {
292292
},
293293
async created() {
294294
this.loadApps()
295+
setInterval(() => { this.getApplications(true) }, 8000)
295296
},
296297
methods: {
297-
async loadApps() {
298-
this.loading = true
298+
loadApps() {
299+
this.getApplications()
300+
this.getSpecs()
301+
},
302+
async getSpecs() {
303+
const specs = await getSpecs()
304+
this.specs = specs.data
305+
},
306+
async getApplications(interval = false) {
307+
if (!interval) this.loading = true
299308
const res = await getMyApplications()
300-
.finally(() => { this.loading = false })
309+
.finally(() => {
310+
if (!interval) this.loading = false
311+
})
301312
const { created, joined } = res.data
302313
this.applications.created = created
303314
this.applications.joined = joined
304-
305-
const specs = await getSpecs()
306-
this.specs = specs.data
307315
},
308316
toDetail(app) {
309317
if (app.status !== 'running') {

0 commit comments

Comments
 (0)