Commit 2451600ddd20a622b2fd9324694bbaefe88fbe71

Authored by ww
1 parent a3955a1c

fix: 修复组态变量图片绑定默认图片显示

1 1 <script setup lang="ts">
2 2 import { ref, unref } from 'vue'
3 3 import type { ComponentExposeType } from '../../..'
  4 +import { usePublicFormContext } from '../../../usePublicFormContext'
4 5 import ImageSettingTable from './ImageSettingTable.vue'
5 6 import { formSchemas } from './config'
6 7 import { BasicForm, useForm } from '@/components/Form'
7 8 import { FormLayoutEnum } from '@/components/Form/src/enum'
8 9 import type { RangeItemType, VariableImageActDataType } from '@/api/node/model'
  10 +import { NodeUtils } from '@/hooks/business/useNodeUtils'
  11 +import type { ImageSelectorDataType } from '@/core/Library/components/ImageSelector'
  12 +import { CellAttributeKeyEnum } from '@/enums/cellAttributeEnum'
9 13
10 14 const imageSettingTableElRef = ref<InstanceType<typeof ImageSettingTable>>()
11 15
  16 +const { getCellInfo } = usePublicFormContext()
  17 +
  18 +const nodeUtils = new NodeUtils()
  19 +
12 20 const [register, formActionType] = useForm({
13 21 schemas: formSchemas,
14 22 showActionButtonGroup: false,
... ... @@ -16,6 +24,17 @@ const [register, formActionType] = useForm({
16 24 baseColProps: { span: 12 },
17 25 })
18 26
  27 +function savaDefaultImageToNodeAttribute(defaultImages: ImageSelectorDataType) {
  28 + const node = nodeUtils.getCellById(unref(getCellInfo).id)
  29 +
  30 + if (!node)
  31 + return
  32 +
  33 + node.setAttribute(CellAttributeKeyEnum.DEFAULT_IMAGE, JSON.stringify(defaultImages))
  34 +
  35 + nodeUtils.refreshCell(node)
  36 +}
  37 +
19 38 const validate = async () => {
20 39 await formActionType.validate()
21 40 await unref(imageSettingTableElRef)?.validate()
... ... @@ -24,6 +43,8 @@ const validate = async () => {
24 43 const getFieldsValue = (): VariableImageActDataType => {
25 44 const value = formActionType.getFieldsValue() as VariableImageActDataType
26 45 const tableValue = unref(imageSettingTableElRef)?.getFieldsValue() as RangeItemType[]
  46 +
  47 + savaDefaultImageToNodeAttribute(value.defaultImage)
27 48 return {
28 49 ...value,
29 50 rangeList: tableValue,
... ... @@ -51,11 +72,11 @@ defineExpose<ComponentExposeType>({
51 72 </template>
52 73
53 74 <style lang="less" scoped>
54   - .variable-image-form {
55   - >:deep(.ant-row) {
56   - >.ant-col {
57   - @apply px-4;
58   - }
  75 +.variable-image-form {
  76 + >:deep(.ant-row) {
  77 + >.ant-col {
  78 + @apply px-4;
59 79 }
60 80 }
  81 +}
61 82 </style>
... ...
... ... @@ -7,9 +7,10 @@ import type { ModalProps } from '@/components/Modal'
7 7 import { BasicModal, useModalInner } from '@/components/Modal'
8 8 import type { ActTypeEnum, EventTypeEnum } from '@/enums/datasource'
9 9 import { DataSourceTypeEnum } from '@/enums/datasource'
10   -import type { NodeDataActJsonType, NodeDataEventJsonType, SingleClickEventDataType } from '@/api/node/model'
  10 +import type { NodeDataActJsonType, NodeDataEventJsonType } from '@/api/node/model'
11 11 import { useContentDataStoreWithOut } from '@/store/modules/contentData'
12 12 import { useTranslation } from '@/hooks/useTranslation'
  13 +import { BasicComponentEnum } from '@/core/Library/packages/Basic'
13 14
14 15 defineEmits(['register'])
15 16
... ... @@ -17,7 +18,7 @@ const { t } = useTranslation()
17 18
18 19 const contentDataStore = useContentDataStoreWithOut()
19 20
20   -const { getNodeData, getNodeAllData, saveNodeAllData } = usePublicFormContext()
  21 +const { getNodeData, getNodeAllData, saveNodeAllData, getCellInfo } = usePublicFormContext()
21 22
22 23 const contentComponent = shallowRef()
23 24
... ... @@ -63,6 +64,10 @@ const handleOk = async () => {
63 64 await handleDoSaveEventData()
64 65
65 66 await getNodeAllData()
  67 +
  68 + if (unref(getCellInfo).componentKey === BasicComponentEnum.VARIABLE_IMAGE)
  69 + window.DrawApp?.saveButton.click()
  70 +
66 71 closeModal()
67 72 contentComponent.value = null
68 73 }
... ... @@ -93,7 +98,10 @@ const handleCancel = () => {
93 98 <template>
94 99 <BasicModal destroy-on-close v-bind="modalProps" @register="register" @ok="handleOk" @cancel="handleCancel">
95 100 <!-- <Spin :spinning="spinning"> -->
96   - <component :is="contentComponent" v-bind="componentProps" ref="componentInstance" @vue:mounted="handleComponentMounted" />
  101 + <component
  102 + :is="contentComponent" v-bind="componentProps" ref="componentInstance"
  103 + @vue:mounted="handleComponentMounted"
  104 + />
97 105 <!-- </Spin> -->
98 106 <!-- -->
99 107 </BasicModal>
... ...
... ... @@ -219,10 +219,13 @@ createPublicFormContext(nodeDataActinType)
219 219 <Divider orientation="left">
220 220 {{ t('dataInteraction') }}
221 221 </Divider>
222   - <DataEvents ref="dataEventsElRef" :before-click="handleBeforeOpenEventOrActModal" :form-setting="getFormSetting" />
  222 + <DataEvents
  223 + ref="dataEventsElRef" :before-click="handleBeforeOpenEventOrActModal"
  224 + :form-setting="getFormSetting"
  225 + />
223 226 <div
224   - v-if="getCellInfo.category === PackageCategoryEnum.CONTROL" class="flex flex-col justify-center passwordInput"
225   - :class="getFormSetting?.actSetting === false && 'mb-4'"
  227 + v-if="getCellInfo.category === PackageCategoryEnum.CONTROL"
  228 + class="flex flex-col justify-center passwordInput" :class="getFormSetting?.actSetting === false && 'mb-4'"
226 229 >
227 230 <Checkbox v-model:checked="operationPassword.checked" :disabled="getSetPasswordStatus">
228 231 <div class="flex">
... ... @@ -254,10 +257,10 @@ createPublicFormContext(nodeDataActinType)
254 257
255 258 <style lang="less" scoped>
256 259 .form-container {
257   -@apply text-sm;
  260 + @apply text-sm;
258 261
259 262 :deep(.ant-divider) {
260   - @apply text-sm;
  263 + @apply text-sm;
261 264 }
262 265 }
263 266
... ...
... ... @@ -68,6 +68,7 @@ export function useNodeData({ cell, immediate = true }: UseNodeDataParamsType) {
68 68 return {
69 69 [CellAttributeKeyEnum.CATEGORY]: cell.getAttribute(CellAttributeKeyEnum.CATEGORY),
70 70 [CellAttributeKeyEnum.COMPONENT_KEY]: cell.getAttribute(CellAttributeKeyEnum.COMPONENT_KEY),
  71 + id: cell.getId(),
71 72 }
72 73 })
73 74
... ...
1 1 <script setup lang="ts">
2 2 import { ref } from 'vue'
3   -import type { RenderComponentExposeType } from '@/core/Library/types'
  3 +import type { RenderComponentExposeType, RenderComponentProps } from '@/core/Library/types'
4 4 import type { CommandSource } from '@/core/websocket/processor'
5 5 import { NodeUtils } from '@/hooks/business/useNodeUtils'
6 6 import { getMeetTheConditionsRange } from '@/core/Library/utils'
... ... @@ -9,8 +9,29 @@ import type { VariableImageActDataType } from '@/api/node/model'
9 9 import { useLatestMessageValue } from '@/core/Library/hook/useLatestMessageValue'
10 10 import { useOnMessage } from '@/core/Library/hook/useOnMessage'
11 11 import type { SubscriptionUpdateMsg } from '@/core/websocket/type/message'
  12 +import { CellAttributeKeyEnum } from '@/enums/cellAttributeEnum'
  13 +import { useJsonParse } from '@/hooks/business/useJSONParse'
  14 +import type { ImageSelectorDataType } from '@/core/Library/components/ImageSelector'
12 15
13   -const imgSrc = ref('data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="48" height="48" viewBox="0 0 48 48"%3E%3Cpath fill="%238CBCD6" d="M31 41H8c-2.2 0-4-1.8-4-4V11c0-2.2 1.8-4 4-4h32c2.2 0 4 1.8 4 4v17c0 7.2-5.8 13-13 13z"%2F%3E%3Ccircle cx="35" cy="16" r="3" fill="%23B3DDF5"%2F%3E%3Cpath fill="%239AC9E3" d="M20 16L9 32h22z"%2F%3E%3Cpath fill="%23B3DDF5" d="m31 22l-8 10h16z"%2F%3E%3Cpath fill="%23E57373" d="m47.7 29.1l-2.8-2.8c-.4-.4-1.1-.4-1.6 0L42 27.6l4.4 4.4l1.3-1.3c.4-.4.4-1.1 0-1.6z"%2F%3E%3Cpath fill="%23FF9800" d="M27.467 42.167L39.77 29.865l4.384 4.384L31.85 46.55z"%2F%3E%3Cpath fill="%23B0BEC5" d="m46.4 32.038l-2.192 2.192l-4.383-4.384l2.192-2.191z"%2F%3E%3Cpath fill="%23FFC107" d="M27.5 42.2L26 48l5.8-1.5z"%2F%3E%3Cpath fill="%2337474F" d="m26.7 45l-.7 3l3-.7z"%2F%3E%3C%2Fsvg%3E')
  16 +const props = defineProps<RenderComponentProps>()
  17 +const nodeUtils = new NodeUtils()
  18 +
  19 +const imgSrc = ref(getDefaultImage() || 'data:image/svg+xml,%3Csvg xmlns="http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg" width="48" height="48" viewBox="0 0 48 48"%3E%3Cpath fill="%238CBCD6" d="M31 41H8c-2.2 0-4-1.8-4-4V11c0-2.2 1.8-4 4-4h32c2.2 0 4 1.8 4 4v17c0 7.2-5.8 13-13 13z"%2F%3E%3Ccircle cx="35" cy="16" r="3" fill="%23B3DDF5"%2F%3E%3Cpath fill="%239AC9E3" d="M20 16L9 32h22z"%2F%3E%3Cpath fill="%23B3DDF5" d="m31 22l-8 10h16z"%2F%3E%3Cpath fill="%23E57373" d="m47.7 29.1l-2.8-2.8c-.4-.4-1.1-.4-1.6 0L42 27.6l4.4 4.4l1.3-1.3c.4-.4.4-1.1 0-1.6z"%2F%3E%3Cpath fill="%23FF9800" d="M27.467 42.167L39.77 29.865l4.384 4.384L31.85 46.55z"%2F%3E%3Cpath fill="%23B0BEC5" d="m46.4 32.038l-2.192 2.192l-4.383-4.384l2.192-2.191z"%2F%3E%3Cpath fill="%23FFC107" d="M27.5 42.2L26 48l5.8-1.5z"%2F%3E%3Cpath fill="%2337474F" d="m26.7 45l-.7 3l3-.7z"%2F%3E%3C%2Fsvg%3E')
  20 +
  21 +function getDefaultImage() {
  22 + const cell = nodeUtils.getCellById(props.config.cellInfo!.id)
  23 +
  24 + if (!cell) return
  25 +
  26 + const defaultImage = cell.getAttribute(CellAttributeKeyEnum.DEFAULT_IMAGE)
  27 +
  28 + if (!defaultImage)
  29 + return
  30 +
  31 + const { imageSource, libPath, path } = useJsonParse(defaultImage).value as ImageSelectorDataType
  32 +
  33 + return imageSource === VariableImageSourceEnum.GALLERY ? libPath : path
  34 +}
14 35
15 36 const onReceiveActMessage = (commandSource: CommandSource, message: SubscriptionUpdateMsg) => {
16 37 const { node, data, type } = commandSource
... ... @@ -50,6 +71,6 @@ defineExpose<RenderComponentExposeType>({
50 71
51 72 <template>
52 73 <div class="w-full h-full flex justify-center items-center">
53   - <img class="w-full" :src="imgSrc">
  74 + <img class="w-full h-full object-contain" :src="imgSrc">
54 75 </div>
55 76 </template>
... ...
1 1 export enum BasicComponentEnum {
2 2 TITLE = 'Title',
3 3 VARIABLE = 'Variable',
  4 + VARIABLE_IMAGE = 'VariableImage',
4 5 }
5 6
6 7 export enum BasicComponentNameEnum {
7 8 TITLE = '标题',
8 9 VARIABLE = '变量',
  10 + VARIABLE_IMAGE = '变量图片',
  11 +
9 12 }
... ...
... ... @@ -3,4 +3,5 @@ export enum CellAttributeKeyEnum {
3 3 CATEGORY = 'category',
4 4 SHAPE_KEY = 'shapeKey',
5 5 COPY_SOURCE = 'copySource',
  6 + DEFAULT_IMAGE = 'defaultImage',
6 7 }
... ...
... ... @@ -54,6 +54,10 @@ export class NodeUtils {
54 54 model.setVisible(cell, value)
55 55 }
56 56
  57 + refreshCell(cell: MxCell) {
  58 + this.graph.refresh(cell)
  59 + }
  60 +
57 61 getNodeComponentKey(node: string | MxCell): Nullable<ComponentKey> {
58 62 const cell = isString(node) ? this.getCellById(node) : node
59 63 const cellValue = cell.getValue() as Element
... ...