Skip to content

Commit 49fd049

Browse files
committed
fix(system-client): fix the function updating pages;
1 parent 834915a commit 49fd049

File tree

9 files changed

+42
-37
lines changed

9 files changed

+42
-37
lines changed

packages/system-client/.vscode/settings.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,8 @@
4949
// json
5050
"[json]": {
5151
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
52-
}
52+
},
53+
"cSpell.words": [
54+
"cloudfunction"
55+
]
5356
}

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

+15
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ export function updateFunction(func_id, function_data) {
6565
})
6666
}
6767

68+
/**
69+
* Update the code of cloud function
70+
* @param {string} func_id
71+
* @param {object} function_data
72+
* @returns
73+
*/
74+
export function updateFunctionCode(func_id, function_data) {
75+
const appid = store.state.app.appid
76+
return request({
77+
url: `/apps/${appid}/function/${func_id}/code`,
78+
method: 'post',
79+
data: function_data
80+
})
81+
}
82+
6883
/**
6984
* Delete a cloud function
7085
* @param {*} func_id

packages/system-client/src/permission.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ router.beforeEach(async(to, from, next) => {
2222
const hasToken = getToken()
2323

2424
if (hasToken) {
25+
if (!store.state.user.name) {
26+
store.dispatch('user/getInfo')
27+
}
2528
if (to.path === '/login') {
2629
// if is logged in, redirect to the home page
2730
next({ path: '/' })
@@ -43,7 +46,8 @@ router.beforeEach(async(to, from, next) => {
4346
await store.dispatch('app/loadCurrentApplication', appid)
4447
} catch (error) {
4548
console.error(`failed to load application: ${appid}`, error)
46-
Message('加载应用信息出错,请重试')
49+
Message('加载应用信息出错,请刷新重试')
50+
return
4751
}
4852

4953
const roles = store.state.app.roles

packages/system-client/src/router/async.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ export const asyncRoutes = [
1919
]
2020
},
2121
{
22-
path: '/app/:appid/development',
22+
path: '/app/:appid/cloudfunction',
2323
component: Layout,
2424
meta: {
2525
title: '云函数', icon: 'example'
2626
},
2727
children: [
2828
{
29-
path: 'functions',
30-
component: () => import('@/views/development/functions'),
29+
path: 'index',
30+
component: () => import('@/views/cloudfunction/index'),
3131
name: 'FunctionListPage',
3232
meta: {
3333
title: '云函数',
@@ -37,7 +37,7 @@ export const asyncRoutes = [
3737
},
3838
{
3939
path: 'functions/:id',
40-
component: () => import('@/views/development/function'),
40+
component: () => import('@/views/cloudfunction/debug'),
4141
name: 'FunctionEditorPage',
4242
hidden: true,
4343
meta: {
@@ -46,17 +46,17 @@ export const asyncRoutes = [
4646
}
4747
},
4848
{
49-
path: 'function-logs',
50-
component: () => import('@/views/development/function_logs'),
49+
path: 'logs',
50+
component: () => import('@/views/cloudfunction/logs'),
5151
name: 'AllFunctionLogs',
5252
meta: {
5353
title: '云函数日志',
5454
icon: 'documentation'
5555
}
5656
},
5757
{
58-
path: 'function-logs/:id',
59-
component: () => import('@/views/development/function_logs'),
58+
path: 'logs/:id',
59+
component: () => import('@/views/cloudfunction/logs'),
6060
name: 'FunctionlogsListPage',
6161
hidden: true,
6262
meta: {
@@ -66,7 +66,7 @@ export const asyncRoutes = [
6666
},
6767
{
6868
path: 'triggers/:funcId',
69-
component: () => import('@/views/development/triggers'),
69+
component: () => import('@/views/cloudfunction/triggers'),
7070
name: 'TriggerListPage',
7171
hidden: true,
7272
meta: {
@@ -142,6 +142,7 @@ export const asyncRoutes = [
142142
title: '成员管理', icon: 'peoples',
143143
noCache: true
144144
},
145+
hidden: true,
145146
children: [
146147
{
147148
path: 'index',

packages/system-client/src/views/development/function.vue renamed to packages/system-client/src/views/cloudfunction/debug.vue

+8-26
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@
106106
import FunctionLogDetail from './components/FunctionLogDetail'
107107
import FunctionEditor from '@/components/FunctionEditor'
108108
import jsonEditor from '@/components/JsonEditor/param'
109-
import { db } from '../../api/cloud'
110-
import { getFunctionById, launchFunction } from '../../api/func'
109+
import { getFunctionById, launchFunction, updateFunctionCode } from '../../api/func'
111110
import { publishFunctions } from '../../api/func'
112-
import { Constants } from '../../api/constants'
113111
114112
const defaultParamValue = {
115113
code: 'laf'
@@ -229,25 +227,21 @@ export default {
229227
if (typeof param !== 'string') {
230228
param = JSON.stringify(this.invokeParams)
231229
}
232-
const r = await db.collection(Constants.cn.functions)
233-
.where({
234-
_id: this.func._id
235-
})
236-
.update({
237-
code: this.value,
238-
update_at: Date.now(),
239-
debugParams: param
240-
})
241230
242-
if (!r.ok) {
231+
const r = await updateFunctionCode(this.func._id, {
232+
code: this.value,
233+
update_at: Date.now(),
234+
debugParams: param
235+
})
236+
237+
if (r.error) {
243238
this.$message('保存失败!')
244239
this.loading = false
245240
return
246241
}
247242
248243
if (showTip) {
249244
await this.getFunction()
250-
await this.addFunctionHistory()
251245
this.$message.success('已保存: ' + this.func.name)
252246
}
253247
@@ -295,18 +289,6 @@ export default {
295289
296290
// this.lastestLogs = res.data || []
297291
},
298-
/**
299-
* 添加函数的更新记录
300-
*/
301-
async addFunctionHistory() {
302-
// const data = Object.assign({}, this.func)
303-
// await db.collection(Constants.cn.function_history)
304-
// .add({
305-
// func_id: this.func._id,
306-
// data: data,
307-
// created_at: Date.now()
308-
// })
309-
},
310292
showLogDetailDlg(log) {
311293
this.logDetail = log
312294
this.isShowLogDetail = true

0 commit comments

Comments
 (0)