feat(settings): add SuperAdmin sync button on advanced settings
Lets deploy admins clear overlay cache and reload can_edit=0 switches like enable_automation without SSH. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -16,4 +16,14 @@ export const getSystemConfiguration = async () =>
|
||||
await useAxios.get<Array<Const>>(`/admin/get_settings`, { params: { system_only: 1 } })
|
||||
|
||||
export const setSystemConfiguration = async (obj: Const & { system_deploy?: boolean }) =>
|
||||
await useAxios.post<Const>(`/admin/get_settings`, { ...obj, system_deploy: true })
|
||||
await useAxios.post<Const>(`/admin/get_settings`, { ...obj, system_deploy: true })
|
||||
|
||||
/** همگامسازی overlay تنظیمات can_edit=0 از سوپرادمین (پاک کردن کش last-good) */
|
||||
export const refreshSuperAdminSettings = async () =>
|
||||
await useAxios.post<{
|
||||
ok?: boolean
|
||||
message?: string
|
||||
count?: number
|
||||
enable_automation?: string | null
|
||||
source?: string
|
||||
}>(`/admin/settings/refresh-superadmin`)
|
||||
|
||||
@@ -36,6 +36,14 @@
|
||||
>
|
||||
افزودن تنظیم
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="isSystemMode"
|
||||
class="settings-toolbar__action"
|
||||
:loading="refreshingSuperAdmin"
|
||||
@click="refreshFromSuperAdmin"
|
||||
>
|
||||
همگامسازی از سوپرادمین
|
||||
</a-button>
|
||||
<a-button class="settings-toolbar__action" :loading="loading" @click="initConfig">
|
||||
بروزرسانی
|
||||
</a-button>
|
||||
@@ -197,7 +205,7 @@ import type { FormInstance } from 'ant-design-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { Const } from '@/model/configuration'
|
||||
import { loading } from '@/utils'
|
||||
import { getEditableConfiguration, getSystemConfiguration, setConfiguration, setSystemConfiguration } from '@/api/configuration'
|
||||
import { getEditableConfiguration, getSystemConfiguration, setConfiguration, setSystemConfiguration, refreshSuperAdminSettings } from '@/api/configuration'
|
||||
import SettingValueField from './SettingValueField.vue'
|
||||
import SettingCard from './SettingCard.vue'
|
||||
import { refreshAppModeMenu } from '@/router'
|
||||
@@ -236,6 +244,7 @@ function refreshMenuAfterStoreChange() {
|
||||
|
||||
const isSystemMode = computed(() => props.mode === 'system')
|
||||
const pageTitle = computed(() => (isSystemMode.value ? 'تنظیمات پیشرفته' : 'تنظیمات'))
|
||||
const refreshingSuperAdmin = ref(false)
|
||||
const settingGroups = computed(() =>
|
||||
isSystemMode.value ? SYSTEM_SETTING_GROUPS : EDITABLE_SETTING_GROUPS
|
||||
)
|
||||
@@ -479,6 +488,28 @@ watch(
|
||||
}
|
||||
)
|
||||
|
||||
async function refreshFromSuperAdmin() {
|
||||
if (!isSystemMode.value || refreshingSuperAdmin.value) return
|
||||
refreshingSuperAdmin.value = true
|
||||
try {
|
||||
const res = await refreshSuperAdminSettings()
|
||||
const auto = res?.enable_automation
|
||||
message.success(
|
||||
auto != null && auto !== ''
|
||||
? `همگام شد (${res?.count ?? 0} کلید) — اتوماسیون: ${isSwitchOn(auto) ? 'روشن' : 'خاموش'}`
|
||||
: (res?.message || `همگام شد (${res?.count ?? 0} کلید)`)
|
||||
)
|
||||
await initConfig()
|
||||
refreshMenuAfterStoreChange()
|
||||
} catch (e: any) {
|
||||
console.error(e)
|
||||
const msg = e?.response?.data?.message || e?.message || 'همگامسازی از سوپرادمین ناموفق بود'
|
||||
message.error(Array.isArray(msg) ? msg.join('، ') : msg)
|
||||
} finally {
|
||||
refreshingSuperAdmin.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function initConfig() {
|
||||
try {
|
||||
loading.value = true
|
||||
|
||||
Reference in New Issue
Block a user