Commit 3ec5a6daeb3e43a3950a7ba16109cf68e3205e9c

Authored by xp.Huang
2 parents c930584c 5ff9b87d

Merge branch 'perf/configuration-id' into 'main_dev'

perf:优化组态节点保存

See merge request yunteng/thingskit-scada!257
@@ -5672,16 +5672,36 @@ App.prototype.save = function (name, done) { @@ -5672,16 +5672,36 @@ App.prototype.save = function (name, done) {
5672 // const data = `${Graph.xmlDeclaration}\n${this.getFileData(true, null, null, null, true, true, null, null, null, false)}`; 5672 // const data = `${Graph.xmlDeclaration}\n${this.getFileData(true, null, null, null, true, true, null, null, null, false)}`;
5673 // this.currentFile.setData(data) 5673 // this.currentFile.setData(data)
5674 5674
5675 - const allCells = this.editor.graph.getModel().cells || {} 5675 + const graph = this.editor.graph
  5676 + const model = graph.model
  5677 + const pages = this.pages
  5678 +
  5679 + const currentPageContentId = this.ui.currentPage.getId()
  5680 + let originalPage
  5681 + const contentPageInfos = pages.map(page => {
  5682 + this.ui.selectPage(page)
  5683 + const cells = model.getChildCells(graph.getDefaultParent())
  5684 + const nodeIds = cells.map(cell => cell.getId())
  5685 + const contentId = this.ui.currentPage.getId()
  5686 +
  5687 + if (contentId === currentPageContentId)
  5688 + originalPage = page
  5689 +
  5690 + return {
  5691 + nodeIds,
  5692 + contentId
  5693 + }
  5694 + })
  5695 + originalPage && this.ui.selectPage(originalPage)
  5696 +
5676 await doSaveConfigurationContent({ 5697 await doSaveConfigurationContent({
5677 configurationContentList: [ 5698 configurationContentList: [
5678 { 5699 {
5679 id: currentFile.getHash(), 5700 id: currentFile.getHash(),
5680 content: this.currentFile.getData(), 5701 content: this.currentFile.getData(),
5681 - contentId: this.currentPage.getId(),  
5682 type: 1, 5702 type: 1,
5683 - nodeIds: Object.keys(allCells),  
5684 - name: this.currentPage.getName() 5703 + name: this.currentPage.getName(),
  5704 + contentPageInfos
5685 } 5705 }
5686 ], 5706 ],
5687 configurationName: currentFile.title, 5707 configurationName: currentFile.title,
@@ -167,26 +167,36 @@ LocalFile.prototype.saveFile = function (title, revision, success, error, useCur @@ -167,26 +167,36 @@ LocalFile.prototype.saveFile = function (title, revision, success, error, useCur
167 const handleSaveContent = async () => { 167 const handleSaveContent = async () => {
168 const { doSaveConfigurationContent, configurationId } = useContentData() 168 const { doSaveConfigurationContent, configurationId } = useContentData()
169 try { 169 try {
170 - const allCells = this.ui.editor.graph.getModel().cells || {}  
171 - // const allCells = this.shadowPages  
172 - // .map(item => {  
173 - // console.log(item)  
174 - // return this.ui.editor.graph.createCellLookup([item.root])  
175 - // })  
176 - // .map(obj => Object.values(obj))  
177 - // .reduce((prev, next) => [...prev, ...next], [])  
178 - 170 + const graph = this.ui.editor.graph
  171 + const model = graph.model
  172 + const pages = this.ui.pages
  173 +
  174 + const currentPageContentId = this.ui.currentPage.getId()
  175 + let originalPage
  176 + const contentPageInfos = pages.map(page => {
  177 + this.ui.selectPage(page)
  178 + const cells = model.getChildCells(graph.getDefaultParent())
  179 + const nodeIds = cells.map(cell => cell.getId())
  180 + const contentId = this.ui.currentPage.getId()
  181 +
  182 + if (contentId === currentPageContentId)
  183 + originalPage = page
  184 +
  185 + return {
  186 + nodeIds,
  187 + contentId
  188 + }
  189 + })
  190 + originalPage && this.ui.selectPage(originalPage)
  191 +
179 await doSaveConfigurationContent({ 192 await doSaveConfigurationContent({
180 configurationContentList: [ 193 configurationContentList: [
181 { 194 {
182 id: this.ui.configurationContentId, 195 id: this.ui.configurationContentId,
183 content: savedData, 196 content: savedData,
184 - // contentId: this.ui.configurationContentId,  
185 - contentId: this.ui.currentPage.getId(),  
186 type: 1, 197 type: 1,
187 - // nodeIds: Array.from(new Set(allCells)),  
188 - nodeIds: Object.keys(allCells),  
189 - name: this.ui.currentPage.getName() 198 + name: this.ui.currentPage.getName(),
  199 + contentPageInfos
190 } 200 }
191 ], 201 ],
192 configurationName: this.ui.currentFile.title, 202 configurationName: this.ui.currentFile.title,
@@ -25,28 +25,28 @@ export const doSaveNodeAllData = (data: SaveNodeDataParamsType) => { @@ -25,28 +25,28 @@ export const doSaveNodeAllData = (data: SaveNodeDataParamsType) => {
25 } 25 }
26 26
27 export const doSaveNodeAct = (params: SaveNodeActParamsType) => { 27 export const doSaveNodeAct = (params: SaveNodeActParamsType) => {
28 - const { configurationId, contentId, id, data } = params 28 + const { configurationId, contentId, configurationNodeId, data } = params
29 return defHttp.post({ 29 return defHttp.post({
30 url: Api.SAVE_NODE_ACT, 30 url: Api.SAVE_NODE_ACT,
31 - params: { configurationId, contentId, id }, 31 + params: { configurationId, contentId, configurationNodeId },
32 data, 32 data,
33 }) 33 })
34 } 34 }
35 35
36 export const doSaveNodeDataSource = (params: SaveNodeDataSourceParamsType) => { 36 export const doSaveNodeDataSource = (params: SaveNodeDataSourceParamsType) => {
37 - const { configurationId, contentId, id, data } = params 37 + const { configurationId, contentId, configurationNodeId, data } = params
38 return defHttp.post({ 38 return defHttp.post({
39 url: Api.SAVE_NODE_DATASOURCE, 39 url: Api.SAVE_NODE_DATASOURCE,
40 - params: { configurationId, contentId, id }, 40 + params: { configurationId, contentId, configurationNodeId },
41 data, 41 data,
42 }) 42 })
43 } 43 }
44 44
45 export const doSaveNodeEvent = (params: SaveNodeEventParamsType) => { 45 export const doSaveNodeEvent = (params: SaveNodeEventParamsType) => {
46 - const { configurationId, contentId, id, data } = params 46 + const { configurationId, contentId, configurationNodeId, data } = params
47 return defHttp.post({ 47 return defHttp.post({
48 url: Api.SAVE_NODE_EVENT, 48 url: Api.SAVE_NODE_EVENT,
49 - params: { configurationId, contentId, id }, 49 + params: { configurationId, contentId, configurationNodeId },
50 data, 50 data,
51 }) 51 })
52 } 52 }
@@ -11,9 +11,10 @@ export enum DeleteNodeDataTypeEnum { @@ -11,9 +11,10 @@ export enum DeleteNodeDataTypeEnum {
11 } 11 }
12 12
13 export interface BasicNodeBindType { 13 export interface BasicNodeBindType {
14 - id: string  
15 contentId: string 14 contentId: string
  15 + configurationNodeId: string
16 configurationId: string 16 configurationId: string
  17 + id?: string
17 } 18 }
18 19
19 export interface SaveNodeDataParamsType extends BasicNodeBindType { 20 export interface SaveNodeDataParamsType extends BasicNodeBindType {
@@ -45,6 +46,7 @@ export interface NodeDataBasicType { @@ -45,6 +46,7 @@ export interface NodeDataBasicType {
45 enabled: boolean 46 enabled: boolean
46 tenantId: string 47 tenantId: string
47 configurationId: string 48 configurationId: string
  49 + configurationNodeId: string
48 contentId: string 50 contentId: string
49 } 51 }
50 52
1 <script lang="ts" setup> 1 <script lang="ts" setup>
2 import { Button } from 'ant-design-vue' 2 import { Button } from 'ant-design-vue'
3 import { basicProps } from '../props' 3 import { basicProps } from '../props'
  4 +import { useTranslation } from '@/hooks/useTranslation'
4 defineProps(basicProps) 5 defineProps(basicProps)
5 const emit = defineEmits(['ok', 'cancel']) 6 const emit = defineEmits(['ok', 'cancel'])
  7 +
  8 +const { t } = useTranslation()
6 function handleOk(e: Event) { 9 function handleOk(e: Event) {
7 emit('ok', e) 10 emit('ok', e)
8 } 11 }
@@ -16,17 +19,11 @@ function handleCancel(e: Event) { @@ -16,17 +19,11 @@ function handleCancel(e: Event) {
16 <div> 19 <div>
17 <slot name="insertFooter" /> 20 <slot name="insertFooter" />
18 <Button v-if="showCancelBtn" v-bind="cancelButtonProps" @click="handleCancel"> 21 <Button v-if="showCancelBtn" v-bind="cancelButtonProps" @click="handleCancel">
19 - {{ cancelText }} 22 + {{ cancelText || t('cancel') }}
20 </Button> 23 </Button>
21 <slot name="centerFooter" /> 24 <slot name="centerFooter" />
22 - <Button  
23 - v-if="showOkBtn"  
24 - :type="okType"  
25 - :loading="confirmLoading"  
26 - v-bind="okButtonProps"  
27 - @click="handleOk"  
28 - >  
29 - {{ okText }} 25 + <Button v-if="showOkBtn" :type="okType" :loading="confirmLoading" v-bind="okButtonProps" @click="handleOk">
  26 + {{ okText || t('ok') }}
30 </Button> 27 </Button>
31 <slot name="appendFooter" /> 28 <slot name="appendFooter" />
32 </div> 29 </div>
@@ -3,9 +3,7 @@ import type { ButtonProps } from 'ant-design-vue/es/button/buttonTypes' @@ -3,9 +3,7 @@ import type { ButtonProps } from 'ant-design-vue/es/button/buttonTypes'
3 import type { ButtonType } from 'ant-design-vue/lib/button' 3 import type { ButtonType } from 'ant-design-vue/lib/button'
4 import type { VueNode } from 'ant-design-vue/es/_util/type' 4 import type { VueNode } from 'ant-design-vue/es/_util/type'
5 import type { ModalWrapperProps } from './typing' 5 import type { ModalWrapperProps } from './typing'
6 -import { useTranslation } from '@/hooks/useTranslation'  
7 6
8 -const { t } = useTranslation()  
9 export const modalProps = { 7 export const modalProps = {
10 open: { type: Boolean }, 8 open: { type: Boolean },
11 scrollTop: { type: Boolean, default: true }, 9 scrollTop: { type: Boolean, default: true },
@@ -14,8 +12,8 @@ export const modalProps = { @@ -14,8 +12,8 @@ export const modalProps = {
14 // open drag 12 // open drag
15 draggable: { type: Boolean, default: true }, 13 draggable: { type: Boolean, default: true },
16 centered: { type: Boolean }, 14 centered: { type: Boolean },
17 - cancelText: { type: String, default: t('cancel') },  
18 - okText: { type: String, default: t('ok') }, 15 + cancelText: { type: String },
  16 + okText: { type: String },
19 17
20 closeFunc: Function as PropType<() => Promise<boolean>>, 18 closeFunc: Function as PropType<() => Promise<boolean>>,
21 } 19 }
@@ -37,7 +37,7 @@ export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => { @@ -37,7 +37,7 @@ export const getFormSchemas = (event: EventTypeEnum): FormSchema[] => {
37 componentProps: { 37 componentProps: {
38 allowClear: false, 38 allowClear: false,
39 options: [ 39 options: [
40 - { label: EventTypeNameEnum[event], value: EventTypeEnum[event] }, 40 + { label: t(EventTypeNameEnum[event]), value: EventTypeEnum[event] },
41 ], 41 ],
42 }, 42 },
43 }, 43 },
@@ -177,8 +177,8 @@ defineExpose<ComponentExposeType>({ @@ -177,8 +177,8 @@ defineExpose<ComponentExposeType>({
177 :validate-status="getValidateStatus(record[TableColumnFieldEnum.DEVICE_PROFILE_ID])" 177 :validate-status="getValidateStatus(record[TableColumnFieldEnum.DEVICE_PROFILE_ID])"
178 > 178 >
179 <Select 179 <Select
180 - v-model:value="record[TableColumnFieldEnum.DEVICE_PROFILE_ID]" :options="productList" :field-names="{ label: 'name', value: 'profileId' }" placeholder="请选择产品"  
181 - class="w-full" 180 + v-model:value="record[TableColumnFieldEnum.DEVICE_PROFILE_ID]" :options="productList"
  181 + :field-names="{ label: 'name', value: 'profileId' }" placeholder="请选择产品" class="w-full"
182 @change="(value, option) => handleSelectProduct(value, option, record as TableRecordItemType)" 182 @change="(value, option) => handleSelectProduct(value, option, record as TableRecordItemType)"
183 /> 183 />
184 </FormItem> 184 </FormItem>
@@ -189,8 +189,8 @@ defineExpose<ComponentExposeType>({ @@ -189,8 +189,8 @@ defineExpose<ComponentExposeType>({
189 :validate-status="getValidateStatus(record[TableColumnFieldEnum.DEVICE_ID])" 189 :validate-status="getValidateStatus(record[TableColumnFieldEnum.DEVICE_ID])"
190 > 190 >
191 <Select 191 <Select
192 - v-model:value="record[TableColumnFieldEnum.DEVICE_ID]" :options="deviceList" :placeholder="t('chooseDevice')"  
193 - class="w-full" 192 + v-model:value="record[TableColumnFieldEnum.DEVICE_ID]" :options="deviceList"
  193 + :placeholder="t('chooseDevice')" class="w-full"
194 @change="(value, option) => handleSelectDevice(value, option, record as TableRecordItemType)" 194 @change="(value, option) => handleSelectDevice(value, option, record as TableRecordItemType)"
195 /> 195 />
196 </FormItem> 196 </FormItem>
@@ -198,8 +198,8 @@ defineExpose<ComponentExposeType>({ @@ -198,8 +198,8 @@ defineExpose<ComponentExposeType>({
198 <template v-if="column.key === TableColumnFieldEnum.WAY"> 198 <template v-if="column.key === TableColumnFieldEnum.WAY">
199 <RadioGroup 199 <RadioGroup
200 v-model:value="record[TableColumnFieldEnum.WAY]" :options="[ 200 v-model:value="record[TableColumnFieldEnum.WAY]" :options="[
201 - { label: CommandWayNameEnum.ONE_WAY, value: CommandWayEnum.ONE_WAY },  
202 - { label: CommandWayNameEnum.TWO_WAY, value: CommandWayEnum.TWO_WAY }, 201 + { label: t(CommandWayNameEnum.ONE_WAY), value: CommandWayEnum.ONE_WAY },
  202 + { label: t(CommandWayNameEnum.TWO_WAY), value: CommandWayEnum.TWO_WAY },
203 ]" 203 ]"
204 /> 204 />
205 </template> 205 </template>
@@ -2,6 +2,7 @@ import { isBoolean } from '@wry-smile/utils-is' @@ -2,6 +2,7 @@ import { isBoolean } from '@wry-smile/utils-is'
2 import type { BasicContentComponentProps } from '../..' 2 import type { BasicContentComponentProps } from '../..'
3 import type { PublicFormSettingType } from '../../..' 3 import type { PublicFormSettingType } from '../../..'
4 import { DataSourceTypeEnum, EventTypeEnum, EventTypeNameEnum } from '@/enums/datasource' 4 import { DataSourceTypeEnum, EventTypeEnum, EventTypeNameEnum } from '@/enums/datasource'
  5 +import { useTranslation } from '@/hooks/useTranslation'
5 6
6 export interface DynamicEffectItemType { 7 export interface DynamicEffectItemType {
7 label: string 8 label: string
@@ -10,29 +11,31 @@ export interface DynamicEffectItemType { @@ -10,29 +11,31 @@ export interface DynamicEffectItemType {
10 componentProps?: BasicContentComponentProps 11 componentProps?: BasicContentComponentProps
11 } 12 }
12 13
  14 +const { t } = useTranslation()
  15 +
13 export const getEventItem = (formSetting?: PublicFormSettingType): DynamicEffectItemType[] => { 16 export const getEventItem = (formSetting?: PublicFormSettingType): DynamicEffectItemType[] => {
14 const list = [ 17 const list = [
15 { 18 {
16 - label: EventTypeNameEnum.DOWN, 19 + label: t(EventTypeNameEnum.DOWN),
17 key: EventTypeEnum.DOWN, 20 key: EventTypeEnum.DOWN,
18 component: () => import('./MouseDownOrUpSetting/index.vue'), 21 component: () => import('./MouseDownOrUpSetting/index.vue'),
19 componentProps: { event: EventTypeEnum.DOWN, type: DataSourceTypeEnum.EVENT }, 22 componentProps: { event: EventTypeEnum.DOWN, type: DataSourceTypeEnum.EVENT },
20 }, 23 },
21 { 24 {
22 - label: EventTypeNameEnum.UP, 25 + label: t(EventTypeNameEnum.UP),
23 key: EventTypeEnum.UP, 26 key: EventTypeEnum.UP,
24 component: () => import('./MouseDownOrUpSetting/index.vue'), 27 component: () => import('./MouseDownOrUpSetting/index.vue'),
25 componentProps: { event: EventTypeEnum.UP, type: DataSourceTypeEnum.EVENT }, 28 componentProps: { event: EventTypeEnum.UP, type: DataSourceTypeEnum.EVENT },
26 29
27 }, 30 },
28 { 31 {
29 - label: EventTypeNameEnum.SINGLE, 32 + label: t(EventTypeNameEnum.SINGLE),
30 key: EventTypeEnum.SINGLE, 33 key: EventTypeEnum.SINGLE,
31 component: () => import('./SingleClickOrDoubleClickSetting/index.vue'), 34 component: () => import('./SingleClickOrDoubleClickSetting/index.vue'),
32 componentProps: { event: EventTypeEnum.SINGLE, type: DataSourceTypeEnum.EVENT }, 35 componentProps: { event: EventTypeEnum.SINGLE, type: DataSourceTypeEnum.EVENT },
33 }, 36 },
34 { 37 {
35 - label: EventTypeNameEnum.DOUBLE, 38 + label: t(EventTypeNameEnum.DOUBLE),
36 key: EventTypeEnum.DOUBLE, 39 key: EventTypeEnum.DOUBLE,
37 component: () => import('./SingleClickOrDoubleClickSetting/index.vue'), 40 component: () => import('./SingleClickOrDoubleClickSetting/index.vue'),
38 componentProps: { event: EventTypeEnum.DOUBLE, type: DataSourceTypeEnum.EVENT }, 41 componentProps: { event: EventTypeEnum.DOUBLE, type: DataSourceTypeEnum.EVENT },
@@ -52,11 +52,16 @@ export function useNodeData({ cell, immediate = true }: UseNodeDataParamsType) { @@ -52,11 +52,16 @@ export function useNodeData({ cell, immediate = true }: UseNodeDataParamsType) {
52 } 52 }
53 53
54 const basicNodeBindData = (type: ActionType): BasicNodeBindType => { 54 const basicNodeBindData = (type: ActionType): BasicNodeBindType => {
55 - return {  
56 - id: type === ActionType.GET ? getSourceCellID () || getCellID () : getCellID(), 55 + const res: BasicNodeBindType = {
  56 + configurationNodeId: type === ActionType.GET ? getSourceCellID() || getCellID() : getCellID(),
57 contentId: window.DrawApp.currentPage.getId(), 57 contentId: window.DrawApp.currentPage.getId(),
58 configurationId, 58 configurationId,
59 } 59 }
  60 +
  61 + if (unref(nodeData)?.id)
  62 + res.id = unref(nodeData)?.id
  63 +
  64 + return res
60 } 65 }
61 66
62 const getCellInfo = computed(() => { 67 const getCellInfo = computed(() => {
@@ -9,7 +9,7 @@ export function useAuth() { @@ -9,7 +9,7 @@ export function useAuth() {
9 const result = { permissions: [] as string[], hasPreview: true, hasDesign: true } 9 const result = { permissions: [] as string[], hasPreview: true, hasDesign: true }
10 10
11 if (isFromEdge()) 11 if (isFromEdge())
12 - return result 12 + return Object.assign(result, { hasDesignAuth: true, hasPreviewAuth: true })
13 13
14 if (isShareMode()) return result 14 if (isShareMode()) return result
15 15