dynamic support text & link
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -316,11 +316,16 @@
|
||||
<div v-else class="text-center">
|
||||
<div class=" font-bold text-red-600">مشتریان گرامی</div>
|
||||
<div class="mt-2">
|
||||
<span>جهت شارژ حساب کاربری خود، کلمه "شماره حساب" را برای پشتیبانی ارسال نمایید.</span>
|
||||
<span>{{ supportMessengerText }}</span>
|
||||
</div>
|
||||
|
||||
<BasicButton>
|
||||
<a class="w-full" href="">
|
||||
<BasicButton v-if="supportMessengerLink">
|
||||
<a
|
||||
class="w-full"
|
||||
:href="supportMessengerLink"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
پیام به پشتیبانی
|
||||
</a>
|
||||
</BasicButton>
|
||||
@@ -386,6 +391,12 @@ import BaseDatePicker from '@/components/BasicPacks/BaseDatePicker'
|
||||
import img from '@/assets/img/user_ly1.svg'
|
||||
import BasicModal from '@/components/BasicPacks/BasicModal.vue'
|
||||
import { useConfigStore } from '@/store/configStore'
|
||||
import {
|
||||
buildSupportMessengerUrl,
|
||||
DEFAULT_SUPPORT_MESSENGER_TEXT,
|
||||
loadSupportMessengerFromSettings,
|
||||
supportMessengerSettings,
|
||||
} from '@/utils/supportMessenger'
|
||||
|
||||
const isDeposit = ref<boolean>(true)
|
||||
const walletStore = useWalletStore()
|
||||
@@ -397,12 +408,25 @@ const refOtpInput = ref<InstanceType<typeof VOtpInput> | null>(null)
|
||||
const withdrawInfModal = ref<boolean>(false)
|
||||
|
||||
const config = useConfigStore()
|
||||
|
||||
const supportMessengerText = computed(() =>
|
||||
supportMessengerSettings.value.messengerText || DEFAULT_SUPPORT_MESSENGER_TEXT
|
||||
)
|
||||
|
||||
const supportMessengerLink = computed(() =>
|
||||
buildSupportMessengerUrl(
|
||||
supportMessengerSettings.value.messenger,
|
||||
supportMessengerSettings.value.messengerId
|
||||
)
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
if (router.currentRoute.value.query.state === 'deposit') {
|
||||
isDeposit.value = true
|
||||
}
|
||||
walletStore.getMyWallet()
|
||||
isDeposit.value = true
|
||||
loadSupportMessengerFromSettings()
|
||||
})
|
||||
|
||||
const form = ref<Transaction>({
|
||||
|
||||
Reference in New Issue
Block a user