2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2022-05-28 14:28:12 +09:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader" :style="`height: ${widgetProps.height}px;`" :scrollable="true" class="mkw-timeline">
|
2020-07-11 10:13:11 +09:00
|
|
|
<template #header>
|
2021-11-19 19:36:12 +09:00
|
|
|
<button class="_button" @click="choose">
|
2022-12-19 13:53:41 +09:00
|
|
|
<i v-if="widgetProps.src === 'home'" class="ti ti-home-2"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'local'" class="ti ti-messages"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'social'" class="ti ti-share"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'global'" class="ti ti-world"></i>
|
2022-01-08 20:30:01 +09:00
|
|
|
<i v-else-if="widgetProps.src === 'list'" class="fas fa-list-ul"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'antenna'" class="fas fa-satellite"></i>
|
|
|
|
<span style="margin-left: 8px;">{{ widgetProps.src === 'list' ? widgetProps.list.name : widgetProps.src === 'antenna' ? widgetProps.antenna.name : $t('_timelines.' + widgetProps.src) }}</span>
|
2021-04-20 23:22:59 +09:00
|
|
|
<i :class="menuOpened ? 'fas fa-angle-up' : 'fas fa-angle-down'" style="margin-left: 8px;"></i>
|
2020-07-11 10:13:11 +09:00
|
|
|
</button>
|
|
|
|
</template>
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-07-11 10:13:11 +09:00
|
|
|
<div>
|
2022-01-08 20:30:01 +09:00
|
|
|
<XTimeline :key="widgetProps.src === 'list' ? `list:${widgetProps.list.id}` : widgetProps.src === 'antenna' ? `antenna:${widgetProps.antenna.id}` : widgetProps.src" :src="widgetProps.src" :list="widgetProps.list ? widgetProps.list.id : null" :antenna="widgetProps.antenna ? widgetProps.antenna.id : null"/>
|
2020-07-11 10:13:11 +09:00
|
|
|
</div>
|
2020-10-17 20:12:00 +09:00
|
|
|
</MkContainer>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, onUnmounted, reactive, ref, watch } from 'vue';
|
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
|
|
|
import * as os from '@/os';
|
2022-09-06 18:21:49 +09:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2022-08-31 00:24:33 +09:00
|
|
|
import XTimeline from '@/components/MkTimeline.vue';
|
2022-01-08 20:30:01 +09:00
|
|
|
import { $i } from '@/account';
|
|
|
|
import { i18n } from '@/i18n';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const name = 'timeline';
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
2022-01-08 20:30:01 +09:00
|
|
|
height: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 300,
|
|
|
|
},
|
|
|
|
src: {
|
|
|
|
type: 'string' as const,
|
|
|
|
default: 'home',
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
antenna: {
|
|
|
|
type: 'object' as const,
|
|
|
|
default: null,
|
|
|
|
hidden: true,
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
2022-01-08 20:30:01 +09:00
|
|
|
list: {
|
|
|
|
type: 'object' as const,
|
|
|
|
default: null,
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
2022-05-25 16:43:12 +09:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 20:30:01 +09:00
|
|
|
|
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const menuOpened = ref(false);
|
|
|
|
|
|
|
|
const setSrc = (src) => {
|
|
|
|
widgetProps.src = src;
|
|
|
|
save();
|
|
|
|
};
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const choose = async (ev) => {
|
|
|
|
menuOpened.value = true;
|
|
|
|
const [antennas, lists] = await Promise.all([
|
|
|
|
os.api('antennas/list'),
|
|
|
|
os.api('users/lists/list')
|
|
|
|
]);
|
|
|
|
const antennaItems = antennas.map(antenna => ({
|
|
|
|
text: antenna.name,
|
|
|
|
icon: 'fas fa-satellite',
|
|
|
|
action: () => {
|
|
|
|
widgetProps.antenna = antenna;
|
|
|
|
setSrc('antenna');
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
const listItems = lists.map(list => ({
|
|
|
|
text: list.name,
|
|
|
|
icon: 'fas fa-list-ul',
|
|
|
|
action: () => {
|
|
|
|
widgetProps.list = list;
|
|
|
|
setSrc('list');
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
os.popupMenu([{
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts._timelines.home,
|
2022-12-19 13:53:41 +09:00
|
|
|
icon: 'ti ti-home-2',
|
2022-06-10 14:36:55 +09:00
|
|
|
action: () => { setSrc('home'); }
|
2022-01-08 20:30:01 +09:00
|
|
|
}, {
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts._timelines.local,
|
2022-12-19 13:53:41 +09:00
|
|
|
icon: 'ti ti-messages',
|
2022-06-10 14:36:55 +09:00
|
|
|
action: () => { setSrc('local'); }
|
2022-01-08 20:30:01 +09:00
|
|
|
}, {
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts._timelines.social,
|
2022-12-19 13:53:41 +09:00
|
|
|
icon: 'ti ti-share',
|
2022-06-10 14:36:55 +09:00
|
|
|
action: () => { setSrc('social'); }
|
2022-01-08 20:30:01 +09:00
|
|
|
}, {
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts._timelines.global,
|
2022-12-19 13:53:41 +09:00
|
|
|
icon: 'ti ti-world',
|
2022-06-10 14:36:55 +09:00
|
|
|
action: () => { setSrc('global'); }
|
2022-01-28 11:53:12 +09:00
|
|
|
}, antennaItems.length > 0 ? null : undefined, ...antennaItems, listItems.length > 0 ? null : undefined, ...listItems], ev.currentTarget ?? ev.target).then(() => {
|
2022-01-08 20:30:01 +09:00
|
|
|
menuOpened.value = false;
|
|
|
|
});
|
|
|
|
};
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
</script>
|