mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
judge: support generate testdata (#695)
Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
1 parent
b83b2e792e
commit
55b4e1aaf0
27 files changed
+454
-68
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import { assign } from 'lodash';
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import DOMAttachedObject from 'vj/components/DOMAttachedObject';
|
||||
import AutoComplete, { AutoCompleteOptions } from '.';
|
||||
import FileSelectAutoCompleteFC from './components/FileSelectAutoComplete';
|
||||
|
||||
interface FileSelectOptions {
|
||||
data: {
|
||||
id: string;
|
||||
name: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
const Component = React.forwardRef<any, any>((props, ref) => {
|
||||
const [value, setValue] = React.useState(props.value);
|
||||
return (
|
||||
<FileSelectAutoCompleteFC
|
||||
ref={ref as any}
|
||||
height="auto"
|
||||
selectedKeys={value.split(',').map((i) => i.trim()).filter((i) => i)}
|
||||
onChange={(v) => {
|
||||
setValue(v);
|
||||
props.onChange(v);
|
||||
}}
|
||||
data={props.data}
|
||||
multi={props.multi}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
export default class FileSelectAutoComplete<Multi extends boolean> extends AutoComplete {
|
||||
static DOMAttachKey = 'ucwFileSelectAutoCompleteInstance';
|
||||
options: FileSelectOptions & AutoCompleteOptions;
|
||||
|
||||
constructor($dom, options: FileSelectOptions & AutoCompleteOptions<Multi>) {
|
||||
super($dom, {
|
||||
classes: 'custom-select',
|
||||
...options,
|
||||
});
|
||||
}
|
||||
|
||||
value(): Multi extends true ? number[] : string {
|
||||
if (this.options.multi) return this.ref?.getSelectedItemKeys().map((i) => +i) ?? this.$dom.val();
|
||||
return this.ref?.getSelectedItems()[0] ?? null;
|
||||
}
|
||||
|
||||
attach() {
|
||||
const value = this.$dom.val();
|
||||
ReactDOM.createRoot(this.container).render(
|
||||
<Component
|
||||
ref={(ref) => { this.ref = ref; }}
|
||||
data={this.options.data}
|
||||
value={value}
|
||||
multi={this.options.multi}
|
||||
onChange={this.onChange}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
assign(FileSelectAutoComplete, DOMAttachedObject);
|
||||
window.Hydro.components.FileSelectAutoComplete = FileSelectAutoComplete;
|
||||
Reference in new issue
Block a user