66 </v-icon >
77 </template >
88 <template v-slot :default =" dialog " >
9+ <v-snackbar
10+ v-model =" snackbar"
11+ timeout =" 5000"
12+ multi-line
13+ :color =" snackbarColor"
14+ >
15+ {{ snackbarText }}
16+ <template v-slot :action =" { attrs } " >
17+ <v-btn text v-bind =" attrs" @click =" snackbar = false" > 关闭 </v-btn >
18+ </template >
19+ </v-snackbar >
920 <v-card >
1021 <v-toolbar color =" primary" dark >
1122 <v-toolbar-title >上传至云端执行</v-toolbar-title >
1728 </v-toolbar-items >
1829 </v-toolbar >
1930 <div style =" padding : 10px ; box-sizing : border-box " >
31+ <a href =" https://docs.scriptcat.org/dev/cloudcat.html" target =" _blank"
32+ >云端执行文档</a
33+ >
2034 <v-input :v-model =" exportConfig.uuid" disabled > </v-input >
2135 <v-select
2236 label =" 上传至"
4155 <v-text-field
4256 v-if =" exportConfig.param"
4357 v-model =" exportConfig.param.secretKey"
58+ type =" password"
4459 label =" SecretKey"
4560 >
4661 </v-text-field >
5368 item-value =" key"
5469 hint =" 地域请查看 https://cloud.tencent.com/document/product/583/17237"
5570 persistent-hint
71+ return-object
5672 single-line
5773 ></v-select >
5874 </div >
87103 <div v-else-if =" exportConfig.dest == 'remote'" ></div >
88104 </div >
89105 <v-card-actions class =" justify-end" >
106+ <v-btn text color =" error" @click =" clear" >{{
107+ btnText[exportConfig.dest] || "清除配置"
108+ }}</v-btn >
90109 <v-btn text color =" success" @click =" submit" >{{
91110 btnText[exportConfig.dest] || "提交"
92111 }}</v-btn >
@@ -122,7 +141,7 @@ import { ScfClient } from '@App/pkg/sdk/tencent_cloud/scf';
122141interface TencentCloud {
123142 secretId: string ;
124143 secretKey: string ;
125- region: { key : string ; value : string } ;
144+ region: string ;
126145 regionList: { key: string ; value: string }[];
127146}
128147
@@ -132,6 +151,10 @@ export default class BgCloud extends Vue {
132151
133152 icons = { mdiCloudUpload , mdiClose };
134153
154+ snackbar = false ;
155+ snackbarText = ' ' ;
156+ snackbarColor = ' red' ;
157+
135158 @Prop ()
136159 script! : Script ;
137160 exportConfig: Export = {
@@ -160,9 +183,8 @@ export default class BgCloud extends Vue {
160183 param: <TencentCloud >{
161184 secretId: ' ' ,
162185 secretKey: ' ' ,
163- region: { value: ' 就近地域接入 ' , key: ' ' } ,
186+ region: ' ap-shanghai ' ,
164187 regionList: [
165- { value: ' 就近地域接入' , key: ' ' },
166188 { value: ' 华东地区(上海)' , key: ' ap-shanghai' },
167189 { value: ' 华北地区(北京)' , key: ' ap-beijing' },
168190 { value: ' 西南地区(成都)' , key: ' ap-chengdu' },
@@ -235,6 +257,17 @@ export default class BgCloud extends Vue {
235257 }
236258 }
237259
260+ async clear() {
261+ let e = await this .exportModel .findOne ({
262+ scriptId: this .script .id ,
263+ dest: this .exportDest .key ,
264+ });
265+ if (e ) {
266+ await this .exportModel .delete (e .id );
267+ }
268+ void this .onChangeDest ();
269+ }
270+
238271 submit() {
239272 this .exportConfig .dest = <EXPORT_DEST >this .exportDest .key ;
240273 switch (this .exportDest .key ) {
@@ -249,32 +282,64 @@ export default class BgCloud extends Vue {
249282 }
250283
251284 async tencent() {
252- const param = <TencentCloud >this .exportDest .param ;
285+ let crontab =
286+ this .script .metadata [' crontab' ] && this .script .metadata [' crontab' ][0 ];
287+ if (! crontab ) {
288+ this .message (' 未检测到@crontab声明暂时只支持定时脚本' );
289+ return ;
290+ }
291+
292+ const param = <TencentCloud >this .exportConfig .param ;
253293 const clientConfig: ClientConfig = {
254294 credential: {
255295 secretId: param .secretId ,
256296 secretKey: param .secretKey ,
257297 },
258- region: param .region . key ,
298+ region: param .region ,
259299 profile: {
260300 httpProfile: {
261- reqMethod: ' POST' , // 请求方法
262- reqTimeout: 30 , // 请求超时时间,默认60s
301+ reqMethod: ' POST' ,
302+ reqTimeout: 30 ,
263303 },
264304 },
265305 };
266306 const cli = new ScfClient (clientConfig );
267307 let zip = await this .pack ();
268- void zip .generateAsync ({ type: ' base64' }).then ((content ) => {
269- void cli .CreateFunction ({
270- FunctionName: ' test ' ,
308+ void zip .generateAsync ({ type: ' base64' }).then (async (content ) => {
309+ const resp = await cli .CreateFunction ({
310+ FunctionName: this . script . uuid ,
271311 Code: {
272312 ZipFile: content ,
273313 },
314+ Handler: ' utils.run' ,
315+ Type: ' Event' ,
316+ Runtime: ' Nodejs12.16' ,
317+ Description:
318+ this .script .name +
319+ ' ' +
320+ (this .script .metadata [' description' ] &&
321+ this .script .metadata [' description' ][0 ]),
322+ InstallDependency: ' TRUE' ,
274323 });
324+ if (resp .Response .Error ) {
325+ this .message (
326+ ' 上传失败! ' +
327+ resp .Response .Error .Code +
328+ ' : ' +
329+ resp .Response .Error .Message
330+ );
331+ return ;
332+ }
333+ this .message (' 上传成功!请前往云函数控制台查看详情!' , ' success' );
275334 });
276335 }
277336
337+ message(text : string , color = ' red' ) {
338+ this .snackbar = true ;
339+ this .snackbarText = text ;
340+ this .snackbarColor = color ;
341+ }
342+
278343 async local() {
279344 let zip = await this .pack ();
280345 void zip .generateAsync ({ type: ' blob' }).then ((content ) => {
0 commit comments