fix bug
This commit is contained in:
@@ -0,0 +1,176 @@
|
|||||||
|
<template>
|
||||||
|
<div class="support-messenger">
|
||||||
|
<div class="settings-section-title">پشتیبانی پیامرسان</div>
|
||||||
|
<div class="support-messenger__card">
|
||||||
|
<div v-if="messengerRow" class="support-messenger__block">
|
||||||
|
<div class="support-messenger__label">پیامرسان</div>
|
||||||
|
<a-radio-group
|
||||||
|
:value="messengerValue || 'bale'"
|
||||||
|
button-style="solid"
|
||||||
|
class="support-messenger__radios"
|
||||||
|
@update:value="onMessengerChange"
|
||||||
|
>
|
||||||
|
<a-radio-button
|
||||||
|
v-for="opt in SUPPORT_MESSENGER_OPTIONS"
|
||||||
|
:key="opt.key"
|
||||||
|
:value="opt.key"
|
||||||
|
>
|
||||||
|
{{ opt.label }}
|
||||||
|
</a-radio-button>
|
||||||
|
</a-radio-group>
|
||||||
|
<div v-if="isSaving(messengerRow.id)" class="support-messenger__status">در حال ذخیره...</div>
|
||||||
|
<div
|
||||||
|
v-else-if="isSavedFlash(messengerRow.id)"
|
||||||
|
class="support-messenger__status support-messenger__status--ok"
|
||||||
|
>
|
||||||
|
ذخیره شد
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="idRow" class="support-messenger__block">
|
||||||
|
<div class="support-messenger__label">شناسه / یوزرنیم</div>
|
||||||
|
<a-input
|
||||||
|
:value="draftValue(idRow)"
|
||||||
|
allow-clear
|
||||||
|
:placeholder="idPlaceholder"
|
||||||
|
@update:value="onFieldChange(idRow, $event)"
|
||||||
|
/>
|
||||||
|
<div class="support-messenger__hint">{{ idHelp }}</div>
|
||||||
|
<div v-if="isSaving(idRow.id)" class="support-messenger__status">در حال ذخیره...</div>
|
||||||
|
<div v-else-if="isSavedFlash(idRow.id)" class="support-messenger__status support-messenger__status--ok">
|
||||||
|
ذخیره شد
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="textRow" class="support-messenger__block">
|
||||||
|
<div class="support-messenger__label">متن دکمه</div>
|
||||||
|
<a-input
|
||||||
|
:value="draftValue(textRow)"
|
||||||
|
allow-clear
|
||||||
|
placeholder="مثلاً پشتیبانی"
|
||||||
|
@update:value="onFieldChange(textRow, $event)"
|
||||||
|
/>
|
||||||
|
<div v-if="isSaving(textRow.id)" class="support-messenger__status">در حال ذخیره...</div>
|
||||||
|
<div v-else-if="isSavedFlash(textRow.id)" class="support-messenger__status support-messenger__status--ok">
|
||||||
|
ذخیره شد
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { Const } from '@/model/configuration'
|
||||||
|
import {
|
||||||
|
SUPPORT_MESSENGER_OPTIONS,
|
||||||
|
supportMessengerIdPlaceholder
|
||||||
|
} from './settingTypes'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
messengerRow?: Const
|
||||||
|
idRow?: Const
|
||||||
|
textRow?: Const
|
||||||
|
draftValue: (row: Const) => string
|
||||||
|
isSaving: (id?: number) => boolean
|
||||||
|
isSavedFlash: (id?: number) => boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:value': [row: Const, value: string]
|
||||||
|
'update:isActive': [row: Const, value: boolean]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const messengerValue = computed(() =>
|
||||||
|
props.messengerRow ? props.draftValue(props.messengerRow) : 'bale'
|
||||||
|
)
|
||||||
|
|
||||||
|
const idPlaceholder = computed(() => supportMessengerIdPlaceholder(messengerValue.value))
|
||||||
|
|
||||||
|
const idHelp = computed(() => {
|
||||||
|
switch ((messengerValue.value || '').trim().toLowerCase()) {
|
||||||
|
case 'telegram':
|
||||||
|
return 'لینک: https://t.me/{username}'
|
||||||
|
case 'whatsapp':
|
||||||
|
return 'لینک: https://wa.me/{شماره}'
|
||||||
|
case 'rubika':
|
||||||
|
return 'لینک: https://rubika.ir/{username}'
|
||||||
|
case 'eitaa':
|
||||||
|
return 'لینک: https://eitaa.com/{username}'
|
||||||
|
case 'soroush':
|
||||||
|
return 'لینک: https://splus.ir/{username}'
|
||||||
|
case 'bale':
|
||||||
|
default:
|
||||||
|
return 'لینک: https://ble.ir/{username}'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function onMessengerChange(value: string) {
|
||||||
|
if (!props.messengerRow) return
|
||||||
|
emit('update:value', props.messengerRow, value)
|
||||||
|
emit('update:isActive', props.messengerRow, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFieldChange(row: Const, value: string) {
|
||||||
|
emit('update:value', row, value)
|
||||||
|
if (value.trim()) {
|
||||||
|
emit('update:isActive', row, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.support-messenger {
|
||||||
|
margin-top: 28px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
|
||||||
|
&__card {
|
||||||
|
border: 1px solid #e8e8e8;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 16px 18px;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__block + &__block {
|
||||||
|
margin-top: 18px;
|
||||||
|
padding-top: 18px;
|
||||||
|
border-top: 1px solid #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__label {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: rgba(0, 0, 0, 0.88);
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__radios {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 8px;
|
||||||
|
|
||||||
|
:deep(.ant-radio-button-wrapper) {
|
||||||
|
border-radius: 6px !important;
|
||||||
|
margin-inline-end: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&__hint {
|
||||||
|
margin-top: 6px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: rgba(0, 0, 0, 0.45);
|
||||||
|
direction: ltr;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__status {
|
||||||
|
margin-top: 6px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: rgba(0, 0, 0, 0.45);
|
||||||
|
min-height: 16px;
|
||||||
|
|
||||||
|
&--ok {
|
||||||
|
color: #52c41a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -66,6 +66,18 @@
|
|||||||
</a-row>
|
</a-row>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<SupportMessengerSettings
|
||||||
|
v-if="supportMessengerBundle"
|
||||||
|
:messenger-row="supportMessengerBundle.messenger"
|
||||||
|
:id-row="supportMessengerBundle.id"
|
||||||
|
:text-row="supportMessengerBundle.text"
|
||||||
|
:draft-value="draftValue"
|
||||||
|
:is-saving="isSaving"
|
||||||
|
:is-saved-flash="isSavedFlash"
|
||||||
|
@update:value="onValueChange"
|
||||||
|
@update:is-active="onActiveChange"
|
||||||
|
/>
|
||||||
|
|
||||||
<template v-if="otherRows.length">
|
<template v-if="otherRows.length">
|
||||||
<div class="settings-section-title settings-section-title--spaced">سایر تنظیمات</div>
|
<div class="settings-section-title settings-section-title--spaced">سایر تنظیمات</div>
|
||||||
<a-row :gutter="[16, 16]" class="settings-grid">
|
<a-row :gutter="[16, 16]" class="settings-grid">
|
||||||
@@ -90,7 +102,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<a-empty
|
<a-empty
|
||||||
v-if="!loading && !switchRows.length && !otherRows.length"
|
v-if="!loading && !switchRows.length && !supportMessengerBundle && !otherRows.length"
|
||||||
description="تنظیمی یافت نشد"
|
description="تنظیمی یافت نشد"
|
||||||
class="mt-8"
|
class="mt-8"
|
||||||
/>
|
/>
|
||||||
@@ -171,13 +183,17 @@ import { loading } from '@/utils'
|
|||||||
import { getConfiguration, setConfiguration } from '@/api/configuration'
|
import { getConfiguration, setConfiguration } from '@/api/configuration'
|
||||||
import SettingValueField from './SettingValueField.vue'
|
import SettingValueField from './SettingValueField.vue'
|
||||||
import SettingCard from './SettingCard.vue'
|
import SettingCard from './SettingCard.vue'
|
||||||
|
import SupportMessengerSettings from './SupportMessengerSettings.vue'
|
||||||
import {
|
import {
|
||||||
SETTING_TYPE_OPTIONS,
|
SETTING_TYPE_OPTIONS,
|
||||||
formatValueForSave,
|
formatValueForSave,
|
||||||
helpText,
|
helpText,
|
||||||
resolveSettingFieldType
|
resolveSettingFieldType,
|
||||||
|
SUPPORT_MESSENGER_KEYS
|
||||||
} from './settingTypes'
|
} from './settingTypes'
|
||||||
|
|
||||||
|
const supportMessengerKeySet = new Set<string>(SUPPORT_MESSENGER_KEYS)
|
||||||
|
|
||||||
const settingTypeOptions = SETTING_TYPE_OPTIONS
|
const settingTypeOptions = SETTING_TYPE_OPTIONS
|
||||||
|
|
||||||
const statusFilterOptions = [
|
const statusFilterOptions = [
|
||||||
@@ -270,9 +286,24 @@ const switchRows = computed(() =>
|
|||||||
)
|
)
|
||||||
|
|
||||||
const otherRows = computed(() =>
|
const otherRows = computed(() =>
|
||||||
filteredRows.value.filter((row) => resolveSettingFieldType(row) !== 'switch')
|
filteredRows.value.filter(
|
||||||
|
(row) =>
|
||||||
|
resolveSettingFieldType(row) !== 'switch' &&
|
||||||
|
!supportMessengerKeySet.has(row.key ?? '')
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const supportMessengerBundle = computed(() => {
|
||||||
|
const rows = filteredRows.value.filter((row) => supportMessengerKeySet.has(row.key ?? ''))
|
||||||
|
if (!rows.length) return null
|
||||||
|
const byKey = Object.fromEntries(rows.map((row) => [row.key, row]))
|
||||||
|
return {
|
||||||
|
messenger: byKey.support_messenger as Const | undefined,
|
||||||
|
id: byKey.support_messenger_id as Const | undefined,
|
||||||
|
text: byKey.support_messenger_text as Const | undefined
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
function rowColSpan(row: Const): number {
|
function rowColSpan(row: Const): number {
|
||||||
return resolveSettingFieldType(row) === 'longtext' ? 24 : 8
|
return resolveSettingFieldType(row) === 'longtext' ? 24 : 8
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ const KEY_TYPE_FALLBACK: Record<string, SettingFieldType> = {
|
|||||||
montzar_closed: 'switch',
|
montzar_closed: 'switch',
|
||||||
montzar_open_buy: 'switch',
|
montzar_open_buy: 'switch',
|
||||||
montzar_open_sell: 'switch',
|
montzar_open_sell: 'switch',
|
||||||
is_requaire_referral: 'switch',
|
|
||||||
product_update_price_on_list: 'switch',
|
product_update_price_on_list: 'switch',
|
||||||
product_auto_close_open_on_list: 'switch',
|
product_auto_close_open_on_list: 'switch',
|
||||||
payping_fin_sync_enabled: 'switch',
|
payping_fin_sync_enabled: 'switch',
|
||||||
@@ -77,7 +76,21 @@ const KEY_TYPE_FALLBACK: Record<string, SettingFieldType> = {
|
|||||||
store_status: 'select',
|
store_status: 'select',
|
||||||
credit_rial_price_unit: 'select',
|
credit_rial_price_unit: 'select',
|
||||||
node_client_id: 'text',
|
node_client_id: 'text',
|
||||||
node_shared_secret: 'text'
|
node_shared_secret: 'text',
|
||||||
|
support_messenger_id: 'text',
|
||||||
|
support_messenger_text: 'text',
|
||||||
|
support_messenger: 'select'
|
||||||
|
}
|
||||||
|
|
||||||
|
const SELECT_LABELS_BY_KEY: Record<string, Record<string, string>> = {
|
||||||
|
support_messenger: {
|
||||||
|
bale: 'بله',
|
||||||
|
telegram: 'تلگرام',
|
||||||
|
whatsapp: 'واتساپ',
|
||||||
|
rubika: 'روبیکا',
|
||||||
|
eitaa: 'ایتا',
|
||||||
|
soroush: 'سروش'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const SELECT_OPTIONS_BY_KEY: Record<string, string> = {
|
const SELECT_OPTIONS_BY_KEY: Record<string, string> = {
|
||||||
@@ -85,7 +98,39 @@ const SELECT_OPTIONS_BY_KEY: Record<string, string> = {
|
|||||||
referral_id: 'required,',
|
referral_id: 'required,',
|
||||||
payping_gateway_name: 'sepal,',
|
payping_gateway_name: 'sepal,',
|
||||||
credit_rial_price_unit: 'gram,mesghal,unit',
|
credit_rial_price_unit: 'gram,mesghal,unit',
|
||||||
store_status: 'باز,بسته'
|
store_status: 'باز,بسته',
|
||||||
|
support_messenger: 'bale,telegram,whatsapp,rubika,eitaa,soroush'
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SUPPORT_MESSENGER_KEYS = [
|
||||||
|
'support_messenger',
|
||||||
|
'support_messenger_id',
|
||||||
|
'support_messenger_text'
|
||||||
|
] as const
|
||||||
|
|
||||||
|
export const SUPPORT_MESSENGER_OPTIONS = [
|
||||||
|
{ key: 'bale', label: 'بله' },
|
||||||
|
{ key: 'telegram', label: 'تلگرام' },
|
||||||
|
{ key: 'whatsapp', label: 'واتساپ' },
|
||||||
|
{ key: 'rubika', label: 'روبیکا' },
|
||||||
|
{ key: 'eitaa', label: 'ایتا' },
|
||||||
|
{ key: 'soroush', label: 'سروش' }
|
||||||
|
] as const
|
||||||
|
|
||||||
|
export function supportMessengerIdPlaceholder(messenger: string): string {
|
||||||
|
switch ((messenger || '').trim().toLowerCase()) {
|
||||||
|
case 'telegram':
|
||||||
|
return 'username بدون @'
|
||||||
|
case 'whatsapp':
|
||||||
|
return '98912xxxxxxx'
|
||||||
|
case 'rubika':
|
||||||
|
case 'eitaa':
|
||||||
|
case 'soroush':
|
||||||
|
return 'username'
|
||||||
|
case 'bale':
|
||||||
|
default:
|
||||||
|
return 'username در ble.ir'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveSettingFieldType(row: Pick<Const, 'key' | 'type'>): SettingFieldType {
|
export function resolveSettingFieldType(row: Pick<Const, 'key' | 'type'>): SettingFieldType {
|
||||||
@@ -111,9 +156,10 @@ export function parseSelectOptions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const opts = source.split(',').map((s) => s.trim())
|
const opts = source.split(',').map((s) => s.trim())
|
||||||
|
const labels = row.key ? SELECT_LABELS_BY_KEY[row.key] : undefined
|
||||||
return opts.map((opt) => ({
|
return opts.map((opt) => ({
|
||||||
key: opt,
|
key: opt,
|
||||||
value: opt === '' ? '(خالی)' : opt
|
value: labels?.[opt] ?? (opt === '' ? '(خالی)' : opt)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user