Merge pull request #190 from Frappet/feat/4-property-managment
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 12s

feat: property managment
This commit is contained in:
Methapon Metanipat 2025-03-13 09:09:25 +07:00 committed by GitHub
commit 169af44eda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 1548 additions and 7 deletions

View file

@ -1,8 +1,11 @@
import { ref, watch } from 'vue';
import { defineStore } from 'pinia';
import { useI18n } from 'vue-i18n';
import { useProperty } from 'src/stores/property';
import { toCamelCase } from '../utils';
const useOptionStore = defineStore('optionStore', () => {
const { getPropertyList } = useProperty();
const { locale } = useI18n();
const globalOption = ref();
@ -12,6 +15,36 @@ const useOptionStore = defineStore('optionStore', () => {
rawOption.value = await fetch('/option/option.json').then((r) => r.json());
_switchOptionLang();
const res = await getPropertyList({ pageSize: 999, activeOnly: true });
const targetOptions = globalOption.value?.propertiesField ?? [];
if (!res) return;
const propList = res.result.map((v) => {
return {
label: locale.value === 'eng' ? v.nameEN : v.name,
value: toCamelCase(v.nameEN),
type: v.type.type,
};
});
globalOption.value.propertiesField = [...targetOptions];
const existingValues = new Set(
globalOption.value.propertiesField.map(
(item: { value: string }) => item.value,
),
);
const newProps = propList.filter((prop) => !existingValues.has(prop.value));
if (newProps) {
globalOption.value.propertiesField.splice(
globalOption.value.propertiesField.length - 4,
0,
...newProps,
);
}
})();
watch(locale, _switchOptionLang);

View file

@ -0,0 +1,71 @@
import { ref } from 'vue';
import { defineStore } from 'pinia';
import { api } from 'src/boot/axios';
import { PaginationResult } from 'src/types';
import { Status } from '../types';
import { Property } from './types';
export const useProperty = defineStore('property-store', () => {
const data = ref<Property[]>([]);
const page = ref<number>(1);
const pageMax = ref<number>(1);
const pageSize = ref<number>(30);
async function getProperty(id: string) {
const res = await api.get<Property[]>(`/property/${id}`);
if (res.status >= 400) return null;
return res.data;
}
async function getPropertyList(params?: {
page?: number;
pageSize?: number;
query?: string;
status?: Status;
activeOnly?: boolean;
}) {
const res = await api.get<PaginationResult<Property>>('/property', {
params,
});
if (res.status >= 400) return null;
return res.data;
}
async function creatProperty(data: Property) {
const res = await api.post<Property>('/property', data);
if (res.status >= 400) return null;
return res;
}
async function editProperty(data: Property) {
const res = await api.put<Property>(`/property/${data.id}`, {
...data,
id: undefined,
});
if (res.status >= 400) return null;
return res;
}
async function deleteProperty(id: string) {
const res = await api.delete<Property>(`/property/${id}`);
if (res.status >= 400) return null;
return res;
}
return {
data,
page,
pageSize,
pageMax,
getProperty,
getPropertyList,
creatProperty,
editProperty,
deleteProperty,
};
});

View file

@ -0,0 +1,10 @@
import { Status } from '../types';
export type Property = {
id?: string;
status?: Status;
registeredBranchId?: string;
name: string;
nameEN: string;
type: Record<string, any>;
};