1- import React , { useRef } from 'react' ;
1+ import React , { useEffect , useRef } from 'react' ;
22import { Button , Space , message } from 'antd' ;
33import { MessageType } from 'antd/lib/message' ;
44import { render } from 'amis' ;
@@ -7,8 +7,16 @@ import './helper.css';
77// import 'amis/lib/helper.css';
88import 'amis/sdk/iconfont.css' ;
99import axios from 'axios' ;
10+ import {
11+ ListenerAction ,
12+ ListenerContext ,
13+ registerAction ,
14+ RendererAction ,
15+ RendererEvent ,
16+ } from 'amis-core' ;
1017import RunScript from '../RunScript' ;
1118import { useState } from '@/hooks/useImmer' ;
19+ import { runScript } from '@/webview/service' ;
1220
1321const request : { count : number ; hideLoading ?: MessageType } = {
1422 count : 0 ,
@@ -27,6 +35,44 @@ interface IProps {
2735 onFormChange : ( values : object ) => void ;
2836}
2937
38+ // 动作定义
39+ interface IRunScriptAction extends ListenerAction {
40+ actionType : 'runScript' ;
41+ args : {
42+ method : string ; // 动作参数1
43+ params : string ; // 动作参数2
44+ } ;
45+ }
46+
47+ const componentData = {
48+ model : { } ,
49+ materialPath : '' ,
50+ privateMaterials : false ,
51+ } ;
52+ export class RunScriptAction implements RendererAction {
53+ // @ts -ignore
54+ run (
55+ action : IRunScriptAction ,
56+ renderer : ListenerContext ,
57+ event : RendererEvent < any > ,
58+ ) {
59+ const props = renderer . props ;
60+ const { method, params } = action . args ;
61+ runScript ( {
62+ script : method ,
63+ params,
64+ model : componentData . model ,
65+ materialPath : componentData . materialPath ,
66+ privateMaterials : componentData . privateMaterials ,
67+ createBlockPath : localStorage . getItem ( 'selectedFolder' ) || undefined ,
68+ } ) ;
69+ }
70+ }
71+
72+ // 注册自定义动作
73+ // @ts -ignore
74+ registerAction ( 'runScript' , new RunScriptAction ( ) ) ;
75+
3076export default ( props : IProps ) => {
3177 const [ scriptModalVisible , setScriptModalVisible ] = useState ( false ) ;
3278 const [ model , setModel ] = useState ( { } as object ) ;
@@ -134,8 +180,17 @@ export default (props: IProps) => {
134180 } ,
135181 isCancel : ( value : any ) => axios . isCancel ( value ) ,
136182 useMobileUI : false ,
183+ copy : ( contents : string , options ?: any ) => {
184+ navigator . clipboard . writeText ( contents ) ;
185+ message . success ( '已复制到剪贴板' ) ;
186+ } ,
137187 } ;
138188
189+ useEffect ( ( ) => {
190+ componentData . model = model ;
191+ componentData . materialPath = props . path ;
192+ } , [ model , props . path ] ) ;
193+
139194 const handleOpenRunScriptModal = ( ) => {
140195 const values = amisScoped . current
141196 . getComponentByName ( 'page.form' )
0 commit comments