Skip to content
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
2 changes: 1 addition & 1 deletion packages/design-core/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { useBroadcastChannel } from '@vueuse/core'
import { constants } from '@opentiny/tiny-engine-utils'

const { BROADCAST_CHANNEL } = constants
const { message } = useModal()

export default {
setup() {
const { message } = useModal()
const registry = getMergeRegistry()
const materialsApi = getMetaApi('engine.plugins.materials')
const blockApi = getMetaApi('engine.plugins.blockmanage')
Expand Down
43 changes: 20 additions & 23 deletions packages/plugins/block/src/js/blockSetting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ import { constants, utils } from '@opentiny/tiny-engine-utils'
import { generateBlock } from '@opentiny/tiny-engine-common/js/vscodeGenerateFile'

const { HOST_TYPE } = constants
const { getBlockList, setBlockList, setCategoryList, getCurrentBlock, addBlockEvent, addBlockProperty } = useBlock()
const { batchCreateI18n } = useTranslate()
const { message, confirm } = useModal()
const { setSaved } = useCanvas()
const { getMaterial } = useMaterial()

const STRING_SLOT = ['Slot', 'slot']

Expand Down Expand Up @@ -346,7 +341,7 @@ export const getEditBlockEvents = () => state.block?.content?.schema?.events
export const addBlockCustomProperty = () => {
const defaultProperty = extend(true, {}, DEFAULT_PROPERTY)

addBlockProperty(defaultProperty, getEditBlock())
useBlock().addBlockProperty(defaultProperty, getEditBlock())

return defaultProperty
}
Expand All @@ -360,7 +355,7 @@ export const addBlockCustomEvent = () => {
event: defaultEvent
}

addBlockEvent(event, getEditBlock())
useBlock().addBlockEvent(event, getEditBlock())

return event
}
Expand All @@ -383,16 +378,15 @@ export const renameBlockEventName = (name, oldName) => {
delete events[oldName]
}

export const initEditBlock = (block = getCurrentBlock()) => {
export const initEditBlock = (block) => {
const currentBlock = useBlock().getCurrentBlock()
// 如果当前点击的区块和画布中的区块是同一区块,则直接获取最新的区块数据
if (block?.id && block?.id === getCurrentBlock()?.id) {
const currentBlock = getCurrentBlock()

if (block?.id && block.id === currentBlock?.id) {
// 这里需要做一次合并,保证区块列表中的数据引用地址和getEditBlock获取的是一样的
Object.assign(block, currentBlock)
}

setEditBlock(block)
setEditBlock(block || currentBlock)
setEditProperty(null)
setEditEvent(null)
}
Expand All @@ -416,6 +410,8 @@ export const getBlockBase64 = () => {
}

export const delBlock = (closePanel) => () => {
const { getBlockList } = useBlock()
const { message } = useModal()
const block = getEditBlock()
const blockId = block?.id

Expand Down Expand Up @@ -540,7 +536,7 @@ export const getDeployProgress = (taskId, block) => {
getDeployProgress(taskId, block)
}, INTERVAL_PROGRESS)
} else if (block.deployStatus === DEPLOY_STATUS.Stopped) {
message({
useModal().message({
title: '异常提示',
status: 'error',
message: {
Expand All @@ -559,7 +555,7 @@ export const getDeployProgress = (taskId, block) => {
const validBlockSlotsName = (block) => {
const slotsTips = configureSlots(block.content)
if (slotsTips) {
confirm({
useModal().confirm({
title: '插槽名称不能重复!!!',
message: `${slotsTips.slice(0, -1)}。`
})
Expand All @@ -581,7 +577,7 @@ export const publishBlock = (params) => {
getDeployProgress(data.id, block)
})
.catch((error) => {
message({ message: error.message, status: 'error' })
useModal().message({ message: error.message, status: 'error' })
setDeployFailed(block)
})
}
Expand All @@ -590,13 +586,14 @@ export const publishBlock = (params) => {
const getCategories = () => {
const appId = useApp().appInfoState.selectedId
fetchCategories({ appId }).then((res) => {
setCategoryList(res)
useBlock().setCategoryList(res)
})
}

// 新建区块
const createBlock = (block = {}) => {
const { appInfoState } = useApp()
const { message } = useModal()
const { selectedId: created_app } = appInfoState
const params = { ...block, created_app }

Expand All @@ -613,8 +610,8 @@ const createBlock = (block = {}) => {
.then((data) => {
// 后台获取区块id后保存id信息
block.id = data.id
batchCreateI18n({ host: block.id, hostType: HOST_TYPE.Block })
setSaved(true)
useTranslate().batchCreateI18n({ host: block.id, hostType: HOST_TYPE.Block })
useCanvas().setSaved(true)
// 新建区块成功后需要同步更新画布上的区块数据ctx上下文环境
useBlock().initBlock(data, {}, true)
message({ message: '新建区块成功!', status: 'success' })
Expand Down Expand Up @@ -664,10 +661,10 @@ const updateBlock = (block = {}) => {
}
)
.then((data) => {
setSaved(true)
useCanvas().setSaved(true)
useBlock().initBlock(data, {}, true)
// 弹出保存区块成功
message({ message: '保存区块成功!', status: 'success' })
useModal().message({ message: '保存区块成功!', status: 'success' })
// 本地生成区块服务
if (isVsCodeEnv) {
generateBlock({ schema: data.content, blockPath: data.path })
Expand All @@ -676,7 +673,7 @@ const updateBlock = (block = {}) => {
getCategories()
})
.catch((error) => {
message({ message: error.message, status: 'error' })
useModal().message({ message: error.message, status: 'error' })
})
}

Expand All @@ -688,7 +685,7 @@ const updateBlock = (block = {}) => {
*/
const generateBlockDeps = (children, deps = { scripts: [], styles: new Set() }) => {
children.forEach((child) => {
const component = getMaterial(child.componentName)
const component = useMaterial().getMaterial(child.componentName)

if (!component) return

Expand Down Expand Up @@ -741,7 +738,7 @@ export const updateBlockList = (params) => {
const appId = useApp().appInfoState.selectedId
fetchBlockList({ appId, ...params }).then((data) => {
const blockListDescByUpdateAt = data.sort((a, b) => new Date(b.updated_at) - new Date(a.updated_at))
setBlockList(blockListDescByUpdateAt)
useBlock().setBlockList(blockListDescByUpdateAt)
})
}

Expand Down
35 changes: 18 additions & 17 deletions packages/plugins/datasource/src/DataSourceRecordForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ import { isEmptyObject } from '@opentiny/vue-renderless/common/type'
import { useDataSource } from '@opentiny/tiny-engine-meta-register'
import { extend } from '@opentiny/vue-renderless/common/object'

const CONSTANCTS = {
const CONSTANTS = {
REQUIRED: 'required',
EVENT_NAME: 'change',
REQUIRED_TIP: '必填',
MIN_VALUE_TIP: '不能小于最小值',
MAX_VALUE_TIP: '不能大于最大值',
MIN: 'min',
MAX: 'max',
FIELD_TPEY_DATE: 'date',
FIELD_TPEY_DATETIME: 'datetime',
FIELD_TPEY_NUMBER: 'number',
FIELD_TYPE_DATE: 'date',
FIELD_TYPE_DATETIME: 'datetime',
FIELD_TYPE_NUMBER: 'number',
MIN_LENGTH_TIP: '长度不小于',
MAX_LENGTH_TIP: '长度不大于'
}
Expand All @@ -88,10 +88,11 @@ export const update = (initialData, formData) => {
dataSourceState.recordCopies = extend(true, {}, recordFormData)
}

export const initi = (data) => {
// TODO: not used, should delete?
export const init = (data) => {
const { dataSourceState } = useDataSource()
data?.forEach((item) => {
recordFormData[item.name] = item.type === CONSTANCTS.FIELD_TPEY_NUMBER ? 0 : ''
recordFormData[item.name] = item.type === CONSTANTS.FIELD_TYPE_NUMBER ? 0 : ''
})

dataSourceState.recordCopies = extend(true, {}, recordFormData)
Expand Down Expand Up @@ -142,9 +143,9 @@ export default {

const validateNumber = (rule, value, callback) => {
if (rule.min > value) {
callback(new Error(`${CONSTANCTS.MIN_VALUE_TIP}${rule.min}`))
callback(new Error(`${CONSTANTS.MIN_VALUE_TIP}${rule.min}`))
} else if (rule.max < value) {
callback(new Error(`${CONSTANCTS.MAX_VALUE_TIP}${rule.max}`))
callback(new Error(`${CONSTANTS.MAX_VALUE_TIP}${rule.max}`))
} else {
callback()
}
Expand All @@ -159,29 +160,29 @@ export default {

!isEmptyObject(format) &&
Object.keys(format).forEach((key) => {
if (key === CONSTANCTS.REQUIRED) {
if (key === CONSTANTS.REQUIRED) {
format[key] && (state.recordMapping[item.name] = format[key])

fieldRules.push({
[key]: format[key],
message: CONSTANCTS.REQUIRED_TIP,
trigger: CONSTANCTS.EVENT_NAME
message: CONSTANTS.REQUIRED_TIP,
trigger: CONSTANTS.EVENT_NAME
})
}

if ((key === CONSTANCTS.MIN && format[key] !== 0) || (key === CONSTANCTS.MAX && format[key] !== 0)) {
if (item.type === CONSTANCTS.FIELD_TPEY_NUMBER) {
if ((key === CONSTANTS.MIN && format[key] !== 0) || (key === CONSTANTS.MAX && format[key] !== 0)) {
if (item.type === CONSTANTS.FIELD_TYPE_NUMBER) {
fieldRules.push({
[key]: format[key],
trigger: CONSTANCTS.EVENT_NAME,
trigger: CONSTANTS.EVENT_NAME,
validator: validateNumber
})
} else {
const str = key === CONSTANCTS.MIN ? CONSTANCTS.MIN_LENGTH_TIP : CONSTANCTS.MAX_LENGTH_TIP
const str = key === CONSTANTS.MIN ? CONSTANTS.MIN_LENGTH_TIP : CONSTANTS.MAX_LENGTH_TIP
fieldRules.push({
[key]: format[key],
message: str + format[key],
trigger: CONSTANCTS.EVENT_NAME
trigger: CONSTANTS.EVENT_NAME
})
}
}
Expand Down Expand Up @@ -224,7 +225,7 @@ export default {
if (text) {
return text
} else if (dateTime) {
return dateTime ? CONSTANCTS.FIELD_TPEY_DATETIME : CONSTANCTS.FIELD_TPEY_DATE
return dateTime ? CONSTANTS.FIELD_TYPE_DATETIME : CONSTANTS.FIELD_TYPE_DATE
}

return undefined
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/script/src/js/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { lint } from '@opentiny/tiny-engine-common/js/linter'
import { isFunction } from '@opentiny/vue-renderless/grid/static'

const { SCHEMA_DATA_TYPE } = constants
const { message, confirm } = useModal()

const state = reactive({
linterWorker: null,
Expand Down Expand Up @@ -81,6 +80,7 @@ export const saveMethod = ({ name, content }) => {
}

const saveMethods = () => {
const { message } = useModal()
if (!state.isChanged) {
return false
}
Expand Down Expand Up @@ -124,6 +124,7 @@ const saveMethods = () => {
}

const close = (emit) => (callback) => {
const { confirm } = useModal()
const callbackFn = isFunction(callback) ? callback : () => emit('close')
if (!state.isChanged) {
callbackFn(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default {
}
},

setup(props, { emit }) {
setup(props) {
const state = reactive({
values: props.modelValue
})
Expand Down
13 changes: 7 additions & 6 deletions packages/toolbars/save/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import { useBlock, useCanvas, useLayout, useNotify, usePage } from '@opentiny/ti
import { constants } from '@opentiny/tiny-engine-utils'
import { handlePageUpdate } from '@opentiny/tiny-engine-common/js/http'

const { pageState, isSaved, isBlock, canvasApi } = useCanvas()
const { PLUGIN_NAME, getPluginApi } = useLayout()
const { getCurrentBlock } = useBlock()
const { PAGE_STATUS } = constants
const { pageSettingState, isTemporaryPage } = usePage()
const state = reactive({
visible: false,
code: '',
Expand All @@ -31,6 +27,8 @@ export const isLoading = ref(false)

// 保存或新建区块
const saveBlock = async (pageSchema) => {
const { PLUGIN_NAME, getPluginApi } = useLayout()
const { getCurrentBlock } = useBlock()
const api = getPluginApi(PLUGIN_NAME.BlockManage)
const block = getCurrentBlock()

Expand All @@ -45,7 +43,7 @@ const saveBlock = async (pageSchema) => {
}

const savePage = async (pageSchema) => {
const { currentPage } = pageState
const { currentPage } = useCanvas().pageState
const params = {
page_content: pageSchema
}
Expand All @@ -56,6 +54,8 @@ const savePage = async (pageSchema) => {
}

export const saveCommon = (value) => {
const { pageSettingState, isTemporaryPage } = usePage()
const { isBlock, canvasApi, pageState } = useCanvas()
const pageSchema = JSON.parse(value)
const { setSchema, selectNode } = canvasApi.value

Expand Down Expand Up @@ -83,6 +83,7 @@ export const saveCommon = (value) => {
return isBlock() ? saveBlock(pageSchema) : savePage(pageSchema)
}
export const openCommon = async () => {
const { isSaved, canvasApi } = useCanvas()
if (isSaved() || state.disabled) {
return
}
Expand Down Expand Up @@ -116,7 +117,7 @@ export const openCommon = async () => {

// 获取请求前schema代码,暂时先屏蔽
/**
if (isBlock()) {
if (useCanvas().isBlock()) {
const api = getPluginApi(PLUGIN_NAME.BlockManage)
const block = getCurrentBlock()
const remote = await api.getBlockById(block?.id)
Expand Down