dynamic support text & link

This commit is contained in:
2026-06-06 17:28:48 +03:30
parent 198f0a164b
commit 949ae212c3
2 changed files with 100 additions and 3 deletions
+73
View File
@@ -0,0 +1,73 @@
import { ref } from 'vue'
import { getSettings } from '@/api/configuration'
export type SupportMessengerType =
| 'bale'
| 'telegram'
| 'whatsapp'
| 'rubika'
| 'eitaa'
| 'soroush'
export interface SupportMessengerSettings {
messenger?: SupportMessengerType | string
messengerId?: string
messengerText?: string
}
export const supportMessengerSettings = ref<SupportMessengerSettings>({})
export const DEFAULT_SUPPORT_MESSENGER_TEXT =
'جهت شارژ حساب کاربری خود، کلمه "شماره حساب" را برای پشتیبانی ارسال نمایید.'
function getActiveSettingValue(settings: Array<{ key?: string; is_active?: boolean; value?: unknown }>, key: string) {
const setting = settings.find((item) => item?.key === key && item?.is_active === true)
const value = setting?.value
if (value === undefined || value === null) return ''
return String(value).trim()
}
export function buildSupportMessengerUrl(messenger?: string, messengerId?: string) {
const id = (messengerId ?? '').trim()
if (!id) return ''
if (/^https?:\/\//i.test(id)) return id
const type = (messenger ?? '').trim().toLowerCase()
const username = id.replace(/^@/, '')
switch (type) {
case 'bale':
if (id.includes('ble.ir')) {
return id.startsWith('http') ? id : `https://${id.replace(/^\/\//, '')}`
}
return `https://ble.ir/${username}`
case 'telegram':
return `https://t.me/${username}`
case 'whatsapp':
return `https://wa.me/${username.replace(/\D/g, '')}`
case 'rubika':
return `https://rubika.ir/${username}`
case 'eitaa':
return `https://eitaa.com/${username}`
case 'soroush':
return `https://splus.ir/splus/${username}`
default:
return ''
}
}
export async function loadSupportMessengerFromSettings() {
try {
const settings = await getSettings()
if (!settings || !Array.isArray(settings)) return
supportMessengerSettings.value = {
messenger: getActiveSettingValue(settings, 'support_messenger'),
messengerId: getActiveSettingValue(settings, 'support_messenger_id'),
messengerText: getActiveSettingValue(settings, 'support_messenger_text'),
}
} catch (e) {
console.log(e)
}
}