141 lines
3.2 KiB
TypeScript
141 lines
3.2 KiB
TypeScript
import type {
|
|
ContentListQueryType,
|
|
ContentListType,
|
|
ContentType
|
|
} from '~/types/contents';
|
|
import { cloneDeep } from 'lodash-es';
|
|
import type { Page } from '~/types/common';
|
|
import { defineStore } from 'pinia';
|
|
import { ref } from 'vue';
|
|
import { useAxios } from '~/composables/useAxios';
|
|
import { message } from 'ant-design-vue';
|
|
|
|
const DEFAULT_CONTENT_QUERY: ContentListQueryType = {
|
|
keyword: '',
|
|
orgId: '',
|
|
page: 1,
|
|
siteId: '',
|
|
size: 10,
|
|
type: 'TOTAL'
|
|
};
|
|
|
|
const DEFAULT_CONTENTS_LIST: Page<ContentListType> = {
|
|
content: [],
|
|
totalElements: 0,
|
|
totalPages: 0
|
|
};
|
|
|
|
const DEFAULT_CONTENTS: ContentType = {
|
|
contentTitle: '',
|
|
contentPlain: '',
|
|
contents: '',
|
|
frstRegDt: '',
|
|
frstRgtrId: '',
|
|
lastMdfcnDt: '',
|
|
lastMdfrId: '',
|
|
orgId: '',
|
|
siteId: '',
|
|
useYn: true
|
|
};
|
|
|
|
export const useContentStore = defineStore('useContentStore', () => {
|
|
const contentsQuery = ref<ContentListQueryType>(
|
|
cloneDeep(DEFAULT_CONTENT_QUERY)
|
|
);
|
|
|
|
const contentsList = ref<Page<ContentListType>>(
|
|
cloneDeep(DEFAULT_CONTENTS_LIST)
|
|
);
|
|
|
|
const contents = ref<ContentType>(cloneDeep(DEFAULT_CONTENTS));
|
|
const initialValue = ref<string>('');
|
|
|
|
const resetContentListQuery = () => {
|
|
contentsQuery.value = cloneDeep(DEFAULT_CONTENT_QUERY);
|
|
};
|
|
|
|
const resetContentList = () => {
|
|
contentsList.value = cloneDeep(DEFAULT_CONTENTS_LIST);
|
|
};
|
|
|
|
const resetContents = () => {
|
|
contents.value = cloneDeep(DEFAULT_CONTENTS);
|
|
initialValue.value = '';
|
|
};
|
|
|
|
const initContentsQuery = () => {
|
|
contentsQuery.value = cloneDeep(DEFAULT_CONTENT_QUERY);
|
|
};
|
|
|
|
const searchContentList = async () => {
|
|
try {
|
|
const { data } = await useAxios().get(
|
|
'/api/admin/contents/contentsList',
|
|
{
|
|
params: {
|
|
...contentsQuery.value
|
|
}
|
|
}
|
|
);
|
|
|
|
contentsList.value = data;
|
|
} catch (e) {
|
|
message.error('사이트 리스트를 불러오는데 실패하였습니다.');
|
|
}
|
|
};
|
|
|
|
const searchContents = async (contentId: number) => {
|
|
try {
|
|
const { data } = await useAxios().get('/api/admin/contents/detail', {
|
|
params: {
|
|
contentId
|
|
}
|
|
});
|
|
|
|
contents.value = data;
|
|
initialValue.value = data.contents;
|
|
} catch (e) {
|
|
message.error('컨텐츠 정보를 불러오는데 실패하였습니다.');
|
|
}
|
|
};
|
|
|
|
const updateContents = () => {
|
|
console.log(contents.value);
|
|
return useAxios().post(
|
|
'/api/admin/contents/updateContents',
|
|
contents.value
|
|
);
|
|
};
|
|
|
|
const deleteContents = async (data: ContentType[]) => {
|
|
try {
|
|
const params = new URLSearchParams();
|
|
data.forEach((item) => {
|
|
params.append('contentId', String(item.contentId));
|
|
});
|
|
|
|
await useAxios().post('/api/admin/contents/deleteContents', null, {
|
|
params
|
|
});
|
|
message.success('컨텐츠 정보가 삭제 되었습니다.');
|
|
} catch (e) {
|
|
message.error('컨텐츠 정보 삭제에 실패하였습니다.');
|
|
}
|
|
};
|
|
|
|
return {
|
|
contentsQuery,
|
|
contentsList,
|
|
contents,
|
|
initialValue,
|
|
resetContentListQuery,
|
|
searchContentList,
|
|
searchContents,
|
|
resetContentList,
|
|
resetContents,
|
|
initContentsQuery,
|
|
deleteContents,
|
|
updateContents
|
|
};
|
|
});
|