forked from FoundKeyGang/FoundKey
refactor classic widgets to composition API
This commit is contained in:
parent
bcb07d819f
commit
2e71083823
1 changed files with 40 additions and 48 deletions
|
@ -1,66 +1,58 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="ddiqwdnk">
|
<div class="ddiqwdnk">
|
||||||
<XWidgets class="widgets" :edit="editMode" :widgets="$store.reactiveState.widgets.value.filter(w => w.place === place)" @add-widget="addWidget" @remove-widget="removeWidget" @update-widget="updateWidget" @update-widgets="updateWidgets" @exit="editMode = false"/>
|
<XWidgets class="widgets" :edit="editMode" :widgets="defaultStore.reactiveState.widgets.value.filter(w => w.place === place)" @add-widget="addWidget" @remove-widget="removeWidget" @update-widget="updateWidget" @update-widgets="updateWidgets" @exit="editMode = false"/>
|
||||||
|
|
||||||
<button v-if="editMode" class="_textButton edit" style="font-size: 0.9em;" @click="editMode = false"><i class="fas fa-check"></i> {{ $ts.editWidgetsExit }}</button>
|
<button v-if="editMode" class="_textButton edit" style="font-size: 0.9em;" @click="editMode = false"><i class="fas fa-check"></i> {{ i81n.ts.editWidgetsExit }}</button>
|
||||||
<button v-else class="_textButton edit" style="font-size: 0.9em;" @click="editMode = true"><i class="fas fa-pencil-alt"></i> {{ $ts.editWidgets }}</button>
|
<button v-else class="_textButton edit" style="font-size: 0.9em;" @click="editMode = true"><i class="fas fa-pencil-alt"></i> {{ i18n.ts.editWidgets }}</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { defineComponent, defineAsyncComponent } from 'vue';
|
import { defineAsyncComponent, onMounted } from 'vue';
|
||||||
import XWidgets from '@/components/widgets.vue';
|
import XWidgets from '@/components/widgets.vue';
|
||||||
|
import { defaultStore } from '@/store';
|
||||||
|
import { i18n } from '@/i18n';
|
||||||
|
|
||||||
export default defineComponent({
|
const emit = defineEmits<{
|
||||||
components: {
|
(ev: 'mounted'): void;
|
||||||
XWidgets
|
}>();
|
||||||
},
|
|
||||||
|
|
||||||
props: {
|
const props = defineProps<{
|
||||||
place: {
|
place: {
|
||||||
type: String,
|
type: string;
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
emits: ['mounted'],
|
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
editMode: false,
|
|
||||||
};
|
};
|
||||||
},
|
}>();
|
||||||
|
|
||||||
mounted() {
|
let editMode: boolean = $ref(false);
|
||||||
this.$emit('mounted', this.$el);
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
onMounted(() => {
|
||||||
addWidget(widget) {
|
emit('mounted');
|
||||||
this.$store.set('widgets', [{
|
}
|
||||||
|
|
||||||
|
function addWidget(widget) {
|
||||||
|
defaultStore.set('widgets', [{
|
||||||
...widget,
|
...widget,
|
||||||
place: this.place,
|
place: props.place,
|
||||||
}, ...this.$store.state.widgets]);
|
}, ...defaultStore.state.widgets]);
|
||||||
},
|
}
|
||||||
|
|
||||||
removeWidget(widget) {
|
function removeWidget(widget) {
|
||||||
this.$store.set('widgets', this.$store.state.widgets.filter(w => w.id !== widget.id));
|
defaultStore.set('widgets', defaultStore.state.widgets.filter(w => w.id !== widget.id));
|
||||||
},
|
}
|
||||||
|
|
||||||
updateWidget({ id, data }) {
|
function updateWidget({ id, data }) {
|
||||||
this.$store.set('widgets', this.$store.state.widgets.map(w => w.id === id ? {
|
defaultStore.set('widgets', defaultStore.state.widgets.map(w => w.id === id ? {
|
||||||
...w,
|
...w,
|
||||||
data,
|
data,
|
||||||
} : w));
|
} : w));
|
||||||
},
|
}
|
||||||
|
|
||||||
updateWidgets(widgets) {
|
function updateWidgets(widgets) {
|
||||||
this.$store.set('widgets', [
|
defaultStore.set('widgets', [
|
||||||
...this.$store.state.widgets.filter(w => w.place !== this.place),
|
...defaultStore.state.widgets.filter(w => w.place !== props.place),
|
||||||
...widgets
|
...widgets
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
Loading…
Reference in a new issue