LightVillageApi.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. import { DataModel, transformArrayDataModel, transformDataModel, type KeyValue } from '@imengyu/js-request-transform';
  2. import { AppServerRequestModule } from '../RequestModules';
  3. import { transformSomeToArray } from '../Utils';
  4. import type { MiniRender } from '@/components/canvas/MiniRender';
  5. export class VillageListItem extends DataModel<VillageListItem> {
  6. constructor() {
  7. super(VillageListItem, "村社详情");
  8. this.setNameMapperCase('Camel', 'Snake');
  9. this._convertTable = {
  10. id: { clientSide: 'number', clientSideRequired: true },
  11. isLight: { clientSide: 'boolean' },
  12. region: { clientSide: 'number' },
  13. rank: { clientSide: 'number' },
  14. volunteerCount: { clientSide: 'number' },
  15. followCount: { clientSide: 'number' },
  16. collectCount: { clientSide: 'number' },
  17. villageType: { clientSide: 'number' },
  18. altitude: { clientSide: 'number' },
  19. longitude: { clientSide: 'number' },
  20. latitude: { clientSide: 'number' },
  21. age: { clientSide: 'number' },
  22. area: { clientSide: 'number' },
  23. villageArea: { clientSide: 'number' },
  24. traditionalBuildings: { clientSide: 'number' },
  25. ichLevel: { clientSide: 'number' },
  26. historyLevel: { clientSide: 'number' },
  27. touristLevel: { clientSide: 'number' },
  28. isFeaturedVillage: { clientSide: 'number' },
  29. registeredPopulationYear: { clientSide: 'number' },
  30. registeredPopulation: { clientSide: 'number' },
  31. permanentPopulationYear: { clientSide: 'number' },
  32. permanentPopulation: { clientSide: 'number' },
  33. personalAnnualIncomeYear: { clientSide: 'number' },
  34. villageAnnualIncomeYear: { clientSide: 'number' },
  35. points: { clientSide: 'number' },
  36. light: { clientSide: 'number' },
  37. lightTotal: { clientSide: 'number' },
  38. fruitOutput: { clientSide: 'number' },
  39. fruitRemain: { clientSide: 'number' },
  40. fruitToday: { clientSide: 'number' },
  41. level: { clientSide: 'number' },
  42. weight: { clientSide: 'number' },
  43. vipLevel: { clientSide: 'number' },
  44. overviewId: { clientSide: 'number' },
  45. myOverviewId: { clientSide: 'number' },
  46. treeLight: { clientSide: 'number' },
  47. nextTreeLight: { clientSide: 'number' },
  48. nextTreeLevel: { clientSide: 'number' },
  49. imageLimit: { clientSide: 'number' },
  50. storageLimit: { clientSide: 'number' },
  51. managerLimit: { clientSide: 'number' },
  52. treeImageAnimProps: { clientSide: 'json' },
  53. }
  54. this._convertKeyType = (key, direction) => {
  55. if (key.endsWith('At'))
  56. return {
  57. clientSide: 'date',
  58. serverSide: 'string',
  59. };
  60. return undefined;
  61. };
  62. this._afterSolveServer = () => {
  63. this.address =
  64. (this.province || '') +
  65. (this.city || '') +
  66. (this.district || '') +
  67. (this.township || '');
  68. if (this.images && this.images && this.images.length > 0 ) {
  69. this.image = this.images[0]
  70. }
  71. this.thumbnail = this.image;
  72. if (!this.name && this.villageName)
  73. this.name = this.villageName as string;
  74. if (this.villageId)
  75. this.id = this.villageId;
  76. }
  77. }
  78. id !: number;
  79. /** 地区 */
  80. region = 0;
  81. /** 省份/省级行政区 */
  82. province = '' as string|null;
  83. /** 城市/地级行政区 */
  84. city = '' as string|null;
  85. /** 区县/县级行政区 */
  86. district = '' as string|null;
  87. /** 乡镇/乡级行政区 */
  88. township = '' as string|null;
  89. /** 拼接地址(客户端计算) */
  90. address = '';
  91. /** 村落编码 */
  92. code = '' as string|null;
  93. /** 是否点亮 */
  94. isLight = false;
  95. isLightText = '';
  96. lightValue = Math.random();
  97. villageVolunteerId = null as number|null;
  98. villageId !:number;
  99. claimReason = '';
  100. /** 状态: 0=完善中, 1=已归档 */
  101. status = '';
  102. statusText = '';
  103. createdAt = null as Date|null;
  104. updatedAt = null as Date|null;
  105. deleteAt = null as Date|null;
  106. /** 录入时间 */
  107. enterAt = null as Date|null;
  108. /** 封面图 */
  109. image = '';
  110. thumbnail = '';
  111. /** 村落形象照片 */
  112. images = [] as string[];
  113. /** 村落名称 */
  114. name = '';
  115. desc = '';
  116. title = '';
  117. /** 排名 */
  118. rank = 0;
  119. /** 乡源人数 */
  120. volunteerCount = 0;
  121. /** 关注人数 */
  122. followCount = 0;
  123. /** 采集投稿数 */
  124. collectCount = 0;
  125. /** 积分 */
  126. points = 0;
  127. /** 可用乡源光 */
  128. light = 0;
  129. /** 累计乡源光 */
  130. lightTotal = 0;
  131. /** 可产果数 */
  132. fruitOutput = 0;
  133. /** 可拾取果数 */
  134. fruitRemain = 0;
  135. /** 今日产果数 */
  136. fruitToday = 0;
  137. /** 等级 */
  138. level = 0;
  139. /** 权重 */
  140. weight = 0;
  141. volunteerName = '';
  142. /** 经度 */
  143. longitude = 0;
  144. /** 纬度 */
  145. latitude = 0;
  146. /** 村落类型 */
  147. villageType = 0;
  148. /** 海拔(米) */
  149. altitude = null as number|null;
  150. /** 地形地貌特征(多选) */
  151. landforms = '' as string|null;
  152. /** 村落形成年代 */
  153. age = null as number|null;
  154. /** 村域面积(平方公里) */
  155. area = null as number|null;
  156. /** 村庄占地面积(亩) */
  157. villageArea = null as number|null;
  158. /** 传统建筑数量 */
  159. traditionalBuildings = null as number|null;
  160. /** 非遗最高级别 */
  161. ichLevel = null as number|null;
  162. /** 列入历史文化名村级别 */
  163. historyLevel = null as number|null;
  164. /** 列入特色景观旅游名村级别 */
  165. touristLevel = null as number|null;
  166. /** 列入少数民族特色村寨试点示范: 0=否, 1=是 */
  167. isFeaturedVillage = 0;
  168. /** 其他认定级别 */
  169. other = '' as string|null;
  170. /** 主要民族 */
  171. nationlity = '' as string|null;
  172. /** 户籍人口年份 */
  173. registeredPopulationYear = null as number|null;
  174. /** 户籍人口 */
  175. registeredPopulation = null as number|null;
  176. /** 常住人口年份 */
  177. permanentPopulationYear = null as number|null;
  178. /** 常住人口 */
  179. permanentPopulation = null as number|null;
  180. /** 人均年收入年份 */
  181. personalAnnualIncomeYear = null as number|null;
  182. /** 人均年收入(万元) */
  183. personalAnnualIncome = '' as string|null;
  184. /** 集体年收入年份 */
  185. villageAnnualIncomeYear = null as number|null;
  186. /** 集体年收入(万元) */
  187. villageAnnualIncome = '' as string|null;
  188. /** 突出价值 */
  189. prominent = '' as string|null;
  190. /** 主要产业_农业 */
  191. agriculture = '' as string|null;
  192. /** 主要产业_其他农业 */
  193. otherAgriculture = '' as string|null;
  194. /** 主要产业_林业 */
  195. forestry = '' as string|null;
  196. /** 主要产业_畜牧业 */
  197. animal = '' as string|null;
  198. /** 主要产业_渔业 */
  199. fishing = '' as string|null;
  200. /** 主要产业_制造业(含手工) */
  201. manufacturing = '' as string|null;
  202. /** 主要产业_建筑业 */
  203. construction = '' as string|null;
  204. /** 主要产业_批发和零售业 */
  205. retail = '' as string|null;
  206. /** 主要产业_服务业 */
  207. service = '' as string|null;
  208. /** 主要产业_其他服务业 */
  209. otherService = '' as string|null;
  210. /** 主要产业_其他 */
  211. otherIndustries = '' as string|null;
  212. /** 来源 */
  213. source = '' as string|null;
  214. /** 图片说明 */
  215. imageDesc = '' as string|null;
  216. /** 组图描述 */
  217. imagesDesc = [] as string[];
  218. /** 音频 */
  219. audio = '' as string|null;
  220. /** 视频 */
  221. video = '' as string|null;
  222. /** 数字档案 */
  223. archives = '' as string|null;
  224. /** 其他附件 */
  225. annex = '' as string|null;
  226. /** 标志 */
  227. flag = '';
  228. /** 关键字 */
  229. keywords = '';
  230. /** 联系人 */
  231. contact = '' as string|null;
  232. /** 联系电话 */
  233. mobile = '' as string|null;
  234. /** 跳转链接 */
  235. url = '' as string|null;
  236. /** VIP等级 */
  237. vipLevel = 0;
  238. /** 概况最新ID */
  239. overviewId = null as number|null;
  240. /** 当前志愿者概况ID */
  241. myOverviewId = null as number|null;
  242. /** 当前等级树名称 */
  243. treeName = '';
  244. /** 当前等级树图片 */
  245. treeImage = '';
  246. /** 当前等级所需乡源光 */
  247. treeLight = 0;
  248. /** 树动画属性 */
  249. treeImageAnimProps ?: VillageTreeAnimProps;
  250. /** 下一级等级树名称 */
  251. nextTreeName = '';
  252. /** 下一级所需乡源光 */
  253. nextTreeLight = 0;
  254. /** 下一级 */
  255. nextTreeLevel = 0;
  256. /** 图片上传最大数量限制 */
  257. imageLimit = 0;
  258. /** 存储内存限制(MB) */
  259. storageLimit = 0;
  260. /** 存储内存已使用(MB) */
  261. storageUsed = 0;
  262. /** 可设置管理人员数量 */
  263. managerLimit = 0;
  264. /** 志愿者在村落昵称 */
  265. villageNickname = '';
  266. }
  267. export interface VillageTreeAnimProps {
  268. width: number,
  269. height: number,
  270. offsetX?: number,
  271. offsetY?: number,
  272. frames: MiniRender.AnimateSpriteFrame[],
  273. framerate: number,
  274. animations: Record<string, {
  275. frames: number[],
  276. }>,
  277. }
  278. export class VillageMapItem extends DataModel<VillageMapItem> {
  279. constructor() {
  280. super(VillageMapItem, "村社地图");
  281. this.setNameMapperCase('Camel', 'Snake');
  282. this._convertTable = {
  283. villageId: { clientSide: 'number' },
  284. isLight: { clientSide: 'boolean' },
  285. latitude: { clientSide: 'number' },
  286. longitude: { clientSide: 'number' },
  287. };
  288. }
  289. villageId!: number|null;
  290. villageName = '';
  291. isLight = false;
  292. areaId = 0;
  293. areaCode = 0;
  294. mergerName = '';
  295. longitude = 0;
  296. latitude = 0;
  297. lightValue = 0;
  298. name = '';
  299. }
  300. export class LightVillageApi extends AppServerRequestModule<DataModel> {
  301. constructor() {
  302. super();
  303. }
  304. /**
  305. * 志愿者排行榜
  306. * POST /village/volunteer/getRanklist
  307. */
  308. async getVolunteerRankList(params?: {
  309. /** 地区(区域内所有村社) */
  310. region_id?: number;
  311. /** 数量:显示前几名(默认10) */
  312. num?: number;
  313. /** 村社ID */
  314. village_id?: number;
  315. }) {
  316. const res = await this.post<{
  317. id: number;
  318. name: string;
  319. mobile: string;
  320. points: number;
  321. level: number;
  322. type: string;
  323. type_text?: string;
  324. sex_text?: string;
  325. status_text?: string;
  326. avatar?: string;
  327. }[]>('/village/volunteer/getRanklist', '志愿者排行榜', params, undefined, undefined, {
  328. cacheEnable: true,
  329. cacheTime: 1000 * 60 * 10, //10min
  330. });
  331. return res.requireData();
  332. }
  333. /**
  334. * 村社排行榜
  335. * POST /village/village/getRanklist
  336. */
  337. async getVillageRankList(params?: {
  338. /** 地区(区域内所有村社) */
  339. region_id?: number;
  340. /** 数量:显示前几名(默认10) */
  341. num?: number;
  342. /** 点亮状态:0=未点亮,1=已点亮 */
  343. is_light?: number;
  344. }) {
  345. const res = await this.post<{
  346. id: number;
  347. name: string;
  348. points: number;
  349. region: number;
  350. status?: string;
  351. is_light: number | string;
  352. status_text?: string;
  353. region_text?: string;
  354. is_light_text?: string;
  355. image?: string;
  356. }[]>('/village/village/getRanklist', '村社排行榜', params, undefined, undefined, {
  357. cacheEnable: true,
  358. cacheTime: 1000 * 60 * 10, //10min
  359. });
  360. return res.requireData();
  361. }
  362. async getVillageList(data?: {
  363. level?: number,
  364. areaCode?: number,
  365. region?: number,
  366. status?: number,
  367. page?: number,
  368. pageSize?: number,
  369. keyword?: string,
  370. }|undefined) {
  371. const res = await this.get<{
  372. data: any[],
  373. total: number,
  374. }>('/village/village/list', '乡源村落列表', {
  375. history_level: data?.level,
  376. status: data?.status,
  377. region: data?.region,
  378. page: data?.page,
  379. pageSize: data?.pageSize,
  380. keyword: data?.keyword,
  381. area_code: data?.areaCode,
  382. });
  383. return {
  384. total: res.requireData().total,
  385. list: transformArrayDataModel<VillageListItem>(VillageListItem, transformSomeToArray(res.requireData().data), `村落`, true)
  386. }
  387. }
  388. async getVillageDetails(id: number) {
  389. const res = await this.get<VillageListItem>('/village/village/getInfo', '村社详情', {
  390. id: id,
  391. }, VillageListItem);
  392. return res.requireData();
  393. }
  394. async getIpAddress() {
  395. const res = await this.get<{
  396. address: string,
  397. address_detail:{
  398. adcode: string,
  399. city: string,
  400. city_code: number,
  401. district: string,
  402. province: string,
  403. street: string,
  404. street_number: string,
  405. },
  406. point: {
  407. x: string,
  408. y: string,
  409. },
  410. }>('/village/volunteer/getIpArea', '获取IP地址');
  411. return res.requireData();
  412. }
  413. async updateVillageGallery(id: number, images: string[]) {
  414. return await this.post<KeyValue>('/village/village/save', '更新村社相册', {
  415. id: id,
  416. images: images,
  417. });
  418. }
  419. async updateVillageInfo(id: number, desc: string, image: string) {
  420. return await this.post<KeyValue>('/village/village/save', '更新村社基本信息', {
  421. id: id,
  422. image: image,
  423. desc: desc,
  424. });
  425. }
  426. async createVillage(data: {
  427. name: string,
  428. longitude: string,
  429. latitude: string,
  430. desc: string,
  431. area_code: number,
  432. /**
  433. * 村落类型:
  434. 95=自然村
  435. 96=行政村,
  436. 334=社区
  437. */
  438. village_type: number,
  439. }) {
  440. return await this.post<KeyValue>('/village/village/addVillage', '创建村社', data);
  441. }
  442. /**
  443. * 村社地图
  444. * POST /village/village/mapVillage
  445. */
  446. async getMapVillage(params: {
  447. /** 地区code */
  448. areaCode: number;
  449. }) {
  450. const res = await this.post<KeyValue[]>('/village/village/mapVillage', '村社地图', {
  451. area_code: params.areaCode,
  452. });
  453. return transformArrayDataModel<VillageMapItem>(VillageMapItem, res.requireData(), '村社地图条目', true);
  454. }
  455. async updateStorage(params: {
  456. /** 村社ID */
  457. villageId: number;
  458. /** 文件大小(字节) */
  459. memorySize: number;
  460. }) {
  461. return await this.post<KeyValue>('/village/village/updateStorage', '更新存储', {
  462. village_id: params.villageId,
  463. memory_size: params.memorySize,
  464. });
  465. }
  466. /**
  467. * 修改本志愿者在本村的昵称
  468. * POST /village/volunteer/nicknameSave
  469. */
  470. async nicknameSave(params: {
  471. /** 村社ID */
  472. villageId: number;
  473. /** 村社昵称 */
  474. villageNickname: string;
  475. }) {
  476. return await this.post<KeyValue>('/village/volunteer/nicknameSave', '修改志愿者昵称', {
  477. village_id: params.villageId,
  478. village_nickname: params.villageNickname,
  479. });
  480. }
  481. }
  482. export default new LightVillageApi();