First Committ
This commit is contained in:
189
src/mixins/mixin-base.ts
Executable file
189
src/mixins/mixin-base.ts
Executable file
@@ -0,0 +1,189 @@
|
||||
import { toolsext } from '@src/store/Modules/toolsext'
|
||||
|
||||
import { useI18n } from '@src/boot/i18n'
|
||||
|
||||
// import { fieldsTable } from '@src/store/Modules/fieldsTable'
|
||||
import MixinMetaTags from '@src/mixins/mixin-metatags'
|
||||
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { useGlobalStore } from '@store/globalStore'
|
||||
import { useQuasar } from 'quasar'
|
||||
import { IDataPass } from '@model'
|
||||
import { shared_consts } from '../common/shared_vuejs'
|
||||
import { tools } from '../store/Modules/tools'
|
||||
import { func_tools } from '../store/Modules/toolsext'
|
||||
import { costanti } from '@costanti'
|
||||
|
||||
// You can declare a mixin as the same style as components.
|
||||
export const MixinBase = {
|
||||
created() {
|
||||
|
||||
},
|
||||
mythis() {
|
||||
return this
|
||||
},
|
||||
|
||||
showNotif(msg: string) {
|
||||
const $q = useQuasar()
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
tools.showNotif($q, t(msg))
|
||||
},
|
||||
|
||||
db_fieldsTable() {
|
||||
// return fieldsTable
|
||||
},
|
||||
|
||||
getValDb(keystr: string, serv: boolean, def?: any, table?: string, subkey?: any, id?: any, idmain?: any) {
|
||||
console.log('getValDb')
|
||||
return toolsext.getValDb(keystr, serv, def, table, subkey, id, idmain)
|
||||
},
|
||||
|
||||
getValDbLang(keystr: string, serv: boolean, def?: any, table?: string, subkey?: any) {
|
||||
let ris = toolsext.getValDb(`${keystr}_${toolsext.getLocale()}`, serv, def, table, subkey)
|
||||
if (ris === def) ris = toolsext.getValDb(`${keystr}_it`, serv, def, table, subkey)
|
||||
return ris
|
||||
},
|
||||
|
||||
async setValDb(key: string, value: any, type: any, serv: boolean, table?: string, subkey?: string, id?: any) {
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
const $q = useQuasar()
|
||||
const { t } = useI18n();
|
||||
|
||||
// console.log('setValDb', key, value, serv, table, subkey)
|
||||
let mydatatosave: IDataPass | null = null
|
||||
if (table === 'users') {
|
||||
const myid = userStore.my._id
|
||||
|
||||
const myfield: any = {}
|
||||
|
||||
if (key === 'profile') {
|
||||
// @ts-ignore
|
||||
userStore.my.profile[subkey] = value
|
||||
} else {
|
||||
// @ts-ignore
|
||||
userStore.my[key] = value
|
||||
}
|
||||
|
||||
// Save to the DB:
|
||||
if (subkey) {
|
||||
myfield[`${key}.${subkey}`] = value
|
||||
} else {
|
||||
myfield[key] = value
|
||||
}
|
||||
|
||||
// console.log('myfield', myfield)
|
||||
|
||||
mydatatosave = {
|
||||
id: myid,
|
||||
table,
|
||||
fieldsvalue: myfield,
|
||||
}
|
||||
} else if (table === 'todos') {
|
||||
const myfield: any = {}
|
||||
|
||||
// Save to the DB:
|
||||
if (subkey) {
|
||||
myfield[`${key}.${subkey}`] = value
|
||||
} else {
|
||||
myfield[key] = value
|
||||
}
|
||||
|
||||
// console.log('myfield', myfield)
|
||||
|
||||
mydatatosave = {
|
||||
id,
|
||||
table,
|
||||
fieldsvalue: myfield,
|
||||
}
|
||||
} else if (table === 'settings') {
|
||||
globalStore.setValueSettingsByKey({ key, value, serv })
|
||||
|
||||
let myrec = globalStore.getrecSettingsByKey(key, serv)
|
||||
if (myrec === undefined) {
|
||||
myrec = {
|
||||
idapp: process.env.APP_ID,
|
||||
key,
|
||||
type,
|
||||
}
|
||||
myrec.serv = serv
|
||||
if ((myrec.type === costanti.FieldType.date) || (myrec.type === costanti.FieldType.onlydate)) myrec.value_date = value
|
||||
else if ((myrec.type === costanti.FieldType.number) || (myrec.type === costanti.FieldType.hours)) myrec.value_num = value
|
||||
else if (myrec.type === costanti.FieldType.boolean) myrec.value_bool = value
|
||||
else myrec.value_str = value
|
||||
|
||||
myrec = await tools.createNewRecord($q, 'settings', myrec).then(
|
||||
(myrecris) => {
|
||||
// console.log('myrec')
|
||||
let recsett = null
|
||||
if (serv) recsett = globalStore.serv_settings
|
||||
else recsett = globalStore.settings
|
||||
|
||||
if (myrecris) recsett.push(myrecris)
|
||||
// @ts-ignore
|
||||
return recsett.find((rec) => rec.key === key)
|
||||
},
|
||||
)
|
||||
}
|
||||
// console.log('myrec', myrec)
|
||||
|
||||
mydatatosave = {
|
||||
// @ts-ignore
|
||||
id: myrec ? myrec._id : '',
|
||||
table: 'settings',
|
||||
// @ts-ignore
|
||||
fieldsvalue: myrec,
|
||||
}
|
||||
} else {
|
||||
const myfield: any = {}
|
||||
|
||||
// Save to the DB:
|
||||
if (subkey) {
|
||||
myfield[`${key}.${subkey}`] = value
|
||||
} else {
|
||||
myfield[key] = value
|
||||
}
|
||||
|
||||
// console.log('myfield', myfield)
|
||||
|
||||
mydatatosave = {
|
||||
id,
|
||||
table: table || '',
|
||||
fieldsvalue: myfield,
|
||||
}
|
||||
}
|
||||
|
||||
// console.log('mydatatosave', mydatatosave)
|
||||
|
||||
// @ts-ignore
|
||||
globalStore.saveFieldValue(mydatatosave).then((esito) => {
|
||||
if (esito) {
|
||||
tools.showPositiveNotif($q, t('db.recupdated'))
|
||||
} else {
|
||||
tools.showNegativeNotif($q, t('db.recfailed'))
|
||||
// Undo...
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
getarrValDb(keystr: string, serv: boolean) {
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
const myval = globalStore.getValueSettingsByKey(keystr, serv)
|
||||
// console.log('myval', myval)
|
||||
try {
|
||||
if (myval) {
|
||||
const myrec: any = JSON.parse(myval)
|
||||
// console.log('*************** getarrValDb')
|
||||
// console.table(myrec)
|
||||
return myrec
|
||||
}
|
||||
return []
|
||||
} catch (e) {
|
||||
return []
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
34
src/mixins/mixin-metatags.ts
Executable file
34
src/mixins/mixin-metatags.ts
Executable file
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
defineComponent, ref,
|
||||
} from 'vue'
|
||||
import { IMetaTags } from '@model'
|
||||
import { tools } from '@store/Modules/tools'
|
||||
import { useQuasar } from 'quasar'
|
||||
|
||||
// You can declare a mixin as the same style as components.
|
||||
export default defineComponent({
|
||||
name: 'MixinMetaTags',
|
||||
setup() {
|
||||
const mymeta = ref<IMetaTags>({ title: '', description: '', keywords: '' })
|
||||
|
||||
const $q = useQuasar()
|
||||
|
||||
function setmeta(mym: IMetaTags) {
|
||||
mymeta.value = mym
|
||||
}
|
||||
|
||||
function getsrcbyimg(myimg: string) {
|
||||
// return src
|
||||
const filefull = tools.getimgFullpathbysize(myimg)
|
||||
|
||||
return tools.getimgbysize(filefull.path, filefull.file)
|
||||
}
|
||||
|
||||
return {
|
||||
$q,
|
||||
setmeta,
|
||||
getsrcbyimg,
|
||||
}
|
||||
},
|
||||
|
||||
})
|
||||
153
src/mixins/mixin-users.ts
Executable file
153
src/mixins/mixin-users.ts
Executable file
@@ -0,0 +1,153 @@
|
||||
import { Vue, Options } from 'vue-class-component'
|
||||
import { defineComponent, ref } from 'vue'
|
||||
|
||||
import { IMessage } from '@src/model'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { useGlobalStore } from '@store/globalStore'
|
||||
import { tools } from '../store/Modules/tools'
|
||||
import { func_tools } from '../store/Modules/toolsext'
|
||||
|
||||
// You can declare a mixin as the same style as components.
|
||||
export default defineComponent({
|
||||
name: 'MixinUsers',
|
||||
setup(props) {
|
||||
function getUserByUsername(username: string) {
|
||||
const userStore = useUserStore()
|
||||
return userStore.getNameSurnameByUsername(username)
|
||||
}
|
||||
|
||||
function getImgByUsername(username: string) {
|
||||
const userStore = useUserStore()
|
||||
return `public/${userStore.getImgByUsername(username)}`
|
||||
}
|
||||
|
||||
function isValidUsername(username: string) {
|
||||
return username && username !== 'nessuno' && username !== 'none'
|
||||
}
|
||||
|
||||
function getMyUsername() {
|
||||
const userStore = useUserStore()
|
||||
return userStore.my.username
|
||||
}
|
||||
|
||||
function getUsernameChatByMsg(msg: IMessage) {
|
||||
if (msg) {
|
||||
if (msg.dest) {
|
||||
if (msg.dest.username !== getMyUsername()) return msg.dest.username
|
||||
return msg.origin ? msg.origin.username : {}
|
||||
}
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
function getnumItemsCart(): any {
|
||||
// ++Todo: conv
|
||||
/* const arrcart = Products.cart
|
||||
if (!!arrcart) {
|
||||
if (!!arrcart.items) {
|
||||
// @ts-ignore
|
||||
const total = arrcart.items.reduce((sum, item) => sum + item.order.quantity, 0)
|
||||
return total
|
||||
}
|
||||
} */
|
||||
return 0
|
||||
}
|
||||
|
||||
function getImgByMsg(msg: IMessage) {
|
||||
const userStore = useUserStore()
|
||||
// @ts-ignore
|
||||
return `public/${userStore.getImgByUsername(this.getUsernameChatByMsg(msg))}`
|
||||
}
|
||||
|
||||
function getMyImg() {
|
||||
const userStore = useUserStore()
|
||||
const ris = userStore.getImgByUsername(userStore.my.username)
|
||||
return (ris !== '') ? `public/${ris}` : ''
|
||||
}
|
||||
|
||||
function getMyImgforIcon() {
|
||||
const userStore = useUserStore()
|
||||
const ris = userStore.getImgByUsername(userStore.my.username)
|
||||
return (ris !== '') ? `img:public/${ris}` : 'fas fa-user'
|
||||
}
|
||||
|
||||
function getIconCart() {
|
||||
const iconcart = 'fas fa-shopping-cart'
|
||||
|
||||
return iconcart
|
||||
}
|
||||
|
||||
function MenuCollapse() {
|
||||
const globalStore = useGlobalStore()
|
||||
return globalStore.menuCollapse
|
||||
// return true
|
||||
}
|
||||
|
||||
function Username() {
|
||||
const userStore = useUserStore()
|
||||
return userStore.my.username
|
||||
}
|
||||
|
||||
function myName() {
|
||||
const userStore = useUserStore()
|
||||
return userStore.my.name
|
||||
}
|
||||
|
||||
function mySurname() {
|
||||
const userStore = useUserStore()
|
||||
return userStore.my.surname
|
||||
}
|
||||
|
||||
function myCell() {
|
||||
const userStore = useUserStore()
|
||||
return userStore.my.profile.cell
|
||||
}
|
||||
|
||||
function Verificato() {
|
||||
const userStore = useUserStore()
|
||||
return userStore.my.verified_email
|
||||
}
|
||||
|
||||
function MadeGift() {
|
||||
const userStore = useUserStore()
|
||||
return userStore.my.made_gift
|
||||
}
|
||||
|
||||
function Email() {
|
||||
const userStore = useUserStore()
|
||||
return userStore.my.email
|
||||
}
|
||||
|
||||
function getNumMsg() {
|
||||
// ++Todo: conv
|
||||
/*
|
||||
return MessageStore.getlasts_messages().length
|
||||
*/
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function getNumMsgUnread() {
|
||||
// return userStore.getlasts_messages().length
|
||||
// ++Todo: conv
|
||||
// return MessageStore.getnumMsgUnread()
|
||||
return 0
|
||||
}
|
||||
|
||||
function getMsgText(msg: IMessage, inarray: boolean) {
|
||||
let add = ''
|
||||
if (msg.origin && msg.origin.username === getMyUsername()) add = 'Tu: '
|
||||
|
||||
const ris = add + msg.message
|
||||
if (inarray) return [ris]
|
||||
return ris
|
||||
}
|
||||
|
||||
return {
|
||||
getUsernameChatByMsg,
|
||||
getMyUsername,
|
||||
}
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user