feat: new settings and mainpage blocks

This commit is contained in:
2025-11-11 00:30:39 +03:00
parent 5fb45000ac
commit 6176c720b1
97 changed files with 1842 additions and 1658 deletions

View File

@@ -1,11 +1,13 @@
import {defineStore} from "pinia";
import {apiGet, apiPost} from "@/utils/http.js";
import {toastBus} from "@/utils/toastHelper.js";
import {md5} from "js-md5";
export const useSettingsStore = defineStore('settings', {
state: () => ({
isLoading: false,
error: null,
originalItemsHash: null,
items: {
app: {
@@ -32,10 +34,6 @@ export const useSettingsStore = defineStore('settings', {
store: {
enable_store: true,
mainpage_products: 'most_viewed',
featured_products: [],
mainpage_categories: 'latest10',
featured_categories: [],
feature_coupons: true,
feature_vouchers: true,
},
@@ -63,6 +61,8 @@ export const useSettingsStore = defineStore('settings', {
slides: [],
},
},
mainpage_blocks: [],
},
}),
@@ -74,6 +74,10 @@ export const useSettingsStore = defineStore('settings', {
const filename = state.items.app.app_icon.substring(0, extIndex);
return `/image/cache/${filename}-100x100${ext}`;
},
hasUnsavedChanges: (state) => {
if (!state.originalItemsHash) return false;
return md5(JSON.stringify(state.items)) !== state.originalItemsHash;
},
},
actions: {
@@ -86,6 +90,8 @@ export const useSettingsStore = defineStore('settings', {
...this.items,
...response.data,
};
// Сохраняем хеш исходного состояния после загрузки
this.originalItemsHash = md5(JSON.stringify(this.items));
} else {
this.error = 'Возникли проблемы при загрузке настроек.';
}
@@ -104,6 +110,8 @@ export const useSettingsStore = defineStore('settings', {
detail: 'Настройки сохранены.',
life: 2000,
});
// Обновляем хеш исходного состояния после успешного сохранения
this.originalItemsHash = md5(JSON.stringify(this.items));
} else {
toastBus.emit('show', {
severity: 'error',
@@ -114,7 +122,6 @@ export const useSettingsStore = defineStore('settings', {
}
this.isLoading = false;
},