update upload image

parent cb9e9c49
...@@ -111,9 +111,9 @@ export type WorkType = { ...@@ -111,9 +111,9 @@ export type WorkType = {
export type BannerType = { export type BannerType = {
bannerUrl: string; bannerUrl: string;
id: number; id?: number;
numIndex: number; numIndex?: number;
status: number; status?: number;
url?: string; url?: string;
file?: File; file?: File;
}; };
...@@ -134,6 +134,8 @@ export type StoriesType = { ...@@ -134,6 +134,8 @@ export type StoriesType = {
content: string; content: string;
imageUrl: string; imageUrl: string;
status: number; status: number;
url?: string;
file?: File;
}; };
export type BankAccountType = { export type BankAccountType = {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
.q-table__bottom, .q-table__bottom,
thead tr:first-child th { thead tr:first-child th {
// / bg color is important for th; just specify one / // / bg color is important for th; just specify one /
background-color: #c1f4cd; background-color: white;
} }
thead tr th { thead tr th {
......
...@@ -88,6 +88,7 @@ export default defineComponent({ ...@@ -88,6 +88,7 @@ export default defineComponent({
const account: Ref<string | null> = ref(null); const account: Ref<string | null> = ref(null);
const avatar: Ref<string | null> = ref(null); const avatar: Ref<string | null> = ref(null);
const avatarFile: Ref<File | null> = ref(null); const avatarFile: Ref<File | null> = ref(null);
const avatarUploaded: Ref<string | null> = ref(null);
const artistCode: Ref<string> = ref(''); const artistCode: Ref<string> = ref('');
const fullName: Ref<string> = ref(''); const fullName: Ref<string> = ref('');
const artistName: Ref<string | null | undefined> = ref(); const artistName: Ref<string | null | undefined> = ref();
...@@ -309,6 +310,8 @@ export default defineComponent({ ...@@ -309,6 +310,8 @@ export default defineComponent({
}; };
const selectedFile = (value: BannerType) => { const selectedFile = (value: BannerType) => {
console.log(value, 'banners');
banners.value.push(value); banners.value.push(value);
console.log(banners.value); console.log(banners.value);
}; };
...@@ -374,6 +377,7 @@ export default defineComponent({ ...@@ -374,6 +377,7 @@ export default defineComponent({
const addStory = (value: StoriesType) => { const addStory = (value: StoriesType) => {
stories.value.push(value); stories.value.push(value);
console.log(stories, 'storiesstoriesstories');
}; };
const deleteStory = (idx: number) => { const deleteStory = (idx: number) => {
...@@ -404,29 +408,84 @@ export default defineComponent({ ...@@ -404,29 +408,84 @@ export default defineComponent({
birthday.value = value; birthday.value = value;
}; };
// const callApiUploadImage = async (file: File) => { const callApiUploadAvatar = async (file: File) => {
// try { try {
// const bodyFormData = new FormData(); const bodyFormData = new FormData();
// bodyFormData.append('file', file); bodyFormData.append('file', file);
// const response = (await api({ const response = (await api({
// headers: { 'Content-Type': 'multipart/form-data' }, headers: { 'Content-Type': 'multipart/form-data' },
// url: 'http://cms.vab.xteldev.com/file/upload', url: 'http://cms.vab.xteldev.com/file/upload',
// method: 'POST', method: 'POST',
// data: bodyFormData, data: bodyFormData,
// })) as AxiosResponse<BaseResponseBody<FileUploadType>>; })) as AxiosResponse<BaseResponseBody<FileUploadType>>;
// if (response.data.error.code === config.API_RES_CODE.OK.code) { if (response.data.error.code === config.API_RES_CODE.OK.code) {
// } avatarUploaded.value =
// } catch (error) {} 'http://cms.vab.xteldev.com/file/upload/' +
// }; response.data.data.fileName;
}
} catch (error) {}
};
const callApiUploadBanners = async (file: File, index: number) => {
try {
const bodyFormData = new FormData();
bodyFormData.append('file', file);
const response = (await api({
headers: { 'Content-Type': 'multipart/form-data' },
url: 'http://cms.vab.xteldev.com/file/upload',
method: 'POST',
data: bodyFormData,
})) as AxiosResponse<BaseResponseBody<FileUploadType>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
const bannerUpload =
'http://cms.vab.xteldev.com/file/upload/' +
response.data.data.fileName;
banners.value[index] = {
bannerUrl: bannerUpload,
};
}
} catch (error) {}
};
const callApiUploadStories = async (file: File, idxStory: number) => {
try {
const bodyFormData = new FormData();
bodyFormData.append('file', file);
const response = (await api({
headers: { 'Content-Type': 'multipart/form-data' },
url: 'http://cms.vab.xteldev.com/file/upload',
method: 'POST',
data: bodyFormData,
})) as AxiosResponse<BaseResponseBody<FileUploadType>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
const urlStoryUpload =
'http://cms.vab.xteldev.com/file/upload/' +
response.data.data.fileName;
stories.value[idxStory].imageUrl = urlStoryUpload;
}
} catch (error) {}
};
const updateInformationArtist = async () => { const updateInformationArtist = async () => {
try { try {
// await callApiUploadImage(avatarFile.value as File); if (avatarFile.value !== null) {
await callApiUploadAvatar(avatarFile.value);
}
for (let index = 0; index < banners.value.length; index++) {
const element = banners.value[index];
if (element.file !== undefined) {
await callApiUploadBanners(element.file, index);
}
}
for (let idx = 0; idx < stories.value.length; idx++) {
const item = stories.value[idx];
if (item.file !== undefined) {
await callApiUploadStories(item.file, idx);
}
}
const response = (await api({ const response = (await api({
url: API_PATHS.updateArtist, url: API_PATHS.updateArtist,
method: 'POST', method: 'POST',
data: { data: {
id: route.params.id, id: route.params.id,
avatar: avatar.value, avatar: avatarUploaded.value,
artistCode: artistCode.value, artistCode: artistCode.value,
artistName: artistName.value, artistName: artistName.value,
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
outlined outlined
></q-select> ></q-select>
</div> </div>
<div class="col-2" dense outlined> <div class="col-2" dense outlined>
<q-select <q-select
v-model="professionSelected" v-model="professionSelected"
......
...@@ -34,6 +34,7 @@ import { ...@@ -34,6 +34,7 @@ import {
SchedulesType, SchedulesType,
CardBankType, CardBankType,
TypeCardType, TypeCardType,
FileUploadType,
} from 'src/assets/type'; } from 'src/assets/type';
export type AvatarType = { export type AvatarType = {
...@@ -87,6 +88,7 @@ export default defineComponent({ ...@@ -87,6 +88,7 @@ export default defineComponent({
const account: Ref<string | null> = ref(null); const account: Ref<string | null> = ref(null);
const avatar: Ref<string | null> = ref(null); const avatar: Ref<string | null> = ref(null);
const avatarFile: Ref<File | null> = ref(null); const avatarFile: Ref<File | null> = ref(null);
const avatarUploaded: Ref<string | null> = ref(null);
const artistCode: Ref<string> = ref(''); const artistCode: Ref<string> = ref('');
const fullName: Ref<string> = ref(''); const fullName: Ref<string> = ref('');
const artistName: Ref<string | null | undefined> = ref(); const artistName: Ref<string | null | undefined> = ref();
...@@ -352,24 +354,86 @@ export default defineComponent({ ...@@ -352,24 +354,86 @@ export default defineComponent({
stories.value.splice(idx, 1); stories.value.splice(idx, 1);
}); });
}; };
// const callApiUploadImage = async (file: File) => {
// try { const callApiUploadAvatar = async (file: File) => {
// const response = await api({ try {
// url: API_PATHS.uploadImage, const bodyFormData = new FormData();
// method: 'GET', bodyFormData.append('file', file);
// params: {}, const response = (await api({
// }); headers: { 'Content-Type': 'multipart/form-data' },
// } catch (error) {} url: 'http://cms.vab.xteldev.com/file/upload',
// }; method: 'POST',
data: bodyFormData,
})) as AxiosResponse<BaseResponseBody<FileUploadType>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
avatarUploaded.value =
'http://cms.vab.xteldev.com/file/upload/' +
response.data.data.fileName;
}
} catch (error) {}
};
const callApiUploadBanners = async (file: File, index: number) => {
try {
const bodyFormData = new FormData();
bodyFormData.append('file', file);
const response = (await api({
headers: { 'Content-Type': 'multipart/form-data' },
url: 'http://cms.vab.xteldev.com/file/upload',
method: 'POST',
data: bodyFormData,
})) as AxiosResponse<BaseResponseBody<FileUploadType>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
const bannerUpload =
'http://cms.vab.xteldev.com/file/upload/' +
response.data.data.fileName;
banners.value[index] = {
bannerUrl: bannerUpload,
};
}
} catch (error) {}
};
const callApiUploadStories = async (file: File, idxStory: number) => {
try {
const bodyFormData = new FormData();
bodyFormData.append('file', file);
const response = (await api({
headers: { 'Content-Type': 'multipart/form-data' },
url: 'http://cms.vab.xteldev.com/file/upload',
method: 'POST',
data: bodyFormData,
})) as AxiosResponse<BaseResponseBody<FileUploadType>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
const urlStoryUpload =
'http://cms.vab.xteldev.com/file/upload/' +
response.data.data.fileName;
stories.value[idxStory].imageUrl = urlStoryUpload;
}
} catch (error) {}
};
const addArtist = async () => { const addArtist = async () => {
try { try {
if (avatarFile.value !== null) {
await callApiUploadAvatar(avatarFile.value);
}
for (let index = 0; index < banners.value.length; index++) {
const element = banners.value[index];
if (element.file !== undefined) {
await callApiUploadBanners(element.file, index);
}
}
for (let idx = 0; idx < stories.value.length; idx++) {
const item = stories.value[idx];
if (item.file !== undefined) {
await callApiUploadStories(item.file, idx);
}
}
const response = (await api({ const response = (await api({
url: API_PATHS.addArtist, url: API_PATHS.addArtist,
method: 'POST', method: 'POST',
data: { data: {
id: route.params.id, id: route.params.id,
avatar: avatar.value, avatar: avatarUploaded.value,
artistCode: artistCode.value, artistCode: artistCode.value,
artistName: artistName.value, artistName: artistName.value,
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment