LightVillageApi.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. import { DataModel, transformArrayDataModel } from '@imengyu/js-request-transform';
  2. import { AppServerRequestModule } from '../RequestModules';
  3. import { transformSomeToArray } from '../Utils';
  4. export class VillageListItem extends DataModel<VillageListItem> {
  5. constructor() {
  6. super(VillageListItem, "活动列表");
  7. this.setNameMapperCase('Camel', 'Snake');
  8. this._convertTable = {
  9. id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
  10. isLight: { clientSide: 'boolean' },
  11. }
  12. this._convertKeyType = (key, direction) => {
  13. if (key.endsWith('At'))
  14. return {
  15. clientSide: 'date',
  16. serverSide: 'string',
  17. };
  18. return undefined;
  19. };
  20. this._afterSolveServer = () => {
  21. this.address =
  22. (this.province || '') +
  23. (this.city || '') +
  24. (this.district || '') +
  25. (this.township || '');
  26. if (this.images && this.images && this.images.length > 0 ) {
  27. this.image = this.images[0]
  28. }
  29. this.thumbnail = this.image;
  30. }
  31. }
  32. id !: number;
  33. province = '' as string|null;
  34. city = '' as string|null;
  35. district = '' as string|null;
  36. township = '' as string|null;
  37. address = '';
  38. isLight = false;
  39. isLightText = '';
  40. lightValue = Math.random();
  41. villageVolunteerId = null as number|null;
  42. villageId !:number;
  43. claimReason = '';
  44. status = '';
  45. statusText = '';
  46. createdAt = null as Date|null;
  47. updatedAt = null as Date|null;
  48. deleteAt = null as Date|null;
  49. image = '';
  50. thumbnail = '';
  51. images = [] as string[];
  52. name = '';
  53. title = '';
  54. volunteerName = '';
  55. }
  56. export class LightVillageApi extends AppServerRequestModule<DataModel> {
  57. constructor() {
  58. super();
  59. }
  60. /**
  61. * 志愿者排行榜
  62. * POST /village/volunteer/getRanklist
  63. */
  64. async getVolunteerRankList(params?: {
  65. /** 地区(区域内所有村社) */
  66. region_id?: number;
  67. /** 数量:显示前几名(默认10) */
  68. num?: number;
  69. /** 村社ID */
  70. village_id?: number;
  71. }) {
  72. const res = await this.post<{
  73. id: number;
  74. name: string;
  75. mobile: string;
  76. points: number;
  77. level: number;
  78. type: string;
  79. type_text?: string;
  80. sex_text?: string;
  81. status_text?: string;
  82. image?: string;
  83. }[]>('/village/volunteer/getRanklist', '志愿者排行榜', params);
  84. return res.requireData();
  85. }
  86. /**
  87. * 村社排行榜
  88. * POST /village/village/getRanklist
  89. */
  90. async getVillageRankList(params?: {
  91. /** 地区(区域内所有村社) */
  92. region_id?: number;
  93. /** 数量:显示前几名(默认10) */
  94. num?: number;
  95. /** 点亮状态:0=未点亮,1=已点亮 */
  96. is_light?: number;
  97. }) {
  98. const res = await this.post<{
  99. id: number;
  100. name: string;
  101. points: number;
  102. region: number;
  103. status?: string;
  104. is_light: number | string;
  105. status_text?: string;
  106. region_text?: string;
  107. is_light_text?: string;
  108. image?: string;
  109. }[]>('/village/village/getRanklist', '村社排行榜', params);
  110. return res.requireData();
  111. }
  112. async getVillageList(level?: number, region?: number, status?: number, page?: number, pageSize?: number) {
  113. const res = await this.get<{
  114. data: any[],
  115. total: number,
  116. }>('/village/village/list', '乡源村落列表', {
  117. history_level: level,
  118. status,
  119. region: region,
  120. page: page,
  121. pageSize: pageSize,
  122. });
  123. return transformArrayDataModel<VillageListItem>(VillageListItem, transformSomeToArray(res.requireData().data), `村落`, true);
  124. }
  125. async getVillageDetails(id: number) {
  126. const res = await this.get<VillageListItem>('/village/village/getInfo', '村社详情', {
  127. id: id,
  128. }, VillageListItem);
  129. return res.requireData();
  130. }
  131. async getIpAddress() {
  132. const res = await this.get<{
  133. address: string,
  134. address_detail:{
  135. adcode: string,
  136. city: string,
  137. city_code: number,
  138. district: string,
  139. province: string,
  140. street: string,
  141. street_number: string,
  142. },
  143. point: {
  144. x: string,
  145. y: string,
  146. },
  147. }>('/village/volunteer/getIpArea', '获取IP地址');
  148. return res.requireData();
  149. }
  150. async getMessages(page: number, pageSize: number, keywords?: string) {
  151. const res = await this.get<{
  152. data: {
  153. id: number;
  154. user_id: number;
  155. village_id: number;
  156. title: string;
  157. content: string | null;
  158. images: string;
  159. image: string;
  160. msgid: string;
  161. jump_url: string;
  162. send_time: string;
  163. like_count: number;
  164. village_name: string | null;
  165. username: string | null;
  166. nick_name: string | null;
  167. }[],
  168. total: number,
  169. }>('/village/collect/wechatContentList', '获取微信贴图列表', {
  170. page,
  171. pageSize,
  172. keywords,
  173. });
  174. return res.requireData();
  175. }
  176. }
  177. export default new LightVillageApi();