chore: 移动控件分类

This commit is contained in:
奔跑的面条
2023-03-11 22:11:57 +08:00
parent b2594d2f66
commit 63db4f8c87
9 changed files with 7 additions and 7 deletions
@@ -0,0 +1,56 @@
import { NDatePicker } from 'naive-ui'
import { PublicConfigClass } from '@/packages/public'
import { CreateComponentType } from '@/packages/index.d'
import { InputsDateConfig } from './index'
import cloneDeep from 'lodash/cloneDeep'
import { chartInitConfig } from '@/settings/designSetting'
import { InteractEventOn, InteractActionType } from '@/enums/eventEnum'
// 时间组件类型
enum ComponentInteractEvent {
DATE = 'date',
DATERANGE = 'daterange'
}
export const option = {
dataset: {
count: 0,
// 时间组件展示类型 daterange & date
type: ComponentInteractEvent.DATE,
range: undefined
}
}
// 定义组件触发回调事件
const interactActions: InteractActionType[] = [
{
interactType: InteractEventOn.CHANGE,
interactName: '完成后的回调',
componentEmitEvents: {
[ComponentInteractEvent.DATE]: [
{
value: 'date',
label: '日期'
}
],
[ComponentInteractEvent.DATERANGE]: [
{
value: 'dateStart',
label: '开始时间'
},
{
value: 'dateEnd',
label: '结束时间'
}
]
}
}
]
export default class Config extends PublicConfigClass implements CreateComponentType {
public key = InputsDateConfig.key
public attr = { ...chartInitConfig, w: 260, h: 32, zIndex: -1 }
public chartConfig = cloneDeep(InputsDateConfig)
public interactActions = interactActions
public option = cloneDeep(option)
}
@@ -0,0 +1,67 @@
<template>
<CollapseItem name="通用的Props" :expanded="true">
<SettingItemBox name="基础">
<setting-item name="类型">
<n-select v-model:value="props.optionData.dataset.type" size="small" :options="datePickerTypeOptions" />
</setting-item>
</SettingItemBox>
<SettingItemBox name="默认值">
<n-date-picker
size="small"
:style="{ width: ['date'].includes(props.optionData.dataset.type) ? 'auto' : '250px' }"
v-model:value="props.optionData.dataset.range"
:type="props.optionData.dataset.type"
clearable
/>
</SettingItemBox>
<SettingItemBox>
<template #name>
<n-text>动态</n-text>
<n-tooltip trigger="hover">
<template #trigger>
<n-icon size="21" :depth="3">
<help-outline-icon></help-outline-icon>
</n-icon>
</template>
<n-text>动态日期以默认值进行计算</n-text>
</n-tooltip>
</template>
<setting-item name="计算值">
<n-input-number v-model:value="props.optionData.dataset.count" size="small" placeholder="0">
<template #prefix>
<n-text depth="3"></n-text>
</template>
</n-input-number>
</setting-item>
</SettingItemBox>
</CollapseItem>
</template>
<script lang="ts" setup>
import { PropType } from 'vue'
import { icon } from '@/plugins'
import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting'
import { option } from './config'
const { HelpOutlineIcon } = icon.ionicons5
const props = defineProps({
optionData: {
type: Object as PropType<typeof option>,
required: true
}
})
const datePickerTypeOptions = [
{
label: '日期',
value: 'date'
},
{
label: '日期范围',
value: 'daterange'
}
]
</script>
@@ -0,0 +1,14 @@
import { ConfigType, PackagesCategoryEnum, ChartFrameEnum } from '@/packages/index.d'
import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const InputsDateConfig: ConfigType = {
key: 'InputsDate',
chartKey: 'VInputsDate',
conKey: 'VCInputsDate',
title: '时间选择器',
category: ChatCategoryEnum.INPUTS,
categoryName: ChatCategoryEnumName.INPUTS,
package: PackagesCategoryEnum.INFORMATIONS,
chartFrame: ChartFrameEnum.COMMON,
image: 'inputs_date.png'
}
@@ -0,0 +1,80 @@
<template>
<div class="mill-date-box">
<div :style="`width:${w}px; height:${h}px;`">
<n-date-picker v-model:value="rangeDate" :type="option.dataset.type" @update:value="onChange" />
</div>
</div>
</template>
<script setup lang="ts">
import { PropType, toRefs, ref, shallowReactive, watch } from 'vue'
import { CreateComponentType } from '@/packages/index.d'
import { useChartDataFetch } from '@/hooks'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { option as configOption } from './config'
import { useChartInteract } from '@/hooks'
import dayjs from 'dayjs'
const props = defineProps({
chartConfig: {
type: Object as PropType<CreateComponentType & typeof option>,
required: true
}
})
const { w, h } = toRefs(props.chartConfig.attr)
const rangeDate = ref()
const option = shallowReactive({
dataset: configOption.dataset
})
const onChange = (v: number | number[]) => {
if (v instanceof Array) {
const dateStart = dayjs(v[0]).format('YYYY-MM-DD')
const dateEnd = dayjs(v[1]).format('YYYY-MM-DD')
useChartInteract(props.chartConfig, useChartEditStore, { dateStart, dateEnd }, 'change')
} else {
const date = dayjs(v).format('YYYY-MM-DD')
useChartInteract(props.chartConfig, useChartEditStore, { date }, 'change')
}
}
// 手动更新
watch(
() => props.chartConfig.option.dataset,
(newData: any) => {
option.dataset = newData
const { range, count } = newData
if (!range) return
if (newData.range instanceof Array) {
const countDate: number[] = [
dayjs(range[0]).add(count, 'day').valueOf(),
dayjs(range[1]).add(count, 'day').valueOf()
]
rangeDate.value = countDate
} else {
const countDate: number = dayjs(range).add(count, 'day').valueOf()
rangeDate.value = countDate
}
},
{
immediate: true,
deep: true
}
)
// 预览更新
useChartDataFetch(props.chartConfig, useChartEditStore)
</script>
<style lang="scss" scoped>
.mill-text-box {
display: flex;
}
:deep(.n-input) {
height: v-bind('h + "px"');
display: flex;
align-items: center;
}
</style>
@@ -0,0 +1,3 @@
import { InputsDateConfig } from './InputsDate/index'
export default [InputsDateConfig]