Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 预览模式下脚本不可用的异常 #75 #77

Merged
merged 2 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/pages/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dataState.loadPlugins([QuickDataPlugin, RestDataPlugin])

onMounted(async () => {
const snapshot = await snapShotState.latestRecord()
console.log(snapshot)
if (snapshot) {
viewer.value!.setLayoutData({
canvasData: snapshot.canvasData as ComponentDataType[],
Expand Down
3 changes: 2 additions & 1 deletion src/designer/Pane/RightSideBar/DataModule/DataAttr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ export default defineComponent({
}
}
return () =>
props.curComponent.dataMode === DataMode.UNIVERSAL ? (
props.curComponent.dataMode ||
props.curComponent.dataIntegrationMode === DataMode.UNIVERSAL ? (
renderContainer()
) : (
<NDescriptions>
Expand Down
5 changes: 4 additions & 1 deletion src/designer/state/scripts.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import type { BaseScript } from 'open-data-v/scripts'
import CustomScriptPlugin from 'open-data-v/scripts/custom'
import SystemScriptPlugin from 'open-data-v/scripts/system'
import { reactive } from 'vue'

type ScriptHandler = { new (key: string, ...args: any): BaseScript }

interface ScriptPlugin {
type: string
name: string
component: any
handler: any
handler: ScriptHandler
}

class ScriptState {
Expand Down
6 changes: 3 additions & 3 deletions src/designer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const buildAfterCallback = (componentObj: CustomComponent, script?: ScriptOption
if (!plugin) {
return
}
const scriptHandler = plugin.handler

const scriptHandlerClasss = plugin.handler
const scriptHandler = new scriptHandlerClasss(script.key)
componentObj.afterCallbackChange(scriptHandler)
}
export function createComponent(component: ComponentDataType): any {
Expand All @@ -59,7 +59,7 @@ export function createComponent(component: ComponentDataType): any {
obj.setStyleValue({ style: component.style })
obj.dataMode = component.dataMode || DataMode.SELF
const data = component.data
if (obj.dataMode === DataMode.UNIVERSAL) {
if (obj.dataMode || obj.dataIntegrationMode === DataMode.UNIVERSAL) {
buildDataHandler(obj, data)
}
buildAfterCallback(obj, component.script)
Expand Down
15 changes: 11 additions & 4 deletions src/models/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export class CustomComponent {
show = true
active = false
dataMode: DataMode = DataMode.SELF
/**
* @deprecated dataIntegrationMode 即将弃用,建议使用 dataMode
*/
dataIntegrationMode: DataMode = DataMode.SELF
callbackProp?: (propKeys: Array<string>, value: any) => void
callbackStyle?: (propKeys: Array<string>, value: any) => void
callbackData?: (result: any, type?: string) => void
Expand Down Expand Up @@ -76,7 +80,7 @@ export class CustomComponent {
}
this.positionStyle.width = detail.width || 100
this.positionStyle.height = detail.height || 100
this.dataMode = detail.dataMode || DataMode.SELF
this.dataMode = detail.dataMode || detail.dataIntegrationMode || DataMode.SELF
}

get propFromValue(): MetaContainerItem[] {
Expand Down Expand Up @@ -237,7 +241,7 @@ export class CustomComponent {
propValue: this.propValue,
style: this.style,
subComponents: subComponents.length > 0 ? subComponents : undefined,
dataMode: this.dataMode,
dataMode: this.dataMode || this.dataIntegrationMode,
script: this.scriptConfig?.toJSON()
}
if (this.dataConfig) {
Expand Down Expand Up @@ -382,10 +386,13 @@ export class CustomComponent {
this.componentDataCallback = callback
this.callbackData = this.buildDataCallback()
const { dataInstance } = this.dataConfig || {}
if (dataInstance && dataInstance.close) {
if (!dataInstance) {
return
}
if (dataInstance.close) {
dataInstance.close()
dataInstance.connect!(this.callbackData)
}
dataInstance.connect!(this.callbackData)
}

buildDataCallback() {
Expand Down
4 changes: 4 additions & 0 deletions src/models/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export interface ComponentType extends Pick<ComponentDataType, 'component' | 'na
width?: number
height?: number
dataMode?: DataMode
/**
* deprecated: 即将废弃,请使用 dataMode 属性
*/
dataIntegrationMode?: DataMode
}
interface CustomContainerProps {
componentType: string | ConcreteComponent
Expand Down