mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-24 21:19:07 +01:00
b954245a4d
Co-authored-by: syuilo <syuilotan@yahoo.co.jp> Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
76 lines
1.1 KiB
TypeScript
76 lines
1.1 KiB
TypeScript
import Vue from 'vue';
|
|
|
|
export default function <T extends object>(data: {
|
|
name: string;
|
|
props?: () => T;
|
|
}) {
|
|
return Vue.extend({
|
|
props: {
|
|
widget: {
|
|
type: Object
|
|
},
|
|
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();
|
|
|
|
this.$root.api('i/update_widget', {
|
|
id: this.id,
|
|
data: this.props
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|