-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[optimize] upgrade Clinic Edit page & components
[fix] Rendering bugs of Query Card pages
- Loading branch information
Showing
14 changed files
with
203 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,98 @@ | ||
import { WebCellProps, component, mixin, watch, createCell } from 'web-cell'; | ||
import { FieldProps, Field } from 'boot-cell/source/Form/Field'; | ||
import { FormField } from 'boot-cell/source/Form/FormField'; | ||
import { InputGroup } from 'boot-cell/source/Form/InputGroup'; | ||
import { Button } from 'boot-cell/source/Form/Button'; | ||
import { WebCell, component, observer, reaction } from 'web-cell'; | ||
import { observable } from 'mobx'; | ||
import { | ||
FormControl, | ||
FormControlProps, | ||
FormGroup, | ||
FormLabel, | ||
InputGroup, | ||
Button, | ||
} from 'boot-cell'; | ||
|
||
import { Contact } from '../service'; | ||
|
||
interface ContactFieldProps extends FieldProps, WebCellProps { | ||
export interface ContactFieldProps | ||
extends Omit<FormControlProps<'input'>, 'list'> { | ||
list: Contact[]; | ||
} | ||
|
||
@component({ | ||
tagName: 'contact-field', | ||
renderTarget: 'children' | ||
}) | ||
export class ContactField extends mixin<ContactFieldProps>() { | ||
@watch | ||
list = []; | ||
export interface ContactField extends WebCell<ContactFieldProps> {} | ||
|
||
private emitChange() { | ||
@component({ tagName: 'contact-field' }) | ||
@observer | ||
export class ContactField | ||
extends HTMLElement | ||
implements WebCell<ContactFieldProps> | ||
{ | ||
@observable | ||
accessor list: Contact[] = []; | ||
|
||
@reaction(({ list }) => list) | ||
emitChange() { | ||
this.emit('change', this.list); | ||
} | ||
|
||
changeItem(index: number, event: Event) { | ||
event.stopPropagation(); | ||
|
||
const { name, value } = event.target as HTMLInputElement; | ||
|
||
this.list[index][name] = value; | ||
|
||
this.emitChange(); | ||
const { list } = this; | ||
const item = list[index], | ||
{ name, value } = event.target as HTMLInputElement; | ||
|
||
this.list = [ | ||
...list.slice(0, index), | ||
{ ...item, [name]: value }, | ||
...list.slice(index + 1) | ||
]; | ||
} | ||
|
||
addItem = async () => { | ||
await this.setProps({ list: this.list.concat({}) }); | ||
|
||
this.emitChange(); | ||
}; | ||
addItem = () => (this.list = [...this.list, {} as Contact]); | ||
|
||
async deleteItem(index: number) { | ||
deleteItem(index: number) { | ||
const { list } = this; | ||
|
||
list.splice(index, 1); | ||
|
||
await this.setProps({ list }); | ||
|
||
this.emitChange(); | ||
this.list = [...list.slice(0, index), ...list.slice(index + 1)]; | ||
} | ||
|
||
render({ list }: ContactFieldProps) { | ||
return ( | ||
<FormField label="联系方式"> | ||
<FormGroup> | ||
<FormLabel>联系方式</FormLabel> | ||
|
||
{list.map(({ name, phone }, index) => ( | ||
<InputGroup | ||
className="my-1" | ||
onChange={(event: Event) => | ||
this.changeItem(index, event) | ||
} | ||
> | ||
<Field name="name" value={name} placeholder="姓名" /> | ||
<Field | ||
<FormControl | ||
as="input" | ||
name="name" | ||
value={name} | ||
placeholder="姓名" | ||
/> | ||
<FormControl | ||
as="input" | ||
type="tel" | ||
name="phone" | ||
value={phone} | ||
placeholder="电话号码(含国家码、区号)" | ||
/> | ||
|
||
<Button color="primary" onClick={this.addItem}> | ||
<Button variant="primary" onClick={this.addItem}> | ||
+ | ||
</Button> | ||
<Button | ||
color="danger" | ||
variant="danger" | ||
disabled={!list[1]} | ||
onClick={() => this.deleteItem(index)} | ||
> | ||
- | ||
</Button> | ||
</InputGroup> | ||
))} | ||
</FormField> | ||
</FormGroup> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
97fe50a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for wuhan2020 ready!
✅ Preview
https://wuhan2020-40jd82xea-techquery.vercel.app
Built with commit 97fe50a.
This pull request is being automatically deployed with vercel-action