Skip to content

Commit 45a85e9

Browse files
committed
feat(sys-client): add func history & code diff editor;
1 parent 83cfe78 commit 45a85e9

File tree

4 files changed

+263
-23
lines changed

4 files changed

+263
-23
lines changed

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

+32
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ export function publishOneFunction(func_id) {
155155
})
156156
}
157157

158+
/**
159+
* Compile the code of cloud function
160+
* @param {string} func_id
161+
* @param {object} function_data
162+
* @returns
163+
*/
164+
export function compileFunctionCode(func_id, function_data) {
165+
const appid = store.state.app.appid
166+
return request({
167+
url: `/apps/${appid}/function/${func_id}/compile`,
168+
method: 'post',
169+
data: function_data
170+
})
171+
}
172+
158173
/**
159174
* Debug cloud function
160175
*/
@@ -210,3 +225,20 @@ export async function getFunctionLogs(query, page, pageSize) {
210225

211226
return res
212227
}
228+
229+
/**
230+
* Get a cloud function's change history
231+
* @param {*} page
232+
* @param {*} pageSize
233+
*/
234+
export function getFunctionChangeHistory(func_id, page = 1, pageSize = 20) {
235+
const appid = store.state.app.appid
236+
return request({
237+
url: `/apps/${appid}/function/${func_id}/changes`,
238+
method: 'get',
239+
params: {
240+
page,
241+
limit: pageSize
242+
}
243+
})
244+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<template>
2+
<div class="json-editor">
3+
<div ref="diffeditor" class="diff-editor" :style="{height: `${minHeight}px`}" />
4+
</div>
5+
</template>
6+
7+
<script>
8+
import * as monaco from 'monaco-editor'
9+
10+
export default {
11+
name: 'FunctionDiffEditor',
12+
/* eslint-disable vue/require-prop-types */
13+
props: ['original', 'modified', 'height', 'dark', 'name'],
14+
data() {
15+
return {
16+
originalModel: null,
17+
modifiedModel: null,
18+
editor: {}
19+
}
20+
},
21+
computed: {
22+
minHeight() {
23+
return this.height || 150
24+
}
25+
},
26+
watch: {
27+
// modified(value) {
28+
// const editorValue = this.modifiedModel?.getValue()
29+
// if (value !== editorValue) {
30+
// console.log(value, editorValue)
31+
// this.modifiedModel.setValue(this.value)
32+
// }
33+
// },
34+
height(value) {
35+
// this.initEditor()
36+
}
37+
},
38+
mounted() {
39+
this.initEditor()
40+
},
41+
methods: {
42+
initEditor() {
43+
this.originalModel = monaco.editor.createModel(this.original, 'typescript', monaco.Uri.parse(`diff-${Math.random()}.ts`))
44+
this.modifiedModel = monaco.editor.createModel(this.modified, 'typescript', monaco.Uri.parse(`diff-${Math.random()}.ts`))
45+
46+
this.editor = monaco.editor.createDiffEditor(this.$refs.diffeditor, {
47+
enableSplitViewResizing: false,
48+
lineNumbers: 'on',
49+
roundedSelection: true,
50+
scrollBeyondLastLine: false,
51+
theme: this.dark ? 'vs-dark' : 'vs',
52+
readOnly: true,
53+
formatOnType: true,
54+
fontSize: 12,
55+
linkedEditing: true,
56+
cursorBlinking: 'expand',
57+
smoothScrolling: true,
58+
renderWhitespace: 'selection',
59+
tabSize: 2,
60+
automaticLayout: true,
61+
autoIndent: true,
62+
showFoldingControls: 'always',
63+
showDeprecated: true,
64+
definitionLinkOpensInPeek: false
65+
})
66+
67+
this.editor.setModel({
68+
original: this.originalModel,
69+
modified: this.modifiedModel
70+
})
71+
72+
// this.editor = monaco.editor.create(this.$refs.jseditor, {
73+
// lineNumbers: 'on',
74+
// roundedSelection: true,
75+
// scrollBeyondLastLine: false,
76+
// theme: this.dark ? 'vs-dark' : 'vs',
77+
// readOnly: false,
78+
// formatOnType: true,
79+
// fontSize: 16,
80+
// linkedEditing: true,
81+
// cursorBlinking: 'expand',
82+
// smoothScrolling: true,
83+
// renderWhitespace: 'selection',
84+
// tabSize: 2,
85+
// automaticLayout: true,
86+
// autoIndent: true,
87+
// showFoldingControls: 'always',
88+
// showDeprecated: true,
89+
// definitionLinkOpensInPeek: false,
90+
// model: monaco.editor.createModel(this.value, 'typescript', monaco.Uri.parse(filename))
91+
// })
92+
93+
// this.editor.onDidChangeModelContent(e => {
94+
// this.$emit('input', this.editor?.getValue())
95+
// this.parseImports(this.getValue())
96+
// })
97+
}
98+
99+
// getValue() {
100+
// return this.editor?.getValue()
101+
// },
102+
}
103+
}
104+
</script>
105+
106+
<style lang="scss" scoped>
107+
.json-editor {
108+
height: 100%;
109+
// position: relative;
110+
111+
.diff-editor {
112+
width: 100%;
113+
min-height: 600px;
114+
}
115+
}
116+
</style>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const asyncRoutes = [
4141
meta: {
4242
title: '调试云函数',
4343
icon: 'bug',
44-
noCache: false
44+
noCache: true
4545
}
4646
},
4747
{

0 commit comments

Comments
 (0)