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

208 lines
4.8 KiB
TypeScript
Raw Normal View History

2022-11-10 19:32:56 +01:00
import {
computed,
defineComponent, onMounted, ref, toRef, watch,
} from 'vue'
2025-03-01 14:14:43 +01:00
import type { IMyElem, IMyPage } from '@src/model'
2022-11-10 19:32:56 +01:00
import { useGlobalStore } from '@store/globalStore'
2025-03-01 14:14:43 +01:00
import { LandingFooter } from '@src/components/LandingFooter'
import { CMyElem } from '@src/components/CMyElem'
import { CTitleBanner } from '@src/components/CTitleBanner'
import { CMyEditElem } from '@src/components/CMyEditElem'
import { CMyPageElem2 } from '@src/components/CMyPageElem2'
import { CExportImportPage } from '@src/components/CExportImportPage'
2022-11-10 19:32:56 +01:00
import { CImgTitle } from '../CImgTitle/index'
import { CTitle } from '../CTitle/index'
2025-03-01 14:14:43 +01:00
import { tools } from '@tools'
2022-11-10 19:32:56 +01:00
import { useQuasar } from 'quasar'
2025-03-01 14:14:43 +01:00
import { useI18n } from 'vue-i18n'
import { shared_consts } from '@src/common/shared_vuejs'
2022-11-17 08:10:43 +01:00
import objectId from '@src/js/objectId'
import { useRouter } from 'vue-router'
2022-11-10 19:32:56 +01:00
export default defineComponent({
name: 'CMyPageElem',
components: {
LandingFooter, CImgTitle, CTitle, CMyElem,
CMyEditElem, CMyPageElem2, CTitleBanner, CExportImportPage,
},
2022-11-10 19:32:56 +01:00
props: {
title: String,
mypath: {
type: String,
required: true,
},
idPage: {
2024-10-31 23:23:06 +01:00
type: String,
required: false,
default: ''
},
2022-11-10 19:32:56 +01:00
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')
2024-10-31 23:23:06 +01:00
const myidPage = toRef(props, 'idPage')
2022-11-10 19:32:56 +01:00
const $q = useQuasar()
const { t } = useI18n()
2022-11-17 08:10:43 +01:00
const globalStore = useGlobalStore()
const $router = useRouter()
2022-11-10 19:32:56 +01:00
const mywidthEditor = ref(400)
const showexportPage = ref(false)
const showimportPage = ref(false)
2022-11-23 10:27:36 +01:00
const editOn = computed({
get(): boolean {
2022-11-23 10:27:36 +01:00
return !!globalStore.editOn ? globalStore.editOn : false
},
set(value: boolean) {
return tools.updateEditOn(value)
2022-11-23 10:27:36 +01:00
}
})
2022-11-18 18:54:30 +01:00
const visuEditor = ref(false)
2022-11-10 19:32:56 +01:00
const addOn = ref(false)
2022-11-17 08:10:43 +01:00
const myelemVoid = ref({ _id: objectId(), active: true, type: shared_consts.ELEMTYPE.TEXT, container: '...', path: mypathin.value } as IMyElem)
2022-11-10 19:32:56 +01:00
2022-11-17 08:10:43 +01:00
2025-03-01 14:14:43 +01:00
const selElem = ref(<IMyElem | null>globalStore.selElem)
2022-11-23 10:27:36 +01:00
const site = ref(globalStore.site)
2022-11-10 19:32:56 +01:00
2024-09-13 19:42:55 +02:00
const onloading = ref(false)
2022-11-10 19:32:56 +01:00
const myelems = computed(() => {
2024-10-31 23:23:06 +01:00
if (myidPage.value)
return globalStore.getMyElemsByIdPage(myidPage.value)
else if (mypathin.value)
2022-11-10 19:32:56 +01:00
return globalStore.getMyElems(mypathin.value)
else
return null
})
2024-09-13 19:42:55 +02:00
async function load() {
2025-03-01 14:14:43 +01:00
console.log('load', mypathin.value, 'idapp', tools.getEnv('VITE_APP_ID'))
2022-11-20 10:21:02 +01:00
2022-11-17 08:10:43 +01:00
if (mypathin.value !== '') {
2024-11-02 19:25:47 +01:00
onloading.value = true
await globalStore.loadPage('/' + mypathin.value, 'cmypageelem')
.then(ris => {
rec.value = ris
// console.log('LoadPage', ris)
})
onloading.value = false
2022-11-17 08:10:43 +01:00
}
if (mypathin.value === 'home_logout' && globalStore.site.name === 'local' && !rec.value) {
$router.replace('/install_site')
}
2022-11-17 08:10:43 +01:00
if (tools.isManager()) {
2023-02-15 21:40:10 +01:00
// console.log('getcookie: ', editOn.value, mypathin.value)
2022-11-17 08:10:43 +01:00
}
2022-11-10 19:32:56 +01:00
}
2022-11-17 08:10:43 +01:00
watch(() => props.mypath, (to: string, from: string) => {
2023-04-04 15:27:03 +02:00
// console.log('... load', mypathin.value, props.mypath)
2022-11-17 08:10:43 +01:00
selElem.value = {}
load()
2022-11-10 19:32:56 +01:00
})
2022-11-17 08:10:43 +01:00
watch(
() => editOn.value,
() => {
if (!editOn.value) {
selElem.value = {}
}
})
2022-11-10 19:32:56 +01:00
2024-09-13 19:42:55 +02:00
async function mounted() {
await load()
2022-11-17 08:10:43 +01:00
}
2022-11-13 22:39:25 +01:00
function saveElem(myelem: IMyElem) {
//
}
2022-11-17 08:10:43 +01:00
function changeVisuDrawer(path: string, edit: boolean) {
globalStore.changeVisuDrawer(path, edit)
2022-11-13 22:39:25 +01:00
}
function toggleSize() {
mywidthEditor.value = mywidthEditor.value === 400 ? 1050 : 400
}
2024-09-13 19:42:55 +02:00
function deleteElem() {
selElem.value = {}
visuEditor.value = false
}
function selElemClick(myelem: IMyElem) {
2025-02-05 12:13:36 +01:00
console.log('mypageelem selElemClick', myelem)
2024-09-13 19:42:55 +02:00
selElem.value = {}
selElem.value = myelem
visuEditor.value = !!myelem
}
2024-10-31 23:23:06 +01:00
async function duplicatePage() {
await globalStore.duplicatePage(mypathin.value, $q, t)
}
2024-09-13 19:42:55 +02:00
2022-11-17 08:10:43 +01:00
onMounted(mounted)
2022-11-10 19:32:56 +01:00
return {
rec, myelems,
mypathin,
editOn,
2022-11-18 18:54:30 +01:00
visuEditor,
2022-11-10 19:32:56 +01:00
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,
mywidthEditor,
toggleSize,
2024-09-13 19:42:55 +02:00
onloading,
deleteElem,
2024-10-31 23:23:06 +01:00
duplicatePage,
showexportPage,
showimportPage,
2022-11-10 19:32:56 +01:00
}
},
})