Files
myprojplanet_vite/src/components/CMyPageElem/CMyPageElem.ts

125 lines
2.9 KiB
TypeScript
Raw Normal View History

2022-11-10 19:32:56 +01:00
import {
computed,
defineComponent, onMounted, ref, toRef, watch,
} from 'vue'
import { IMyElem, IMyPage } from '@src/model'
import { useGlobalStore } from '@store/globalStore'
import { LandingFooter } from '@/components/LandingFooter'
import { CMyElem } from '@/components/CMyElem'
2022-11-13 22:39:25 +01:00
import { CMyEditElem } from '@/components/CMyEditElem'
2022-11-10 19:32:56 +01:00
import { CImgTitle } from '../CImgTitle/index'
import { CTitle } from '../CTitle/index'
import { tools } from '@store/Modules/tools'
import { useQuasar } from 'quasar'
import { useI18n } from '@/boot/i18n'
import { shared_consts } from '@/common/shared_vuejs'
export default defineComponent({
name: 'CMyPageElem',
2022-11-13 22:39:25 +01:00
components: { LandingFooter, CImgTitle, CTitle, CMyElem, CMyEditElem },
2022-11-10 19:32:56 +01:00
props: {
title: String,
mypath: {
type: String,
required: true,
},
img: {
type: String,
required: false,
default: '',
},
imgbackground: {
type: String,
required: false,
default: '',
},
sizes: {
type: String,
required: false,
default: '',
},
styleadd: {
type: String,
required: false,
default: '',
},
nofooter: {
type: Boolean,
required: false,
default: false,
},
},
setup(props) {
const rec = ref<IMyPage | null>(null)
const mypathin = toRef(props, 'mypath')
const $q = useQuasar()
const { t } = useI18n()
const editOn = ref(false)
const addOn = ref(false)
2022-11-13 22:39:25 +01:00
const selElem = ref({} as IMyElem)
2022-11-11 18:16:28 +01:00
const myelemVoid = ref({active: true, type: shared_consts.ELEMTYPE.TEXT, container: '...', path: mypathin.value} as IMyElem)
2022-11-10 19:32:56 +01:00
const globalStore = useGlobalStore()
const myelems = computed(() => {
if (mypathin.value)
return globalStore.getMyElems(mypathin.value)
else
return null
})
const load = async (): Promise<void> => {
// console.log('load', mypathin.value)
if (mypathin.value !== '') rec.value = await globalStore.loadPage('/' + mypathin.value)
2022-11-13 22:39:25 +01:00
editOn.value = tools.getCookie('EDIT_' + mypathin.value) === '-1' ? true : false
if (mypathin.value === 'home')
editOn.value = false
console.log('getcookie: ', editOn.value, mypathin.value)
2022-11-10 19:32:56 +01:00
}
watch(() => props.mypath, async (to: string, from: string) => {
console.log('... load', mypathin.value, props.mypath)
await load()
})
2022-11-13 22:39:25 +01:00
function selElemClick(myelem: IMyElem) {
selElem.value = myelem
}
function saveElem(myelem: IMyElem) {
//
}
function changeVisuDrawer() {
console.log('changeVisuDrawer')
tools.setCookie('EDIT_' + mypathin.value, editOn.value ? '-1' : '0')
}
2022-11-10 19:32:56 +01:00
onMounted(load)
return {
rec, myelems,
mypathin,
editOn,
addOn,
tools,
shared_consts,
2022-11-11 18:16:28 +01:00
myelemVoid,
2022-11-13 22:39:25 +01:00
selElemClick,
selElem,
saveElem,
changeVisuDrawer,
2022-11-10 19:32:56 +01:00
}
},
})