Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nova funcionalidade: cotação/conversão de moedas. #129

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 20.0.0
47 changes: 47 additions & 0 deletions components/CurrencyInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<template>
<v-card elevation="2" v-if="store.conversion && store.conversion.rates">
<v-card-title class="text-h6">Conversão entre Moedas</v-card-title>
<v-card-text>
<v-form @submit.prevent>
<CurrencyAmountInput />
<div class="currency-container">
<CurrencyTypeInput />
</div>
<div>{{ store.amount }} {{ store.origin.title }} é igual a</div>
<div class="text-h5">
{{ store.conversionRate }} {{ store.target.title }}
</div>
<div>
{{ new Date(store.conversion.date).toLocaleDateString("pt-BR") }}
</div>
</v-form>
</v-card-text>
</v-card>
</template>

<script setup lang="ts">
import { useCurrencyStore } from "~/store/currencies";
const store = useCurrencyStore();
let debounce = false;
watch(
() => [store.amount, store.origin, store.target],
() => {
//"debouncing"
if (debounce) return;
debounce = true;
setTimeout(() => {
store.fetchConversion();
store.fetchHistoricalData();
debounce = false;
}, 500);
}
);
</script>

<style scoped>
.currency-container {
display: flex;
flex-direction: row;
align-items: center;
}
</style>
5 changes: 4 additions & 1 deletion components/NavigationBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
<v-btn icon to="/">
<v-icon>mdi-calculator</v-icon>
</v-btn>
<v-btn icon to="/currency">
<v-icon>mdi-currency-usd</v-icon>
</v-btn>
<v-btn icon to="/sobre">
<v-icon>mdi-information-variant</v-icon>
</v-btn>
</span>
</template>
</template>
23 changes: 23 additions & 0 deletions components/currency/currencyAmountInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<v-text-field
v-model.number="store.amount"
type="number"
variant="underlined"
label="Valor"
prepend-icon="mdi-cash-multiple"
min="0"
:rules="[rules.required, rules.positive]"
>
</v-text-field>
</template>

<script setup lang="ts">
import { useCurrencyStore } from "~/store/currencies";
const store = useCurrencyStore();

const rules = {
required: (value: any) => !!value || "Obrigatório",
positive: (value: any) =>
parseInt(value) > 0 || "Deve ser um número positivo",
};
</script>
74 changes: 74 additions & 0 deletions components/currency/currencyTimeSeriesChart.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<template>
<div>
<v-chart class="chart" :option="option" autoresize />
</div>
</template>

<script setup lang="ts">
import { useCurrencyStore } from "~/store/currencies";
const store = useCurrencyStore();
import { use } from "echarts/core";
import { LineChart } from "echarts/charts";
import {
TitleComponent,
TooltipComponent,
GridComponent,
} from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
import VChart from "vue-echarts";

use([
TitleComponent,
TooltipComponent,
GridComponent,
LineChart,
CanvasRenderer,
]);

const option = ref({});

function render() {
option.value = {
tooltip: {
trigger: "axis",
axisPointer: {
animation: false,
},
},
xAxis: {
type: "time",
splitLine: {
show: false,
},
},
yAxis: {
type: "value",
boundaryGap: [0, "100%"],
splitLine: {
show: true,
},
},
series: [
{
name: store.target.title,
type: "line",
showSymbol: true,
data: store.currencySeries,
},
],
};
}

watch(
() => [store.currencySeries],
() => {
render();
}
);
</script>

<style scoped>
.chart {
height: 75vh;
}
</style>
49 changes: 49 additions & 0 deletions components/currency/currencyTypeInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<v-container>
<v-row align="center" justify="center" class="switch-btn">
<v-col cols="auto">
<v-btn
density="compact"
icon="mdi-arrow-left-right"
@click="store.flipCurrencies()"
></v-btn>
</v-col>
</v-row>
<v-row align="center" justify="center">
<v-select
v-model="store.origin"
:items="store.currencies"
@update:modelValue="currencyOriginChange"
item-title="title"
item-value="value"
label="Origin Currency"
return-object
></v-select>
<v-select
v-model="store.target"
:items="currenciesWOOrigin"
item-title="title"
item-value="value"
label="Target Currency"
return-object
></v-select>
</v-row>
</v-container>
</template>

<script setup lang="ts">
import { useCurrencyStore } from "~/store/currencies";
const store = useCurrencyStore();
const currenciesWOOrigin = ref();
const currencyOriginChange = () => {
currenciesWOOrigin.value = store.currencies.filter((o) => o != store.origin);
store.target =
store.origin === store.target ? currenciesWOOrigin.value[0] : store.target;
};
currencyOriginChange();
</script>
<style scoped>
.switch-btn {
margin-top: -2em;
}
</style>
166 changes: 84 additions & 82 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,91 @@
// https://nuxt.com/docs/api/configuration/nuxt-config

export default defineNuxtConfig({
app: {
head: {
titleTemplate: '%s | Renda Fixa',
htmlAttrs: {
lang: 'pt'
},
title: 'Calculadora',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{
hid: 'apple-mobile-web-app-title',
name: 'apple-mobile-web-app-title',
content: 'Renda Fixa'
},
{
hid: 'og:title',
name: 'og:title',
content: 'Calculadora Renda Fixa'
},
{
hid: 'og:site_name',
name: 'og:site_name',
content: 'Calculadora Renda Fixa'
},
{ name: 'format-detection', content: 'telephone=no' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
{
rel: 'apple-touch-icon',
sizes: '180x180',
href: '/apple-touch-icon.png'
},
{
rel: 'icon',
type: 'image/png',
sizes: '32x32',
href: '/favicon-32x32.png'
},
{
rel: 'icon',
type: 'image/png',
sizes: '16x16',
href: '/favicon-16x16.png'
},
{ rel: 'manifest', href: '/site.webmanifest' }
]
app: {
head: {
titleTemplate: "%s | Renda Fixa",
htmlAttrs: {
lang: "pt",
},
title: "Calculadora",
meta: [
{ charset: "utf-8" },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
{
hid: "apple-mobile-web-app-title",
name: "apple-mobile-web-app-title",
content: "Renda Fixa",
},
{
hid: "og:title",
name: "og:title",
content: "Calculadora Renda Fixa",
},
{
hid: "og:site_name",
name: "og:site_name",
content: "Calculadora Renda Fixa",
},
{ name: "format-detection", content: "telephone=no" },
],
link: [
{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" },
{
rel: "apple-touch-icon",
sizes: "180x180",
href: "/apple-touch-icon.png",
},
{
rel: "icon",
type: "image/png",
sizes: "32x32",
href: "/favicon-32x32.png",
},
pageTransition: { name: 'page', mode: 'out-in' }
{
rel: "icon",
type: "image/png",
sizes: "16x16",
href: "/favicon-16x16.png",
},
{ rel: "manifest", href: "/site.webmanifest" },
],
},
modules: [
'@invictus.codes/nuxt-vuetify',
'@pinia/nuxt',
'@pinia-plugin-persistedstate/nuxt'
],
extends: [
'nuxt-seo-kit'
],
runtimeConfig: {
public: {
siteUrl: process.env.NUXT_PUBLIC_SITE_URL || 'https://rendafixa.github.io',
siteName: 'Calculadora Renda Fixa',
siteDescription: 'Calculadora de investimentos Renda Fixa para simulação de ' +
'rentabilidade em CDB, RDB, LC, LCI, LCA, Poupança e Tesouro Direto',
language: 'pt'
}
},
devtools: { enabled: true },
piniaPersistedstate: {
storage: 'localStorage'
pageTransition: { name: "page", mode: "out-in" },
},
modules: [
"@invictus.codes/nuxt-vuetify",
"@pinia/nuxt",
"@pinia-plugin-persistedstate/nuxt",
],
extends: ["nuxt-seo-kit"],
runtimeConfig: {
public: {
siteUrl:
process.env.NUXT_PUBLIC_SITE_URL || "https://rendafixa.github.io",
siteName: "Calculadora Renda Fixa",
siteDescription:
"Calculadora de investimentos Renda Fixa para simulação de " +
"rentabilidade em CDB, RDB, LC, LCI, LCA, Poupança e Tesouro Direto",
language: "pt",
},
vuetify: {
vuetifyOptions: {
},
moduleOptions: {
treeshaking: true,
useIconCDN: true,
},
devtools: { enabled: true },
build: {
transpile: [/echarts/, /zrender/, , /resize-detector/],
},
piniaPersistedstate: {
storage: "localStorage",
},
vuetify: {
vuetifyOptions: {},
moduleOptions: {
treeshaking: true,
useIconCDN: true,

/* vite-plugin-vuetify options */
styles: true,
autoImport: true,
useVuetifyLabs: false
}
}
})
/* vite-plugin-vuetify options */
styles: true,
autoImport: true,
useVuetifyLabs: false,
},
},
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"vitest": "^0.34.3"
},
"dependencies": {
"@pinia/nuxt": "^0.5.1"
"@pinia/nuxt": "^0.5.1",
"echarts": "^5.4.3",
"vue-echarts": "^6.6.8"
}
}
Loading