update

parent f5b9b2ce
import { i18n } from 'src/boot/i18n'; import { i18n } from 'src/boot/i18n';
import { defineComponent, Ref, ref } from 'vue'; import { defineComponent, PropType, Ref, ref, watch } from 'vue';
import UploadImage from 'components/upload-image/index.vue'; import UploadImage from 'components/upload-image/index.vue';
import { PostType } from 'src/assets/type'; import { PostType, LanguageType } from 'src/assets/type';
import ListPostDialog from 'components/post-category/list-post-dialog/index.vue'; import ListPostDialog from 'components/post-category/list-post-dialog/index.vue';
export default defineComponent({ export default defineComponent({
// name: 'ComponentName' // name: 'ComponentName'
components: { UploadImage, ListPostDialog }, components: { UploadImage, ListPostDialog },
props: { props: {
isOpenAddDialog: { type: Boolean, required: true }, isOpenAddDialog: { type: Boolean, required: true },
languages: { type: Array as PropType<LanguageType[]>, required: true },
}, },
setup() { setup(props) {
type FromDataType = {
name: string;
title: string;
status: number;
language: LanguageType;
};
watch(
() => props.isOpenAddDialog,
(value) => {
if (value) {
langs.value = props.languages.reduce((acc: FromDataType[], info) => {
acc.push({
name: '',
title: '',
status: 1,
language: {
id: info.id,
code: info.code,
name: info.name,
status: info.status,
},
});
return acc;
}, []);
}
console.log(langs.value, 'langs');
}
);
const name: Ref<string | null> = ref(null); const name: Ref<string | null> = ref(null);
const title: Ref<string | null> = ref(null); const title: Ref<string | null> = ref(null);
const image: Ref<string | null> = ref(null); const image: Ref<string | null> = ref(null);
...@@ -77,6 +107,8 @@ export default defineComponent({ ...@@ -77,6 +107,8 @@ export default defineComponent({
]; ];
const userTableRowsPost: Ref<PostType[]> = ref([]); const userTableRowsPost: Ref<PostType[]> = ref([]);
const isOpenListPost: Ref<boolean> = ref(false); const isOpenListPost: Ref<boolean> = ref(false);
const langs: Ref<FromDataType[]> = ref([]);
const tabName: Ref<string> = ref('vi');
const uploadImage = (value: FileList) => { const uploadImage = (value: FileList) => {
urlFileLocal.value = URL.createObjectURL(value[0]); urlFileLocal.value = URL.createObjectURL(value[0]);
file.value = value[0]; file.value = value[0];
...@@ -101,6 +133,8 @@ export default defineComponent({ ...@@ -101,6 +133,8 @@ export default defineComponent({
userTableRowsPost, userTableRowsPost,
keywordSearch, keywordSearch,
deletePostSelected, deletePostSelected,
langs,
tabName,
}; };
}, },
emits: [ emits: [
......
...@@ -18,16 +18,43 @@ ...@@ -18,16 +18,43 @@
<q-separator /> <q-separator />
<q-card-section <q-card-section
class="overflow-auto" class="overflow-auto"
style="max-height: calc(100vh - 10rem)" style="max-height: calc(100vh - 14rem)"
> >
<q-input <q-tabs
v-model="name" v-model="tabName"
:label="$t('postCategory.labelInput.namePost')" dense
type="text" class="text-grey"
class="q-my-sm" active-color="primary"
outlined indicator-color="primary"
:rules="nameRules" align="left"
></q-input> narrow-indicator
>
<q-tab
v-for="(lang, idxLang) in langs"
:key="`${lang.language.id}-${idxLang}`"
:name="lang.language.code"
:label="lang.language.name"
no-caps
/>
</q-tabs>
<q-separator />
<q-tab-panels v-model="tabName" animated>
<q-tab-panel
v-for="(info, index) in langs"
:key="`${info.language.id}-${index}`"
:name="info.language.code"
>
<q-input
v-model="info.name"
:label="$t('postCategory.labelInput.namePost')"
type="text"
class="q-my-sm"
outlined
:rules="nameRules"
></q-input>
</q-tab-panel>
</q-tab-panels>
<q-input <q-input
v-model="title" v-model="title"
:label="$t('postCategory.labelInput.description')" :label="$t('postCategory.labelInput.description')"
...@@ -73,8 +100,6 @@ ...@@ -73,8 +100,6 @@
size="50px" size="50px"
></q-toggle> ></q-toggle>
</div> </div>
</q-card-section>
<q-card-section>
<div class="row q-col-gutter-sm flex-center q-mt-sm"> <div class="row q-col-gutter-sm flex-center q-mt-sm">
<div <div
class=" class="
...@@ -170,6 +195,7 @@ ...@@ -170,6 +195,7 @@
</div> </div>
</div> </div>
</q-card-section> </q-card-section>
<q-card-actions align="right"> <q-card-actions align="right">
<div> <div>
<q-btn <q-btn
......
...@@ -3,7 +3,7 @@ import { defineComponent, onMounted, Ref, ref } from 'vue'; ...@@ -3,7 +3,7 @@ import { defineComponent, onMounted, Ref, ref } from 'vue';
import { API_PATHS, config } from 'src/assets/configurations'; import { API_PATHS, config } from 'src/assets/configurations';
import { AxiosResponse } from 'axios'; import { AxiosResponse } from 'axios';
import { api, BaseResponseBody } from 'src/boot/axios'; import { api, BaseResponseBody } from 'src/boot/axios';
import { CategoryPostType } from 'src/assets/type'; import { CategoryPostType, LanguageType } from 'src/assets/type';
import AddCategoryPostDialog from 'components/post-category/add-post-category/index.vue'; import AddCategoryPostDialog from 'components/post-category/add-post-category/index.vue';
// import { Dialog, Notify } from 'quasar'; // import { Dialog, Notify } from 'quasar';
export default defineComponent({ export default defineComponent({
...@@ -68,6 +68,7 @@ export default defineComponent({ ...@@ -68,6 +68,7 @@ export default defineComponent({
]; ];
const userTableRowsCategoryPost: Ref<CategoryPostType[]> = ref([]); const userTableRowsCategoryPost: Ref<CategoryPostType[]> = ref([]);
const isOpenAddDialog: Ref<boolean> = ref(false); const isOpenAddDialog: Ref<boolean> = ref(false);
const languages: Ref<LanguageType[]> = ref([]);
const getListCategoryPost = async () => { const getListCategoryPost = async () => {
try { try {
const response = (await api({ const response = (await api({
...@@ -83,9 +84,22 @@ export default defineComponent({ ...@@ -83,9 +84,22 @@ export default defineComponent({
} }
} catch (error) {} } catch (error) {}
}; };
const getLanguages = async () => {
try {
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) {
languages.value = response.data.data;
}
} catch (error) {}
};
onMounted(() => { onMounted(() => {
void getListCategoryPost(); void getListCategoryPost();
void getLanguages();
}); });
return { return {
configImg, configImg,
...@@ -94,6 +108,8 @@ export default defineComponent({ ...@@ -94,6 +108,8 @@ export default defineComponent({
userTableRowsCategoryPost, userTableRowsCategoryPost,
isOpenAddDialog, isOpenAddDialog,
getListCategoryPost, getListCategoryPost,
getLanguages,
languages,
}; };
}, },
}); });
...@@ -102,6 +102,7 @@ ...@@ -102,6 +102,7 @@
</div> </div>
<AddCategoryPostDialog <AddCategoryPostDialog
v-model:is-open-add-dialog="isOpenAddDialog" v-model:is-open-add-dialog="isOpenAddDialog"
:languages="languages"
@click:closeBtnDialog="isOpenAddDialog = false" @click:closeBtnDialog="isOpenAddDialog = false"
/> />
</div> </div>
......
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