22import { onMounted , ref } from ' vue' ;
33import ModuleView , { type ModuleBase } from ' ./ModuleView.vue' ;
44import ModuleSelectView from ' ./ModuleSelectView.vue'
5+ import NamedModuleSelectView ,{type NamedModuleSelect } from ' ./NamedModuleSelectView.vue' ;
56
6- export interface Module extends ModuleBase {
7+ export interface Module extends ModuleBase {
78 is_or: number ,
89 revers: number ,
910 ref? : string
@@ -20,7 +21,7 @@ export interface ChainValue {
2021 mark? : Module [],
2122}
2223export interface Chain {
23- add? : boolean ,
24+ add? : boolean ,
2425 action: string ,
2526 jump? : string ,
2627 k: ChainKey ,
@@ -43,7 +44,7 @@ function submit_chain() {
4344 formData .append (" index" , props .chain .k .index .toString ());
4445 formData .append (" id" , props .chain .k .id .toString ());
4546 if (props .chain .add ) {
46- formData .append (" add" ," 1" );
47+ formData .append (" add" , " 1" );
4748 }
4849 fetch (' /core.whm?whm_call=edit_chain&format=json' , {
4950 method: ' POST' ,
@@ -74,27 +75,25 @@ function updateModule(type: number, index: number, module: string) {
7475 chain_value .value .mark [index ].module = module
7576 }
7677}
77- function UpModule(type : number ,index : number ) {
78- if (index == 0 ) {
79- return ;
80- }
81- if (chain_value .value == null ) {
78+ function UpModule(type : number , index : number ) {
79+ if (index == 0 || chain_value .value == null ) {
8280 return ;
8381 }
82+
8483 if (type == 0 ) {
8584 if (chain_value .value ?.acl == null ) {
8685 return ;
8786 }
88- var m = chain_value .value .acl [index ];
89- chain_value .value .acl [index ] = chain_value .value .acl [index - 1 ];
90- chain_value .value .acl [index - 1 ] = m ;
87+ var m = chain_value .value .acl [index ];
88+ chain_value .value .acl [index ] = chain_value .value .acl [index - 1 ];
89+ chain_value .value .acl [index - 1 ] = m ;
9190 } else {
9291 if (chain_value .value ?.mark == null ) {
9392 return
9493 }
95- var m = chain_value .value .mark [index ];
96- chain_value .value .mark [index ] = chain_value .value .mark [index - 1 ];
97- chain_value .value .mark [index - 1 ] = m ;
94+ var m = chain_value .value .mark [index ];
95+ chain_value .value .mark [index ] = chain_value .value .mark [index - 1 ];
96+ chain_value .value .mark [index - 1 ] = m ;
9897 }
9998}
10099function delModule(type : number , index : number ) {
@@ -144,42 +143,65 @@ function addModule(type: number, index: number) {
144143 chain_value.value.mark.splice(index, 0, emptyModule)
145144 }
146145}
147- */
146+ */
147+ function addNamedModule(type : number , mb : NamedModuleSelect ) {
148+ if (chain_value .value == null ) {
149+ return ;
150+ }
151+ let m: Module = {
152+ is_or: 0 ,
153+ revers: 0 ,
154+ html: " " ,
155+ ref: mb .name ,
156+ module: mb .module
157+ };
158+ if (type == 0 ) {
159+ if (chain_value .value ?.acl == null ) {
160+ chain_value .value .acl = <Module []>[];
161+ }
162+ chain_value .value .acl .push (m );
163+ } else {
164+ if (chain_value .value ?.mark == null ) {
165+ chain_value .value .mark = <Module []>[];
166+ }
167+ chain_value .value .mark .push (m );
168+ }
169+ }
148170function addModule(type : number , mb : ModuleBase ) {
149171 if (chain_value .value == null ) {
150172 return ;
151173 }
152- let m: Module = {
153- is_or:0 ,
154- revers:0 ,
155- html:mb .html ,
156- module:mb .module
174+ let m: Module = {
175+ is_or: 0 ,
176+ revers: 0 ,
177+ html: mb .html ,
178+ module: mb .module
157179 };
158180 if (type == 0 ) {
159181 if (chain_value .value ?.acl == null ) {
160182 chain_value .value .acl = <Module []>[];
161- }
162- chain_value .value .acl .push (m );
183+ }
184+ chain_value .value .acl .push (m );
163185 } else {
164186 if (chain_value .value ?.mark == null ) {
165187 chain_value .value .mark = <Module []>[];
166- }
167- chain_value .value .mark .push (m );
188+ }
189+ chain_value .value .mark .push (m );
168190 }
169191}
170192onMounted (() => {
171193 if (! props .chain .add ) {
172194 fetch (' /core.whm?whm_call=get_chain&access=' + props .access +
173195 ' &table=' + props .table +
174196 ' &file=' + props .chain .k .file +
175- ' &index=' + props .chain .k .index +
176- (props .vh ? ' &vh=' + props .vh : " " ) +
197+ ' &index=' + props .chain .k .index +
198+ (props .vh ? ' &vh=' + props .vh : " " ) +
177199 ' &id=' + props .chain .k .id +
178200 ' &format=json' ).then ((res ) => res .json ()).then ((json ) => {
179201 chain_value .value = json .result ;
180202 });
181203 } else {
182- chain_value .value = {hit:0 }
204+ chain_value .value = { hit: 0 }
183205 }
184206}
185207);
@@ -195,39 +217,38 @@ onMounted(() => {
195217 </tr >
196218 <template v-for =" (modules , type ) in [chain_value .acl , chain_value .mark ] " >
197219 <tr v-for =" (m, index) in modules" >
198- <td >
220+ <td >
199221 [<a href =# @click =" delModule(type, index)" >删</a >]
200222 [<a href =# @click =" UpModule(type, index)" >UP</a >]
201223 <span v-if =" m.module" >
202224 {{ m.module }}
203225 </span >
204226 </td >
205227 <td >
206- <div v-if =" m.module != ''" >
207- <input type =" hidden" name =" begin_sub_form"
208- :value =" (type == 0 ? 'acl_' : 'mark_') + m.module" />
209- <template v-if =" m .ref " >
210- <input type =" hidden" name =" ref" :value =" m.ref" />ref:{{ m.ref }}
211- </template >
212- <template v-else >
213- <ModuleView :module =" m" />
214- </template >
215- <input type =" hidden" name =" end_sub_form" value =' 1' />
216- </div >
217- <div v-else >
218- <ModuleSelectView :access =" props.access" :type =" type" />
219- </div >
228+
229+ <input type =" hidden" name =" begin_sub_form" :value =" (type == 0 ? 'acl_' : 'mark_') + m.module" />
230+ <template v-if =" m .ref " >
231+ <input type =" hidden" name =" ref" :value =" m.ref" />命名模块:{{ m.ref }}
232+ </template >
233+ <template v-else >
234+ <ModuleView :module =" m" />
235+ </template >
236+ <input type =" hidden" name =" end_sub_form" value =' 1' />
237+
220238 </td >
221239 </tr >
222-
223240 <tr >
224- <td colspan =" 2" >{{ type==0?"可用的匹配模块":"可用的标记模块" }}<ModuleSelectView @select_module =" addModule(type,$event)" :access =" props.access" :type =" type" /></td >
241+ <td colspan =" 2" >
242+ <ModuleSelectView @select_module =" addModule(type, $event)" :access =" props.access" :type =" type" />
243+ <NamedModuleSelectView @select_module =" addNamedModule(type, $event)" :access =" props.access"
244+ :type =" type" />
245+ </td >
225246 </tr >
226247 </template >
227248 <tr >
228249 <td colspan =" 2" >
229- <button @click =" submit_chain()" >确定</button >
230- <button @click =" cancel_chain()" >取消</button >
250+ <button @click =" submit_chain()" >确定</button >
251+ <button @click =" cancel_chain()" >取消</button >
231252 </td >
232253 </tr >
233254 </table >
0 commit comments