1
1
<template >
2
2
<div class =" app-container" >
3
3
<div v-if =" func" class =" header" >
4
- <span style =" font-size : 22px ;line-height : 40px ;" ><b >{{ func.label }}</b > </span >
4
+ <span style =" font-size : 22px ;line-height : 40px ;" >
5
+ <!-- <el-tag v-if="saved_code_diff" type="warning" size="mini" effect="plain">*</el-tag> -->
6
+ <b >{{ func.label }}</b >
7
+ <span v-if =" saved_code_diff" style =" margin-left : 8px ; font-size : 18px ; color : red " >
8
+ <i class =" el-icon-edit" />
9
+ </span >
10
+ </span >
5
11
<el-tag v-clipboard:message =" func.name" v-clipboard:success =" onCopy" style =" margin-left : 14px ; " size =" mini" type =" success" >{{ func.name }}</el-tag >
12
+
6
13
<el-button
7
14
style =" margin-left : 20px "
8
15
icon =" el-icon-refresh"
9
16
type =" text"
10
- :disabled =" loading"
11
17
size =" default"
18
+ :loading =" loading"
12
19
@click =" getFunction"
13
20
>刷新</el-button >
14
21
<el-button
15
- type =" success"
16
22
size =" mini"
17
23
style =" margin-left : 20px ;"
18
- :disabled =" loading || !func"
24
+ :loading =" loading"
25
+ :disabled =" !saved_code_diff"
26
+ :type =" saved_code_diff ? 'success' : 'success'"
19
27
@click =" updateFunc"
20
28
>保存(S)</el-button >
21
29
<el-button
22
- type =" warning"
23
- plain
30
+ :type =" published_version_diff ? 'default' : 'text'"
24
31
size =" mini"
32
+ :loading =" loading"
25
33
style =" margin-left : 15px ;"
26
- :disabled =" loading || !func "
34
+ :disabled =" !published_version_diff "
27
35
@click =" publishFunction"
28
- >发布 </el-button >
36
+ >{{ published_version_diff ? '发布': '已发布' }} </el-button >
29
37
<el-button size =" small" style =" float : right ;" type =" primary" @click =" showDebugPanel = true" >显示调试面板(J)</el-button >
30
38
</div >
31
39
69
77
size =" mini"
70
78
type =" success"
71
79
style =" margin-left : 10px "
72
- :disabled =" loading || !func "
80
+ :loading =" loading"
73
81
@click =" launch"
74
82
>运行(B)</el-button >
75
83
</div >
114
122
import FunctionLogDetail from ' ./components/FunctionLogDetail'
115
123
import FunctionEditor from ' @/components/FunctionEditor'
116
124
import jsonEditor from ' @/components/JsonEditor/param'
117
- import { getFunctionById , getFunctionLogs , launchFunction , publishOneFunction , updateFunctionCode } from ' ../../api/func'
125
+ import { getFunctionById , getFunctionLogs , getPublishedFunction , launchFunction , publishOneFunction , updateFunctionCode } from ' ../../api/func'
118
126
import { showError , showSuccess } from ' @/utils/show'
119
127
import { debounce } from ' lodash'
128
+ import { hashString } from ' @/utils/hash'
120
129
121
130
const defaultParamValue = {
122
131
code: ' laf'
@@ -130,6 +139,7 @@ export default {
130
139
value: ' ' ,
131
140
editorHeight: 500 ,
132
141
func: null ,
142
+ published_func: null ,
133
143
func_id: ' ' ,
134
144
invokeParams: defaultParamValue,
135
145
// 调用云函数返回的值
@@ -156,6 +166,21 @@ export default {
156
166
},
157
167
app () {
158
168
return this .$store .state .app .application
169
+ },
170
+ published_version_diff () {
171
+ const cur = this .func ? .version
172
+ const pub = this .published_func ? .version
173
+ return cur !== pub
174
+ },
175
+ published_code_diff () {
176
+ const cur = this .func ? .hash
177
+ const pub = this .published_func ? .hash
178
+ return cur !== pub
179
+ },
180
+ saved_code_diff () {
181
+ const cur = hashString (this .value )
182
+ const saved = this .func ? .hash
183
+ return cur !== saved
159
184
}
160
185
},
161
186
watch: {
@@ -201,11 +226,16 @@ export default {
201
226
this .value = this .func .code
202
227
this .invokeParams = this .parseInvokeParam (this .func .debugParams ) ?? defaultParamValue
203
228
this .loading = false
229
+
230
+ this .published_func = await getPublishedFunction (func_id)
204
231
},
205
232
/**
206
233
* 保存函数代码
207
234
*/
208
235
async updateFunc (showTip = true ) {
236
+ if (! this .saved_code_diff ) {
237
+ return
238
+ }
209
239
if (this .loading ) { return }
210
240
if (this .validate ()) { return }
211
241
@@ -224,12 +254,8 @@ export default {
224
254
225
255
if (r .error ) { return showError (' 保存失败!' ) }
226
256
227
- this .func = r .data
228
- this .value = this .func .code
229
- this .invokeParams = this .parseInvokeParam (this .func .debugParams ) ?? defaultParamValue
230
-
257
+ await this .getFunction ()
231
258
if (showTip) {
232
- // await this.getFunction()
233
259
showSuccess (' 已保存: ' + this .func .name )
234
260
}
235
261
},
@@ -268,6 +294,7 @@ export default {
268
294
269
295
if (r .error ) { return showError (' 发布失败!' ) }
270
296
297
+ this .getFunction ()
271
298
showSuccess (' 已发布: ' + this .func .name )
272
299
},
273
300
async getLogByRequestId (requestId ) {
0 commit comments