| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- import { DataModel, transformArrayDataModel, type NewDataModel } from '@imengyu/js-request-transform';
- import { AppServerRequestModule } from '../RequestModules';
- import CommonContent from '../CommonContent';
- export class CategoryListItem extends DataModel<CategoryListItem> {
- constructor() {
- super(CategoryListItem, "分类列表");
- this.setNameMapperCase('Camel', 'Snake');
- this._convertTable = {
- id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
- pid: { clientSide: 'number', serverSide: 'number' },
- haschild: { clientSide: 'boolean', serverSide: 'number' },
- }
- }
- id !: number;
- pid !: number;
- title = '';
- status = 'normal';
- weight = 0;
- spacer = '';
- haschild = false;
- children?: CategoryListItem[];
- }
- export class CommonInfoModel extends DataModel<CommonInfoModel> {
- constructor() {
- super(CommonInfoModel, "信息详情");
- this.setNameMapperCase('Camel', 'Snake');
- this._convertTable = {
- id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
- },
- this._blackList.toServer.push(
- 'updatedAt', 'createdAt', 'deletedAt',
- );
- this._afterSolveServer = () => {
- if (this.province && this.city && this.district) {
- this.cityAddress = [this.province as string, this.city as string, this.district as string];
- }
- };
- this._afterSolveClient = (data) => {
- if (this.cityAddress) {
- data.province = this.cityAddress[0];
- data.city = this.cityAddress[1];
- data.district = this.cityAddress[2];
- }
- };
- }
- id !: number;
- cityAddress?: string[];
- }
- export class VillageEnvInfo extends DataModel<VillageEnvInfo> {
- constructor() {
- super(VillageEnvInfo, "地理信息");
- this.setNameMapperCase('Camel', 'Snake');
- this._convertTable = {
- id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
- landforms: [
- { clientSide: 'splitCommaArray', serverSide: 'commaArrayMerge' },
- { clientSide: 'arrayInt', serverSide: 'original' },
- ],
- villageType: { clientSide: 'number', serverSide: 'number' },
- },
- this._blackList.toServer.push(
- 'updatedAt', 'createdAt', 'deletedAt',
- );
- this._afterSolveServer = () => {
- if (this.longitude && this.latitude) {
- this.lonlat = [this.longitude as number, this.latitude as number];
- }
- };
- this._afterSolveClient = (data) => {
- if (this.lonlat) {
- data.longitude = this.lonlat[0];
- data.latitude = this.lonlat[1];
- }
- };
- }
- id !: number;
- lonlat?: number[];
- landforms = [] as string[];
- }
- export class VillageListItem extends DataModel<VillageListItem> {
- constructor() {
- super(VillageListItem, "村庄信息");
- this.setNameMapperCase('Camel', 'Snake');
- this._convertTable = {
- id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
- },
- this._blackList.toServer.push(
- 'updatedAt', 'createdAt', 'deletedAt',
- );
- this._convertKeyType = (key, direction) => {
- if (key.endsWith('At'))
- return {
- clientSide: 'date',
- serverSide: 'string',
- };
- return undefined;
- };
- this._afterSolveServer = () => {
- if (!this.title) {
- if (this.name) this.title = this.name as string;
- if (typeof this.content === 'object' && (this.content as any)?.title) this.title = (this.content as any).title as string;
- if (this.content) this.title = this.content as string;
- if (this.structure) this.title = this.structure as string;
- if (this.wisdom) this.title = this.wisdom as string;
- }
- if (!this.image) {
- if (this.distribution) this.image = this.distribution as string;
- }
- };
- }
- id !: number;
- createdAt = new Date();
- updatedAt = new Date();
- title = '';
- image = '';
- }
- export class VillageBulidingInfo extends DataModel<VillageBulidingInfo> {
- constructor() {
- super(VillageBulidingInfo, "历史建筑信息");
- this.setNameMapperCase('Camel', 'Snake');
- this._convertTable = {
- id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
- }
- this._blackList.toServer.push(
- 'updatedAt', 'createdAt', 'deletedAt',
- );
- const commaArrayKeys = [
- 'purpose','floorType','wallType','roofForm','bearingType',
- ]
- this._convertKeyType = (key, direction) => {
- if (commaArrayKeys.includes(key))
- return [
- { clientSide: 'splitCommaArray', serverSide: 'commaArrayMerge' },
- { clientSide: 'arrayInt', serverSide: 'original' },
- ];
- return undefined;
- };
- }
- id !: number;
- }
- export class VillageInfoApi extends AppServerRequestModule<DataModel> {
- constructor() {
- super();
- }
- /**
- * 获取分类列表
- * @param type 根级类型:1=区域、2=级别、3=文物类型、4=非遗类型、42=事件类型
- * @param withself 是否返回包含自己:true=是,false=否 ,默认false
- * @returns
- */
- getCategoryList(
- type?: number,
- withself?: boolean,
- ) {
- return CommonContent.getCategoryList(type, withself);
- }
- /**
- * 用于获取某一个分类需要用的子级
- * @param pid 父级
- * @returns
- */
- getCategoryChildList(pid?: number) {
- return CommonContent.getCategoryChildList(pid);
- }
- async getInfo<T extends DataModel>(
- sub: string,
- subId: number,
- villageId: number,
- villageVolunteerId: number,
- id?: number,
- modelClassCreator: (new () => T) = CommonInfoModel as any
- ) {
- return (await this.post(`/village/${sub}/getInfo`, {
- type: subId,
- village_id: villageId,
- village_volunteer_id: villageVolunteerId,
- id,
- }, '获取信息详情', undefined, modelClassCreator)).data as T
- }
- async getList<T extends DataModel = VillageListItem>(
- sub: string,
- subId: number|undefined,
- subKey: string|undefined,
- villageId: number,
- villageVolunteerId: number,
- modelClassCreator: (new () => T) = VillageListItem as any
- ) {
- return (this.post(`/village/${sub}/getList`, {
- [subKey ? subKey : 'type']: subId,
- village_id: villageId,
- village_volunteer_id: villageVolunteerId,
- }, '获取信息详情'))
- .then(res => transformArrayDataModel<T>(modelClassCreator, (res.data2.data || res.data2) ?? [], `获取分类列表`, true))
- .catch(e => { throw e });
- }
- async updateInfo<T extends DataModel>(
- sub: string,
- villageId: number,
- villageVolunteerId: number,
- data: T,
- ) {
- return (await this.post(`/village/${sub}/save`, {
- sub,
- village_id: villageId,
- village_volunteer_id: villageVolunteerId,
- ...data.toServerSide(),
- }, '更新信息详情'));
- }
- }
- export default new VillageInfoApi();
|