Merge pull request 'refs #6339 clipboard' (!159) from 6339-cilpboard into dev
gitea/salix-front/pipeline/head This commit looks good Details

Reviewed-on: #159
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Carlos Satorres 2024-01-29 14:09:02 +00:00
commit fac4e0f9ca
9 changed files with 70 additions and 25 deletions

View File

@ -1,19 +1,19 @@
<script setup> <script setup>
import { onMounted, computed } from 'vue'; import { onMounted, computed } from 'vue';
import { Dark, Quasar, useQuasar } from 'quasar'; import { Dark, Quasar } from 'quasar';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import axios from 'axios'; import axios from 'axios';
import { useState } from 'src/composables/useState'; import { useState } from 'src/composables/useState';
import { useSession } from 'src/composables/useSession'; import { useSession } from 'src/composables/useSession';
import { localeEquivalence } from "src/i18n/index"; import { localeEquivalence } from 'src/i18n/index';
const state = useState(); const state = useState();
const session = useSession(); const session = useSession();
const router = useRouter(); const router = useRouter();
const { t, locale } = useI18n(); const { t, locale } = useI18n();
const quasar = useQuasar(); import { useClipboard } from 'src/composables/useClipboard';
const { copyText } = useClipboard();
const userLocale = computed({ const userLocale = computed({
get() { get() {
return locale.value; return locale.value;
@ -21,7 +21,7 @@ const userLocale = computed({
set(value) { set(value) {
locale.value = value; locale.value = value;
value = localeEquivalence[value] ?? value value = localeEquivalence[value] ?? value;
try { try {
/* @vite-ignore */ /* @vite-ignore */
@ -82,11 +82,7 @@ function logout() {
} }
function copyUserToken() { function copyUserToken() {
navigator.clipboard.writeText(session.getToken()); copyText(session.getToken(), { label: 'components.userPanel.copyToken' });
quasar.notify({
type: 'positive',
message: t('components.userPanel.copyToken'),
});
} }
</script> </script>
@ -129,7 +125,11 @@ function copyUserToken(){
<div class="text-subtitle1 q-mt-md"> <div class="text-subtitle1 q-mt-md">
<strong>{{ user.nickname }}</strong> <strong>{{ user.nickname }}</strong>
</div> </div>
<div class="text-subtitle3 text-grey-7 q-mb-xs copyUserToken" @click="copyUserToken()" >@{{ user.name }} <div
class="text-subtitle3 text-grey-7 q-mb-xs copyText"
@click="copyUserToken()"
>
@{{ user.name }}
</div> </div>
<QBtn <QBtn
@ -152,7 +152,7 @@ function copyUserToken(){
width: 150px; width: 150px;
} }
.copyUserToken { .copyText {
&:hover { &:hover {
cursor: alias; cursor: alias;
} }

View File

@ -2,6 +2,7 @@
import { computed } from 'vue'; import { computed } from 'vue';
import { dashIfEmpty } from 'src/filters'; import { dashIfEmpty } from 'src/filters';
import { useClipboard } from 'src/composables/useClipboard';
const $props = defineProps({ const $props = defineProps({
label: { type: String, default: null }, label: { type: String, default: null },
value: { value: {
@ -10,8 +11,19 @@ const $props = defineProps({
}, },
info: { type: String, default: null }, info: { type: String, default: null },
dash: { type: Boolean, default: true }, dash: { type: Boolean, default: true },
copy: { type: Boolean, default: false },
}); });
const isBooleanValue = computed(() => typeof $props.value === 'boolean'); const isBooleanValue = computed(() => typeof $props.value === 'boolean');
const { copyText } = useClipboard();
function copyValueText() {
copyText($props.value, {
component: {
copyValue: $props.value,
},
});
}
</script> </script>
<style scoped> <style scoped>
.label, .label,
@ -48,5 +60,16 @@ const isBooleanValue = computed(() => typeof $props.value === 'boolean');
</QTooltip> </QTooltip>
</QIcon> </QIcon>
</div> </div>
<div class="copy" v-if="$props.copy && $props.value" @click="copyValueText()">
<QIcon name="Content_Copy" color="primary" />
</div>
</div> </div>
</template> </template>
<style lang="scss" scoped>
.copy {
&:hover {
cursor: pointer;
}
}
</style>

View File

@ -0,0 +1,17 @@
import { useQuasar } from 'quasar';
import { useI18n } from 'vue-i18n';
export function useClipboard() {
const quasar = useQuasar();
const { t } = useI18n();
/**
*
* @param {String} value Value to send to clipboardAPI
* @param {Object} {label, component} Refer to Quasar notify configuration. Label is the text to translate
*/
function copyText(value, { label = 'components.VnLv.copyText', component = {} }) {
navigator.clipboard.writeText(value);
quasar.notify({ type: 'positive', message: t(label, component) });
}
return { copyText };
}

View File

@ -1060,6 +1060,7 @@ export default {
totalEntries: 'Total entries', totalEntries: 'Total entries',
}, },
}, },
components: { components: {
topbar: {}, topbar: {},
userPanel: { userPanel: {
@ -1083,5 +1084,8 @@ export default {
addToPinned: 'Add to pinned', addToPinned: 'Add to pinned',
removeFromPinned: 'Remove from pinned', removeFromPinned: 'Remove from pinned',
}, },
VnLv: {
copyText: '{copyValue} has been copied to the clipboard',
},
}, },
}; };

View File

@ -1083,5 +1083,8 @@ export default {
addToPinned: 'Añadir a fijados', addToPinned: 'Añadir a fijados',
removeFromPinned: 'Eliminar de fijados', removeFromPinned: 'Eliminar de fijados',
}, },
VnLv: {
copyText: '{copyValue} se ha copiado al portapepeles',
},
}, },
}; };

View File

@ -81,7 +81,7 @@ const creditWarning = computed(() => {
<VnLinkPhone :phone-number="entity.mobile" /> <VnLinkPhone :phone-number="entity.mobile" />
</template> </template>
</VnLv> </VnLv>
<VnLv :label="t('customer.summary.email')" :value="entity.email" /> <VnLv :label="t('customer.summary.email')" :value="entity.email" copy />
<VnLv <VnLv
:label="t('customer.summary.salesPerson')" :label="t('customer.summary.salesPerson')"
:value="entity?.salesPersonUser?.name" :value="entity?.salesPersonUser?.name"

View File

@ -90,17 +90,15 @@ const removeDepartment = () => {
</QItem> </QItem>
</template> </template>
<template #body="{ entity }"> <template #body="{ entity }">
<VnLv :label="t('department.chat')" :value="entity.chatName" dash /> <VnLv :label="t('department.chat')" :value="entity.chatName" />
<VnLv :label="t('department.email')" :value="entity.notificationEmail" dash /> <VnLv :label="t('department.email')" :value="entity.notificationEmail" copy />
<VnLv <VnLv
:label="t('department.selfConsumptionCustomer')" :label="t('department.selfConsumptionCustomer')"
:value="entity.client?.name" :value="entity.client?.name"
dash
/> />
<VnLv <VnLv
:label="t('department.bossDepartment')" :label="t('department.bossDepartment')"
:value="entity.worker?.user?.name" :value="entity.worker?.user?.name"
dash
/> />
</template> </template>
<template #actions> <template #actions>

View File

@ -101,7 +101,7 @@ const setData = (entity) => {
</template> </template>
<template #body="{ entity }"> <template #body="{ entity }">
<VnLv :label="t('worker.card.name')" :value="entity.user?.nickname" /> <VnLv :label="t('worker.card.name')" :value="entity.user?.nickname" />
<VnLv :label="t('worker.card.email')" :value="entity.user?.email"> </VnLv> <VnLv :label="t('worker.card.email')" :value="entity.user?.email" copy />
<VnLv <VnLv
:label="t('worker.list.department')" :label="t('worker.list.department')"
:value="entity.department ? entity.department.department.name : null" :value="entity.department ? entity.department.department.name : null"

View File

@ -80,7 +80,7 @@ const filter = {
:label="t('worker.list.department')" :label="t('worker.list.department')"
:value="worker.department.department.name" :value="worker.department.department.name"
/> />
<VnLv :label="t('worker.list.email')" :value="worker.user.email" /> <VnLv :label="t('worker.list.email')" :value="worker.user.email" copy />
<VnLv :label="t('worker.summary.boss')" link> <VnLv :label="t('worker.summary.boss')" link>
<template #value> <template #value>
<VnUserLink <VnUserLink