11<template >
2- <div v-if =" mode" >{{ computedValue }}</div >
2+ <div v-if =" mode" :style =" customCss" >
3+ <span class =" prefix" >{{ prefix }}</span >
4+ <span class =" computed-value" >{{ computedValue }}</span >
5+ <span class =" suffix" >{{ suffix }}</span >
6+ </div >
37 <v-input v-else v-model =" value" />
8+ <v-notice v-if =" errorMsg" type =" danger" >{{ errorMsg }}</v-notice >
49</template >
510
611<script lang="ts">
@@ -18,6 +23,10 @@ export default defineComponent({
1823 type: String ,
1924 default: null ,
2025 },
26+ type: {
27+ type: String ,
28+ default: null ,
29+ },
2130 collection: {
2231 type: String ,
2332 default: ' ' ,
@@ -34,10 +43,22 @@ export default defineComponent({
3443 type: String ,
3544 default: null ,
3645 },
46+ prefix: {
47+ type: String ,
48+ default: null ,
49+ },
50+ suffix: {
51+ type: String ,
52+ default: null ,
53+ },
54+ customCss: {
55+ type: Object ,
56+ default: null ,
57+ },
3758 },
3859 emits: [' input' ],
3960 setup(props , { emit }) {
40- const computedValue = ref (props .value );
61+ const computedValue = ref < string | number | null > (props .value );
4162 const relations = useCollectionRelations (props .collection );
4263 const values = useDeepValues (
4364 inject <ComputedRef <Record <string , any >>>(' values' )! ,
@@ -47,6 +68,7 @@ export default defineComponent({
4768 props .primaryKey ,
4869 props .template
4970 );
71+ const errorMsg = ref <string | null >(null );
5072
5173 if (values ) {
5274 watch (values , () => {
@@ -64,13 +86,26 @@ export default defineComponent({
6486
6587 return {
6688 computedValue ,
89+ errorMsg ,
6790 };
6891
6992 function compute() {
70- return props .template .replace (/ {{. *? }}/ g , (match ) => {
71- const expression = match .slice (2 , - 2 ).trim ();
72- return parseExpression (expression , values .value );
73- });
93+ try {
94+ const res = props .template .replace (/ {{. *? }}/ g , (match ) => {
95+ const expression = match .slice (2 , - 2 ).trim ();
96+ return parseExpression (expression , values .value );
97+ });
98+ if ([' integer' , ' decimal' , ' bigInteger' ].includes (props .type )) {
99+ return parseInt (res ) || 0 ;
100+ }
101+ if ([' float' ].includes (props .type )) {
102+ return parseFloat (res ) || 0 ;
103+ }
104+ return res ;
105+ } catch (err ) {
106+ errorMsg .value = err .message ?? ' Unknown error' ;
107+ return null ;
108+ }
74109 }
75110 },
76111});
0 commit comments