小区编辑组建的注意事项

一、 village.api.ts
随机数不宜过大,比如在randomNumber()设置为randomNumber(10)。在选择小区的时候,小区属于社区,社区属于乡镇,所以在确定了社区的时候,小区所属于的乡镇也就自动确定了。
在entity/village.ts 就可以删除掉乡镇模型 image.png

      return {
        id,
        name: randomString('名称'),
        pinyin: randomString('pinyin'),
        longitude: randomNumber(10),
        latitude: randomNumber(10),
        type: randomNumber(2),
        establishTime: randomTimestamp(),
        model: {
          id: randomNumber(7),
          name: randomString('3D模型'),
          pinyin: randomString('pinyin'),
        } as Model,
        community: {
          id: randomNumber(10),
          name: randomString('社区名称'),
          pinyin: randomString('shequpinyin'),
          town: {
            id: randomNumber(10),
            name: randomString('乡镇'),
          } as Town,
        } as Community,
      } as Village;

编辑的时候需要返回所有的信息(比如模型信息,社区信息,乡镇信息等)。

      Assert.isDefined(body, body.community, body.model, 'data validate false');
      Assert.isString(body.name, body.pinyin, 'some properties must be string');
      Assert.isNumber(body.longitude,
        body.latitude,
        body.type,
        body.community.id,
        body.model.id,
        body.establishTime, 'some properties must be number');

编辑时需要对信息的修改做一定提示,以确保编辑功能的正常实现。

二、edit.component.html:字段的完整性

  <input type="text" [formControlName]="formKeys.name" class="form-control" name="name" id="name">
  <small *ngIf="formGroup.get(formKeys.name).invalid" class="text-danger">名称不能为空</small>

名称:name,小区名称不能为空;

  <input type="text" [formControlName]="formKeys.pinyin" class="form-control" name="pinyin" id="pinyin">
  <small *ngIf="formGroup.get(formKeys.pinyin).invalid" class="text-danger">拼音不能为空</small>

拼音:pinyin,小区拼音不能为空;

  <input type="number" [formControlName]="formKeys.longitude" class="form-control"  id="longitude" >
  <small *ngIf="formGroup.get(formKeys.longitude).invalid" class="text-danger">经度不能为空</small>

经度:longitude,经度不能为空

  <input type="number" [formControlName]="formKeys.latitude" class="form-control"  id="latitude" >
  <small *ngIf="formGroup.get(formKeys.latitude).invalid" class="text-danger">纬度不能为空</small>

纬度:latitude,纬度不能为空

  <select class="form-control" [formControlName]="formKeys.type">
    <option [ngValue]="null">请选择</option>
    <option [ngValue]="0">平房</option>
    <option [ngValue]="1">楼房</option>
  </select>
  <small *ngIf="formGroup.get(formKeys.type).invalid" class="text-danger">请选择一种类型</small>

房屋类型:type,房屋类型不能为空,在entity.enum.village-type.ts中对房屋类型做了约束,只有平房和楼房两种类型;

  <app-community3d-select [formControlName]="formKeys.modelId"></app-community3d-select>
  <small *ngIf="formGroup.get(formKeys.modelId).invalid" class="text-danger">请选择一种3D模型类型</small>

3D模型:modelId,3D模型不能为空,调用模型选择组件

  <input type="date" class="form-control" [formControlName]="formKeys.establishTime" id="establishTime">
  <small *ngIf="formGroup.get(formKeys.establishTime).invalid" class="text-danger">请选择建成日期</small>

建成时间:establishTime,建成时间不能为空,将时间的type设置为date,利于我们来选择调整时间
在建成时间这里,我尝试了很久并没有完成,老师对我的代码进行了修正,在common增加了时间转换的方法,将时间戳转换为日期,从而实现了这一个功能。

  <app-town-select [formControlName]="formKeys.townId"></app-town-select>
  <small *ngIf="formGroup.get(formKeys.townId).invalid" class="text-danger">请选择一个乡镇</small>

所属乡镇:townId,所属乡镇不能为空,调用乡镇选择组件

  <app-community-select [formControlName]="formKeys.communityId"></app-community-select>
  <small *ngIf="formGroup.get(formKeys.communityId).invalid" class="text-danger">请选择一个社区</small>

所属社区:communityId,所属社区不能为空,调用社区选择组件

三、village.service.ts

Assert.isNumber(village.longitude, 'type of village longitude must be number');
Assert.isNumber(village.latitude, 'type of village latitude must be number');
Assert.isDefined(village.community, village.community.id, 'some type is defined');
Assert.isDefined(village.model, village.model.id, 'some type is defined');
Assert.isString(village.establishTime, 'type of establishTime must be string');
Assert.isNumber(village.type, 'type of VillageType must be number');

在这里只需要保障方法运行,所以只需要一个id即可。

Assert.isNumber(id, 'type of id must be number');

四、文件发生冲突,在网页修改代码
在前面的工作中,我在网页上直接修改代码时,由于忘记点击commit导致了很多次bug,代码一直报冲突。
image.png
对这里图片上的问题,由于是在自己的分支上添加主分支没有的代码,所以直接删除冲突的标记,保证语法正确,然后点击右上角的commit提交,就可以解决这个冲突的bug了。

五、总结
在完成编辑功能的时候,要多联系其余组件,防止遗漏。尤其是在完成任务的时候,要认真仔细,一定要保证字段的完整性,避免出现一些不该出现的错误。


忘忧
6 声望1 粉丝