perf: useOpenURL SaySimple
gitea/salix-front/pipeline/pr-master This commit looks good Details

This commit is contained in:
Javier Segarra 2024-12-01 19:57:15 +01:00
parent e2304396d8
commit 137798c959
1 changed files with 17 additions and 11 deletions

View File

@ -2,6 +2,7 @@
import { reactive, useAttrs, onBeforeMount, capitalize } from 'vue';
import axios from 'axios';
import { parsePhone } from 'src/filters';
import useOpenURL from 'src/composables/useOpenURL';
const props = defineProps({
phoneNumber: { type: [String, Number], default: null },
channel: { type: Number, default: null },
@ -11,25 +12,31 @@ const config = reactive({
sip: { icon: 'phone', href: `sip:${props.phoneNumber}` },
'say-simple': {
icon: 'vn:saysimple',
href: null,
channel: props.channel,
url: null,
},
});
const type = Object.keys(config).find((key) => key in useAttrs()) || 'sip';
onBeforeMount(async () => {
let { channel } = config[type];
let { channel, url } = config[type];
if (type === 'say-simple') {
const { url, defaultChannel } = (await axios.get('SaySimpleConfigs/findOne'))
.data;
if (!channel) channel = defaultChannel;
config[type].href = `${url}?customerIdentity=%2B${parsePhone(
props.phoneNumber
)}&channelId=${channel}`;
const { url: defaultUrl, defaultChannel } = (
await axios.get('SaySimpleConfigs/findOne')
).data;
if (!channel) config[type].channel = defaultChannel;
if (!url) config[type].url = defaultUrl;
}
});
function openSaySimple() {
useOpenURL(
`${config[type].url}?customerIdentity=%2B${parsePhone(
props.phoneNumber
)}&channelId=${config[type].channel}`
);
}
</script>
<template>
<QBtn
@ -40,8 +47,7 @@ onBeforeMount(async () => {
size="sm"
color="primary"
padding="none"
:href="config[type].href"
@click.stop
@click.stop="openSaySimple"
>
<QTooltip>
{{ capitalize(type).replace('-', '') }}