First Committ

This commit is contained in:
Paolo Arena
2021-08-31 18:09:59 +02:00
commit 1d6c55807c
299 changed files with 55382 additions and 0 deletions

153
src/mixins/mixin-users.ts Executable file
View 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,
}
},
})