From ac237efd8827ad91b441588dbf98116e1211add9 Mon Sep 17 00:00:00 2001 From: maslow Date: Thu, 5 Aug 2021 00:17:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=92=8C=E4=BD=BF=E7=94=A8=E4=BA=91=E5=87=BD=E6=95=B0=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=BB=A4=E7=89=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/devops-admin/src/api/func.js | 7 +++++-- packages/devops-admin/src/store/modules/user.js | 6 +++++- packages/devops-admin/src/utils/auth.js | 17 +++++++++++++++++ .../devops-admin/src/views/database/policy.vue | 3 ++- .../src/views/development/function.vue | 10 ++++++---- .../src/views/development/functions.vue | 8 ++++---- 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/packages/devops-admin/src/api/func.js b/packages/devops-admin/src/api/func.js index 7870c4b545..94896f82bc 100644 --- a/packages/devops-admin/src/api/func.js +++ b/packages/devops-admin/src/api/func.js @@ -5,9 +5,12 @@ import request from '@/utils/request' */ export function launchFunction(functionName, data, debug = false) { return request({ - url: `/app/func/invoke/${functionName}?debug=${debug}`, + url: `/app/func/invoke/${functionName}`, method: 'post', - data: data + data: data, + headers: { + 'debug-token': debug + } }) } diff --git a/packages/devops-admin/src/store/modules/user.js b/packages/devops-admin/src/store/modules/user.js index 449a933a49..e55c96d35a 100644 --- a/packages/devops-admin/src/store/modules/user.js +++ b/packages/devops-admin/src/store/modules/user.js @@ -1,5 +1,5 @@ import { login, getInfo } from '@/api/user' -import { getToken, setToken, removeToken } from '@/utils/auth' +import { getToken, setToken, removeToken, setDebugToken, removeDebugToken } from '@/utils/auth' import router, { resetRouter } from '@/router' const state = { @@ -41,6 +41,9 @@ const actions = { const { data } = response commit('SET_TOKEN', data.access_token) setToken(data.access_token, data.expire) + if (data.debug_token) { + setDebugToken(data.debug_token) + } resolve() }).catch(error => { reject(error) @@ -88,6 +91,7 @@ const actions = { commit('SET_PERMISSIONS', []) removeToken() + removeDebugToken() resetRouter() // reset visited views and cached views diff --git a/packages/devops-admin/src/utils/auth.js b/packages/devops-admin/src/utils/auth.js index 4f6eb4fa53..6073b4f7e1 100644 --- a/packages/devops-admin/src/utils/auth.js +++ b/packages/devops-admin/src/utils/auth.js @@ -8,6 +8,7 @@ export function getToken() { if (!expire || expire <= Date.now() / 1000) { removeToken() + removeDebugToken() } return token @@ -22,3 +23,19 @@ export function removeToken() { localStorage.removeItem(kExpire) return localStorage.removeItem(kToken) } + +/** + * 获取调试云函数的 token + */ +export function getDebugToken() { + const token = localStorage.getItem('debug_token') + return token +} + +export function setDebugToken(token) { + return localStorage.setItem('debug_token', token) +} + +export function removeDebugToken() { + return localStorage.removeItem('debug_token') +} diff --git a/packages/devops-admin/src/views/database/policy.vue b/packages/devops-admin/src/views/database/policy.vue index 63bc2ccdb2..b468b36a7f 100644 --- a/packages/devops-admin/src/views/database/policy.vue +++ b/packages/devops-admin/src/views/database/policy.vue @@ -17,7 +17,7 @@
选择集合
- + {{ item }} @@ -316,6 +316,7 @@ export default { .collection-list { width: 200px; border-radius: 5px; + box-sizing: border-box; .label { font-size: 14px; diff --git a/packages/devops-admin/src/views/development/function.vue b/packages/devops-admin/src/views/development/function.vue index 3579c2c76c..b3f478cbcf 100644 --- a/packages/devops-admin/src/views/development/function.vue +++ b/packages/devops-admin/src/views/development/function.vue @@ -109,9 +109,10 @@ import FunctionLogDetail from './components/FunctionLogDetail' import FunctionEditor from '@/components/FunctionEditor' import jsonEditor from '@/components/JsonEditor/param' -import { db, dbm_cloud } from '@/api/cloud' -import { launchFunction } from '@/api/func' -import { publishFunctions } from '@/api/publish' +import { db, dbm_cloud } from '../../api/cloud' +import { launchFunction } from '../../api/func' +import { publishFunctions } from '../../api/publish' +import { getDebugToken } from '../../utils/auth' const defaultParamValue = { code: 'laf' @@ -249,6 +250,7 @@ export default { * 运行函数代码 */ async launch() { + const debug_token = getDebugToken() await this.updateFunc(false) if (this.loading) { return @@ -258,7 +260,7 @@ export default { const param = this.parseInvokeParam(this.invokeParams) - const res = await launchFunction(this.func.name, param, true) + const res = await launchFunction(this.func.name, param, debug_token) .catch(err => { console.error(err) this.$message.warning('运行失败: ' + err) diff --git a/packages/devops-admin/src/views/development/functions.vue b/packages/devops-admin/src/views/development/functions.vue index fddebe8aaa..eb0fc9eb3b 100644 --- a/packages/devops-admin/src/views/development/functions.vue +++ b/packages/devops-admin/src/views/development/functions.vue @@ -409,16 +409,16 @@ export default { async handleDelete(row, index) { await this.$confirm('确认要删除此数据?', '删除确认') - if(row.status) { + if (row.status) { return this.$message.error('请先停用函数,再删除!') } const $ = db.command // 执行删除请求 const r = await db.collection('__functions') - .where({ - _id: row._id, - status: 0, + .where({ + _id: row._id, + status: 0, reserved: $.neq(true) }) .remove()