other components... (2)
This commit is contained in:
@@ -1,164 +1,226 @@
|
||||
import { Component, Prop, Watch } from 'vue-property-decorator'
|
||||
|
||||
import { tools } from '../../store/Modules/tools'
|
||||
import { toolsext } from '@src/store/Modules/toolsext'
|
||||
|
||||
import { QEditor } from 'quasar'
|
||||
import { CMyEditor } from '../CMyEditor'
|
||||
import { defineComponent, PropType, ref, watch } from 'vue'
|
||||
import { useQuasar } from 'quasar'
|
||||
import { useI18n } from '@/boot/i18n'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { useGlobalStore } from '@store/globalStore'
|
||||
import { IColGridTable } from 'model'
|
||||
import { fieldsTable } from '@store/Modules/fieldsTable'
|
||||
import { tools } from '@store/Modules/tools'
|
||||
import { toolsext } from '@store/Modules/toolsext'
|
||||
import { costanti } from '@costanti'
|
||||
import MixinBase from '../../mixins/mixin-base'
|
||||
import { fieldsTable } from '../../store/Modules/fieldsTable'
|
||||
import { IColGridTable } from '../../model'
|
||||
import { CMySelect } from '../CMySelect'
|
||||
import { GlobalStore, UserStore } from '../../store/Modules'
|
||||
import { CMyChipList } from '../CMyChipList'
|
||||
import { CMyToggleList } from '../CMyToggleList'
|
||||
import translate from '@src/globalroutines/util'
|
||||
import { CDateTime } from '../CDateTime'
|
||||
|
||||
@Component({
|
||||
export default defineComponent({
|
||||
name: 'CMyFieldDb',
|
||||
components: { CMyEditor, CMySelect, CMyChipList, CMyToggleList, CDateTime }
|
||||
props: {
|
||||
title: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
mykey: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
mysubkey: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: '',
|
||||
},
|
||||
type: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
serv: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
disable: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
jointable: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: '',
|
||||
},
|
||||
table: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: 'settings',
|
||||
},
|
||||
myimg: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: '',
|
||||
},
|
||||
id: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: '',
|
||||
},
|
||||
idmain: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: '',
|
||||
},
|
||||
},
|
||||
// components: { CMyEditor, CMySelect, CMyChipList, CMyToggleList, CDateTime },
|
||||
setup(props, { emit }) {
|
||||
const $q = useQuasar()
|
||||
const { t } = useI18n()
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
const myvalue = ref('')
|
||||
|
||||
const col: IColGridTable = { name: 'test' }
|
||||
|
||||
const canEdit = ref(true)
|
||||
|
||||
const countryname = ref('')
|
||||
|
||||
const { setValDb, getValDb } = MixinBase()
|
||||
|
||||
function crea() {
|
||||
|
||||
myvalue.value = getValDb(props.mykey, props.serv, '', props.table, props.mysubkey, props.id, props.idmain)
|
||||
col.jointable = props.jointable
|
||||
col.fieldtype = props.type
|
||||
col.label = props.title
|
||||
|
||||
// console.log('CMyFieldDb crea', myvalue)
|
||||
}
|
||||
|
||||
watch(() => props.id, (newval, oldval) => {
|
||||
crea()
|
||||
})
|
||||
|
||||
function getclassCol(col: any) {
|
||||
if (col) {
|
||||
let mycl = (props.disable || col.disable) ? '' : 'colmodif '
|
||||
mycl += ((col.fieldtype === costanti.FieldType.date) || (col.fieldtype === costanti.FieldType.onlydate)) ? ' coldate flex flex-container ' : ''
|
||||
|
||||
return mycl
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
function visuValByType(val: any) {
|
||||
if (col.fieldtype === costanti.FieldType.date) {
|
||||
if (val === undefined) {
|
||||
return '[]'
|
||||
} else {
|
||||
return tools.getstrDateTime(val)
|
||||
}
|
||||
} else if (col.fieldtype === costanti.FieldType.onlydate) {
|
||||
if (val === undefined) {
|
||||
return '[]'
|
||||
} else {
|
||||
return tools.getstrDate(val)
|
||||
}
|
||||
} else if (col.fieldtype === costanti.FieldType.boolean) {
|
||||
return (val) ? t('dialog.yes') : t('dialog.no')
|
||||
} else if (col.fieldtype === costanti.FieldType.binary) {
|
||||
if (val === undefined)
|
||||
return '[---]'
|
||||
else
|
||||
return globalStore.getArrStrByValueBinary(col, val)
|
||||
} else if (col.fieldtype === costanti.FieldType.select) {
|
||||
if (val === undefined)
|
||||
return '[---]'
|
||||
else
|
||||
return globalStore.getValueByTable(col, val)
|
||||
} else if (col.fieldtype === costanti.FieldType.multiselect) {
|
||||
if (val === undefined)
|
||||
return '[---]'
|
||||
else
|
||||
return globalStore.getMultiValueByTable(col, val)
|
||||
} else if (col.fieldtype === costanti.FieldType.multioption) {
|
||||
if (val === undefined)
|
||||
return '[---]'
|
||||
else
|
||||
return globalStore.getMultiValueByTable(col, val)
|
||||
} else if (col.fieldtype === costanti.FieldType.password) {
|
||||
if (val === undefined)
|
||||
return '[---]'
|
||||
else
|
||||
return '***************'
|
||||
} else {
|
||||
if (val === undefined)
|
||||
return ' <span class="text-grey">(' + t('reg.select') + ')</span> '
|
||||
else if (val === '') {
|
||||
return ' <span class="text-grey">(' + t('reg.select') + ')</span> '
|
||||
} else {
|
||||
let mystr = tools.firstchars(val, 5000)
|
||||
if (val) {
|
||||
if (val.length > 5000)
|
||||
mystr += '...'
|
||||
} else {
|
||||
return val
|
||||
}
|
||||
return mystr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mycl() {
|
||||
if (props.disable) {
|
||||
return 'cldisable'
|
||||
}
|
||||
}
|
||||
|
||||
function myvalprinted() {
|
||||
return visuValByType(myvalue)
|
||||
}
|
||||
|
||||
function savefield(value: any, initialval: any) {
|
||||
myvalue.value = value
|
||||
setValDb(props.mykey, myvalue.value, props.type, props.serv, props.table, props.mysubkey, props.id)
|
||||
}
|
||||
|
||||
function savefieldboolean(value: any) {
|
||||
if (myvalue.value === undefined)
|
||||
myvalue.value = 'true'
|
||||
else
|
||||
myvalue.value = value
|
||||
|
||||
setValDb(props.mykey, myvalue, props.type, props.serv, props.table, props.mysubkey, props.id)
|
||||
}
|
||||
|
||||
function selectcountry({ name, iso2, dialCode }: { name: string, iso2: string, dialCode: string }) {
|
||||
// console.log(name, iso2, dialCode)
|
||||
myvalue.value = iso2
|
||||
countryname.value = name
|
||||
}
|
||||
|
||||
function intcode_change(coderec: any) {
|
||||
myvalue.value = '+' + coderec.dialCode
|
||||
}
|
||||
|
||||
function onInput(phone: any, phoneObject: any, input: any) {
|
||||
if (phoneObject?.formatted) {
|
||||
myvalue.value = phoneObject.formatted
|
||||
}
|
||||
}
|
||||
|
||||
crea()
|
||||
|
||||
return {
|
||||
mycl,
|
||||
intcode_change,
|
||||
selectcountry,
|
||||
savefieldboolean,
|
||||
savefield,
|
||||
myvalprinted,
|
||||
getclassCol,
|
||||
canEdit,
|
||||
myvalue,
|
||||
col,
|
||||
countryname,
|
||||
onInput,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export default class CMyFieldDb extends MixinBase {
|
||||
@Prop({ required: true }) public title
|
||||
@Prop({ required: true }) public mykey: string
|
||||
@Prop({ required: false, default: '' }) public mysubkey: string
|
||||
@Prop({ required: true }) public type: number
|
||||
@Prop({ required: false, default: false }) public serv: boolean
|
||||
@Prop({ required: false, default: false }) public disable: boolean
|
||||
@Prop({ required: false, default: '' }) public jointable: string
|
||||
@Prop({ required: false, default: 'settings' }) public table: string
|
||||
@Prop({ required: false, default: '' }) public myimg: string
|
||||
@Prop({ required: false, default: '' }) public id: string
|
||||
@Prop({ required: false, default: '' }) public idmain: string
|
||||
|
||||
public $t
|
||||
public myvalue = ''
|
||||
public col: IColGridTable = { name: 'test' }
|
||||
public canEdit: boolean = true
|
||||
public countryname = ''
|
||||
|
||||
public created() {
|
||||
this.crea()
|
||||
}
|
||||
|
||||
public crea() {
|
||||
|
||||
this.myvalue = this.getValDb(this.mykey, this.serv, '', this.table, this.mysubkey, this.id, this.idmain)
|
||||
this.col.jointable = this.jointable
|
||||
this.col.fieldtype = this.type
|
||||
this.col.label = this.title
|
||||
|
||||
// console.log('CMyFieldDb crea', this.myvalue)
|
||||
}
|
||||
|
||||
@Watch('id')
|
||||
public idchanged(value) {
|
||||
this.crea()
|
||||
}
|
||||
|
||||
public getclassCol(col) {
|
||||
if (col) {
|
||||
let mycl = (this.disable || col.disable) ? '' : 'colmodif '
|
||||
mycl += ((col.fieldtype === tools.FieldType.date) || (col.fieldtype === tools.FieldType.onlydate)) ? ' coldate flex flex-container ' : ''
|
||||
|
||||
return mycl
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
public visuValByType(val) {
|
||||
if (this.col.fieldtype === tools.FieldType.date) {
|
||||
if (val === undefined) {
|
||||
return '[]'
|
||||
} else {
|
||||
return tools.getstrDateTime(val)
|
||||
}
|
||||
} else if (this.col.fieldtype === tools.FieldType.onlydate) {
|
||||
if (val === undefined) {
|
||||
return '[]'
|
||||
} else {
|
||||
return tools.getstrDate(val)
|
||||
}
|
||||
} else if (this.col.fieldtype === tools.FieldType.boolean) {
|
||||
return (val) ? this.$t('dialog.yes') : this.$t('dialog.no')
|
||||
} else if (this.col.fieldtype === tools.FieldType.binary) {
|
||||
if (val === undefined)
|
||||
return '[---]'
|
||||
else
|
||||
return fieldsTable.getArrStrByValueBinary(this, this.col, val)
|
||||
} else if (this.col.fieldtype === tools.FieldType.select) {
|
||||
if (val === undefined)
|
||||
return '[---]'
|
||||
else
|
||||
return fieldsTable.getValueByTable(this.col, val)
|
||||
} else if (this.col.fieldtype === tools.FieldType.multiselect) {
|
||||
if (val === undefined)
|
||||
return '[---]'
|
||||
else
|
||||
return fieldsTable.getMultiValueByTable(this.col, val)
|
||||
} else if (this.col.fieldtype === tools.FieldType.multioption) {
|
||||
if (val === undefined)
|
||||
return '[---]'
|
||||
else
|
||||
return fieldsTable.getMultiValueByTable(this.col, val)
|
||||
} else if (this.col.fieldtype === tools.FieldType.password) {
|
||||
if (val === undefined)
|
||||
return '[---]'
|
||||
else
|
||||
return '***************'
|
||||
} else {
|
||||
if (val === undefined)
|
||||
return ' <span class="text-grey">(' + translate('reg.select') + ')</span> '
|
||||
else if (val === '') {
|
||||
return ' <span class="text-grey">(' + translate('reg.select') + ')</span> '
|
||||
} else {
|
||||
let mystr = tools.firstchars(val, 5000)
|
||||
if (val) {
|
||||
if (val.length > 5000)
|
||||
mystr += '...'
|
||||
} else {
|
||||
return val
|
||||
}
|
||||
return mystr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get mycl() {
|
||||
if (this.disable) {
|
||||
return 'cldisable'
|
||||
}
|
||||
}
|
||||
|
||||
get myvalprinted() {
|
||||
return this.visuValByType(this.myvalue)
|
||||
}
|
||||
|
||||
public savefield(value, initialval) {
|
||||
this.myvalue = value
|
||||
this.setValDb(this.mykey, this.myvalue, this.type, this.serv, this.table, this.mysubkey, this.id)
|
||||
}
|
||||
|
||||
public savefieldboolean(value) {
|
||||
if (this.myvalue === undefined)
|
||||
this.myvalue = 'true'
|
||||
else
|
||||
this.myvalue = value
|
||||
|
||||
this.setValDb(this.mykey, this.myvalue, this.type, this.serv, this.table, this.mysubkey, this.id)
|
||||
}
|
||||
|
||||
public selectcountry({ name, iso2, dialCode }) {
|
||||
// console.log(name, iso2, dialCode)
|
||||
this.myvalue = iso2
|
||||
this.countryname = name
|
||||
}
|
||||
|
||||
public intcode_change(coderec) {
|
||||
this.myvalue = '+' + coderec.dialCode
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user