2020-10-17 04:12:00 -07:00
|
|
|
<template>
|
|
|
|
<div class="efzpzdvf">
|
|
|
|
<template v-if="editMode">
|
|
|
|
<MkButton primary @click="addWidget" class="add"><Fa :icon="faPlus"/></MkButton>
|
|
|
|
<XDraggable
|
2020-12-04 19:50:09 -08:00
|
|
|
v-model="widgets"
|
|
|
|
item-key="id"
|
2020-10-17 04:12:00 -07:00
|
|
|
handle=".handle"
|
|
|
|
animation="150"
|
|
|
|
class="sortable"
|
|
|
|
>
|
2020-12-04 19:50:09 -08:00
|
|
|
<template #item="{element}">
|
|
|
|
<div class="customize-container _panel">
|
|
|
|
<header>
|
|
|
|
<span class="handle"><Fa :icon="faBars"/></span>{{ $t('_widgets.' + element.name) }}<button class="remove _button" @click="removeWidget(element)"><Fa :icon="faTimes"/></button>
|
|
|
|
</header>
|
|
|
|
<div @click="widgetFunc(element.id)">
|
2020-12-11 05:36:57 -08:00
|
|
|
<component class="_inContainer_ _forceContainerFull_" :is="`mkw-${element.name}`" :widget="element" :ref="element.id" :setting-callback="setting => settings[element.id] = setting"/>
|
2020-12-04 19:50:09 -08:00
|
|
|
</div>
|
2020-10-17 04:12:00 -07:00
|
|
|
</div>
|
2020-12-04 19:50:09 -08:00
|
|
|
</template>
|
2020-10-17 04:12:00 -07:00
|
|
|
</XDraggable>
|
|
|
|
<button @click="editMode = false" class="_textButton" style="font-size: 0.9em;"><Fa :icon="faCheck"/> {{ $t('editWidgetsExit') }}</button>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
2020-12-11 05:36:57 -08:00
|
|
|
<component v-for="widget in widgets" class="_inContainer_ _forceContainerFull_" :is="`mkw-${widget.name}`" :key="widget.id" :widget="widget"/>
|
2020-10-17 04:12:00 -07:00
|
|
|
<button @click="editMode = true" class="_textButton" style="font-size: 0.9em;"><Fa :icon="faPencilAlt"/> {{ $t('editWidgets') }}</button>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent, defineAsyncComponent } from 'vue';
|
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
import { faPencilAlt, faPlus, faBars, faTimes, faCheck } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { widgets } from '@/widgets';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
components: {
|
|
|
|
MkButton,
|
2020-12-04 19:50:09 -08:00
|
|
|
XDraggable: defineAsyncComponent(() => import('vuedraggable').then(x => x.default)),
|
2020-10-17 04:12:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
emits: ['mounted'],
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
editMode: false,
|
|
|
|
settings: {},
|
|
|
|
faPencilAlt, faPlus, faBars, faTimes, faCheck,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2020-12-04 19:50:09 -08:00
|
|
|
widgets: {
|
|
|
|
get() {
|
|
|
|
return this.$store.state.deviceUser.widgets;
|
|
|
|
},
|
|
|
|
set(value) {
|
|
|
|
this.$store.commit('deviceUser/setWidgets', value);
|
|
|
|
}
|
2020-10-17 04:12:00 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.$emit('mounted', this.$el);
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
widgetFunc(id) {
|
|
|
|
this.settings[id]();
|
|
|
|
},
|
|
|
|
|
|
|
|
async addWidget() {
|
|
|
|
const { canceled, result: widget } = await os.dialog({
|
|
|
|
type: null,
|
|
|
|
title: this.$t('chooseWidget'),
|
|
|
|
select: {
|
|
|
|
items: widgets.map(widget => ({
|
|
|
|
value: widget,
|
|
|
|
text: this.$t('_widgets.' + widget),
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
showCancelButton: true
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
this.$store.commit('deviceUser/addWidget', {
|
|
|
|
name: widget,
|
|
|
|
id: uuid(),
|
|
|
|
place: null,
|
|
|
|
data: {}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
removeWidget(widget) {
|
|
|
|
this.$store.commit('deviceUser/removeWidget', widget);
|
|
|
|
},
|
|
|
|
|
|
|
|
saveHome() {
|
|
|
|
this.$store.commit('deviceUser/setWidgets', this.widgets);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.efzpzdvf {
|
|
|
|
position: sticky;
|
|
|
|
height: min-content;
|
|
|
|
min-height: 100vh;
|
|
|
|
padding: var(--margin) 0;
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
|
|
> * {
|
|
|
|
margin: var(--margin) 0;
|
|
|
|
width: 300px;
|
|
|
|
|
|
|
|
&:first-child {
|
|
|
|
margin-top: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .add {
|
|
|
|
margin: 0 auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.customize-container {
|
|
|
|
margin: 8px 0;
|
|
|
|
|
|
|
|
> header {
|
|
|
|
position: relative;
|
|
|
|
line-height: 32px;
|
|
|
|
|
|
|
|
> .handle {
|
|
|
|
padding: 0 8px;
|
|
|
|
cursor: move;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .remove {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
padding: 0 8px;
|
|
|
|
line-height: 32px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> div {
|
|
|
|
padding: 8px;
|
|
|
|
|
|
|
|
> * {
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|