Commit 34d02d6c authored by Tình Trương's avatar Tình Trương

update

parent 796d2d59
...@@ -73,4 +73,7 @@ export enum API_PATHS { ...@@ -73,4 +73,7 @@ export enum API_PATHS {
getPostCategory = 'postCategory', getPostCategory = 'postCategory',
addPost = 'post/add', addPost = 'post/add',
getListCategoryPost = 'postCategory', getListCategoryPost = 'postCategory',
getLanguage = 'language',
getDetailPost = 'post/detail',
updatePost = 'post/update',
} }
...@@ -331,6 +331,7 @@ export type LanguageType = { ...@@ -331,6 +331,7 @@ export type LanguageType = {
code: string; code: string;
name: string; name: string;
status: number; status: number;
isDefault?: number;
}; };
export type LangType = { export type LangType = {
...@@ -373,3 +374,15 @@ export type PostCategoryDetailType = { ...@@ -373,3 +374,15 @@ export type PostCategoryDetailType = {
updateBy?: string; updateBy?: string;
updateTime?: string; updateTime?: string;
}; };
export type PostAddType = {
id: number;
image: string;
status: number;
langs: LangType[];
category: CategoryPostType;
createBy?: string;
createTime?: string;
updateBy?: string;
updateTime?: string;
};
This diff is collapsed.
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
style="width: 9rem" style="width: 9rem"
fit="contain" fit="contain"
:ratio="16 / 9" :ratio="16 / 9"
:src="image.row.image" :src="configImg.API_IMAGE_ENDPOINT + image.row.image"
></q-img> ></q-img>
</q-td> </q-td>
</template> </template>
...@@ -148,7 +148,7 @@ ...@@ -148,7 +148,7 @@
:categoryOptions="categoryOptions" :categoryOptions="categoryOptions"
@SetAvatar="setAvatar($event)" @SetAvatar="setAvatar($event)"
@deleteAvatar="deleteAvatar" @deleteAvatar="deleteAvatar"
@savePostInfo="updateNewPost" @savePostInfo="confirmUpdatePost"
/> />
</div> </div>
</template> </template>
...@@ -165,7 +165,9 @@ import { ...@@ -165,7 +165,9 @@ import {
PostType, PostType,
FileUploadType, FileUploadType,
CategoryPostType, CategoryPostType,
LanguageType,
PostDetailType, PostDetailType,
PostAddType,
} from 'src/assets/type'; } from 'src/assets/type';
import { config } from 'src/assets/configurations'; import { config } from 'src/assets/configurations';
import { PostStatus } from 'src/assets/enums'; import { PostStatus } from 'src/assets/enums';
...@@ -280,8 +282,8 @@ export default defineComponent({ ...@@ -280,8 +282,8 @@ export default defineComponent({
const postTableRows: Ref<unknown[]> = ref([]); const postTableRows: Ref<unknown[]> = ref([]);
const addPostDialogIsOpened = ref(false); const addPostDialogIsOpened = ref(false);
const updatePostDialogIsOpened = ref(false); const updatePostDialogIsOpened = ref(false);
const category: Ref<number | undefined> = ref(undefined); const category: Ref<CategoryPostType | undefined> = ref();
const categoryOptions: Ref<unknown[]> = ref([]); const categoryOptions: Ref<CategoryPostType[]> = ref([]);
const name = ref(''); const name = ref('');
const content = ref(''); const content = ref('');
const image: Ref<string | null> = ref(null); const image: Ref<string | null> = ref(null);
...@@ -289,11 +291,9 @@ export default defineComponent({ ...@@ -289,11 +291,9 @@ export default defineComponent({
const postId: Ref<number | undefined> = ref(undefined); const postId: Ref<number | undefined> = ref(undefined);
const namePost = ref(''); const namePost = ref('');
const avatarFile: Ref<File | null> = ref(null); const avatarFile: Ref<File | null> = ref(null);
const avatarUploaded: Ref<string | null> = ref(null); const avatarUploaded: Ref<string> = ref('');
const languageOptions = ref([ const imageChange: Ref<string> = ref('');
{ id: 1, code: 'vn', name: 'Tiếng Việt' }, const languageOptions: Ref<FromType> = ref([]);
{ id: 2, code: 'en', name: 'Tiếng Anh' },
]);
const changePageSize = () => { const changePageSize = () => {
pageIndex.value = 1; pageIndex.value = 1;
...@@ -353,26 +353,29 @@ export default defineComponent({ ...@@ -353,26 +353,29 @@ export default defineComponent({
}; };
const openAddPostDialog = () => { const openAddPostDialog = () => {
name.value = ''; void getLanguage();
category.value = undefined;
content.value = '';
image.value = null;
status.value = PostStatus.active; status.value = PostStatus.active;
image.value = null;
category.value = undefined;
addPostDialogIsOpened.value = true; addPostDialogIsOpened.value = true;
}; };
//gọi api add //gọi api add
const addNewPost = async () => { const addNewPost = async () => {
avatarUploaded.value = await callApiUploadAvatar(
avatarFile.value as File
);
const data = { const data = {
image: image.value, image: avatarUploaded.value,
status: status.value, status: status.value,
category: category.value, category: { id: category.value?.id },
langs: languageOptions.value,
}; };
const response = (await api({ const response = (await api({
url: API_PATHS.addPost, url: API_PATHS.addPost,
method: 'POST', method: 'POST',
data, data,
})) as AxiosResponse<BaseResponseBody<PostDetailType[]>>; })) as AxiosResponse<BaseResponseBody<PostAddType[]>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) { if (response.data.error.code === config.API_RES_CODE.OK.code) {
addPostDialogIsOpened.value = false; addPostDialogIsOpened.value = false;
Notify.create({ Notify.create({
...@@ -391,46 +394,59 @@ export default defineComponent({ ...@@ -391,46 +394,59 @@ export default defineComponent({
//gọi api detail //gọi api detail
const getDetailPost = async (id: number) => { const getDetailPost = async (id: number) => {
// try { try {
// const response = (await api({ const response = (await api({
// url: API_PATHS.getDetailPost, url: API_PATHS.getDetailPost,
// method: 'GET', method: 'GET',
// params: { params: {
// id: id, id: id,
// }, },
// })) as AxiosResponse<BaseResponseBody<DetailPost>>; })) as AxiosResponse<BaseResponseBody<PostDetailType>>;
// if (response.data.error.code === config.API_RES_CODE.OK.code) { if (response.data.error.code === config.API_RES_CODE.OK.code) {
// postId.value = response.data.data.id; postId.value = response.data.data.id;
// name.value = response.data.data.name; image.value = config.API_IMAGE_ENDPOINT + response.data.data.image;
// description.value = response.data.data.description; imageChange.value = response.data.data.image;
// status.value = response.data.data.status; languageOptions.value = response.data.data.langs;
// } status.value = response.data.data.status;
// } catch (error) {} category.value = response.data.data.category;
}
} catch (error) {}
}; };
//gọi api update //gọi api update
const updateNewPost = async () => { const confirmUpdatePost = async () => {
// const data = { if (avatarFile.value) {
// id: postId.value, avatarUploaded.value = await callApiUploadAvatar(avatarFile.value);
// name: name.value, void updatePost(avatarUploaded.value);
// description: description.value, } else {
// status: status.value, void updatePost(imageChange.value);
// }; }
// const response = (await api({
// // url: API_PATHS.updatePost,
// method: 'POST',
// data,
// })) as AxiosResponse<BaseResponseBody<[]>>;
// if (response.data.error.code === config.API_RES_CODE.OK.code) {
// updatePostDialogIsOpened.value = false;
// Notify.create({
// type: 'positive',
// message: i18n.global.t('post.actionMessages.updatePostAccess'),
// actions: [{ icon: 'close', color: 'white' }],
// });
// void getListPost();
// }
}; };
const updatePost = async (image: string) => {
const data = {
id: postId.value,
image,
status: status.value,
category: { id: category.value?.id },
langs: languageOptions.value,
};
const response = (await api({
url: API_PATHS.updatePost,
method: 'POST',
data,
})) as AxiosResponse<BaseResponseBody<PostDetailType[]>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
updatePostDialogIsOpened.value = false;
Notify.create({
type: 'positive',
message: i18n.global.t('post.actionMessages.updatePostAccess'),
actions: [{ icon: 'close', color: 'white' }],
});
void getListPost();
}
};
const setAvatar = (value: { file?: File; url?: string }) => { const setAvatar = (value: { file?: File; url?: string }) => {
avatarFile.value = value.file as File; avatarFile.value = value.file as File;
image.value = value.url as string; image.value = value.url as string;
...@@ -442,19 +458,25 @@ export default defineComponent({ ...@@ -442,19 +458,25 @@ export default defineComponent({
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 = response.data.data.fileName; return response.data.data.fileName;
} else {
return '';
} }
} catch (error) {} } catch (error) {
return '';
}
}; };
const deleteAvatar = () => { const deleteAvatar = () => {
image.value = null; image.value = null;
}; };
const configImg = config;
//gọi api danh mục bv //gọi api danh mục bv
const getpostCategory = async () => { const getpostCategory = async () => {
const response = (await api({ const response = (await api({
...@@ -467,6 +489,45 @@ export default defineComponent({ ...@@ -467,6 +489,45 @@ export default defineComponent({
} }
}; };
type FromType = {
name: string;
title: string;
content: string;
status: number;
language: {
id: number;
code: string;
name: string;
};
}[];
const getLanguage = async () => {
const response = (await api({
url: API_PATHS.getLanguage,
method: 'GET',
params: {},
})) as AxiosResponse<BaseResponseBody<LanguageType[]>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
languageOptions.value = response.data.data.reduce(
(acc: FromType, info) => {
acc.push({
name: '',
title: '',
content: '',
status: 1,
language: {
id: info.id,
code: info.code,
name: info.name,
},
});
return acc;
},
[]
);
}
};
onMounted(() => { onMounted(() => {
void getListPost(); void getListPost();
void getpostCategory(); void getpostCategory();
...@@ -492,7 +553,7 @@ export default defineComponent({ ...@@ -492,7 +553,7 @@ export default defineComponent({
deletePost, deletePost,
openUpdatePostDialog, openUpdatePostDialog,
getDetailPost, getDetailPost,
updateNewPost, updatePost,
namePost, namePost,
content, content,
languageOptions, languageOptions,
...@@ -502,6 +563,9 @@ export default defineComponent({ ...@@ -502,6 +563,9 @@ export default defineComponent({
callApiUploadAvatar, callApiUploadAvatar,
deleteAvatar, deleteAvatar,
getpostCategory, getpostCategory,
getLanguage,
configImg,
confirmUpdatePost,
}; };
}, },
}); });
......
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