Skip to content

Commit

Permalink
[optimize] upgrade Clinic Edit page & components
Browse files Browse the repository at this point in the history
[fix] Rendering bugs of Query Card pages
  • Loading branch information
TechQuery committed Jan 21, 2024
1 parent 5c0179d commit 97fe50a
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 167 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"url": "https://github.com/EasyWebApp/wuhan2020/issues"
},
"dependencies": {
"boot-cell": "^2.0.0-beta.8",
"boot-cell": "^2.0.0-beta.9",
"browser-unhandled-rejection": "^1.0.2",
"cell-router": "^3.0.0-rc.5",
"classnames": "^2.5.1",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 17 additions & 5 deletions source/component/CardsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import {
ScrollBoundary,
TouchHandler
} from 'boot-cell';
import { CustomElement } from 'web-utility';

import { DistrictEvent, DistrictFilter, District } from './DistrictFilter';
import { VerifiableModel, session } from '../model';

export abstract class CardsPage<T> extends HTMLElement {
export abstract class CardsPage<T>
extends HTMLElement
implements CustomElement
{
abstract scope: string;
abstract model: VerifiableModel;
abstract name: string;
Expand All @@ -20,6 +24,10 @@ export abstract class CardsPage<T> extends HTMLElement {
verified: !session.hasRole('Admin')
};

connectedCallback() {
this.model.getNextPage(this.filter);
}

loadMore: TouchHandler = detail => {
if (detail === 'bottom') return this.model.getNextPage(this.filter);
};
Expand Down Expand Up @@ -56,7 +64,7 @@ export abstract class CardsPage<T> extends HTMLElement {
<header className="d-flex justify-content-between align-items-center my-3">
<h2 className="m-0">{title}</h2>
<span>
<Button variant="warning" href={scope + '/edit'}>
<Button variant="warning" href={`#${scope}/edit`}>
发布
</Button>
</span>
Expand All @@ -74,11 +82,15 @@ export abstract class CardsPage<T> extends HTMLElement {
<ScrollBoundary onTouch={this.loadMore}>
<SpinnerBox
cover={loading}
className="card-deck justify-content-around"
className="row row-cols-1 row-cols-sm-2 row-cols-md-4 g-3"
>
{list.map(this.renderItem)}
{list.map(item => (
<div className="col">
{this.renderItem(item as T)}
</div>
))}
</SpinnerBox>
<p slot="bottom" className="text-center mt-2">
<p className="text-center mt-2">
{noMore ? '没有更多数据了' : '加载更多...'}
</p>
</ScrollBoundary>
Expand Down
86 changes: 50 additions & 36 deletions source/component/ContactField.tsx
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>
);
}
}
2 changes: 2 additions & 0 deletions source/component/SessionBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class SessionBox extends HTMLElement implements WebCell {

<InputGroup size="lg" className="mb-3">
<FormControl
as="input"
type="tel"
name="phone"
maxLength={11}
Expand All @@ -79,6 +80,7 @@ export class SessionBox extends HTMLElement implements WebCell {

<InputGroup size="lg" className="mb-3">
<FormControl
as="input"
name="code"
required
placeholder="短信验证码"
Expand Down
Loading

1 comment on commit 97fe50a

@github-actions
Copy link
Contributor

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

Please sign in to comment.