diff --git a/src/store/seller/index.ts b/src/store/seller/index.ts index 3ca93278..a72b3227 100644 --- a/src/store/seller/index.ts +++ b/src/store/seller/index.ts @@ -49,8 +49,11 @@ const seller: Module = { }, set_designerInfo(state: Seller, value: DesignerInfo) { state.designerInfo = { + ...state.designerInfo, ...value, - socialLinks: JSON.parse(value.socialLinks) + } + if (value.socialLinks) { + state.designerInfo.socialLinks = JSON.parse(value.socialLinks) } }, }, diff --git a/src/tool/https.js b/src/tool/https.js index 3c734e5a..ac775971 100644 --- a/src/tool/https.js +++ b/src/tool/https.js @@ -474,6 +474,7 @@ export const Https = { // 卖家端接口 + sellerUploadFile: '/seller/file/upload', // 卖家上传文件 checkSellerDesigner: '/seller/designer/check', // 检查卖家是否为设计师 getSellerApplyStatus: '/seller/designer/apply/status', // 获取卖家申请状态 submitSellerApply: '/seller/designer/apply', // 提交卖家申请 diff --git a/src/views/SellerDashboard/BrandProfile/image-clip.vue b/src/views/SellerDashboard/BrandProfile/image-clip.vue index f0009b42..572eb218 100644 --- a/src/views/SellerDashboard/BrandProfile/image-clip.vue +++ b/src/views/SellerDashboard/BrandProfile/image-clip.vue @@ -7,7 +7,7 @@ crossOrigin="Anonymous" :autoCrop="true" :fixedNumber="ratio" - :fixed="type !== 'apparel' && isProduct" + :fixed="type !== 'apparel'" movable centerBox :fixedBox="fixedBox" @@ -36,361 +36,345 @@ diff --git a/src/views/SellerDashboard/BrandProfile/index.vue b/src/views/SellerDashboard/BrandProfile/index.vue index aed75777..3fbaf999 100644 --- a/src/views/SellerDashboard/BrandProfile/index.vue +++ b/src/views/SellerDashboard/BrandProfile/index.vue @@ -69,13 +69,25 @@ input.click() } + const uploadFile = async (file) => { + const formData = new FormData() + formData.append("file", file) + return Https.axiosPost(Https.httpUrls.sellerUploadFile, formData, { + headers: { + "Content-Type": "multipart/form-data" + } + }) + } + const onChangeBanner = () => { uploadImg(({ url }) => { imageClipDialogRef.value.open( url, - (file) => { - // banner.value = URL.createObjectURL(file) - console.log(URL.createObjectURL(file)) + async (file) => { + store.commit("set_loading", true) + const res = await uploadFile(file) + onSubmit({ brandBanner: res }) + store.commit("set_loading", false) }, { ratio: [40, 7], isPreview: false, title: "Crop Brand Banner" } ) @@ -85,9 +97,11 @@ uploadImg(({ url }) => { imageClipDialogRef.value.open( url, - (file) => { - // avatar.value = URL.createObjectURL(file) - console.log(URL.createObjectURL(file)) + async (file) => { + store.commit("set_loading", true) + const res = await uploadFile(file) + onSubmit({ avatar: res }) + store.commit("set_loading", false) }, { ratio: [1, 1], isPreview: true, title: "Crop Avatar" } ) @@ -99,12 +113,16 @@ const onCancel = () => { isEdit.value = false } - const onSubmit = async () => { - const res = await brandInfoRef.value.submit() + const onSubmit = async (value = null) => { + const res = value ? value : await brandInfoRef.value.submit() const data = { ...designerInfo.value, - ...res, - socialLinks: JSON.stringify(res.socialLinks) + ...res + } + try { + data.socialLinks = JSON.stringify(data.socialLinks) + } catch (error) { + data.socialLinks = JSON.stringify([]) } Https.axiosPut(Https.httpUrls.updateDesignerInfo, data).then((res) => { isEdit.value = false