Skip to content

Commit

Permalink
fix(system-client): fix the function updating pages;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Sep 4, 2021
1 parent 834915a commit 49fd049
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 37 deletions.
5 changes: 4 additions & 1 deletion packages/system-client/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@
// json
"[json]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
},
"cSpell.words": [
"cloudfunction"
]
}
15 changes: 15 additions & 0 deletions packages/system-client/src/api/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ export function updateFunction(func_id, function_data) {
})
}

/**
* Update the code of cloud function
* @param {string} func_id
* @param {object} function_data
* @returns
*/
export function updateFunctionCode(func_id, function_data) {
const appid = store.state.app.appid
return request({
url: `/apps/${appid}/function/${func_id}/code`,
method: 'post',
data: function_data
})
}

/**
* Delete a cloud function
* @param {*} func_id
Expand Down
6 changes: 5 additions & 1 deletion packages/system-client/src/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ router.beforeEach(async(to, from, next) => {
const hasToken = getToken()

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

const roles = store.state.app.roles
Expand Down
19 changes: 10 additions & 9 deletions packages/system-client/src/router/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ export const asyncRoutes = [
]
},
{
path: '/app/:appid/development',
path: '/app/:appid/cloudfunction',
component: Layout,
meta: {
title: '云函数', icon: 'example'
},
children: [
{
path: 'functions',
component: () => import('@/views/development/functions'),
path: 'index',
component: () => import('@/views/cloudfunction/index'),
name: 'FunctionListPage',
meta: {
title: '云函数',
Expand All @@ -37,7 +37,7 @@ export const asyncRoutes = [
},
{
path: 'functions/:id',
component: () => import('@/views/development/function'),
component: () => import('@/views/cloudfunction/debug'),
name: 'FunctionEditorPage',
hidden: true,
meta: {
Expand All @@ -46,17 +46,17 @@ export const asyncRoutes = [
}
},
{
path: 'function-logs',
component: () => import('@/views/development/function_logs'),
path: 'logs',
component: () => import('@/views/cloudfunction/logs'),
name: 'AllFunctionLogs',
meta: {
title: '云函数日志',
icon: 'documentation'
}
},
{
path: 'function-logs/:id',
component: () => import('@/views/development/function_logs'),
path: 'logs/:id',
component: () => import('@/views/cloudfunction/logs'),
name: 'FunctionlogsListPage',
hidden: true,
meta: {
Expand All @@ -66,7 +66,7 @@ export const asyncRoutes = [
},
{
path: 'triggers/:funcId',
component: () => import('@/views/development/triggers'),
component: () => import('@/views/cloudfunction/triggers'),
name: 'TriggerListPage',
hidden: true,
meta: {
Expand Down Expand Up @@ -142,6 +142,7 @@ export const asyncRoutes = [
title: '成员管理', icon: 'peoples',
noCache: true
},
hidden: true,
children: [
{
path: 'index',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@
import FunctionLogDetail from './components/FunctionLogDetail'
import FunctionEditor from '@/components/FunctionEditor'
import jsonEditor from '@/components/JsonEditor/param'
import { db } from '../../api/cloud'
import { getFunctionById, launchFunction } from '../../api/func'
import { getFunctionById, launchFunction, updateFunctionCode } from '../../api/func'
import { publishFunctions } from '../../api/func'
import { Constants } from '../../api/constants'
const defaultParamValue = {
code: 'laf'
Expand Down Expand Up @@ -229,25 +227,21 @@ export default {
if (typeof param !== 'string') {
param = JSON.stringify(this.invokeParams)
}
const r = await db.collection(Constants.cn.functions)
.where({
_id: this.func._id
})
.update({
code: this.value,
update_at: Date.now(),
debugParams: param
})
if (!r.ok) {
const r = await updateFunctionCode(this.func._id, {
code: this.value,
update_at: Date.now(),
debugParams: param
})
if (r.error) {
this.$message('保存失败!')
this.loading = false
return
}
if (showTip) {
await this.getFunction()
await this.addFunctionHistory()
this.$message.success('已保存: ' + this.func.name)
}
Expand Down Expand Up @@ -295,18 +289,6 @@ export default {
// this.lastestLogs = res.data || []
},
/**
* 添加函数的更新记录
*/
async addFunctionHistory() {
// const data = Object.assign({}, this.func)
// await db.collection(Constants.cn.function_history)
// .add({
// func_id: this.func._id,
// data: data,
// created_at: Date.now()
// })
},
showLogDetailDlg(log) {
this.logDetail = log
this.isShowLogDetail = true
Expand Down

0 comments on commit 49fd049

Please sign in to comment.