|
|
@@ -0,0 +1,170 @@
|
|
|
+import { DataModel, transformArrayDataModel, type KeyValue } from '@imengyu/js-request-transform';
|
|
|
+import { RequestApiConfig, type RequestOptions } from '@imengyu/imengyu-utils';
|
|
|
+import { AppServerRequestModule } from '../RequestModules';
|
|
|
+import { transformSomeToArray } from '../Utils';
|
|
|
+
|
|
|
+export class GalleryItem extends DataModel<GalleryItem> {
|
|
|
+ constructor() {
|
|
|
+ super(GalleryItem, '相册图片');
|
|
|
+ this.setNameMapperCase('Camel', 'Snake');
|
|
|
+ this._convertTable = {
|
|
|
+ id: { clientSide: 'number', serverSide: 'number', clientSideRequired: true },
|
|
|
+ userId: { clientSide: 'number', serverSide: 'number' },
|
|
|
+ villageId: { clientSide: 'number', serverSide: 'number' },
|
|
|
+ groupId: { clientSide: 'number', serverSide: 'number' },
|
|
|
+ status: { clientSide: 'number', serverSide: 'number' },
|
|
|
+ };
|
|
|
+ this._convertKeyType = (key) => {
|
|
|
+ if (key === 'createtime' || key === 'updatetime' || key === 'deletetime')
|
|
|
+ return { clientSide: 'date', serverSide: 'string' };
|
|
|
+ return undefined;
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ id!: number;
|
|
|
+ /** 名称 */
|
|
|
+ name = '';
|
|
|
+ /** 图片 */
|
|
|
+ image = '';
|
|
|
+ /** 说明 */
|
|
|
+ desc = '';
|
|
|
+ /** 用户ID */
|
|
|
+ userId = 0;
|
|
|
+ /** 村社ID */
|
|
|
+ villageId = 0;
|
|
|
+ /** 分组ID */
|
|
|
+ groupId = 0;
|
|
|
+ /** 状态: -1=驳回, 0=待审核, 1=通过 */
|
|
|
+ status = 0;
|
|
|
+ statusText = '';
|
|
|
+ /** 图片列表 */
|
|
|
+ images = [] as string[];
|
|
|
+ /** 附件列表 */
|
|
|
+ annex = [] as string[];
|
|
|
+ /** 创建时间 */
|
|
|
+ createtime = null as Date | null;
|
|
|
+ /** 更新时间 */
|
|
|
+ updatetime = null as Date | null;
|
|
|
+ /** 删除时间 */
|
|
|
+ deletetime = null as Date | null;
|
|
|
+}
|
|
|
+
|
|
|
+export class GalleryApi extends AppServerRequestModule<DataModel> {
|
|
|
+
|
|
|
+ constructor() {
|
|
|
+ super();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 相册图片列表
|
|
|
+ * POST /village/village/albumList
|
|
|
+ */
|
|
|
+ async getAlbumList(params?: {
|
|
|
+ villageId?: number;
|
|
|
+ userId?: number;
|
|
|
+ page?: number;
|
|
|
+ pageSize?: number;
|
|
|
+ keywords?: string;
|
|
|
+ }) {
|
|
|
+ const res = await this.post<{
|
|
|
+ data: any[];
|
|
|
+ total: number;
|
|
|
+ }>('/village/village/albumList', '相册图片列表', {
|
|
|
+ village_id: params?.villageId,
|
|
|
+ user_id: params?.userId,
|
|
|
+ page: params?.page,
|
|
|
+ pageSize: params?.pageSize,
|
|
|
+ keywords: params?.keywords,
|
|
|
+ });
|
|
|
+ return {
|
|
|
+ total: res.requireData().total,
|
|
|
+ list: transformArrayDataModel<GalleryItem>(GalleryItem, transformSomeToArray(res.requireData().data), '相册图片', true),
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增/修改相册图片
|
|
|
+ * POST /village/village/saveVillageImage
|
|
|
+ */
|
|
|
+ async saveVillageImageWithFile(params: {
|
|
|
+ /** 修改时必填 */
|
|
|
+ id?: number;
|
|
|
+ /** 图片文件路径(新增时必填) */
|
|
|
+ filePath: string;
|
|
|
+ /** 村落ID */
|
|
|
+ villageId: number;
|
|
|
+ /** 说明 */
|
|
|
+ desc?: string;
|
|
|
+ /** 名称 */
|
|
|
+ name?: string;
|
|
|
+ }, receiveTask?: (task: UniApp.UploadTask) => void) {
|
|
|
+ let url = RequestApiConfig.getConfig().BaseUrl + '/village/village/saveVillageImage';
|
|
|
+ const req: RequestOptions = {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {},
|
|
|
+ };
|
|
|
+ if (this.config.requestInterceptor) {
|
|
|
+ const { newReq, newUrl } = await this.config.requestInterceptor(url, req);
|
|
|
+ url = newUrl;
|
|
|
+ Object.assign(req, newReq);
|
|
|
+ }
|
|
|
+ return new Promise<KeyValue>((resolve, reject) => {
|
|
|
+ const task = uni.uploadFile({
|
|
|
+ url,
|
|
|
+ name: 'file',
|
|
|
+ header: req.headers,
|
|
|
+ filePath: params.filePath,
|
|
|
+ formData: {
|
|
|
+ id: params.id ?? '',
|
|
|
+ village_id: params.villageId,
|
|
|
+ desc: params.desc ?? '',
|
|
|
+ name: params.name ?? '',
|
|
|
+ },
|
|
|
+ success: (result) => {
|
|
|
+ const data = JSON.parse(result.data);
|
|
|
+ if (data.code !== 1) {
|
|
|
+ reject(new Error(data.msg ?? 'code: ' + data.code));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ resolve(data.data);
|
|
|
+ },
|
|
|
+ fail: (err) => reject(err),
|
|
|
+ });
|
|
|
+ receiveTask?.(task);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增/修改相册图片
|
|
|
+ * POST /village/village/saveVillageImage
|
|
|
+ */
|
|
|
+ async saveVillageImage(params: {
|
|
|
+ /** 修改时必填 */
|
|
|
+ id?: number;
|
|
|
+ /** 村落ID */
|
|
|
+ villageId: number;
|
|
|
+ /** 说明 */
|
|
|
+ desc?: string;
|
|
|
+ /** 名称 */
|
|
|
+ name?: string;
|
|
|
+ }) {
|
|
|
+ return await this.post<KeyValue>('/village/village/saveVillageImage', '保存相册图片', {
|
|
|
+ id: params.id,
|
|
|
+ village_id: params.villageId,
|
|
|
+ desc: params.desc,
|
|
|
+ name: params.name,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除相册图片
|
|
|
+ * POST /village/village/delVillageImage
|
|
|
+ */
|
|
|
+ async delVillageImage(id: number) {
|
|
|
+ return await this.post<KeyValue>('/village/village/delVillageImage', '删除相册图片', {
|
|
|
+ id,
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export default new GalleryApi();
|