diff --git a/packages/system-client/.vscode/settings.json b/packages/system-client/.vscode/settings.json index f6caa32f76..7f12680804 100644 --- a/packages/system-client/.vscode/settings.json +++ b/packages/system-client/.vscode/settings.json @@ -49,5 +49,8 @@ // json "[json]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" - } + }, + "cSpell.words": [ + "cloudfunction" + ] } \ No newline at end of file diff --git a/packages/system-client/src/api/func.js b/packages/system-client/src/api/func.js index 1361760c98..bd925c19ac 100644 --- a/packages/system-client/src/api/func.js +++ b/packages/system-client/src/api/func.js @@ -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 diff --git a/packages/system-client/src/permission.js b/packages/system-client/src/permission.js index e505c726b8..8e0be9660f 100644 --- a/packages/system-client/src/permission.js +++ b/packages/system-client/src/permission.js @@ -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: '/' }) @@ -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 diff --git a/packages/system-client/src/router/async.js b/packages/system-client/src/router/async.js index c19355c5b7..3821579c9e 100644 --- a/packages/system-client/src/router/async.js +++ b/packages/system-client/src/router/async.js @@ -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: '云函数', @@ -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: { @@ -46,8 +46,8 @@ export const asyncRoutes = [ } }, { - path: 'function-logs', - component: () => import('@/views/development/function_logs'), + path: 'logs', + component: () => import('@/views/cloudfunction/logs'), name: 'AllFunctionLogs', meta: { title: '云函数日志', @@ -55,8 +55,8 @@ export const asyncRoutes = [ } }, { - path: 'function-logs/:id', - component: () => import('@/views/development/function_logs'), + path: 'logs/:id', + component: () => import('@/views/cloudfunction/logs'), name: 'FunctionlogsListPage', hidden: true, meta: { @@ -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: { @@ -142,6 +142,7 @@ export const asyncRoutes = [ title: '成员管理', icon: 'peoples', noCache: true }, + hidden: true, children: [ { path: 'index', diff --git a/packages/system-client/src/views/development/components/FunctionLogDetail.vue b/packages/system-client/src/views/cloudfunction/components/FunctionLogDetail.vue similarity index 100% rename from packages/system-client/src/views/development/components/FunctionLogDetail.vue rename to packages/system-client/src/views/cloudfunction/components/FunctionLogDetail.vue diff --git a/packages/system-client/src/views/development/function.vue b/packages/system-client/src/views/cloudfunction/debug.vue similarity index 93% rename from packages/system-client/src/views/development/function.vue rename to packages/system-client/src/views/cloudfunction/debug.vue index 77ffa5ae57..90f59a30b0 100644 --- a/packages/system-client/src/views/development/function.vue +++ b/packages/system-client/src/views/cloudfunction/debug.vue @@ -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' @@ -229,17 +227,14 @@ 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 @@ -247,7 +242,6 @@ export default { if (showTip) { await this.getFunction() - await this.addFunctionHistory() this.$message.success('已保存: ' + this.func.name) } @@ -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 diff --git a/packages/system-client/src/views/development/functions.vue b/packages/system-client/src/views/cloudfunction/index.vue similarity index 100% rename from packages/system-client/src/views/development/functions.vue rename to packages/system-client/src/views/cloudfunction/index.vue diff --git a/packages/system-client/src/views/development/function_logs.vue b/packages/system-client/src/views/cloudfunction/logs.vue similarity index 100% rename from packages/system-client/src/views/development/function_logs.vue rename to packages/system-client/src/views/cloudfunction/logs.vue diff --git a/packages/system-client/src/views/development/triggers.vue b/packages/system-client/src/views/cloudfunction/triggers.vue similarity index 100% rename from packages/system-client/src/views/development/triggers.vue rename to packages/system-client/src/views/cloudfunction/triggers.vue