|
@@ -56,6 +56,16 @@
|
|
|
label-position="left"
|
|
label-position="left"
|
|
|
:model="projectStore.activeWidget"
|
|
:model="projectStore.activeWidget"
|
|
|
>
|
|
>
|
|
|
|
|
+ <el-form-item
|
|
|
|
|
+ v-if="formConfig.styles?.find((item) => item.field === 'part')"
|
|
|
|
|
+ label="主题"
|
|
|
|
|
+ label-width="60px"
|
|
|
|
|
+ class="mb-12px!"
|
|
|
|
|
+ >
|
|
|
|
|
+ <el-select v-model="editTheme" class="w-full" :options="themeOptions">
|
|
|
|
|
+ </el-select>
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+
|
|
|
<el-form-item
|
|
<el-form-item
|
|
|
v-if="formConfig.styles?.find((item) => item.field === 'part')"
|
|
v-if="formConfig.styles?.find((item) => item.field === 'part')"
|
|
|
label="模块/状态"
|
|
label="模块/状态"
|
|
@@ -100,6 +110,7 @@ import CusFormItem from './CusFormItem.vue'
|
|
|
import { useProjectStore } from '@/store/modules/project'
|
|
import { useProjectStore } from '@/store/modules/project'
|
|
|
import componentMap from '@/lvgl-widgets'
|
|
import componentMap from '@/lvgl-widgets'
|
|
|
import StylePart from './components/StylePart.vue'
|
|
import StylePart from './components/StylePart.vue'
|
|
|
|
|
+import { DEFAULT_THEME_KEY } from '@/constants'
|
|
|
|
|
|
|
|
import { LuSliders } from 'vue-icons-plus/lu'
|
|
import { LuSliders } from 'vue-icons-plus/lu'
|
|
|
import { IoColorPaletteOutline } from 'vue-icons-plus/io'
|
|
import { IoColorPaletteOutline } from 'vue-icons-plus/io'
|
|
@@ -118,10 +129,19 @@ const part = ref<{
|
|
|
state: '',
|
|
state: '',
|
|
|
expandStyle: true
|
|
expandStyle: true
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+const editTheme = ref(DEFAULT_THEME_KEY)
|
|
|
|
|
+
|
|
|
|
|
+const getStyleTheme = (item?: Record<string, any>) => {
|
|
|
|
|
+ return item?.theme || DEFAULT_THEME_KEY
|
|
|
|
|
+}
|
|
|
// 样式表单数据
|
|
// 样式表单数据
|
|
|
const styleFormData = computed(() => {
|
|
const styleFormData = computed(() => {
|
|
|
const item = projectStore.activeWidget?.style?.find(
|
|
const item = projectStore.activeWidget?.style?.find(
|
|
|
- (item) => item?.part.name === part.value?.name && item?.part.state === part.value?.state
|
|
|
|
|
|
|
+ (item) =>
|
|
|
|
|
+ item?.part.name === part.value?.name &&
|
|
|
|
|
+ item?.part.state === part.value?.state &&
|
|
|
|
|
+ getStyleTheme(item) === editTheme.value
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
return item
|
|
return item
|
|
@@ -137,17 +157,58 @@ const parts = computed(() => {
|
|
|
return projectStore.activeWidget ? componentMap[projectStore.activeWidget.type].parts : []
|
|
return projectStore.activeWidget ? componentMap[projectStore.activeWidget.type].parts : []
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+// 主题选项
|
|
|
|
|
+const themeOptions = computed(() => {
|
|
|
|
|
+ return projectStore.project?.themes.map((item) => ({
|
|
|
|
|
+ label: `${item.key}${item.description ? `(${item.description})` : ''}`,
|
|
|
|
|
+ value: item.key
|
|
|
|
|
+ }))
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+watch(
|
|
|
|
|
+ () => projectStore.project?.themes?.map((item) => item.key).join('|'),
|
|
|
|
|
+ () => {
|
|
|
|
|
+ const themeKeys = projectStore.project?.themes?.map((item) => item.key) || []
|
|
|
|
|
+ if (!themeKeys.length) {
|
|
|
|
|
+ editTheme.value = DEFAULT_THEME_KEY
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!themeKeys.includes(editTheme.value)) {
|
|
|
|
|
+ editTheme.value = projectStore.project?.currentTheme || themeKeys[0]
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ immediate: true
|
|
|
|
|
+ }
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+const setPartByEditThemeStyle = () => {
|
|
|
|
|
+ const widgetStyles = projectStore.activeWidget?.style || []
|
|
|
|
|
+ const currentPartThemeStyle = widgetStyles.find(
|
|
|
|
|
+ (item) =>
|
|
|
|
|
+ item?.part?.name === part.value.name &&
|
|
|
|
|
+ item?.part?.state === part.value.state &&
|
|
|
|
|
+ getStyleTheme(item) === editTheme.value
|
|
|
|
|
+ )
|
|
|
|
|
+ const currentThemeStyle = widgetStyles.find((item) => getStyleTheme(item) === editTheme.value)
|
|
|
|
|
+ const fallbackThemeStyle = widgetStyles.find((item) => getStyleTheme(item) === DEFAULT_THEME_KEY)
|
|
|
|
|
+ const fallbackStyle = widgetStyles[0]
|
|
|
|
|
+ const first = currentPartThemeStyle || currentThemeStyle || fallbackThemeStyle || fallbackStyle
|
|
|
|
|
+
|
|
|
|
|
+ if (first) {
|
|
|
|
|
+ part.value.name = first.part.name
|
|
|
|
|
+ part.value.state = first.part.state
|
|
|
|
|
+ }
|
|
|
|
|
+ part.value.expandStyle = true
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
provide('parts', parts)
|
|
provide('parts', parts)
|
|
|
|
|
|
|
|
watch(
|
|
watch(
|
|
|
() => projectStore.activeWidget?.id,
|
|
() => projectStore.activeWidget?.id,
|
|
|
() => {
|
|
() => {
|
|
|
- const first = projectStore.activeWidget?.style?.[0]
|
|
|
|
|
- if (first) {
|
|
|
|
|
- part.value.name = first.part.name
|
|
|
|
|
- part.value.state = first.part.state
|
|
|
|
|
- part.value.expandStyle = true
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ editTheme.value = projectStore.project?.currentTheme || DEFAULT_THEME_KEY
|
|
|
|
|
+ setPartByEditThemeStyle()
|
|
|
scrollContainerRef.value?.scrollTo({
|
|
scrollContainerRef.value?.scrollTo({
|
|
|
top: 0
|
|
top: 0
|
|
|
})
|
|
})
|
|
@@ -157,6 +218,13 @@ watch(
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+watch(
|
|
|
|
|
+ () => editTheme.value,
|
|
|
|
|
+ () => {
|
|
|
|
|
+ setPartByEditThemeStyle()
|
|
|
|
|
+ }
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
watch(
|
|
watch(
|
|
|
() => part.value,
|
|
() => part.value,
|
|
|
({ name, state }) => {
|
|
({ name, state }) => {
|
|
@@ -212,7 +280,8 @@ const onChangeStateStyle = (field: string, type: 'add' | 'delete') => {
|
|
|
part: {
|
|
part: {
|
|
|
name: part.value.name,
|
|
name: part.value.name,
|
|
|
state: part.value.state
|
|
state: part.value.state
|
|
|
- }
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ theme: editTheme.value
|
|
|
})
|
|
})
|
|
|
projectStore.activeWidget?.style?.push(result)
|
|
projectStore.activeWidget?.style?.push(result)
|
|
|
}
|
|
}
|
|
@@ -236,14 +305,18 @@ const onChangeStyleByState = (type: 'add' | 'delete') => {
|
|
|
part: {
|
|
part: {
|
|
|
name: part.value.name,
|
|
name: part.value.name,
|
|
|
state: part.value.state
|
|
state: part.value.state
|
|
|
- }
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ theme: editTheme.value
|
|
|
})
|
|
})
|
|
|
projectStore.activeWidget?.style?.push(result)
|
|
projectStore.activeWidget?.style?.push(result)
|
|
|
} else {
|
|
} else {
|
|
|
// 删除样式
|
|
// 删除样式
|
|
|
const index =
|
|
const index =
|
|
|
projectStore.activeWidget?.style.findIndex(
|
|
projectStore.activeWidget?.style.findIndex(
|
|
|
- (item) => item.part.name === part.value.name && item.part.state === part.value.state
|
|
|
|
|
|
|
+ (item) =>
|
|
|
|
|
+ item.part.name === part.value.name &&
|
|
|
|
|
+ item.part.state === part.value.state &&
|
|
|
|
|
+ getStyleTheme(item) === editTheme.value
|
|
|
) ?? -1
|
|
) ?? -1
|
|
|
if (index !== -1) {
|
|
if (index !== -1) {
|
|
|
projectStore.activeWidget?.style.splice(index, 1)
|
|
projectStore.activeWidget?.style.splice(index, 1)
|