@@ -15,6 +15,10 @@ import {
1515 push_dst_ip_rules_rule ,
1616 update_dst_ip_rules_rule ,
1717} from " @/api/dst_ip_rule" ;
18+ import {
19+ copy_context_to_clipboard ,
20+ read_context_from_clipboard ,
21+ } from " @/lib/common" ;
1822
1923interface Props {
2024 flow_id: number ;
@@ -98,6 +102,31 @@ async function saveRule() {
98102 emit (" refresh" );
99103 }
100104}
105+
106+ async function export_config() {
107+ if (rule .value ) {
108+ let configs = rule .value .source ;
109+ await copy_context_to_clipboard (message , JSON .stringify (configs , null , 2 ));
110+ }
111+ }
112+
113+ async function import_rules() {
114+ if (rule .value ) {
115+ try {
116+ let rules = JSON .parse (await read_context_from_clipboard ());
117+ rule .value .source = rules ;
118+ } catch (e ) {}
119+ }
120+ }
121+
122+ async function append_import_rules() {
123+ if (rule .value ) {
124+ try {
125+ let rules = JSON .parse (await read_context_from_clipboard ());
126+ rule .value .source .unshift (... rules );
127+ } catch (e ) {}
128+ }
129+ }
101130 </script >
102131
103132<template >
@@ -136,7 +165,43 @@ async function saveRule() {
136165 <n-form-item label =" 备注" >
137166 <n-input v-model:value =" rule.remark" type =" text" />
138167 </n-form-item >
139- <n-form-item label =" 匹配的 IP" >
168+ <n-form-item >
169+ <template #label >
170+ <n-flex
171+ align =" center"
172+ justify =" space-between"
173+ :wrap =" false"
174+ @click.stop
175+ >
176+ <n-flex > 匹配的 IP </n-flex >
177+ <n-flex >
178+ <!-- 不确定为什么点击 label 会触发第一个按钮, 所以放置一个不可见的按钮 -->
179+ <button
180+ style ="
181+ width : 0 ;
182+ height : 0 ;
183+ overflow : hidden ;
184+ opacity : 0 ;
185+ position : absolute ;
186+ "
187+ ></button >
188+
189+ <n-button :focusable =" false" size =" tiny" @click =" export_config" >
190+ 复制
191+ </n-button >
192+ <n-button :focusable =" false" size =" tiny" @click =" import_rules" >
193+ 替换粘贴
194+ </n-button >
195+ <n-button
196+ :focusable =" false"
197+ size =" tiny"
198+ @click =" append_import_rules"
199+ >
200+ 增量粘贴
201+ </n-button >
202+ </n-flex >
203+ </n-flex >
204+ </template >
140205 <n-dynamic-input v-model:value =" rule.source" :on-create =" onCreate" >
141206 <template #create-button-default > 增加一条 Wan 规则 </template >
142207 <template #default =" { value , index } " >
0 commit comments