From e4186f613bf81fe649fc494a5c44aafa81f7e672 Mon Sep 17 00:00:00 2001 From: wkj <278599135@qq.com> Date: Thu, 26 Oct 2023 16:48:51 +0800 Subject: [PATCH] =?UTF-8?q?extraFile=20avatar=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/extraFile/avatar/index.ts | 57 +++++++++++------------- src/pages/user/info/index.xml | 2 +- src/pages/user/info/web.pc.tsx | 11 ++++- src/pages/user/info/web.tsx | 1 + 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/components/extraFile/avatar/index.ts b/src/components/extraFile/avatar/index.ts index 616bf9998..f0be8ab94 100644 --- a/src/components/extraFile/avatar/index.ts +++ b/src/components/extraFile/avatar/index.ts @@ -14,16 +14,20 @@ export default OakComponent({ objectId: 1, filename: 1, extra1: 1, + extra2: 1, extension: 1, type: 1, entity: 1, entityId: 1, + sort: 1, + applicationId: 1, }, + features: ['extraFile2'], formData({ data: extraFiles, features }) { const avatar = extraFiles?.filter( (ele) => !ele.$$deleteAt$$ && ele.tag1 === 'avatar' )[0]; - const avatarUrl = features.extraFile.getUrl( + const avatarUrl = features.extraFile2.getUrl( avatar as EntityDict['extraFile']['OpSchema'] ); return { @@ -44,8 +48,8 @@ export default OakComponent({ preview: true as boolean, entity: '' as keyof EntityDict, entityId: '' as string, + autoUpload: false, }, - methods: { async onPickByMp() { try { @@ -109,13 +113,14 @@ export default OakComponent({ size: number; }) { const { origin, type, tag1, avatar } = this.state; - const { entityId, entity } = this.props; + const { entityId, entity, autoUpload = false } = this.props; const { name, extra1, fileType, size } = options; const extension = name.substring(name.lastIndexOf('.') + 1); const filename = name.substring(0, name.lastIndexOf('.')); + const applicationId = this.features.application.getApplicationId(); assert(entity, '必须传入entity'); const updateData = { - extra1, + applicationId, origin, type, tag1, @@ -127,35 +132,25 @@ export default OakComponent({ fileType, id: generateNewId(), entityId, + sort: 1000, } as EntityDict['extraFile']['CreateSingle']['data']; - // try { - // const { bucket } = await this.features.extraFile.upload( - // updateData - // ); - // Object.assign(updateData, { - // bucket, - // extra1: null, - // }); - // } catch (error) { - // //todo 保存extraFile失败 需要remove七牛图片 - - // throw error; - // } - - this.addItem(Object.assign({}, updateData, { - extra1: null, - }), undefined, async () => { - await this.features.extraFile.upload( - updateData, extra1 - ) - }); - if (avatar) { - this.removeItem(avatar.id as string); - } - // 如果entityId不存在, 说明是级联创建 - if (entityId) { - await this.execute(); + // 如果autoUpload + if (autoUpload) { + await this.features.extraFile2.autoUpload( + updateData as EntityDict['extraFile']['OpSchema'], + extra1 + ); + if (avatar) { + this.removeItem(avatar.id as string); + this.execute(); + } + } else { + const id = this.addItem(updateData); + if (avatar) { + this.removeItem(avatar.id as string); + } + this.features.extraFile2.addLocalFile(id, extra1); } }, }, diff --git a/src/pages/user/info/index.xml b/src/pages/user/info/index.xml index 438a99814..a824eb1cc 100644 --- a/src/pages/user/info/index.xml +++ b/src/pages/user/info/index.xml @@ -2,7 +2,7 @@ - + diff --git a/src/pages/user/info/web.pc.tsx b/src/pages/user/info/web.pc.tsx index 37d1d6806..2cee1dc9b 100644 --- a/src/pages/user/info/web.pc.tsx +++ b/src/pages/user/info/web.pc.tsx @@ -16,6 +16,7 @@ import { WebComponentProps } from 'oak-frontend-base'; import { EntityDict } from '../../../oak-app-domain'; import PageHeader from '../../../components/common/pageHeader'; import OakAvatar from '../../../components/extraFile/avatar'; +import ExtraFileCommit from '../../../components/extraFile/commit'; import MobileLogin from '../../../pages/mobile/login'; import WechatLoginQrCode from '../../../components/wechatLogin/qrCode'; import WechatUserList from '../../../components/wechatUser/bindingList'; @@ -203,7 +204,7 @@ export default function Render( }} > - + */} + diff --git a/src/pages/user/info/web.tsx b/src/pages/user/info/web.tsx index 190e4219e..b3708e82f 100644 --- a/src/pages/user/info/web.tsx +++ b/src/pages/user/info/web.tsx @@ -88,6 +88,7 @@ export default function render( } entity="user" entityId={id} + autoUpload={true} /> }