mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-12-15 23:28:20 +09:00
c0a60260c2
* wip * wip * wip * wip * wip * wip * wip * wip * Fix bug * wip * Update notifications.vue * Update user-menu.vue * deck settings * indicate
84 lines
1.3 KiB
TypeScript
84 lines
1.3 KiB
TypeScript
import Vue from 'vue';
|
|
|
|
export default function <T extends object>(data: {
|
|
name: string;
|
|
props?: () => T;
|
|
}) {
|
|
return Vue.extend({
|
|
props: {
|
|
widget: {
|
|
type: Object
|
|
},
|
|
column: {
|
|
type: Object,
|
|
default: null
|
|
},
|
|
platform: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
isCustomizeMode: {
|
|
type: Boolean,
|
|
default: false
|
|
}
|
|
},
|
|
|
|
computed: {
|
|
id(): string {
|
|
return this.widget.id;
|
|
},
|
|
|
|
props(): T {
|
|
return this.widget.data;
|
|
}
|
|
},
|
|
|
|
data() {
|
|
return {
|
|
bakedOldProps: null
|
|
};
|
|
},
|
|
|
|
created() {
|
|
this.mergeProps();
|
|
|
|
this.$watch('props', () => {
|
|
this.mergeProps();
|
|
});
|
|
|
|
this.bakeProps();
|
|
},
|
|
|
|
methods: {
|
|
bakeProps() {
|
|
this.bakedOldProps = JSON.stringify(this.props);
|
|
},
|
|
|
|
mergeProps() {
|
|
if (data.props) {
|
|
const defaultProps = data.props();
|
|
for (const prop of Object.keys(defaultProps)) {
|
|
if (this.props.hasOwnProperty(prop)) continue;
|
|
Vue.set(this.props, prop, defaultProps[prop]);
|
|
}
|
|
}
|
|
},
|
|
|
|
save() {
|
|
if (this.bakedOldProps == JSON.stringify(this.props)) return;
|
|
|
|
this.bakeProps();
|
|
|
|
if (this.platform == 'deck') {
|
|
this.$store.commit('device/updateDeckColumn', this.column);
|
|
} else {
|
|
this.$root.api('i/update_widget', {
|
|
id: this.id,
|
|
data: this.props
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|